RED-9140 - Add more information to changes

This commit is contained in:
Andrei Isvoran 2024-06-13 12:21:11 +03:00
parent 8d02fd4fdf
commit 1d9903c3bf
9 changed files with 79 additions and 36 deletions

View File

@ -48,6 +48,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualRedactionEntry;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualResizeRedaction;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.utils.ChangeUtils;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.service.EntityLogMongoService;
import io.micrometer.observation.annotation.Observed;
@ -281,7 +282,7 @@ public class EntityLogMergeService {
public EntityLogEntry buildEntityLogEntry(ManualRedactionEntry manualRedactionEntry, int analysisNumber, DossierEntity dossier) {
List<ManualChange> manualChanges = new ArrayList<>();
manualChanges.add(ManualChangeFactory.toLocalManualChange(manualRedactionEntry));
manualChanges.add(ManualChangeFactory.toLocalManualChange(manualRedactionEntry, 0);
List<Change> changes = new ArrayList<>();
changes.add(ChangeFactory.toChange(ChangeType.ADDED, manualRedactionEntry.getRequestDate(), analysisNumber));
@ -349,13 +350,15 @@ public class EntityLogMergeService {
entityLogEntry.setState(EntryState.IGNORED);
entityLogEntry.getEngines().add(Engine.MANUAL);
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(idRemoval));
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(idRemoval, 0));
}
public void mergeResizeRedaction(ManualResizeRedaction manualResizeRedaction, EntityLogEntry entityLogEntry, int analysisNumber) {
List<Change> changes = new ArrayList<>();
List<Position> currentPositions = entityLogEntry.getPositions();
List<Position> newPositions = convertPositions(manualResizeRedaction.getPositions());
changes.add(ChangeFactory.toChange(ChangeType.RESIZED,
manualResizeRedaction.getRequestDate(),
analysisNumber,
@ -369,15 +372,20 @@ public class EntityLogMergeService {
.oldValue(entityLogEntry.getTextBefore())
.newValue(manualResizeRedaction.getTextBefore())
.build(),
PropertyChange.builder().property("value").oldValue(entityLogEntry.getValue()).newValue(manualResizeRedaction.getValue()).build()));
PropertyChange.builder().property("value").oldValue(entityLogEntry.getValue()).newValue(manualResizeRedaction.getValue()).build(),
PropertyChange.builder()
.property("positions")
.oldValue(ChangeUtils.prettifyPositions(currentPositions))
.newValue(ChangeUtils.prettifyPositions(newPositions))
.build()));
addChanges(entityLogEntry, changes);
entityLogEntry.setTextAfter(manualResizeRedaction.getTextAfter());
entityLogEntry.setTextBefore(manualResizeRedaction.getTextBefore());
entityLogEntry.setPositions(convertPositions(manualResizeRedaction.getPositions()));
entityLogEntry.setPositions(newPositions);
entityLogEntry.setValue(manualResizeRedaction.getValue());
entityLogEntry.getEngines().add(Engine.MANUAL);
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(manualResizeRedaction));
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(manualResizeRedaction, 0));
}
@ -407,7 +415,7 @@ public class EntityLogMergeService {
entityLogEntry.setSection(manualLegalBasisChange.getSection());
entityLogEntry.setValue(manualLegalBasisChange.getValue());
entityLogEntry.getEngines().add(Engine.MANUAL);
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(manualLegalBasisChange));
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(manualLegalBasisChange, 0));
}
@ -466,7 +474,7 @@ public class EntityLogMergeService {
}
addChanges(entityLogEntry, changes);
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(recategorization));
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(recategorization, 0));
return null;
}
@ -489,7 +497,7 @@ public class EntityLogMergeService {
entityLogEntry.setState(newState);
entityLogEntry.getEngines().add(Engine.MANUAL);
addChanges(entityLogEntry, changes);
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(forceRedaction));
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(forceRedaction, 0));
}

View File

