Merge branch 'RED-6864' into 'main'
RED-6864 - Switch to new storage-commons download See merge request fforesight/layout-parser!9
This commit is contained in:
commit
f56ab8fa49
@ -16,7 +16,7 @@ dependencies {
|
|||||||
exclude("org.springframework.boot", "spring-boot-starter-validation")
|
exclude("org.springframework.boot", "spring-boot-starter-validation")
|
||||||
}
|
}
|
||||||
implementation("com.knecon.fforesight:tenant-commons:0.10.0")
|
implementation("com.knecon.fforesight:tenant-commons:0.10.0")
|
||||||
implementation("com.iqser.red.commons:storage-commons:2.1.0")
|
implementation("com.iqser.red.commons:storage-commons:2.27.0")
|
||||||
|
|
||||||
implementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
implementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
||||||
implementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
implementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.knecon.fforesight.service.layoutparser.processor;
|
package com.knecon.fforesight.service.layoutparser.processor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -24,6 +25,7 @@ import com.knecon.fforesight.service.layoutparser.processor.python_api.model.tab
|
|||||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -37,7 +39,7 @@ public class LayoutParsingStorageService {
|
|||||||
|
|
||||||
public PDDocument getOriginFile(String storageId) throws IOException {
|
public PDDocument getOriginFile(String storageId) throws IOException {
|
||||||
|
|
||||||
try (var originDocumentInputStream = storageService.getObject(TenantContext.getTenantId(), storageId).getInputStream()) {
|
try (var originDocumentInputStream = getObject(storageId)) {
|
||||||
File tempFile = createTempFile("document", ".pdf");
|
File tempFile = createTempFile("document", ".pdf");
|
||||||
try (var tempFileOutputStream = new FileOutputStream(tempFile)) {
|
try (var tempFileOutputStream = new FileOutputStream(tempFile)) {
|
||||||
IOUtils.copy(originDocumentInputStream, tempFileOutputStream);
|
IOUtils.copy(originDocumentInputStream, tempFileOutputStream);
|
||||||
@ -49,7 +51,7 @@ public class LayoutParsingStorageService {
|
|||||||
|
|
||||||
public ImageServiceResponse getImagesFile(String storageId) throws IOException {
|
public ImageServiceResponse getImagesFile(String storageId) throws IOException {
|
||||||
|
|
||||||
try (InputStream inputStream = storageService.getObject(TenantContext.getTenantId(), storageId).getInputStream()) {
|
try (InputStream inputStream = getObject(storageId)) {
|
||||||
|
|
||||||
return objectMapper.readValue(inputStream, ImageServiceResponse.class);
|
return objectMapper.readValue(inputStream, ImageServiceResponse.class);
|
||||||
}
|
}
|
||||||
@ -58,7 +60,7 @@ public class LayoutParsingStorageService {
|
|||||||
|
|
||||||
public TableServiceResponse getTablesFile(String storageId) throws IOException {
|
public TableServiceResponse getTablesFile(String storageId) throws IOException {
|
||||||
|
|
||||||
try (var tableClassificationStream = storageService.getObject(TenantContext.getTenantId(), storageId).getInputStream()) {
|
try (var tableClassificationStream = getObject(storageId)) {
|
||||||
|
|
||||||
return objectMapper.readValue(tableClassificationStream, TableServiceResponse.class);
|
return objectMapper.readValue(tableClassificationStream, TableServiceResponse.class);
|
||||||
|
|
||||||
@ -117,4 +119,13 @@ public class LayoutParsingStorageService {
|
|||||||
storageService.storeJSONObject(TenantContext.getTenantId(), layoutParsingRequest.simplifiedTextStorageId(), simplifiedText);
|
storageService.storeJSONObject(TenantContext.getTenantId(), layoutParsingRequest.simplifiedTextStorageId(), simplifiedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private InputStream getObject(String storageId) {
|
||||||
|
|
||||||
|
File tempFile = File.createTempFile("temp", ".data");
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
storageService.downloadTo(TenantContext.getTenantId(), storageId, tempFile);
|
||||||
|
return new FileInputStream(tempFile);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ dependencies {
|
|||||||
implementation(project(":layoutparser-service-processor"))
|
implementation(project(":layoutparser-service-processor"))
|
||||||
implementation(project(":layoutparser-service-internal-api"))
|
implementation(project(":layoutparser-service-internal-api"))
|
||||||
|
|
||||||
implementation("com.iqser.red.commons:storage-commons:2.1.0")
|
implementation("com.iqser.red.commons:storage-commons:2.27.0")
|
||||||
implementation("com.knecon.fforesight:tenant-commons:0.10.0")
|
implementation("com.knecon.fforesight:tenant-commons:0.10.0")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-actuator:3.1.2")
|
implementation("org.springframework.boot:spring-boot-starter-actuator:3.1.2")
|
||||||
implementation("com.amazonaws:aws-java-sdk-s3:1.12.514")
|
implementation("com.amazonaws:aws-java-sdk-s3:1.12.514")
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import java.util.Map;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@ -36,14 +35,14 @@ public class FileSystemBackedStorageService implements StorageService {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public InputStreamResource getObject(String tenantId, String objectId) {
|
public void downloadTo(String tenantId, String objectId, File destinationFile) {
|
||||||
|
|
||||||
var res = dataMap.get(objectId);
|
var res = dataMap.get(objectId);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
throw new StorageObjectDoesNotExist(new RuntimeException());
|
throw new StorageObjectDoesNotExist(new RuntimeException());
|
||||||
}
|
}
|
||||||
return new InputStreamResource(new FileInputStream(res));
|
|
||||||
|
|
||||||
|
IOUtils.copy(new FileInputStream(res), new FileOutputStream(destinationFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user