Pull request #584: RED-5608: Ocr is only possible for processed files
Merge in RED/persistence-service from RED-5608 to master * commit 'fb9838054326d910d659b84517d4505a01ba40d6': RED-5608: Ocr is only possible for processed files
This commit is contained in:
commit
bf91d66e65
@ -28,6 +28,7 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
|
|||||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.DeleteImportedRedactionsRequest;
|
import com.iqser.red.service.persistence.service.v1.api.model.annotations.DeleteImportedRedactionsRequest;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
|
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
|
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
|
||||||
|
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.ProcessingStatus;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.WorkflowStatus;
|
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.WorkflowStatus;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.resources.ReanalysisResource;
|
import com.iqser.red.service.persistence.service.v1.api.resources.ReanalysisResource;
|
||||||
|
|
||||||
@ -72,6 +73,7 @@ public class ReanalysisController implements ReanalysisResource {
|
|||||||
|
|
||||||
relevantFiles.stream()
|
relevantFiles.stream()
|
||||||
.filter(fileStatus -> fileStatus.getOcrStartTime() == null)
|
.filter(fileStatus -> fileStatus.getOcrStartTime() == null)
|
||||||
|
.filter(fileStatus -> fileStatus.getProcessingStatus().equals(ProcessingStatus.PROCESSED))
|
||||||
.forEach(fileStatus -> fileStatusService.setStatusOcrQueued(dossierId, fileStatus.getId()));
|
.forEach(fileStatus -> fileStatusService.setStatusOcrQueued(dossierId, fileStatus.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +82,12 @@ public class ReanalysisController implements ReanalysisResource {
|
|||||||
|
|
||||||
var relevantFiles = getRelevantFiles(dossierId, fileIds);
|
var relevantFiles = getRelevantFiles(dossierId, fileIds);
|
||||||
|
|
||||||
|
if (relevantFiles.stream()
|
||||||
|
.anyMatch(fileStatus -> !fileStatus.getProcessingStatus().equals(ProcessingStatus.PROCESSED) && !fileStatus.getProcessingStatus()
|
||||||
|
.equals(ProcessingStatus.OCR_PROCESSING_QUEUED) && !fileStatus.getProcessingStatus().equals(ProcessingStatus.OCR_PROCESSING))) {
|
||||||
|
throw new ConflictException("File is not processed");
|
||||||
|
}
|
||||||
|
|
||||||
relevantFiles.stream()
|
relevantFiles.stream()
|
||||||
.filter(fileStatus -> fileStatus.getOcrStartTime() == null)
|
.filter(fileStatus -> fileStatus.getOcrStartTime() == null)
|
||||||
.forEach(fileStatus -> fileStatusService.setStatusOcrQueued(dossierId, fileStatus.getId()));
|
.forEach(fileStatus -> fileStatusService.setStatusOcrQueued(dossierId, fileStatus.getId()));
|
||||||
@ -91,17 +99,23 @@ public class ReanalysisController implements ReanalysisResource {
|
|||||||
@RequestParam(value = "force", required = false, defaultValue = FALSE) boolean force) {
|
@RequestParam(value = "force", required = false, defaultValue = FALSE) boolean force) {
|
||||||
|
|
||||||
dossierPersistenceService.getAndValidateDossier(dossierId);
|
dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||||
|
FileModel dossierFile = fileStatusService.getStatus(fileId);
|
||||||
|
|
||||||
|
if (!dossierFile.getProcessingStatus().equals(ProcessingStatus.PROCESSED) && !dossierFile.getProcessingStatus()
|
||||||
|
.equals(ProcessingStatus.OCR_PROCESSING_QUEUED) && !dossierFile.getProcessingStatus().equals(ProcessingStatus.OCR_PROCESSING)) {
|
||||||
|
throw new ConflictException("File is not processed");
|
||||||
|
}
|
||||||
|
|
||||||
if (force) {
|
if (force) {
|
||||||
fileStatusService.setStatusOcrQueued(dossierId, fileId);
|
fileStatusService.setStatusOcrQueued(dossierId, fileId);
|
||||||
} else {
|
} else {
|
||||||
FileModel dossierFile = fileStatusService.getStatus(fileId);
|
|
||||||
if (dossierFile.isSoftOrHardDeleted() || dossierFile.getWorkflowStatus().equals(WorkflowStatus.APPROVED)) {
|
if (dossierFile.isSoftOrHardDeleted() || dossierFile.getWorkflowStatus().equals(WorkflowStatus.APPROVED)) {
|
||||||
throw new ConflictException("Cannot analyse a deleted/approved file");
|
throw new ConflictException("Cannot analyse a deleted/approved file");
|
||||||
}
|
}
|
||||||
if (dossierFile.getOcrStartTime() != null) {
|
if (dossierFile.getOcrStartTime() != null) {
|
||||||
throw new ConflictException("File already has been OCR processed");
|
throw new ConflictException("File already has been OCR processed");
|
||||||
}
|
}
|
||||||
|
|
||||||
ocrFiles(dossierId, Sets.newHashSet(fileId));
|
ocrFiles(dossierId, Sets.newHashSet(fileId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,8 +42,16 @@ public class ReanalysisTest extends AbstractPersistenceServerServiceTest {
|
|||||||
|
|
||||||
var file = fileTesterAndProvider.testAndProvideFile(dossier);
|
var file = fileTesterAndProvider.testAndProvideFile(dossier);
|
||||||
|
|
||||||
reanalysisClient.ocrDossier(dossier.getId());
|
|
||||||
var loadedFile = fileClient.getFileStatus(dossier.getId(), file.getId());
|
var loadedFile = fileClient.getFileStatus(dossier.getId(), file.getId());
|
||||||
|
assertThat(loadedFile.getProcessingStatus()).isNotEqualTo(ProcessingStatus.PROCESSED);
|
||||||
|
|
||||||
|
reanalysisClient.ocrDossier(dossier.getId());
|
||||||
|
loadedFile = fileClient.getFileStatus(dossier.getId(), file.getId());
|
||||||
|
assertThat(loadedFile.getProcessingStatus()).isNotEqualTo(ProcessingStatus.PROCESSED);
|
||||||
|
resetProcessingStatus(file);
|
||||||
|
|
||||||
|
reanalysisClient.ocrDossier(dossier.getId());
|
||||||
|
loadedFile = fileClient.getFileStatus(dossier.getId(), file.getId());
|
||||||
assertThat(loadedFile.getProcessingStatus()).isEqualTo(ProcessingStatus.OCR_PROCESSING_QUEUED);
|
assertThat(loadedFile.getProcessingStatus()).isEqualTo(ProcessingStatus.OCR_PROCESSING_QUEUED);
|
||||||
resetProcessingStatus(file);
|
resetProcessingStatus(file);
|
||||||
|
|
||||||
@ -77,13 +85,13 @@ public class ReanalysisTest extends AbstractPersistenceServerServiceTest {
|
|||||||
fileRepository.findById(file.getId()).ifPresent(savedFile -> {
|
fileRepository.findById(file.getId()).ifPresent(savedFile -> {
|
||||||
|
|
||||||
savedFile.setOcrStartTime(null);
|
savedFile.setOcrStartTime(null);
|
||||||
savedFile.setProcessingStatus(ProcessingStatus.UNPROCESSED);
|
savedFile.setProcessingStatus(ProcessingStatus.PROCESSED);
|
||||||
fileRepository.save(savedFile);
|
fileRepository.save(savedFile);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var loadedFile = fileClient.getFileStatus(file.getDossierId(), file.getId());
|
var loadedFile = fileClient.getFileStatus(file.getDossierId(), file.getId());
|
||||||
assertThat(loadedFile.getProcessingStatus()).isEqualTo(ProcessingStatus.UNPROCESSED);
|
assertThat(loadedFile.getProcessingStatus()).isEqualTo(ProcessingStatus.PROCESSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user