@ -208,7 +208,7 @@ public class PendingDictionaryEntryFactory {
public EntityLogEntry buildPendingImageRecategorizationEntry(ManualRecategorization manualChange, EntityLogEntry originalEntry) {
var manualChanges = List.of(ManualChangeFactory.toLocalManualChange(manualChange));
var manualChanges = List.of(ManualChangeFactory.toLocalManualChange(manualChange, 0));
String reason = String.format("Image has been recategorized from %s to %s", originalEntry.getType(), manualChange.getType());

View File

@ -15,6 +15,7 @@ import static org.mockito.Mockito.when;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@ -2378,7 +2379,7 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.dictionaryEntry(false)
.dossierDictionaryEntry(false)
.excluded(false)
.changes(List.of(new Change(1, ChangeType.ADDED, OffsetDateTime.now())))
.changes(List.of(new Change(1, ChangeType.ADDED, OffsetDateTime.now(), Collections.emptyMap())))
.build();
var entityLog = new EntityLog(1,
1,
@ -2447,7 +2448,7 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.dictionaryEntry(true)
.dossierDictionaryEntry(false)
.excluded(false)
.changes(List.of(new Change(1, ChangeType.ADDED, OffsetDateTime.now())))
.changes(List.of(new Change(1, ChangeType.ADDED, OffsetDateTime.now(), Collections.emptyMap())))
.engines(Set.of(Engine.DICTIONARY))
.build();
var entityLog = new EntityLog(1,

View File

@ -25,12 +25,13 @@ public class ManualChange {
private int processedAnalysisNumber;
public static ManualChange from(BaseAnnotation baseAnnotation) {
public static ManualChange from(BaseAnnotation baseAnnotation, int processedAnalysisNumber) {
ManualChange manualChange = new ManualChange();
manualChange.processedDate = baseAnnotation.getProcessedDate();
manualChange.requestedDate = baseAnnotation.getRequestDate();
manualChange.userId = baseAnnotation.getUser();
manualChange.processedAnalysisNumber = processedAnalysisNumber;
return manualChange;
}

View File

@ -61,4 +61,11 @@ public class Position {
return rectangle[3];
}
@Override
public String toString() {
return "[" + x() + ", " + y() + ", " + w() + ", " + h() + ", " + pageNumber + "]";
}
}

View File

@ -6,6 +6,7 @@ import java.util.Arrays;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Change;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.ChangeType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.PropertyChange;
import com.iqser.red.service.persistence.service.v1.api.shared.model.utils.ChangeUtils;
import lombok.experimental.UtilityClass;
@ -31,27 +32,9 @@ public class ChangeFactory {
Arrays.stream(propertyChanges)
.forEach(propertyChange -> {
if (!propertyChange.getOldValue().equals(propertyChange.getNewValue())) {
change.addChange(propertyChange.getProperty(), buildVisualChange(propertyChange.getOldValue(), propertyChange.getNewValue()));
change.addChange(propertyChange.getProperty(), ChangeUtils.buildVisualChange(propertyChange.getOldValue(), propertyChange.getNewValue()));
}
});
}
private String buildVisualChange(String oldValue, String newValue) {
String result = oldValue + " -> " + newValue;
if (result.length() > 200) {
if (oldValue.length() > 100) {
oldValue = oldValue.substring(0, 100) + "...";
}
if (newValue.length() > 100) {
newValue = newValue.substring(0, 100) + "...";
}
result = oldValue + " -> " + newValue;
}
return result;
}
}

View File

@ -20,10 +20,10 @@ import lombok.experimental.UtilityClass;
@UtilityClass
public class ManualChangeFactory {
public List<ManualChange> toLocalManualChangeList(List<BaseAnnotation> manualChanges, boolean markAsProcessed) {
public List<ManualChange> toLocalManualChangeList(List<BaseAnnotation> manualChanges, boolean markAsProcessed, int processedAnalysisNumber) {
return manualChanges.stream()
.map(ManualChangeFactory::toLocalManualChange)
.map(manualChange -> toLocalManualChange(manualChange, processedAnalysisNumber))
.peek(manualChange -> {
if (markAsProcessed) {
manualChange.setProcessedDate(OffsetDateTime.now());
@ -33,13 +33,13 @@ public class ManualChangeFactory {
}
public ManualChange toLocalManualChange(BaseAnnotation baseAnnotation) {
public ManualChange toLocalManualChange(BaseAnnotation baseAnnotation, int processedAnalysisNumber) {
if (!baseAnnotation.isLocal()) {
throw new IllegalArgumentException(String.format("Manual change %s is not a local manual change", baseAnnotation));
}
ManualChange manualChange = ManualChange.from(baseAnnotation);
ManualChange manualChange = ManualChange.from(baseAnnotation, processedAnalysisNumber);
if (baseAnnotation instanceof ManualRecategorization recategorization) {
manualChange.withManualRedactionType(ManualRedactionType.RECATEGORIZE)
.withChange("type", recategorization.getType())

View File

@ -1,6 +1,5 @@
package com.iqser.red.service.persistence.service.v1.api.shared.model.annotations;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualResizeRedaction;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.Point;
import lombok.AllArgsConstructor;

View File

@ -0,0 +1,44 @@
package com.iqser.red.service.persistence.service.v1.api.shared.model.utils;
import java.util.List;
import java.util.stream.Collectors;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Position;
import lombok.experimental.UtilityClass;
@UtilityClass
public class ChangeUtils {
public String buildVisualChange(String oldValue, String newValue) {
String result = oldValue + " -> " + newValue;
String shortenedOldValue = oldValue;
String shortenedNewValue = oldValue;
if (result.length() > 200) {
if (oldValue.length() > 100) {
shortenedOldValue = oldValue.substring(0, 100) + "...";
}
if (newValue.length() > 100) {
shortenedNewValue = newValue.substring(0, 100) + "...";
}
result = shortenedOldValue + " -> " + shortenedNewValue;
}
return result;
}
public String prettifyPositions(List<Position> positions) {
if (positions.size() == 1) {
return positions.get(0).toString();
} else {
return positions.stream()
.map(Position::toString)
.collect(Collectors.joining(", ", "[", "]"));
}
}
}