HOTFIX: RED-3800 ocr all files that have been ocrd
This commit is contained in:
parent
1f7b72183c
commit
d96c9cae41
@ -113,4 +113,7 @@ public class DossierEntity {
|
||||
@Column(updatable = false, insertable = false, name = "dossier_status_id")
|
||||
private String dossierStatusId;
|
||||
|
||||
public boolean isDeleted() {
|
||||
return softDeletedTime != null || hardDeletedTime != null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,20 +29,17 @@ public class MigrationPersistenceService {
|
||||
|
||||
var migrations = migrationRepository.findByVersionGreaterThan(lastProcessedVersion);
|
||||
if (migrations == null || migrations.isEmpty()) {
|
||||
if(version > lastProcessedVersion){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return version <= lastProcessedVersion;
|
||||
}
|
||||
|
||||
return migrations.stream().filter(m -> m.getVersion() == version).findFirst().isPresent();
|
||||
return migrations.stream().anyMatch(m -> m.getVersion() == version);
|
||||
}
|
||||
|
||||
|
||||
public Long getLatestProcessedVersion() {
|
||||
|
||||
var migrations = migrationRepository.findAll();
|
||||
if (migrations == null || migrations.isEmpty()) {
|
||||
if (migrations.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return migrations.stream().sorted(Comparator.comparing(MigrationEntity::getVersion).reversed()).collect(Collectors.toList()).get(0).getVersion();
|
||||
|
||||
@ -1,16 +1,22 @@
|
||||
package com.iqser.red.service.peristence.v1.server.internal;
|
||||
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.service.DossierService;
|
||||
import com.iqser.red.service.peristence.v1.server.service.FileManagementStorageService;
|
||||
import com.iqser.red.service.peristence.v1.server.service.FileStatusService;
|
||||
import com.iqser.red.service.peristence.v1.server.settings.FileManagementServiceSettings;
|
||||
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.WorkflowStatus;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/private/admin")
|
||||
@ -20,6 +26,8 @@ public class AdminInterfaceController {
|
||||
private final FileStatusService fileStatusService;
|
||||
private final FileManagementServiceSettings fileManagementServiceSettings;
|
||||
|
||||
private final DossierService dossierService;
|
||||
|
||||
|
||||
@PostMapping("/reset-file")
|
||||
public void resetFile(@RequestParam("dossierId") String dossierId, @RequestParam("fileId") String fileId) {
|
||||
@ -53,4 +61,36 @@ public class AdminInterfaceController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/ocr-all-files-that-have-already-been-ocrd")
|
||||
public void forceOCR(@RequestParam(value = "dryRun", defaultValue = "true") boolean dryRun) {
|
||||
|
||||
var dossiers = dossierService.getAllDossiers();
|
||||
for (var dossier : dossiers) {
|
||||
if (!dossier.isDeleted()) {
|
||||
var files = fileStatusService.getActiveFiles(dossier.getId());
|
||||
var filesThatRequireOCR = files.stream()
|
||||
.filter(f -> !f.isExcluded())
|
||||
.filter(f -> !f.isExcludedFromAutomaticAnalysis())
|
||||
.filter(f -> !f.isSoftOrHardDeleted())
|
||||
.filter(f -> f.getLastOCRTime() != null)
|
||||
.filter(f -> f.getWorkflowStatus() != WorkflowStatus.APPROVED).collect(Collectors.toList());
|
||||
|
||||
|
||||
for (var file : filesThatRequireOCR) {
|
||||
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) {
|
||||
fileStatusService.updateLastOCRTime(file.getId());
|
||||
fileStatusService.setStatusOcrProcessing(file.getDossierId(), file.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user