Pull request #194: RED-3241: Added LastManualRedaction time to annoationModificationDate

Merge in RED/persistence-service from RED-3241 to master

* commit '43b264263e3dd26f93b36457fdae530fcf7fbf4f':
  RED-3241: Added LastManualRedaction time to annoationModificationDate
This commit is contained in:
Dominique Eiflaender 2022-01-25 13:30:43 +01:00 committed by Ali Oezyetimoglu
commit fc09c71b86
2 changed files with 34 additions and 40 deletions

View File

@ -5,6 +5,7 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.ViewedPagesPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import com.iqser.red.service.redaction.v1.model.RedactionLogEntry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
@ -24,7 +25,6 @@ public class AnalysisFlagsCalculationService {
private final RedactionLogService redactionLogService;
private final ViewedPagesPersistenceService viewedPagesPersistenceService;
@Async
public void calculateFlags(String dossierId, String fileId) {
@ -76,7 +76,7 @@ public class AnalysisFlagsCalculationService {
var lastChange = entry.getChanges().isEmpty() ? null : entry.getChanges().get(entry.getChanges().size() - 1);
if(lastModification == null || lastChange.getDateTime().isAfter(lastModification)){
if(lastChange != null && (lastModification == null || lastChange.getDateTime().isAfter(lastModification))){
lastModification = lastChange.getDateTime();
}
@ -101,15 +101,23 @@ public class AnalysisFlagsCalculationService {
fileStatusPersistenceService.updateFlags(fileId, hasRedactions, hasHints, hasImages, hasSuggestions, hasComments, hasUpdates);
}
if(file.getAnnotationModificationDate() == null || file.getAnnotationModificationDate().isBefore(lastModification)) {
fileStatusPersistenceService.setLastAnnotationModificationDateForFile(fileId, lastModification);
OffsetDateTime lastManualRedactionTime = file.getLastManualRedaction();
if(lastModification == null || lastManualRedactionTime.isAfter(lastModification)){
lastModification = lastManualRedactionTime;
}
if(lastModification != null && (file.getAnnotationModificationDate() == null || file.getAnnotationModificationDate().isBefore(lastModification))) {
fileStatusPersistenceService.setLastAnnotationModificationDateForFile(fileId, lastModification);
}
}
private String getType(String typeId) {
return typeId.split(":")[0];
}
}

View File

@ -20,9 +20,11 @@ import com.iqser.red.service.redaction.v1.model.AnalyzeRequest;
import com.iqser.red.service.redaction.v1.model.MessageType;
import com.iqser.red.service.redaction.v1.model.RedactionLog;
import com.iqser.red.service.redaction.v1.model.RedactionLogEntry;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
@ -86,12 +88,10 @@ public class ManualRedactionService {
Long commentId = null;
if (addRedactionRequest.getComment() != null) {
commentId = addComment(fileId, annotationId, addRedactionRequest.getComment(), addRedactionRequest.getUser())
.getId();
commentId = addComment(fileId, annotationId, addRedactionRequest.getComment(), addRedactionRequest.getUser()).getId();
}
handleAddToDictionary(fileId, annotationId, addRedactionRequest.getTypeId(), addRedactionRequest.getValue(), addRedactionRequest
.getStatus(), addRedactionRequest.isAddToDictionary(), addRedactionRequest.isAddToDossierDictionary(), false, dossierId);
handleAddToDictionary(fileId, annotationId, addRedactionRequest.getTypeId(), addRedactionRequest.getValue(), addRedactionRequest.getStatus(), addRedactionRequest.isAddToDictionary(), addRedactionRequest.isAddToDossierDictionary(), false, dossierId);
if (addRedactionRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
fileStatusPersistenceService.setUpdateLastManualRedactionAndHasSuggestions(fileId, now, true);
@ -99,12 +99,9 @@ public class ManualRedactionService {
fileStatusPersistenceService.updateLastManualRedaction(fileId, now);
}
if (!addRedactionRequest.getPositions().isEmpty()) {
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
if (!addRedactionRequest.isAddToDictionary() && !addRedactionRequest.isAddToDossierDictionary() && !addRedactionRequest
.isRectangle()) {
if (!addRedactionRequest.isAddToDictionary() && !addRedactionRequest.isAddToDossierDictionary() && !addRedactionRequest.isRectangle()) {
var loaded = convert(getAddRedaction(fileId, annotationId), ManualRedactionEntry.class, new ManualRedactionMapper());
ManualRedactions manualRedactions = ManualRedactions.builder().entriesToAdd(Set.of(loaded)).build();
addManualRedactionToAnalysisQueue(dossierId, fileId, manualRedactions);
@ -125,12 +122,10 @@ public class ManualRedactionService {
Long commentId = null;
if (removeRedactionRequest.getComment() != null) {
commentId = addComment(fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getComment(), removeRedactionRequest
.getUser()).getId();
commentId = addComment(fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getComment(), removeRedactionRequest.getUser()).getId();
}
handleRemoveFromDictionary(dossierId, fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getStatus(), removeRedactionRequest
.isRemoveFromDictionary(), false);
handleRemoveFromDictionary(dossierId, fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getStatus(), removeRedactionRequest.isRemoveFromDictionary(), false);
if (removeRedactionRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
fileStatusPersistenceService.setUpdateLastManualRedactionAndHasSuggestions(fileId, now, true);
@ -164,8 +159,7 @@ public class ManualRedactionService {
Long commentId = null;
if (forceRedactionRequest.getComment() != null) {
commentId = addComment(fileId, forceRedactionRequest.getAnnotationId(), forceRedactionRequest.getComment(), forceRedactionRequest
.getUser()).getId();
commentId = addComment(fileId, forceRedactionRequest.getAnnotationId(), forceRedactionRequest.getComment(), forceRedactionRequest.getUser()).getId();
}
if (forceRedactionRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
@ -198,8 +192,7 @@ public class ManualRedactionService {
Long commentId = null;
if (legalBasisChangeRequest.getComment() != null) {
commentId = addComment(fileId, legalBasisChangeRequest.getAnnotationId(), legalBasisChangeRequest.getComment(), legalBasisChangeRequest
.getUser()).getId();
commentId = addComment(fileId, legalBasisChangeRequest.getAnnotationId(), legalBasisChangeRequest.getComment(), legalBasisChangeRequest.getUser()).getId();
}
if (legalBasisChangeRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
@ -228,8 +221,7 @@ public class ManualRedactionService {
Long commentId = null;
if (imageRecategorizationRequest.getComment() != null) {
commentId = addComment(fileId, imageRecategorizationRequest.getAnnotationId(), imageRecategorizationRequest.getComment(), imageRecategorizationRequest
.getUser()).getId();
commentId = addComment(fileId, imageRecategorizationRequest.getAnnotationId(), imageRecategorizationRequest.getComment(), imageRecategorizationRequest.getUser()).getId();
}
if (imageRecategorizationRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
@ -270,8 +262,7 @@ public class ManualRedactionService {
Long commentId = null;
if (resizeRedactionRequest.getComment() != null) {
commentId = addComment(fileId, resizeRedactionRequest.getAnnotationId(), resizeRedactionRequest.getComment(), resizeRedactionRequest
.getUser()).getId();
commentId = addComment(fileId, resizeRedactionRequest.getAnnotationId(), resizeRedactionRequest.getComment(), resizeRedactionRequest.getUser()).getId();
}
if (resizeRedactionRequest.getStatus().equals(AnnotationStatus.REQUESTED)) {
@ -340,8 +331,7 @@ public class ManualRedactionService {
var addRedaction = getAddRedaction(fileId, annotationId);
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
handleAddToDictionary(fileId, annotationId, addRedaction.getTypeId(), addRedaction.getValue(), addRedaction.getStatus(), addRedaction
.isAddToDictionary(), addRedaction.isAddToDossierDictionary(), true, dossier.getId());
handleAddToDictionary(fileId, annotationId, addRedaction.getTypeId(), addRedaction.getValue(), addRedaction.getStatus(), addRedaction.isAddToDictionary(), addRedaction.isAddToDossierDictionary(), true, dossier.getId());
addRedactionPersistenceService.softDelete(fileId, annotationId, OffsetDateTime.now());
@ -352,9 +342,8 @@ public class ManualRedactionService {
fileStatusPersistenceService.updateLastManualRedaction(fileId, OffsetDateTime.now());
}
if (!addRedaction.getPositions().isEmpty()) {
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
@ -555,7 +544,6 @@ public class ManualRedactionService {
dossierPersistenceService.getAndValidateDossier(dossierId);
ManualRedactionEntryEntity manualRedactionEntry = addRedactionPersistenceService.findAddRedaction(fileId, annotationId);
boolean hasPositions = !manualRedactionEntry.getPositions().isEmpty();
if (manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary()) {
if (annotationStatus == AnnotationStatus.APPROVED) {
addToDictionary(manualRedactionEntry.getTypeId(), manualRedactionEntry.getValue(), dossierId, fileId);
@ -571,9 +559,8 @@ public class ManualRedactionService {
boolean hasSuggestions = calculateHasSuggestions(fileId);
fileStatusPersistenceService.setUpdateLastManualRedactionAndHasSuggestions(fileId, OffsetDateTime.now(), hasSuggestions);
if (hasPositions) {
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
@ -594,8 +581,9 @@ public class ManualRedactionService {
}
private void handleAddToDictionary(String fileId, String annotationId, String typeId, String value, AnnotationStatus status,
boolean addToDictionary, boolean addToDossierDictionary, boolean revert, String dossierId) {
private void handleAddToDictionary(String fileId, String annotationId, String typeId, String value,
AnnotationStatus status, boolean addToDictionary, boolean addToDossierDictionary,
boolean revert, String dossierId) {
if (status == AnnotationStatus.APPROVED) {
addRedactionPersistenceService.updateStatus(fileId, annotationId, status, addToDictionary, addToDossierDictionary);
@ -726,13 +714,11 @@ public class ManualRedactionService {
public void updateManualRedactions(String fileId, ManualRedactions manualRedactions) {
manualRedactions.getEntriesToAdd().forEach(e -> {
addRedactionPersistenceService.updateSurroundingText(new AnnotationEntityId(e.getAnnotationId(), fileId), e.getTextBefore(), e
.getTextAfter());
addRedactionPersistenceService.updateSurroundingText(new AnnotationEntityId(e.getAnnotationId(), fileId), e.getTextBefore(), e.getTextAfter());
});
manualRedactions.getResizeRedactions().forEach(e -> {
resizeRedactionPersistenceService.updateSurroundingText(new AnnotationEntityId(e.getAnnotationId(), fileId), e
.getTextBefore(), e.getTextAfter());
resizeRedactionPersistenceService.updateSurroundingText(new AnnotationEntityId(e.getAnnotationId(), fileId), e.getTextBefore(), e.getTextAfter());
});
}