proper error handling for image clasification
This commit is contained in:
parent
ed5686dc51
commit
a34d2fb675
@ -35,7 +35,7 @@ public class ImageClassificationService {
|
||||
var mockFile = new MockMultipartFile("file", "Image.png", "image/png", baos.toByteArray());
|
||||
ImageClassificationResponse response = imageClassificationClient.classify(mockFile);
|
||||
image.setImageType(ImageType.valueOf(response.getCategory()));
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("Could not classify image", e);
|
||||
}
|
||||
|
||||
|
||||
@ -127,7 +127,8 @@ public class PdfSegmentationService {
|
||||
|
||||
|
||||
public Document parseDocument(InputStream documentInputStream) throws IOException {
|
||||
|
||||
PDDocument pdDocument = null;
|
||||
try {
|
||||
//create tempFile
|
||||
File tempFile = File.createTempFile("document", ".pdf");
|
||||
IOUtils.copy(documentInputStream, new FileOutputStream(tempFile));
|
||||
@ -137,7 +138,7 @@ public class PdfSegmentationService {
|
||||
List<Page> pages = new ArrayList<>();
|
||||
|
||||
|
||||
PDDocument pdDocument = reinitializePDDocument(tempFile, null);
|
||||
pdDocument = reinitializePDDocument(tempFile, null);
|
||||
long pageCount = pdDocument.getNumberOfPages();
|
||||
|
||||
for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) {
|
||||
@ -201,6 +202,11 @@ public class PdfSegmentationService {
|
||||
tempFile.delete();
|
||||
|
||||
return document;
|
||||
} finally {
|
||||
if (pdDocument != null) {
|
||||
pdDocument.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PDDocument reinitializePDDocument(File tempFile, PDDocument pdDocument) throws IOException {
|
||||
|
||||
@ -19,7 +19,6 @@ import lombok.SneakyThrows;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.kie.api.KieServices;
|
||||
@ -452,7 +451,6 @@ public class RedactionIntegrationTest {
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testLargeScannedFileOOM() {
|
||||
AnalyzeRequest request = prepareStorage("scanned/VV-377031.pdf");
|
||||
MemoryStats.printMemoryStats();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user