RED-8670: add features to status update
This commit is contained in:
parent
80dfa16103
commit
b6666f6953
@ -1,16 +1,24 @@
|
||||
package com.knecon.fforesight.service.ocr.processor.service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.AzureOcrFeature;
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.DocumentRequest;
|
||||
|
||||
@Service
|
||||
public interface IOcrMessageSender {
|
||||
|
||||
void sendUpdate(String fileId, int finishedImages, int totalImages);
|
||||
void sendUpdate(String fileId, int finishedImages, int totalImages, Set<AzureOcrFeature> features);
|
||||
|
||||
void sendOCRStarted(String fileId);
|
||||
|
||||
void sendOcrFinished(String fileId, int totalImages);
|
||||
void sendOCRStarted(String fileId, Set<AzureOcrFeature> features);
|
||||
|
||||
void sendOcrResponse(String dossierId, String fileId);
|
||||
|
||||
void sendOcrFinished(String fileId, int totalImages, Set<AzureOcrFeature> features);
|
||||
|
||||
|
||||
void sendOcrResponse(DocumentRequest request);
|
||||
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ public class OCRService {
|
||||
|
||||
OCGWatermarkRemovalService.removeWatermarks(pdfDoc);
|
||||
|
||||
OcrExecutionSupervisor supervisor = new OcrExecutionSupervisor(pdfDoc.getPageCount(), ocrMessageSender, fileId, settings);
|
||||
OcrExecutionSupervisor supervisor = new OcrExecutionSupervisor(pdfDoc.getPageCount(), ocrMessageSender, fileId, settings, features);
|
||||
supervisor.getStatistics().setStart();
|
||||
|
||||
List<PageBatch> batches = batchFactory.splitIntoBatches(pdfDoc, supervisor, features, runDir);
|
||||
|
||||
@ -14,6 +14,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import com.knecon.fforesight.service.ocr.processor.OcrServiceSettings;
|
||||
import com.knecon.fforesight.service.ocr.processor.model.PageBatch;
|
||||
import com.knecon.fforesight.service.ocr.processor.model.Statistics;
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.AzureOcrFeature;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
@ -39,12 +40,15 @@ public class OcrExecutionSupervisor {
|
||||
|
||||
String fileId;
|
||||
|
||||
Set<AzureOcrFeature> features;
|
||||
|
||||
public OcrExecutionSupervisor(int totalPageCount, IOcrMessageSender ocrMessageSender, String fileId, OcrServiceSettings settings) {
|
||||
|
||||
public OcrExecutionSupervisor(int totalPageCount, IOcrMessageSender ocrMessageSender, String fileId, OcrServiceSettings settings, Set<AzureOcrFeature> features) {
|
||||
|
||||
this.totalPageCount = totalPageCount;
|
||||
this.ocrMessageSender = ocrMessageSender;
|
||||
this.fileId = fileId;
|
||||
this.features = features;
|
||||
this.errorPages = Collections.synchronizedSet(new HashSet<>());
|
||||
this.countDownPagesToProcess = new CountDownLatch(totalPageCount);
|
||||
this.statistics = new Statistics();
|
||||
@ -86,7 +90,7 @@ public class OcrExecutionSupervisor {
|
||||
if (!statistics.getBatchStats(pageRange).isUploadFinished()) {
|
||||
log.info("Batch {}: Pages {} is in progress", pageRange.getIndex(), pageRange);
|
||||
statistics.getBatchStats(pageRange).finishUpload();
|
||||
ocrMessageSender.sendUpdate(fileId, processedPages(), getTotalPageCount());
|
||||
ocrMessageSender.sendUpdate(fileId, processedPages(), getTotalPageCount(), features);
|
||||
} else {
|
||||
log.debug("Batch {}: Pages {} still in progress", pageRange.getIndex(), pageRange);
|
||||
}
|
||||
@ -97,14 +101,14 @@ public class OcrExecutionSupervisor {
|
||||
|
||||
batch.forEach(pageIndex -> countDownPagesToProcess.countDown());
|
||||
statistics.getBatchStats(batch).finishMappingResult();
|
||||
ocrMessageSender.sendUpdate(fileId, this.processedPages(), getTotalPageCount());
|
||||
ocrMessageSender.sendUpdate(fileId, this.processedPages(), getTotalPageCount(), features);
|
||||
}
|
||||
|
||||
|
||||
public void logPageSkipped(Integer pageIndex) {
|
||||
|
||||
this.countDownPagesToProcess.countDown();
|
||||
ocrMessageSender.sendUpdate(fileId, this.processedPages(), getTotalPageCount());
|
||||
ocrMessageSender.sendUpdate(fileId, this.processedPages(), getTotalPageCount(), features);
|
||||
log.debug("{}/{}: No images to ocr on page {}", processedPages(), getTotalPageCount(), pageIndex);
|
||||
|
||||
}
|
||||
@ -114,7 +118,7 @@ public class OcrExecutionSupervisor {
|
||||
|
||||
this.errorPages.add(batch);
|
||||
batch.forEach(pageIndex -> this.countDownPagesToProcess.countDown());
|
||||
ocrMessageSender.sendUpdate(fileId, this.processedPages(), getTotalPageCount());
|
||||
ocrMessageSender.sendUpdate(fileId, this.processedPages(), getTotalPageCount(), features);
|
||||
log.error("{}/{}: Error occurred in batch {} with pages {}", processedPages(), getTotalPageCount(), batch.getIndex(), batch, e);
|
||||
}
|
||||
|
||||
@ -167,7 +171,7 @@ public class OcrExecutionSupervisor {
|
||||
requireNoErrors();
|
||||
|
||||
log.info("{}/{}: Finished OCR on all pages", getTotalPageCount(), getTotalPageCount());
|
||||
ocrMessageSender.sendOcrFinished(fileId, getTotalPageCount());
|
||||
ocrMessageSender.sendOcrFinished(fileId, getTotalPageCount(), features);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
package com.knecon.fforesight.service.ocr.v1.server.queue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.knecon.fforesight.service.ocr.processor.service.IOcrMessageSender;
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.AzureOcrFeature;
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.DocumentRequest;
|
||||
import com.knecon.fforesight.service.ocr.v1.server.configuration.MessagingConfiguration;
|
||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||
@ -22,24 +25,24 @@ public class NoStatusUpdateOcrMessageSender implements IOcrMessageSender {
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
public void sendOcrFinished(String fileId, int totalImages) {
|
||||
public void sendOcrFinished(String fileId, int totalImages, Set<AzureOcrFeature> features) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void sendOCRStarted(String fileId) {
|
||||
public void sendOCRStarted(String fileId, Set<AzureOcrFeature> features) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void sendUpdate(String fileId, int finishedImages, int totalImages) {
|
||||
public void sendUpdate(String fileId, int finishedImages, int totalImages, Set<AzureOcrFeature> features) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void sendOcrResponse(String dossierId, String fileId) {
|
||||
public void sendOcrResponse(DocumentRequest request) {
|
||||
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.OCR_RESPONSE_EXCHANGE, TenantContext.getTenantId(), new DocumentRequest(dossierId, fileId));
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.OCR_RESPONSE_EXCHANGE, TenantContext.getTenantId(), request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public class OcrMessageReceiver {
|
||||
MDC.put("fileId", fileId);
|
||||
log.info("--------------------------------------------------------------------------");
|
||||
|
||||
ocrMessageSender.sendOCRStarted(fileId);
|
||||
ocrMessageSender.sendOCRStarted(fileId, request.getFeatures());
|
||||
|
||||
File documentFile = runDir.resolve(DOCUMENT_FILE_NAME).toFile();
|
||||
File viewerDocumentFile = runDir.resolve(VIEWER_DOCUMENT_FILE_NAME).toFile();
|
||||
@ -73,7 +73,7 @@ public class OcrMessageReceiver {
|
||||
|
||||
fileStorageService.storeFiles(request, documentFile, viewerDocumentFile, analyzeResultFile);
|
||||
|
||||
ocrMessageSender.sendOcrResponse(dossierId, fileId);
|
||||
ocrMessageSender.sendOcrResponse(request);
|
||||
} catch (Exception e) {
|
||||
log.warn("An exception occurred in ocr file stage: {}", e.getMessage());
|
||||
in.getMessageProperties().getHeaders().put(MessagingConfiguration.X_ERROR_INFO_HEADER, e.getMessage());
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
package com.knecon.fforesight.service.ocr.v1.server.queue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.knecon.fforesight.service.ocr.processor.service.IOcrMessageSender;
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.AzureOcrFeature;
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.DocumentRequest;
|
||||
import com.knecon.fforesight.service.ocr.v1.api.model.OCRStatusUpdateResponse;
|
||||
import com.knecon.fforesight.service.ocr.v1.server.configuration.MessagingConfiguration;
|
||||
@ -25,7 +28,7 @@ public class OcrMessageSender implements IOcrMessageSender {
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
public void sendOcrFinished(String fileId, int totalImages) {
|
||||
public void sendOcrFinished(String fileId, int totalImages, Set<AzureOcrFeature> features) {
|
||||
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.OCR_STATUS_UPDATE_RESPONSE_EXCHANGE,
|
||||
TenantContext.getTenantId(),
|
||||
@ -33,7 +36,7 @@ public class OcrMessageSender implements IOcrMessageSender {
|
||||
}
|
||||
|
||||
|
||||
public void sendOCRStarted(String fileId) {
|
||||
public void sendOCRStarted(String fileId, Set<AzureOcrFeature> features) {
|
||||
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.OCR_STATUS_UPDATE_RESPONSE_EXCHANGE,
|
||||
TenantContext.getTenantId(),
|
||||
@ -42,16 +45,21 @@ public class OcrMessageSender implements IOcrMessageSender {
|
||||
}
|
||||
|
||||
|
||||
public void sendUpdate(String fileId, int finishedImages, int totalImages) {
|
||||
public void sendUpdate(String fileId, int finishedImages, int totalImages, Set<AzureOcrFeature> features) {
|
||||
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.OCR_STATUS_UPDATE_RESPONSE_EXCHANGE,
|
||||
TenantContext.getTenantId(),
|
||||
OCRStatusUpdateResponse.builder().fileId(fileId).numberOfPagesToOCR(totalImages).numberOfOCRedPages(finishedImages).build());
|
||||
OCRStatusUpdateResponse.builder()
|
||||
.fileId(fileId)
|
||||
.features(features)
|
||||
.numberOfPagesToOCR(totalImages)
|
||||
.numberOfOCRedPages(finishedImages)
|
||||
.build());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void sendOcrResponse(String dossierId, String fileId) {
|
||||
public void sendOcrResponse(DocumentRequest request) {
|
||||
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.OCR_RESPONSE_EXCHANGE, TenantContext.getTenantId(), new DocumentRequest(dossierId, fileId));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user