|
|
|
|
@ -9,21 +9,17 @@ import com.iqser.red.service.redaction.v1.server.parsing.model.TextPositionSeque
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.redaction.model.Entity;
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.redaction.model.EntityPositionSequence;
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.redaction.model.Image;
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.redaction.model.ReasonHolder;
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.redaction.utils.IdBuilder;
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.AbstractTextContainer;
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Cell;
|
|
|
|
|
import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table;
|
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@ -71,7 +67,7 @@ public class RedactionLogCreatorService {
|
|
|
|
|
|
|
|
|
|
RedactionLogEntry redactionLogEntry = RedactionLogEntry.builder()
|
|
|
|
|
.id(id)
|
|
|
|
|
.color(getColorForImage(image, dossierTemplateId, false))
|
|
|
|
|
.color(getColorForImage(image.getType(), dossierTemplateId, false, image.isRedaction()))
|
|
|
|
|
.isImage(true)
|
|
|
|
|
.type(image.getType())
|
|
|
|
|
.redacted(image.isRedaction())
|
|
|
|
|
@ -89,117 +85,7 @@ public class RedactionLogCreatorService {
|
|
|
|
|
.section(image.getSection())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getImageRecategorizations().isEmpty()) {
|
|
|
|
|
for (ManualImageRecategorization recategorization : manualRedactions.getImageRecategorizations()) {
|
|
|
|
|
if (recategorization.getId().equals(id)) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (recategorization.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
image.setType(recategorization.getType());
|
|
|
|
|
image.setRedaction(recategorization.isRedacted());
|
|
|
|
|
image.setLegalBasis(recategorization.getLegalBasis());
|
|
|
|
|
redactionLogEntry.setType(recategorization.getType());
|
|
|
|
|
redactionLogEntry.setHint(dictionaryService.isHint(recategorization.getType(), dossierTemplateId));
|
|
|
|
|
redactionLogEntry.setRedacted(recategorization.isRedacted());
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
redactionLogEntry.setLegalBasis(recategorization.getLegalBasis());
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", recategorized by manual override";
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(image, dossierTemplateId, false));
|
|
|
|
|
} else if (recategorization.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", requested to recategorize";
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(image, dossierTemplateId, true));
|
|
|
|
|
redactionLogEntry.setRecategorizationType(recategorization.getType());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.RECATEGORIZE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getIdsToRemove().isEmpty()) {
|
|
|
|
|
for (IdRemoval manualRemoval : manualRedactions.getIdsToRemove()) {
|
|
|
|
|
if (manualRemoval.getId().equals(id)) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualRemoval.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
image.setRedaction(false);
|
|
|
|
|
redactionLogEntry.setRedacted(false);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", removed by manual override";
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(image, dossierTemplateId, false));
|
|
|
|
|
} else if (manualRemoval.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", requested to remove";
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(image, dossierTemplateId, true));
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.REMOVE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getForceRedacts().isEmpty()) {
|
|
|
|
|
for (ManualForceRedact manualForceRedact : manualRedactions.getForceRedacts()) {
|
|
|
|
|
if (manualForceRedact.getId().equals(id)) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualForceRedact.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
image.setRedaction(true);
|
|
|
|
|
redactionLogEntry.setRedacted(true);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(image, dossierTemplateId, false));
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", forced by manual override";
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else if (manualForceRedact.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", requested to force redact";
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(image, dossierTemplateId, true));
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.FORCE_REDACT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getManualLegalBasisChanges().isEmpty()) {
|
|
|
|
|
for (ManualLegalBasisChange manualLegalBasisChange : manualRedactions.getManualLegalBasisChanges()) {
|
|
|
|
|
if (manualLegalBasisChange.getId().equals(id)) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualLegalBasisChange.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", legal basis was manually changed";
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else if (manualLegalBasisChange.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = image.getRedactionReason() + ", legal basis change requested";
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(image, dossierTemplateId, true));
|
|
|
|
|
redactionLogEntry.setLegalBasisChangeValue(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.LEGAL_BASIS_CHANGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
processImageEntry(manualRedactions, dossierTemplateId, image, redactionLogEntry);
|
|
|
|
|
|
|
|
|
|
redactionLogEntities.add(redactionLogEntry);
|
|
|
|
|
}
|
|
|
|
|
@ -207,6 +93,118 @@ public class RedactionLogCreatorService {
|
|
|
|
|
return redactionLogEntities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void processImageEntry(ManualRedactions manualRedactions, String dossierTemplateId, ReasonHolder image, RedactionLogEntry redactionLogEntry) {
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getImageRecategorizations().isEmpty()) {
|
|
|
|
|
for (ManualImageRecategorization recategorization : manualRedactions.getImageRecategorizations()) {
|
|
|
|
|
if (recategorization.getId().equals(redactionLogEntry.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (recategorization.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
image.setRedaction(recategorization.isRedacted());
|
|
|
|
|
redactionLogEntry.setType(recategorization.getType());
|
|
|
|
|
redactionLogEntry.setHint(dictionaryService.isHint(recategorization.getType(), dossierTemplateId));
|
|
|
|
|
redactionLogEntry.setRedacted(recategorization.isRedacted());
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
redactionLogEntry.setLegalBasis(recategorization.getLegalBasis());
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", recategorized by manual override");
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted()));
|
|
|
|
|
} else if (recategorization.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", requested to recategorize");
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted()));
|
|
|
|
|
redactionLogEntry.setRecategorizationType(recategorization.getType());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.RECATEGORIZE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getIdsToRemove().isEmpty()) {
|
|
|
|
|
for (IdRemoval manualRemoval : manualRedactions.getIdsToRemove()) {
|
|
|
|
|
if (manualRemoval.getId().equals(redactionLogEntry.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualRemoval.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
image.setRedaction(false);
|
|
|
|
|
redactionLogEntry.setRedacted(false);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", removed by manual override");
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted()));
|
|
|
|
|
} else if (manualRemoval.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", requested to remove");
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted()));
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.REMOVE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getForceRedacts().isEmpty()) {
|
|
|
|
|
for (ManualForceRedact manualForceRedact : manualRedactions.getForceRedacts()) {
|
|
|
|
|
if (manualForceRedact.getId().equals(redactionLogEntry.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualForceRedact.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
image.setRedaction(true);
|
|
|
|
|
redactionLogEntry.setRedacted(true);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted()));
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", forced by manual override");
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else if (manualForceRedact.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", requested to force redact");
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted()));
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.FORCE_REDACT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getManualLegalBasisChanges().isEmpty()) {
|
|
|
|
|
for (ManualLegalBasisChange manualLegalBasisChange : manualRedactions.getManualLegalBasisChanges()) {
|
|
|
|
|
if (manualLegalBasisChange.getId().equals(redactionLogEntry.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualLegalBasisChange.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", legal basis was manually changed");
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else if (manualLegalBasisChange.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(image.getRedactionReason(), ", legal basis change requested");
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColorForImage(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted()));
|
|
|
|
|
redactionLogEntry.setLegalBasisChangeValue(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : image.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.LEGAL_BASIS_CHANGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Set<Integer> getManualRedactionPages(ManualRedactions manualRedactions) {
|
|
|
|
|
|
|
|
|
|
@ -236,7 +234,6 @@ public class RedactionLogCreatorService {
|
|
|
|
|
entityLoop:
|
|
|
|
|
for (Entity entity : entities.get(page)) {
|
|
|
|
|
|
|
|
|
|
List<Comment> comments = null;
|
|
|
|
|
|
|
|
|
|
for (EntityPositionSequence entityPositionSequence : entity.getPositionSequences()) {
|
|
|
|
|
|
|
|
|
|
@ -249,85 +246,8 @@ public class RedactionLogCreatorService {
|
|
|
|
|
processedIds.add(entityPositionSequence.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getIdsToRemove().isEmpty()) {
|
|
|
|
|
for (IdRemoval manualRemoval : manualRedactions.getIdsToRemove()) {
|
|
|
|
|
if (manualRemoval.getId().equals(entityPositionSequence.getId())) {
|
|
|
|
|
comments = manualRedactions.getComments().get(manualRemoval.getId());
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualRemoval.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
entity.setRedaction(false);
|
|
|
|
|
redactionLogEntry.setRedacted(false);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = entity.getRedactionReason() + ", removed by manual override";
|
|
|
|
|
redactionLogEntry.setColor(getColor(entity, dossierTemplateId, false));
|
|
|
|
|
} else if (manualRemoval.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = entity.getRedactionReason() + ", requested to remove";
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(entity, dossierTemplateId, true));
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : entity.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.REMOVE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getForceRedacts().isEmpty()) {
|
|
|
|
|
for (ManualForceRedact manualForceRedact : manualRedactions.getForceRedacts()) {
|
|
|
|
|
if (manualForceRedact.getId().equals(entityPositionSequence.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualForceRedact.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
entity.setRedaction(true);
|
|
|
|
|
redactionLogEntry.setRedacted(true);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(entity, dossierTemplateId, false));
|
|
|
|
|
manualOverrideReason = entity.getRedactionReason() + ", forced by manual override";
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else if (manualForceRedact.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = entity.getRedactionReason() + ", requested to force redact";
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(entity, dossierTemplateId, true));
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : entity.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.FORCE_REDACT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getManualLegalBasisChanges().isEmpty()) {
|
|
|
|
|
for (ManualLegalBasisChange manualLegalBasisChange : manualRedactions.getManualLegalBasisChanges()) {
|
|
|
|
|
if (manualLegalBasisChange.getId().equals(entityPositionSequence.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualLegalBasisChange.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = entity.getRedactionReason() + ", legal basis was manually changed";
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else if (manualLegalBasisChange.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = entity.getRedactionReason() + ", legal basis change requested";
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(entity, dossierTemplateId, true));
|
|
|
|
|
redactionLogEntry.setLegalBasisChangeValue(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : entity.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.LEGAL_BASIS_CHANGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
redactionLogEntry.setId(entityPositionSequence.getId());
|
|
|
|
|
processRedactionLogEntry(manualRedactions, dossierTemplateId, redactionLogEntry, entity);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(entityPositionSequence.getSequences())) {
|
|
|
|
|
List<Rectangle> rectanglesPerLine = getRectanglesPerLine(entityPositionSequence.getSequences()
|
|
|
|
|
@ -335,16 +255,11 @@ public class RedactionLogCreatorService {
|
|
|
|
|
.flatMap(seq -> seq.getTextPositions().stream())
|
|
|
|
|
.collect(Collectors.toList()), page);
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null) {
|
|
|
|
|
comments = manualRedactions.getComments().get(entityPositionSequence.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redactionLogEntry.setComments(comments);
|
|
|
|
|
redactionLogEntry.getPositions().addAll(rectanglesPerLine);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redactionLogEntry.setId(entityPositionSequence.getId());
|
|
|
|
|
|
|
|
|
|
// FIXME ids should never be null. Figure out why this happens.
|
|
|
|
|
if (redactionLogEntry.getId() != null) {
|
|
|
|
|
@ -356,6 +271,109 @@ public class RedactionLogCreatorService {
|
|
|
|
|
return redactionLogEntities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void processRedactionLogEntry(ManualRedactions manualRedactions, String dossierTemplateId, RedactionLogEntry redactionLogEntry, ReasonHolder reasonHolder) {
|
|
|
|
|
|
|
|
|
|
List<Comment> comments = null;
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getIdsToRemove().isEmpty()) {
|
|
|
|
|
for (IdRemoval manualRemoval : manualRedactions.getIdsToRemove()) {
|
|
|
|
|
if (manualRemoval.getId().equals(redactionLogEntry.getId())) {
|
|
|
|
|
comments = manualRedactions.getComments().get(manualRemoval.getId());
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualRemoval.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
reasonHolder.setRedaction(false);
|
|
|
|
|
redactionLogEntry.setRedacted(false);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(reasonHolder.getRedactionReason(), ", removed by manual override");
|
|
|
|
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted()));
|
|
|
|
|
} else if (manualRemoval.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(reasonHolder.getRedactionReason(), ", requested to remove");
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted()));
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reasonHolder.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : reasonHolder.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.REMOVE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getForceRedacts().isEmpty()) {
|
|
|
|
|
for (ManualForceRedact manualForceRedact : manualRedactions.getForceRedacts()) {
|
|
|
|
|
if (manualForceRedact.getId().equals(redactionLogEntry.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualForceRedact.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
reasonHolder.setRedaction(true);
|
|
|
|
|
redactionLogEntry.setRedacted(true);
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted()));
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(reasonHolder.getRedactionReason(), ", forced by manual override");
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else if (manualForceRedact.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(reasonHolder.getRedactionReason(), ", requested to force redact");
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted()));
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reasonHolder.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : reasonHolder.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.FORCE_REDACT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null && !manualRedactions.getManualLegalBasisChanges().isEmpty()) {
|
|
|
|
|
for (ManualLegalBasisChange manualLegalBasisChange : manualRedactions.getManualLegalBasisChanges()) {
|
|
|
|
|
if (manualLegalBasisChange.getId().equals(redactionLogEntry.getId())) {
|
|
|
|
|
String manualOverrideReason = null;
|
|
|
|
|
if (manualLegalBasisChange.getStatus().equals(Status.APPROVED)) {
|
|
|
|
|
redactionLogEntry.setStatus(Status.APPROVED);
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(reasonHolder.getRedactionReason(), ", legal basis was manually changed");
|
|
|
|
|
redactionLogEntry.setLegalBasis(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else if (manualLegalBasisChange.getStatus().equals(Status.REQUESTED)) {
|
|
|
|
|
manualOverrideReason = mergeReasonIfNecessary(reasonHolder.getRedactionReason(), ", legal basis change requested");
|
|
|
|
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
|
|
|
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted()));
|
|
|
|
|
redactionLogEntry.setLegalBasisChangeValue(manualLegalBasisChange.getLegalBasis());
|
|
|
|
|
} else {
|
|
|
|
|
redactionLogEntry.setStatus(Status.DECLINED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reasonHolder.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : reasonHolder.getRedactionReason());
|
|
|
|
|
redactionLogEntry.setReason(manualOverrideReason);
|
|
|
|
|
redactionLogEntry.setManual(true);
|
|
|
|
|
redactionLogEntry.setManualRedactionType(ManualRedactionType.LEGAL_BASIS_CHANGE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (manualRedactions != null) {
|
|
|
|
|
comments = manualRedactions.getComments().get(redactionLogEntry.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redactionLogEntry.setComments(comments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String mergeReasonIfNecessary(String currentReason, String addition) {
|
|
|
|
|
if (currentReason != null) {
|
|
|
|
|
if (!currentReason.contains(addition)) {
|
|
|
|
|
return currentReason + addition;
|
|
|
|
|
}
|
|
|
|
|
return currentReason;
|
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Rectangle> getRectanglesPerLine(List<RedTextPosition> textPositions, int page) {
|
|
|
|
|
|
|
|
|
|
@ -450,14 +468,14 @@ public class RedactionLogCreatorService {
|
|
|
|
|
private RedactionLogEntry createRedactionLogEntry(Entity entity, String dossierTemplateId) {
|
|
|
|
|
|
|
|
|
|
return RedactionLogEntry.builder()
|
|
|
|
|
.color(getColor(entity, dossierTemplateId, false))
|
|
|
|
|
.color(getColor(entity.getType(), dossierTemplateId, false, entity.isRedaction()))
|
|
|
|
|
.reason(entity.getRedactionReason())
|
|
|
|
|
.legalBasis(entity.getLegalBasis())
|
|
|
|
|
.value(entity.getWord())
|
|
|
|
|
.type(entity.getType())
|
|
|
|
|
.redacted(entity.isRedaction())
|
|
|
|
|
.isHint(isHint(entity, dossierTemplateId))
|
|
|
|
|
.isRecommendation(isRecommendation(entity, dossierTemplateId))
|
|
|
|
|
.isHint(isHint(entity.getType(), dossierTemplateId))
|
|
|
|
|
.isRecommendation(isRecommendation(entity.getType(), dossierTemplateId))
|
|
|
|
|
.section(entity.getHeadline())
|
|
|
|
|
.sectionNumber(entity.getSectionNumber())
|
|
|
|
|
.matchedRule(entity.getMatchedRule())
|
|
|
|
|
@ -471,15 +489,15 @@ public class RedactionLogCreatorService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private float[] getColor(Entity entity, String dossierTemplateId, boolean requestedToRemove) {
|
|
|
|
|
private float[] getColor(String type, String dossierTemplateId, boolean requestedToRemove, boolean isRedaction) {
|
|
|
|
|
|
|
|
|
|
if (requestedToRemove) {
|
|
|
|
|
return dictionaryService.getRequestRemoveColor(dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
if (!entity.isRedaction() && !isHint(entity, dossierTemplateId)) {
|
|
|
|
|
if (!isRedaction && !isHint(type, dossierTemplateId)) {
|
|
|
|
|
return dictionaryService.getNotRedactedColor(dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
return dictionaryService.getColor(entity.getType(), dossierTemplateId);
|
|
|
|
|
return dictionaryService.getColor(type, dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -500,27 +518,27 @@ public class RedactionLogCreatorService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private float[] getColorForImage(Image image, String dossierTemplateId, boolean requestedToRemove) {
|
|
|
|
|
private float[] getColorForImage(String type, String dossierTemplateId, boolean requestedToRemove, boolean isRedaction) {
|
|
|
|
|
|
|
|
|
|
if (requestedToRemove) {
|
|
|
|
|
return dictionaryService.getRequestRemoveColor(dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
if (!image.isRedaction() && !dictionaryService.isHint(image.getType(), dossierTemplateId)) {
|
|
|
|
|
if (!isRedaction && !dictionaryService.isHint(type, dossierTemplateId)) {
|
|
|
|
|
return dictionaryService.getNotRedactedColor(dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
return dictionaryService.getColor(image.getType(), dossierTemplateId);
|
|
|
|
|
return dictionaryService.getColor(type, dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isHint(Entity entity, String dossierTemplateId) {
|
|
|
|
|
private boolean isHint(String type, String dossierTemplateId) {
|
|
|
|
|
|
|
|
|
|
return dictionaryService.isHint(entity.getType(), dossierTemplateId);
|
|
|
|
|
return dictionaryService.isHint(type, dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isRecommendation(Entity entity, String dossierTemplateId) {
|
|
|
|
|
private boolean isRecommendation(String type, String dossierTemplateId) {
|
|
|
|
|
|
|
|
|
|
return dictionaryService.isRecommendation(entity.getType(), dossierTemplateId);
|
|
|
|
|
return dictionaryService.isRecommendation(type, dossierTemplateId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -567,4 +585,74 @@ public class RedactionLogCreatorService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RedactionLog getRedactionLogPreview(RedactionLog redactionLog, String dossierTemplateId, ManualRedactions manualRedactions) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var manualRedactionPages = getManualRedactionPages(manualRedactions);
|
|
|
|
|
|
|
|
|
|
// generate all manual entries
|
|
|
|
|
var manualRedactionLogEntries = new HashMap<String, RedactionLogEntry>();
|
|
|
|
|
for (var page : manualRedactionPages) {
|
|
|
|
|
|
|
|
|
|
var pageEntries = addManualAddEntries(manualRedactions.getEntriesToAdd(), manualRedactions.getComments(), page, dossierTemplateId);
|
|
|
|
|
|
|
|
|
|
for (var entry : pageEntries) {
|
|
|
|
|
manualRedactionLogEntries.put(entry.getId(), entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var manualEntry : manualRedactionLogEntries.values()) {
|
|
|
|
|
var existingEntry = redactionLog.getRedactionLogEntry().stream().filter(e -> e.getId().equals(manualEntry.getId())).findAny();
|
|
|
|
|
if (existingEntry.isPresent()) {
|
|
|
|
|
// if it has already been processed of sorts, update it
|
|
|
|
|
BeanUtils.copyProperties(manualEntry, existingEntry.get());
|
|
|
|
|
} else {
|
|
|
|
|
// not yet in the redaction-log - add it
|
|
|
|
|
redactionLog.getRedactionLogEntry().add(manualEntry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (RedactionLogEntry entry : redactionLog.getRedactionLogEntry()) {
|
|
|
|
|
|
|
|
|
|
var reasonHolder = new PreviewReasonHolder(entry);
|
|
|
|
|
|
|
|
|
|
if (entry.isImage()) {
|
|
|
|
|
processImageEntry(manualRedactions, dossierTemplateId, reasonHolder, entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
processRedactionLogEntry(manualRedactions, dossierTemplateId, entry, reasonHolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redactionLog;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class PreviewReasonHolder implements ReasonHolder {
|
|
|
|
|
|
|
|
|
|
private final RedactionLogEntry entry;
|
|
|
|
|
|
|
|
|
|
public PreviewReasonHolder(RedactionLogEntry entry) {
|
|
|
|
|
this.entry = entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRedactionReason() {
|
|
|
|
|
return entry.getReason();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setRedactionReason(String reason) {
|
|
|
|
|
entry.setReason(reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isRedaction() {
|
|
|
|
|
return entry.isRedacted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setRedaction(boolean value) {
|
|
|
|
|
entry.setRedacted(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|