fixed errors on windows because of not closed input stream #161

Merged
yannik.hampe merged 2 commits from windows-hotfix into master 2023-10-06 12:04:52 +02:00
9 changed files with 23 additions and 154 deletions

View File

@ -204,6 +204,7 @@
<dependency>
<groupId>com.iqser.red.commons</groupId>
<artifactId>storage-commons</artifactId>
<version>${storage.commons.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>

View File

@ -1,6 +1,5 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations.model.reducetext;
import com.dslplatform.json.JsonAttribute;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -31,24 +30,18 @@ public class RedTextPosition {
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private float YDirAdj;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@JsonAttribute
private float heightDir;
@JsonAttribute
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private float widthDirAdj;
// Moved To TextPositionSequence
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@JsonAttribute
private float pageHeight;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@JsonAttribute
private float pageWidth;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@JsonAttribute
private float dir;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@JsonAttribute
private int rotation;
// Removed values
@ -58,7 +51,6 @@ public class RedTextPosition {
private float width;
@JsonAttribute()
public float[] getPosition() {
var pos = new float[4];
@ -77,7 +69,6 @@ public class RedTextPosition {
@JsonAlias("xdirAdj")
@JsonAttribute(alternativeNames = {"xdirAdj"})
@JsonProperty
public void setXDirAdj(float XDirAdj) {
@ -90,7 +81,6 @@ public class RedTextPosition {
@JsonAlias("ydirAdj")
@JsonAttribute(alternativeNames = {"ydirAdj"})
@JsonProperty
public void setYDirAdj(float YDirAdj) {this.YDirAdj = YDirAdj;}

View File

@ -25,7 +25,6 @@ import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import com.amazonaws.util.StringUtils;
import com.iqser.red.service.dictionarymerge.commons.CommonsDictionaryModel;
import com.iqser.red.service.dictionarymerge.commons.DictionaryEntry;
import com.iqser.red.service.dictionarymerge.commons.DictionaryEntryModel;
@ -273,19 +272,19 @@ public class DictionaryService {
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted(Comparator.comparing(StringUtils::lowerCase))
.sorted(Comparator.comparing(String::toLowerCase))
.collect(Collectors.toList()))
.falsePositiveEntries(dictionaryForType.getFalsePositiveEntries()
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted(Comparator.comparing(StringUtils::lowerCase))
.sorted(Comparator.comparing(String::toLowerCase))
.collect(Collectors.toList()))
.falseRecommendationEntries(dictionaryForType.getFalseRecommendationEntries()
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted(Comparator.comparing(StringUtils::lowerCase))
.sorted(Comparator.comparing(String::toLowerCase))
.collect(Collectors.toList()))
.hexColor(dictionaryForType.getHexColor())
.recommendationHexColor(dictionaryForType.getRecommendationHexColor())
@ -338,19 +337,19 @@ public class DictionaryService {
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted(Comparator.comparing(StringUtils::lowerCase))
.sorted(Comparator.comparing(String::toLowerCase))
.collect(Collectors.toList()))
.falsePositiveEntries(cdm.getFalsePositives()
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted(Comparator.comparing(StringUtils::lowerCase))
.sorted(Comparator.comparing(String::toLowerCase))
.collect(Collectors.toList()))
.falseRecommendationEntries(cdm.getFalseRecommendations()
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntry::getValue)
.sorted(Comparator.comparing(StringUtils::lowerCase))
.sorted(Comparator.comparing(String::toLowerCase))
.collect(Collectors.toList()))
.hexColor(entity.getHexColor())
.recommendationHexColor(entity.getRecommendationHexColor())

View File

@ -380,10 +380,13 @@ public class DownloadPreparationService {
}
@SneakyThrows
private void storeZipFile(DownloadStatusEntity downloadStatus, FileSystemBackedArchiver fileSystemBackedArchiver) {
long start = System.currentTimeMillis();
fileManagementStorageService.storeObject(downloadStatus.getStorageId(), fileSystemBackedArchiver.toInputStream());
try(var in = fileSystemBackedArchiver.toInputStream()) {
fileManagementStorageService.storeObject(downloadStatus.getStorageId(), in);
}
log.info("Successfully stored zip for downloadId {}, took {}", downloadStatus.getStorageId(), System.currentTimeMillis() - start);
}

View File

@ -23,7 +23,11 @@
<artifactId>persistence-service-processor-v1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.iqser.red.commons</groupId>
<artifactId>storage-commons</artifactId>
<version>${storage.commons.version}</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.amqp</groupId>

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.peristence.v1.server.integration.utils;
import com.iqser.red.commons.jackson.ObjectMapperFactory;
import com.iqser.red.service.peristence.v1.server.Application;
import com.iqser.red.service.peristence.v1.server.integration.client.ApplicationConfigClient;
import com.iqser.red.service.peristence.v1.server.integration.client.FileClient;
@ -23,6 +24,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemp
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxValidation;
import com.iqser.red.storage.commons.service.StorageService;
import com.iqser.red.storage.commons.utils.FileSystemBackedStorageService;
import com.knecon.fforesight.databasetenantcommons.providers.TenantCreatedListener;
import com.knecon.fforesight.databasetenantcommons.providers.events.TenantCreatedEvent;
import com.knecon.fforesight.databasetenantcommons.providers.utils.MagicConverter;
@ -431,7 +433,7 @@ public abstract class AbstractPersistenceServerServiceTest {
@Primary
public StorageService inmemoryStorage() {
return new FileSystemBackedStorageService();
return new FileSystemBackedStorageService(ObjectMapperFactory.create());
}
}

View File

@ -1,132 +0,0 @@
package com.iqser.red.service.peristence.v1.server.integration.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.InputStreamResource;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.commons.jackson.ObjectMapperFactory;
import com.iqser.red.storage.commons.exception.StorageObjectDoesNotExist;
import com.iqser.red.storage.commons.service.StorageService;
import lombok.SneakyThrows;
public class FileSystemBackedStorageService implements StorageService {
private final Map<String, File> dataMap = new HashMap<>();
public FileSystemBackedStorageService() {
}
@Override
@SneakyThrows
public <T> void storeJSONObject(String tenantId, String objectId, T any) {
File tempFile = File.createTempFile("test", ".tmp");
getMapper().writeValue(new FileOutputStream(tempFile), any);
dataMap.put(objectId, tempFile);
}
private ObjectMapper getMapper() {
return ObjectMapperFactory.create();
}
@Override
@SneakyThrows
public <T> T readJSONObject(String tenantId, String objectId, Class<T> clazz) {
if (dataMap.get(objectId) == null || !dataMap.get(objectId).exists()) {
throw new StorageObjectDoesNotExist("Stored object not found");
}
return getMapper().readValue(new FileInputStream(dataMap.get(objectId)), clazz);
}
@SneakyThrows
public void storeObject(String tenantId, String objectId, InputStream stream) {
File tempFile = File.createTempFile("test", ".tmp");
try (var fileOutputStream = new FileOutputStream(tempFile)) {
IOUtils.copy(stream, fileOutputStream);
}
dataMap.put(objectId, tempFile);
}
@SneakyThrows
@Override
public void downloadTo(String tenantId, String objectId, File destinationFile) {
var res = dataMap.get(objectId);
if (res == null) {
throw new StorageObjectDoesNotExist(new RuntimeException());
}
IOUtils.copy(new FileInputStream(res), new FileOutputStream(destinationFile));
}
@Override
public void deleteObject(String tenantId, String objectId) {
dataMap.remove(objectId);
}
@Override
public boolean objectExists(String tenantId, String objectId) {
return dataMap.containsKey(objectId);
}
public List<String> listPaths() {
return new ArrayList<>(dataMap.keySet());
}
public List<String> listFilePaths() {
return dataMap.values().stream().map(File::getAbsolutePath).collect(Collectors.toList());
}
public void clearStorage() {
this.dataMap.forEach((k, v) -> {
v.delete();
});
this.dataMap.clear();
}
@SneakyThrows
@Override
public InputStreamResource getObject(String tenantId, String objectId) {
var res = dataMap.get(objectId);
if (res == null) {
throw new StorageObjectDoesNotExist(new RuntimeException());
}
return new InputStreamResource(new FileInputStream(res));
}
}

View File

@ -44,8 +44,9 @@ public class FileSystemBackArchiverTest {
var contentSize = fsba.getContentLength();
try (FileOutputStream fos = new FileOutputStream(f)) {
IOUtils.copy(fsba.toInputStream(), fos);
try (FileOutputStream fos = new FileOutputStream(f); var in = fsba.toInputStream()) {
IOUtils.copy(in, fos);
log.info("File: {}", f.getAbsolutePath());
assertThat(f.length()).isEqualTo(contentSize);

View File

@ -36,6 +36,7 @@
<pdftron-redaction-service.version>4.29.0</pdftron-redaction-service.version>
<redaction-report-service.version>4.13.0</redaction-report-service.version>
<ocr-service.version>3.10.0</ocr-service.version>
<storage.commons.version>2.45.0</storage.commons.version>
</properties>
<dependencyManagement>