Pull request #426: RED-4686: Stream objects to storage
Merge in RED/redaction-service from RED-4686 to master * commit '99a8b9788e1b1062c8d8a93d4b5d4b65f3d34ce2': RED-4686: Stream objects to storage
This commit is contained in:
commit
e4b5bb93e1
@ -37,7 +37,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.iqser.red</groupId>
|
<groupId>com.iqser.red</groupId>
|
||||||
<artifactId>platform-commons-dependency</artifactId>
|
<artifactId>platform-commons-dependency</artifactId>
|
||||||
<version>1.14.0</version>
|
<version>1.15.0</version>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@ -55,24 +55,26 @@ public class RedactionStorageService {
|
|||||||
@Timed("redactmanager_storeObject")
|
@Timed("redactmanager_storeObject")
|
||||||
public void storeObject(String dossierId, String fileId, FileType fileType, Object any) {
|
public void storeObject(String dossierId, String fileId, FileType fileType, Object any) {
|
||||||
|
|
||||||
var bytes = serializeObject(any);
|
try(var byteArrayOutputStream = serializeObject(any)){
|
||||||
storageService.storeObject(StorageIdUtils.getStorageId(dossierId, fileId, fileType), bytes);
|
storageService.storeObject(StorageIdUtils.getStorageId(dossierId, fileId, fileType), byteArrayOutputStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Timed("redactmanager_serializeObject")
|
@Timed("redactmanager_serializeObject")
|
||||||
private byte[] serializeObject(Object any) {
|
private ByteArrayOutputStream serializeObject(Object any) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var baos = new ByteArrayOutputStream();
|
var baos = new ByteArrayOutputStream();
|
||||||
dslJson.serialize(any, baos);
|
dslJson.serialize(any, baos);
|
||||||
return baos.toByteArray();
|
return baos;
|
||||||
} catch (com.dslplatform.json.SerializationException e) {
|
} catch (com.dslplatform.json.SerializationException e) {
|
||||||
// Fails on file 49 Cyprodinil - EU AIR3 - MCA Section 8 Supplement - Ecotoxicological studies on the active substance.pdf
|
// Fails on file 49 Cyprodinil - EU AIR3 - MCA Section 8 Supplement - Ecotoxicological studies on the active substance.pdf
|
||||||
var bytes = objectMapper.writeValueAsBytes(any);
|
var baos = new ByteArrayOutputStream();
|
||||||
|
objectMapper.writeValue(baos, any);
|
||||||
dslJson.newWriter();
|
dslJson.newWriter();
|
||||||
return bytes;
|
return baos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,12 +7,14 @@ import lombok.SneakyThrows;
|
|||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
public class FileSystemBackedStorageService implements StorageService{
|
public class FileSystemBackedStorageService implements StorageService{
|
||||||
|
|
||||||
@ -63,7 +65,9 @@ public class FileSystemBackedStorageService implements StorageService{
|
|||||||
public void storeObject(String objectId, byte[] data) {
|
public void storeObject(String objectId, byte[] data) {
|
||||||
File tempFile = File.createTempFile("storage", objectId.replace("/","-"));
|
File tempFile = File.createTempFile("storage", objectId.replace("/","-"));
|
||||||
|
|
||||||
IOUtils.write(data, new FileOutputStream(tempFile));
|
try(var fileOutputStream = new FileOutputStream(tempFile)) {
|
||||||
|
IOUtils.write(data, fileOutputStream);
|
||||||
|
}
|
||||||
|
|
||||||
dataMap.put(objectId, tempFile);
|
dataMap.put(objectId, tempFile);
|
||||||
}
|
}
|
||||||
@ -73,11 +77,27 @@ public class FileSystemBackedStorageService implements StorageService{
|
|||||||
public void storeObject(String objectId, InputStream stream) {
|
public void storeObject(String objectId, InputStream stream) {
|
||||||
File tempFile = File.createTempFile("test", ".tmp");
|
File tempFile = File.createTempFile("test", ".tmp");
|
||||||
|
|
||||||
IOUtils.copy(stream, new FileOutputStream(tempFile));
|
try(var fileOutputStream = new FileOutputStream(tempFile)) {
|
||||||
|
IOUtils.copy(stream, fileOutputStream);
|
||||||
|
}
|
||||||
|
|
||||||
dataMap.put(objectId, tempFile);
|
dataMap.put(objectId, tempFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void storeObject(String objectId, ByteArrayOutputStream stream) {
|
||||||
|
|
||||||
|
File tempFile = File.createTempFile("test", ".tmp");
|
||||||
|
try(var fileOutputStream = new FileOutputStream(tempFile)){
|
||||||
|
stream.writeTo(fileOutputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataMap.put(objectId, tempFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void clearStorage() {
|
public void clearStorage() {
|
||||||
this.dataMap.forEach((k, v) -> {
|
this.dataMap.forEach((k, v) -> {
|
||||||
v.delete();
|
v.delete();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user