Pull request #474: RED-4496: Fixed missing dictionary version update after update dictionary at resize redactions
Merge in RED/persistence-service from RED-4496 to master * commit '336ea7a5305c437de0dcf62c223c27c5927753d0': RED-4496: Fixed missing dictionary version update after update dictionary at resize redactions
This commit is contained in:
commit
b83ad16ee7
@ -7,7 +7,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -41,7 +40,6 @@ import com.iqser.red.service.persistence.management.v1.processor.exception.NotFo
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierTemplatePersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.EntryPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.AddRedactionPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.CommentPersistenceService;
|
||||
@ -96,7 +94,6 @@ public class ManualRedactionService {
|
||||
private final StopwordService stopwordService;
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final EntryPersistenceService entryPersistenceService;
|
||||
private final RedactionLogService redactionLogService;
|
||||
|
||||
private final HashFunction hashFunction = Hashing.murmur3_128();
|
||||
@ -486,33 +483,14 @@ public class ManualRedactionService {
|
||||
List<ResizeRedactionRequest> resizeRedactionRequests) {
|
||||
|
||||
var response = new ArrayList<ManualAddResponse>();
|
||||
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
|
||||
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId, true, true);
|
||||
|
||||
for (ResizeRedactionRequest resizeRedactionRequest : resizeRedactionRequests) {
|
||||
resizeRedactionPersistenceService.insert(fileId, resizeRedactionRequest);
|
||||
|
||||
if (resizeRedactionRequest.getUpdateDictionary() != null && resizeRedactionRequest.getUpdateDictionary()) {
|
||||
if (resizeRedactionRequest.getUpdateDictionary() != null && resizeRedactionRequest.getUpdateDictionary() && resizeRedactionRequest.getStatus()
|
||||
.equals(AnnotationStatus.APPROVED)) {
|
||||
|
||||
Optional<RedactionLogEntry> redactionLogEntry = redactionLog.getRedactionLogEntry()
|
||||
.stream()
|
||||
.filter(r -> r.getId().equals(resizeRedactionRequest.getAnnotationId()))
|
||||
.findFirst();
|
||||
if (redactionLogEntry.isPresent() && (redactionLogEntry.get()
|
||||
.isDictionaryEntry() || redactionLogEntry.get().isDossierDictionaryEntry())) {
|
||||
|
||||
String typeId = redactionLogEntry.get().getType() + ":" + dossier.getDossierTemplateId();
|
||||
|
||||
if (redactionLogEntry.get().getValue().length() > resizeRedactionRequest.getValue().length()) {
|
||||
log.info("Remove old value '{}' from dictionary", redactionLogEntry.get().getValue());
|
||||
entryPersistenceService.deleteEntries(typeId, List.of(redactionLogEntry.get()
|
||||
.getValue()), redactionLog.getAnalysisVersion(), DictionaryEntryType.ENTRY);
|
||||
}
|
||||
|
||||
log.info("Add new value '{}' to dictionary", resizeRedactionRequest.getValue());
|
||||
entryPersistenceService.addEntries(typeId, new HashSet<>(Collections.singleton(resizeRedactionRequest.getValue())), redactionLog.getAnalysisVersion(), DictionaryEntryType.ENTRY);
|
||||
}
|
||||
updateDictionaryForResizeRedactions(dossierId, fileId, resizeRedactionRequest.getAnnotationId(), resizeRedactionRequest.getValue());
|
||||
}
|
||||
|
||||
Long commentId = null;
|
||||
@ -535,6 +513,44 @@ public class ManualRedactionService {
|
||||
}
|
||||
|
||||
|
||||
private void updateDictionaryForResizeRedactions(String dossierId, String fileId, String annotationId,
|
||||
String newValue) {
|
||||
|
||||
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId, true, true);
|
||||
|
||||
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
|
||||
Optional<RedactionLogEntry> redactionLogEntry = redactionLog.getRedactionLogEntry()
|
||||
.stream()
|
||||
.filter(r -> r.getId().equals(annotationId))
|
||||
.findFirst();
|
||||
if (redactionLogEntry.isPresent() && (redactionLogEntry.get().isDictionaryEntry() || redactionLogEntry.get()
|
||||
.isDossierDictionaryEntry())) {
|
||||
|
||||
if (redactionLogEntry.get().getValue().length() > newValue.length()) {
|
||||
log.info("Remove old value '{}' from dictionary", redactionLogEntry.get().getValue());
|
||||
removeFromDictionary(buildTypeId(redactionLogEntry.get(), dossier), redactionLogEntry.get()
|
||||
.getValue(), dossierId, fileId, getDictionaryEntryType(redactionLogEntry.get()));
|
||||
}
|
||||
|
||||
log.info("Add new value '{}' to dictionary", newValue);
|
||||
addToDictionary(buildTypeId(redactionLogEntry.get(), dossier), newValue, dossierId, fileId, getDictionaryEntryType(redactionLogEntry.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DictionaryEntryType getDictionaryEntryType(RedactionLogEntry redactionLogEntry) {
|
||||
|
||||
if (redactionLogEntry.isRecommendation() && redactionLogEntry.isFalsePositive()) {
|
||||
return DictionaryEntryType.FALSE_RECOMMENDATION;
|
||||
} else if (redactionLogEntry.isFalsePositive()) {
|
||||
return DictionaryEntryType.FALSE_POSITIVE;
|
||||
} else {
|
||||
return DictionaryEntryType.ENTRY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("PMD")
|
||||
public void updateRemoveRedactionStatus(String dossierId, String fileId, List<String> annotationIds,
|
||||
AnnotationStatus annotationStatus) {
|
||||
@ -641,6 +657,12 @@ public class ManualRedactionService {
|
||||
|
||||
dossierPersistenceService.getAndValidateDossier(dossierId);
|
||||
for (var annotationId : annotationIds) {
|
||||
|
||||
var resizeRedaction = resizeRedactionPersistenceService.findResizeRedaction(fileId, annotationId);
|
||||
if (resizeRedaction.getUpdateDictionary() != null && resizeRedaction.getUpdateDictionary() && annotationStatus.equals(AnnotationStatus.APPROVED)) {
|
||||
updateDictionaryForResizeRedactions(dossierId, fileId, annotationId, resizeRedaction.getValue());
|
||||
}
|
||||
|
||||
resizeRedactionPersistenceService.updateStatus(fileId, annotationId, annotationStatus);
|
||||
}
|
||||
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user