DM-357: always schedule reanalysis, when any manual redaction happens
* refactored code slightly
This commit is contained in:
parent
f9af48af8c
commit
1f89d64d81
@ -70,7 +70,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class ManualRedactionService {
|
||||
|
||||
private final DossierPersistenceService dossierPersistenceService;
|
||||
private final DossierTemplatePersistenceService dossierTemplatePersistenceService;
|
||||
private final AddRedactionPersistenceService addRedactionPersistenceService;
|
||||
private final RemoveRedactionPersistenceService removeRedactionPersistenceService;
|
||||
private final ForceRedactionPersistenceService forceRedactionPersistenceService;
|
||||
@ -85,8 +84,6 @@ public class ManualRedactionService {
|
||||
private final ManualRedactionProviderService manualRedactionProviderService;
|
||||
private final AnalysisFlagsCalculationService analysisFlagsCalculationService;
|
||||
private final StopwordService stopwordService;
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final RedactionLogService redactionLogService;
|
||||
private final DictionaryManagementService dictionaryManagementService;
|
||||
private final HashFunction hashFunction = Hashing.murmur3_128();
|
||||
@ -98,12 +95,13 @@ public class ManualRedactionService {
|
||||
var response = new ArrayList<ManualAddResponse>();
|
||||
|
||||
dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
var actionPerformed = false;
|
||||
|
||||
// validate add to dossier template dictionaries
|
||||
addRedactionRequests.forEach(request -> dictionaryManagementService.validateAddRemoveToDossierTemplateDictionary(request.getDossierTemplateTypeId(),
|
||||
request.isAddToDictionary(),
|
||||
request.isAddToAllDossiers()));
|
||||
|
||||
boolean actionPerformed = false;
|
||||
for (var addRedactionRequest : addRedactionRequests) {
|
||||
if (addRedactionRequest.isAddToDictionary()) {
|
||||
validateDictionary(addRedactionRequest);
|
||||
@ -118,7 +116,7 @@ public class ManualRedactionService {
|
||||
commentId = addComment(fileId, annotationId, addRedactionRequest.getComment(), addRedactionRequest.getUser()).getId();
|
||||
}
|
||||
|
||||
var addedToDictionary = handleAddToDictionary(fileId,
|
||||
handleAddToDictionary(fileId,
|
||||
annotationId,
|
||||
addRedactionRequest.getDossierTemplateTypeId(),
|
||||
addRedactionRequest.getValue(),
|
||||
@ -129,28 +127,14 @@ public class ManualRedactionService {
|
||||
dossierId,
|
||||
addRedactionRequest.getDictionaryEntryType());
|
||||
|
||||
actionPerformed = actionPerformed || addedToDictionary;
|
||||
|
||||
response.add(ManualAddResponse.builder().annotationId(annotationId).commentId(commentId).build());
|
||||
actionPerformed = actionPerformed || addRedactionRequest.getStatus().equals(AnnotationStatus.APPROVED);
|
||||
}
|
||||
|
||||
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
|
||||
|
||||
if (actionPerformed) {
|
||||
// in case of add to dict, there is no need to process surrounding text
|
||||
reprocess(dossierId, fileId);
|
||||
} else {
|
||||
|
||||
var manualTextRedactions = response.stream()
|
||||
.map(r -> manualRedactionProviderService.getAddRedaction(fileId, r.getAnnotationId()))
|
||||
.filter(m -> !m.isAddToDictionary() && !m.isRectangle())
|
||||
.toList();
|
||||
|
||||
if (!manualTextRedactions.isEmpty()) {
|
||||
ManualRedactions manualRedactions = ManualRedactions.builder().entriesToAdd(new HashSet<>(manualTextRedactions)).build();
|
||||
addManualRedactionToAnalysisQueue(dossierId, fileId, manualRedactions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return response;
|
||||
@ -244,20 +228,6 @@ public class ManualRedactionService {
|
||||
}
|
||||
|
||||
|
||||
private void addManualRedactionToAnalysisQueue(String dossierId, String fileId, ManualRedactions manualRedactions) {
|
||||
|
||||
fileStatusPersistenceService.updateProcessingStatus(fileId, ProcessingStatus.SURROUNDING_TEXT_PROCESSING);
|
||||
|
||||
var analyseRequest = AnalyzeRequest.builder().messageType(MessageType.SURROUNDING_TEXT).dossierId(dossierId).fileId(fileId).manualRedactions(manualRedactions).build();
|
||||
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.REDACTION_QUEUE, analyseRequest, message -> {
|
||||
message.getMessageProperties().setPriority(1);
|
||||
return message;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void removeFromDictionary(String typeId, String value, String dossierId, String fileId, DictionaryEntryType dictionaryEntryType) {
|
||||
|
||||
try {
|
||||
@ -286,7 +256,7 @@ public class ManualRedactionService {
|
||||
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
RedactionLog redactionLog = fileManagementStorageService.getRedactionLog(dossier.getId(), fileId);
|
||||
|
||||
var actionPerformed = false;
|
||||
var requiresReAnalysis = false;
|
||||
var manualRedactions = manualRedactionProviderService.getManualRedactions(fileId);
|
||||
|
||||
//validate removing from dossier template dictionary
|
||||
@ -314,18 +284,16 @@ public class ManualRedactionService {
|
||||
if (removeRedactionRequest.getComment() != null) {
|
||||
commentId = addComment(fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getComment(), removeRedactionRequest.getUser()).getId();
|
||||
}
|
||||
|
||||
if (!removeRedactionRequest.isRemoveFromDictionary() && AnnotationStatus.APPROVED.equals(removeRedactionRequest.getStatus())) {
|
||||
RedactionLogEntry redactionLogEntry = null;
|
||||
boolean requiresAnalysis = false;
|
||||
boolean matchingEntryFound;
|
||||
try {
|
||||
redactionLogEntry = getRedactionLogEntry(redactionLog, removeRedactionRequest.getAnnotationId());
|
||||
requiresAnalysis = redactionLogEntry.isHint();
|
||||
getRedactionLogEntry(redactionLog, removeRedactionRequest.getAnnotationId());
|
||||
matchingEntryFound = true;
|
||||
} catch (NotFoundException e) {
|
||||
requiresAnalysis = false;
|
||||
matchingEntryFound = false;
|
||||
}
|
||||
actionPerformed = actionPerformed || requiresAnalysis;
|
||||
if (!requiresAnalysis && idRemoval.isApproved()) {
|
||||
requiresReAnalysis = requiresReAnalysis || matchingEntryFound;
|
||||
if (!matchingEntryFound && idRemoval.isApproved()) {
|
||||
removeRedactionPersistenceService.markAsProcessed(idRemoval);
|
||||
}
|
||||
}
|
||||
@ -343,13 +311,13 @@ public class ManualRedactionService {
|
||||
removeRedactionPersistenceService.markAsProcessed(idRemoval);
|
||||
}
|
||||
|
||||
actionPerformed = actionPerformed || removedFromDictionary;
|
||||
requiresReAnalysis = requiresReAnalysis || removedFromDictionary;
|
||||
|
||||
response.add(ManualAddResponse.builder().annotationId(removeRedactionRequest.getAnnotationId()).commentId(commentId).build());
|
||||
}
|
||||
}
|
||||
|
||||
if (actionPerformed) {
|
||||
if (requiresReAnalysis) {
|
||||
reprocess(dossierId, fileId);
|
||||
}
|
||||
|
||||
@ -458,7 +426,7 @@ public class ManualRedactionService {
|
||||
|
||||
commentId = addComment(fileId, forceRedactionRequest.getAnnotationId(), forceRedactionRequest.getComment(), forceRedactionRequest.getUser()).getId();
|
||||
}
|
||||
actionPerformed = actionPerformed || AnnotationStatus.APPROVED.equals(forceRedactionRequest.getStatus());
|
||||
actionPerformed = actionPerformed || forceRedactionRequest.getStatus().equals(AnnotationStatus.APPROVED);
|
||||
response.add(ManualAddResponse.builder().annotationId(forceRedactionRequest.getAnnotationId()).commentId(commentId).build());
|
||||
}
|
||||
|
||||
@ -514,7 +482,7 @@ public class ManualRedactionService {
|
||||
imageRecategorizationRequest.getUser()).getId();
|
||||
}
|
||||
|
||||
actionPerformed = actionPerformed || !AnnotationStatus.REQUESTED.equals(imageRecategorizationRequest.getStatus());
|
||||
actionPerformed = actionPerformed || imageRecategorizationRequest.getStatus().equals(AnnotationStatus.APPROVED);
|
||||
|
||||
response.add(ManualAddResponse.builder().annotationId(imageRecategorizationRequest.getAnnotationId()).commentId(commentId).build());
|
||||
}
|
||||
@ -745,7 +713,10 @@ public class ManualRedactionService {
|
||||
addToDictionary(typeId, newValue, dossierId, fileId, dictionaryEntryType);
|
||||
typeIdsOfModifiedDictionaries.add(typeId);
|
||||
|
||||
resizeRedactionPersistenceService.updateStatus(resizeRedaction.getId().getFileId(), resizeRedaction.getId().getAnnotationId(), resizeRedaction.getStatus(), typeIdsOfModifiedDictionaries);
|
||||
resizeRedactionPersistenceService.updateStatus(resizeRedaction.getId().getFileId(),
|
||||
resizeRedaction.getId().getAnnotationId(),
|
||||
resizeRedaction.getStatus(),
|
||||
typeIdsOfModifiedDictionaries);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ManualAddResponse {
|
||||
|
||||
private String annotationId;
|
||||
private Long commentId;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user