HOTFIX RED-3800 endpoint to reset text for all files that are not approved/deleted

This commit is contained in:
Timo Bejan 2022-04-29 18:43:32 +03:00
parent d96c9cae41
commit 6d5927f667

View File

@ -65,6 +65,10 @@ public class AdminInterfaceController {
@PostMapping("/ocr-all-files-that-have-already-been-ocrd")
public void forceOCR(@RequestParam(value = "dryRun", defaultValue = "true") boolean dryRun) {
if (dryRun) {
log.info("Dry run!");
}
var dossiers = dossierService.getAllDossiers();
for (var dossier : dossiers) {
if (!dossier.isDeleted()) {
@ -93,4 +97,47 @@ public class AdminInterfaceController {
}
}
@PostMapping("/reset-text-for-all-files")
public void resetText(@RequestParam(value = "dryRun", defaultValue = "true") boolean dryRun) {
if (dryRun) {
log.info("Dry run!");
}
var dossiers = dossierService.getAllDossiers();
for (var dossier : dossiers) {
if (!dossier.isDeleted()) {
var files = fileStatusService.getActiveFiles(dossier.getId());
var filesThatRequireTextReset = files.stream()
.filter(f -> !f.isExcluded())
.filter(f -> !f.isExcludedFromAutomaticAnalysis())
.filter(f -> !f.isSoftOrHardDeleted())
.filter(f -> f.getWorkflowStatus() != WorkflowStatus.APPROVED).collect(Collectors.toList());
for (var file : filesThatRequireTextReset) {
log.info("Will OCR file: {} from dossier {} with status {} and processing status {} with last OCR time {}",
file.getId(), file.getDossierId(), file.getWorkflowStatus(), file.getProcessingStatus(), file.getLastOCRTime());
if (!dryRun) {
var dossierId = file.getDossierId();
var fileId = file.getId();
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.SECTION_GRID);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.REDACTION_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.TEXT);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.NER_ENTITIES);
fileStatusService.setStatusFullReprocess(dossierId, fileId, true, true);
}
}
}
}
}
}