Merge branch 'RED-8347' into 'master'
RED-8347 - Add manual changes in entity log for removed entities Closes RED-8347 See merge request redactmanager/redaction-service!266
This commit is contained in:
commit
4d191d7bbd
@ -12,19 +12,26 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
|
|||||||
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.ChangeType;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLogEntry;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLogEntry;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryState;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryState;
|
||||||
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ManualRedactions;
|
||||||
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.IdRemoval;
|
||||||
|
|
||||||
import io.micrometer.core.annotation.Timed;
|
import io.micrometer.core.annotation.Timed;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.experimental.FieldDefaults;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@FieldDefaults(makeFinal=true, level= AccessLevel.PRIVATE)
|
||||||
public class EntityChangeLogService {
|
public class EntityChangeLogService {
|
||||||
|
|
||||||
|
ManualChangeFactory manualChangeFactory;
|
||||||
|
|
||||||
|
|
||||||
@Timed("redactmanager_computeChanges")
|
@Timed("redactmanager_computeChanges")
|
||||||
public boolean computeChanges(List<EntityLogEntry> previousEntityLogEntries, List<EntityLogEntry> newEntityLogEntries, int analysisNumber) {
|
public boolean computeChanges(List<EntityLogEntry> previousEntityLogEntries, List<EntityLogEntry> newEntityLogEntries, ManualRedactions manualRedactions, int analysisNumber) {
|
||||||
|
|
||||||
var now = OffsetDateTime.now();
|
var now = OffsetDateTime.now();
|
||||||
if (previousEntityLogEntries.isEmpty()) {
|
if (previousEntityLogEntries.isEmpty()) {
|
||||||
@ -49,13 +56,14 @@ public class EntityChangeLogService {
|
|||||||
entityLogEntry.getChanges().add(new Change(analysisNumber, changeType, now));
|
entityLogEntry.getChanges().add(new Change(analysisNumber, changeType, now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addRemovedEntriesAsRemoved(previousEntityLogEntries, newEntityLogEntries, analysisNumber, now);
|
addRemovedEntriesAsRemoved(previousEntityLogEntries, newEntityLogEntries, manualRedactions, analysisNumber, now);
|
||||||
return hasChanges;
|
return hasChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void addRemovedEntriesAsRemoved(List<EntityLogEntry> previousEntityLogEntries,
|
private void addRemovedEntriesAsRemoved(List<EntityLogEntry> previousEntityLogEntries,
|
||||||
List<EntityLogEntry> newEntityLogEntries,
|
List<EntityLogEntry> newEntityLogEntries,
|
||||||
|
ManualRedactions manualRedactions,
|
||||||
int analysisNumber,
|
int analysisNumber,
|
||||||
OffsetDateTime now) {
|
OffsetDateTime now) {
|
||||||
|
|
||||||
@ -65,10 +73,24 @@ public class EntityChangeLogService {
|
|||||||
.toList();
|
.toList();
|
||||||
removedEntries.forEach(entry -> entry.getChanges().add(new Change(analysisNumber, ChangeType.REMOVED, now)));
|
removedEntries.forEach(entry -> entry.getChanges().add(new Change(analysisNumber, ChangeType.REMOVED, now)));
|
||||||
removedEntries.forEach(entry -> entry.setState(EntryState.REMOVED));
|
removedEntries.forEach(entry -> entry.setState(EntryState.REMOVED));
|
||||||
|
removedEntries.forEach(entry -> addManualChangeForDictionaryRemovals(entry, manualRedactions));
|
||||||
newEntityLogEntries.addAll(removedEntries);
|
newEntityLogEntries.addAll(removedEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void addManualChangeForDictionaryRemovals(EntityLogEntry entry, ManualRedactions manualRedactions) {
|
||||||
|
|
||||||
|
if (manualRedactions == null || manualRedactions.getIdsToRemove().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
manualRedactions.getIdsToRemove().stream()
|
||||||
|
.filter(IdRemoval::isRemoveFromDictionary)//
|
||||||
|
.filter(removed -> removed.getAnnotationId().equals(entry.getId()))//
|
||||||
|
.findFirst()//
|
||||||
|
.ifPresent(idRemove -> entry.getManualChanges().add(manualChangeFactory.toManualChange(idRemove, false)));
|
||||||
|
}
|
||||||
|
|
||||||
private ChangeType calculateChangeType(EntryState state, EntryState previousState) {
|
private ChangeType calculateChangeType(EntryState state, EntryState previousState) {
|
||||||
|
|
||||||
if (state.equals(previousState)) {
|
if (state.equals(previousState)) {
|
||||||
|
|||||||
@ -77,7 +77,7 @@ public class EntityLogCreatorService {
|
|||||||
|
|
||||||
List<EntityLogEntry> previousExistingEntityLogEntries = getPreviousEntityLogEntries(analyzeRequest.getDossierId(), analyzeRequest.getFileId());
|
List<EntityLogEntry> previousExistingEntityLogEntries = getPreviousEntityLogEntries(analyzeRequest.getDossierId(), analyzeRequest.getFileId());
|
||||||
|
|
||||||
entityChangeLogService.computeChanges(previousExistingEntityLogEntries, entityLogEntries, analyzeRequest.getAnalysisNumber());
|
entityChangeLogService.computeChanges(previousExistingEntityLogEntries, entityLogEntries, analyzeRequest.getManualRedactions(), analyzeRequest.getAnalysisNumber());
|
||||||
|
|
||||||
return entityLog;
|
return entityLog;
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ public class EntityLogCreatorService {
|
|||||||
.toList();
|
.toList();
|
||||||
previousEntityLog.getEntityLogEntry().removeAll(previousEntriesFromReAnalyzedSections);
|
previousEntityLog.getEntityLogEntry().removeAll(previousEntriesFromReAnalyzedSections);
|
||||||
|
|
||||||
boolean hasChanges = entityChangeLogService.computeChanges(previousEntriesFromReAnalyzedSections, newEntityLogEntries, analyzeRequest.getAnalysisNumber());
|
boolean hasChanges = entityChangeLogService.computeChanges(previousEntriesFromReAnalyzedSections, newEntityLogEntries, analyzeRequest.getManualRedactions(), analyzeRequest.getAnalysisNumber());
|
||||||
previousEntityLog.getEntityLogEntry().addAll(newEntityLogEntries);
|
previousEntityLog.getEntityLogEntry().addAll(newEntityLogEntries);
|
||||||
|
|
||||||
return updateVersionsAndReturnChanges(previousEntityLog, dictionaryVersion, analyzeRequest, hasChanges);
|
return updateVersionsAndReturnChanges(previousEntityLog, dictionaryVersion, analyzeRequest, hasChanges);
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public class ManualChangeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private ManualChange toManualChange(BaseAnnotation baseAnnotation, boolean isHint) {
|
public ManualChange toManualChange(BaseAnnotation baseAnnotation, boolean isHint) {
|
||||||
|
|
||||||
ManualChange manualChange = ManualChange.from(baseAnnotation);
|
ManualChange manualChange = ManualChange.from(baseAnnotation);
|
||||||
if (baseAnnotation instanceof ManualRecategorization imageRecategorization) {
|
if (baseAnnotation instanceof ManualRecategorization imageRecategorization) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user