RED-2015: Fixed (Manual) Redactions in download reports/files for excluded pages
This commit is contained in:
parent
b2acdc646d
commit
9650ff75ca
@ -1,5 +1,8 @@
|
|||||||
package com.iqser.red.service.redaction.v1.model;
|
package com.iqser.red.service.redaction.v1.model;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -15,4 +18,6 @@ public class RedactionRequest {
|
|||||||
private String fileId;
|
private String fileId;
|
||||||
private String dossierTemplateId;
|
private String dossierTemplateId;
|
||||||
private ManualRedactions manualRedactions;
|
private ManualRedactions manualRedactions;
|
||||||
|
@Builder.Default
|
||||||
|
private Set<Integer> excludedPages = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,7 +159,7 @@ public class RedactionController implements RedactionResource {
|
|||||||
// old redaction logs are returned directly
|
// old redaction logs are returned directly
|
||||||
return redactionLog;
|
return redactionLog;
|
||||||
} else {
|
} else {
|
||||||
return redactionLogMergeService.mergeRedactionLogData(redactionLog, redactionRequest.getDossierTemplateId(), redactionRequest.getManualRedactions());
|
return redactionLogMergeService.mergeRedactionLogData(redactionLog, redactionRequest.getDossierTemplateId(), redactionRequest.getManualRedactions(), redactionRequest.getExcludedPages());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -311,9 +311,11 @@ public class ReanalyzeService {
|
|||||||
|
|
||||||
private void excludeExcludedPages(RedactionLog redactionLog, Set<Integer> excludedPages) {
|
private void excludeExcludedPages(RedactionLog redactionLog, Set<Integer> excludedPages) {
|
||||||
|
|
||||||
redactionLog.getRedactionLogEntry()
|
if(excludedPages != null && !excludedPages.isEmpty()) {
|
||||||
.forEach(entry -> entry.getPositions()
|
redactionLog.getRedactionLogEntry().forEach(entry -> entry.getPositions().forEach(pos -> { if (excludedPages.contains(pos.getPage())) {
|
||||||
.forEach(pos -> entry.setExcluded(excludedPages != null && excludedPages.contains(pos.getPage()))));
|
entry.setExcluded(true);
|
||||||
|
}}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,31 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.redaction.service;
|
package com.iqser.red.service.redaction.v1.server.redaction.service;
|
||||||
|
|
||||||
import com.iqser.red.service.file.management.v1.api.model.manual.ForceRedactionRequest;
|
import java.time.OffsetDateTime;
|
||||||
import com.iqser.red.service.redaction.v1.model.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.iqser.red.service.redaction.v1.model.Comment;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.IdRemoval;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.ManualForceRedact;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.ManualImageRecategorization;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.ManualLegalBasisChange;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.ManualRedactionEntry;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.ManualRedactionType;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.ManualRedactions;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.RedactionLog;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.RedactionLogEntry;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.Status;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.kie.api.definition.rule.All;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -21,7 +35,8 @@ public class RedactionLogMergeService {
|
|||||||
private final DictionaryService dictionaryService;
|
private final DictionaryService dictionaryService;
|
||||||
|
|
||||||
|
|
||||||
public RedactionLog mergeRedactionLogData(RedactionLog redactionLog, String dossierTemplateId, ManualRedactions manualRedactions) {
|
public RedactionLog mergeRedactionLogData(RedactionLog redactionLog, String dossierTemplateId,
|
||||||
|
ManualRedactions manualRedactions, Set<Integer> excludedPages) {
|
||||||
|
|
||||||
log.info("Merging Redaction log with manual redactions {}", manualRedactions);
|
log.info("Merging Redaction log with manual redactions {}", manualRedactions);
|
||||||
if (manualRedactions != null) {
|
if (manualRedactions != null) {
|
||||||
@ -34,10 +49,19 @@ public class RedactionLogMergeService {
|
|||||||
|
|
||||||
for (RedactionLogEntry entry : redactionLog.getRedactionLogEntry()) {
|
for (RedactionLogEntry entry : redactionLog.getRedactionLogEntry()) {
|
||||||
|
|
||||||
processRedactionLogEntry(manualRedactionWrappers.stream().filter(mr -> entry.getId().equals(mr.getId()))
|
processRedactionLogEntry(manualRedactionWrappers.stream()
|
||||||
|
.filter(mr -> entry.getId().equals(mr.getId()))
|
||||||
.collect(Collectors.toList()), dossierTemplateId, entry);
|
.collect(Collectors.toList()), dossierTemplateId, entry);
|
||||||
|
|
||||||
entry.setComments(manualRedactions.getComments().get(entry.getId()));
|
entry.setComments(manualRedactions.getComments().get(entry.getId()));
|
||||||
|
|
||||||
|
if (excludedPages != null && !excludedPages.isEmpty()) {
|
||||||
|
entry.getPositions().forEach(pos -> {
|
||||||
|
if (excludedPages.contains(pos.getPage())) {
|
||||||
|
entry.setExcluded(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -47,8 +71,7 @@ public class RedactionLogMergeService {
|
|||||||
|
|
||||||
|
|
||||||
private List<ManualRedactionWrapper> createManualRedactionWrappers(ManualRedactions manualRedactions) {
|
private List<ManualRedactionWrapper> createManualRedactionWrappers(ManualRedactions manualRedactions) {
|
||||||
|
|
||||||
|
|
||||||
List<ManualRedactionWrapper> manualRedactionWrappers = new ArrayList<>();
|
List<ManualRedactionWrapper> manualRedactionWrappers = new ArrayList<>();
|
||||||
|
|
||||||
manualRedactions.getImageRecategorizations().forEach(item -> {
|
manualRedactions.getImageRecategorizations().forEach(item -> {
|
||||||
@ -75,16 +98,14 @@ public class RedactionLogMergeService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Collections.sort(manualRedactionWrappers);
|
Collections.sort(manualRedactionWrappers);
|
||||||
|
|
||||||
return manualRedactionWrappers;
|
return manualRedactionWrappers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRedactionLogEntry(List<ManualRedactionWrapper> manualRedactionWrappers, String dossierTemplateId, RedactionLogEntry redactionLogEntry) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void processRedactionLogEntry(List<ManualRedactionWrapper> manualRedactionWrappers,
|
||||||
|
String dossierTemplateId, RedactionLogEntry redactionLogEntry) {
|
||||||
|
|
||||||
manualRedactionWrappers.forEach(mrw -> {
|
manualRedactionWrappers.forEach(mrw -> {
|
||||||
|
|
||||||
@ -98,7 +119,8 @@ public class RedactionLogMergeService {
|
|||||||
} else if (imageRecategorization.getStatus().equals(Status.REQUESTED)) {
|
} else if (imageRecategorization.getStatus().equals(Status.REQUESTED)) {
|
||||||
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", requested to recategorize");
|
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", requested to recategorize");
|
||||||
redactionLogEntry.setStatus(Status.REQUESTED);
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
||||||
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted(), false));
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry
|
||||||
|
.isRedacted(), false));
|
||||||
redactionLogEntry.setRecategorizationType(imageRecategorization.getType());
|
redactionLogEntry.setRecategorizationType(imageRecategorization.getType());
|
||||||
} else {
|
} else {
|
||||||
redactionLogEntry.setStatus(Status.DECLINED);
|
redactionLogEntry.setStatus(Status.DECLINED);
|
||||||
@ -117,11 +139,13 @@ public class RedactionLogMergeService {
|
|||||||
redactionLogEntry.setRedacted(false);
|
redactionLogEntry.setRedacted(false);
|
||||||
redactionLogEntry.setStatus(Status.APPROVED);
|
redactionLogEntry.setStatus(Status.APPROVED);
|
||||||
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", removed by manual override");
|
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", removed by manual override");
|
||||||
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted(), true));
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry
|
||||||
|
.isRedacted(), true));
|
||||||
} else if (manualRemoval.getStatus().equals(Status.REQUESTED)) {
|
} else if (manualRemoval.getStatus().equals(Status.REQUESTED)) {
|
||||||
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", requested to remove");
|
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", requested to remove");
|
||||||
redactionLogEntry.setStatus(Status.REQUESTED);
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
||||||
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted(), false));
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry
|
||||||
|
.isRedacted(), false));
|
||||||
} else {
|
} else {
|
||||||
redactionLogEntry.setStatus(Status.DECLINED);
|
redactionLogEntry.setStatus(Status.DECLINED);
|
||||||
}
|
}
|
||||||
@ -134,20 +158,21 @@ public class RedactionLogMergeService {
|
|||||||
redactionLogEntry.setDossierDictionaryEntry(manualRemoval.isRemoveFromDictionary());
|
redactionLogEntry.setDossierDictionaryEntry(manualRemoval.isRemoveFromDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (mrw.getItem() instanceof ManualForceRedact) {
|
if (mrw.getItem() instanceof ManualForceRedact) {
|
||||||
var manualForceRedact = (ManualForceRedact) mrw.getItem();
|
var manualForceRedact = (ManualForceRedact) mrw.getItem();
|
||||||
String manualOverrideReason = null;
|
String manualOverrideReason = null;
|
||||||
if (manualForceRedact.getStatus().equals(Status.APPROVED)) {
|
if (manualForceRedact.getStatus().equals(Status.APPROVED)) {
|
||||||
redactionLogEntry.setRedacted(true);
|
redactionLogEntry.setRedacted(true);
|
||||||
redactionLogEntry.setStatus(Status.APPROVED);
|
redactionLogEntry.setStatus(Status.APPROVED);
|
||||||
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry.isRedacted(), false));
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, false, redactionLogEntry
|
||||||
|
.isRedacted(), false));
|
||||||
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", forced by manual override");
|
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", forced by manual override");
|
||||||
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
||||||
} else if (manualForceRedact.getStatus().equals(Status.REQUESTED)) {
|
} else if (manualForceRedact.getStatus().equals(Status.REQUESTED)) {
|
||||||
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", requested to force redact");
|
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", requested to force redact");
|
||||||
redactionLogEntry.setStatus(Status.REQUESTED);
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
||||||
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted(), false));
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry
|
||||||
|
.isRedacted(), false));
|
||||||
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
redactionLogEntry.setLegalBasis(manualForceRedact.getLegalBasis());
|
||||||
} else {
|
} else {
|
||||||
redactionLogEntry.setStatus(Status.DECLINED);
|
redactionLogEntry.setStatus(Status.DECLINED);
|
||||||
@ -170,7 +195,8 @@ public class RedactionLogMergeService {
|
|||||||
} else if (manualLegalBasisChange.getStatus().equals(Status.REQUESTED)) {
|
} else if (manualLegalBasisChange.getStatus().equals(Status.REQUESTED)) {
|
||||||
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", legal basis change requested");
|
manualOverrideReason = mergeReasonIfNecessary(redactionLogEntry.getReason(), ", legal basis change requested");
|
||||||
redactionLogEntry.setStatus(Status.REQUESTED);
|
redactionLogEntry.setStatus(Status.REQUESTED);
|
||||||
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry.isRedacted(), false));
|
redactionLogEntry.setColor(getColor(redactionLogEntry.getType(), dossierTemplateId, true, redactionLogEntry
|
||||||
|
.isRedacted(), false));
|
||||||
redactionLogEntry.setLegalBasisChangeValue(manualLegalBasisChange.getLegalBasis());
|
redactionLogEntry.setLegalBasisChangeValue(manualLegalBasisChange.getLegalBasis());
|
||||||
} else {
|
} else {
|
||||||
redactionLogEntry.setStatus(Status.DECLINED);
|
redactionLogEntry.setStatus(Status.DECLINED);
|
||||||
@ -186,7 +212,9 @@ public class RedactionLogMergeService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String mergeReasonIfNecessary(String currentReason, String addition) {
|
private String mergeReasonIfNecessary(String currentReason, String addition) {
|
||||||
|
|
||||||
if (currentReason != null) {
|
if (currentReason != null) {
|
||||||
if (!currentReason.contains(addition)) {
|
if (!currentReason.contains(addition)) {
|
||||||
return currentReason + addition;
|
return currentReason + addition;
|
||||||
@ -198,14 +226,16 @@ public class RedactionLogMergeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<RedactionLogEntry> addManualAddEntries(Set<ManualRedactionEntry> manualAdds, Map<String, List<Comment>> comments, String dossierTemplateId) {
|
public List<RedactionLogEntry> addManualAddEntries(Set<ManualRedactionEntry> manualAdds,
|
||||||
|
Map<String, List<Comment>> comments, String dossierTemplateId) {
|
||||||
|
|
||||||
List<RedactionLogEntry> redactionLogEntries = new ArrayList<>();
|
List<RedactionLogEntry> redactionLogEntries = new ArrayList<>();
|
||||||
|
|
||||||
for (ManualRedactionEntry manualRedactionEntry : manualAdds) {
|
for (ManualRedactionEntry manualRedactionEntry : manualAdds) {
|
||||||
|
|
||||||
if (!approvedAndShouldBeInDictionary(manualRedactionEntry)) {
|
if (!approvedAndShouldBeInDictionary(manualRedactionEntry)) {
|
||||||
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry, manualRedactionEntry.getId(), dossierTemplateId);
|
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry, manualRedactionEntry
|
||||||
|
.getId(), dossierTemplateId);
|
||||||
redactionLogEntry.setPositions(manualRedactionEntry.getPositions());
|
redactionLogEntry.setPositions(manualRedactionEntry.getPositions());
|
||||||
redactionLogEntry.setComments(comments.get(manualRedactionEntry.getId()));
|
redactionLogEntry.setComments(comments.get(manualRedactionEntry.getId()));
|
||||||
redactionLogEntries.add(redactionLogEntry);
|
redactionLogEntries.add(redactionLogEntry);
|
||||||
@ -218,7 +248,8 @@ public class RedactionLogMergeService {
|
|||||||
|
|
||||||
private boolean approvedAndShouldBeInDictionary(ManualRedactionEntry manualRedactionEntry) {
|
private boolean approvedAndShouldBeInDictionary(ManualRedactionEntry manualRedactionEntry) {
|
||||||
|
|
||||||
return manualRedactionEntry.getStatus().equals(Status.APPROVED) && (manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary());
|
return manualRedactionEntry.getStatus()
|
||||||
|
.equals(Status.APPROVED) && (manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -246,7 +277,9 @@ public class RedactionLogMergeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private float[] getColor(String type, String dossierTemplateId, boolean requested, boolean isRedaction, boolean skipped) {
|
private float[] getColor(String type, String dossierTemplateId, boolean requested, boolean isRedaction,
|
||||||
|
boolean skipped) {
|
||||||
|
|
||||||
if (requested) {
|
if (requested) {
|
||||||
return dictionaryService.getRequestRemoveColor(dossierTemplateId);
|
return dictionaryService.getRequestRemoveColor(dossierTemplateId);
|
||||||
}
|
}
|
||||||
@ -273,6 +306,7 @@ public class RedactionLogMergeService {
|
|||||||
return dictionaryService.getColor(type, dossierTemplateId);
|
return dictionaryService.getColor(type, dossierTemplateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private static class ManualRedactionWrapper implements Comparable<ManualRedactionWrapper> {
|
private static class ManualRedactionWrapper implements Comparable<ManualRedactionWrapper> {
|
||||||
@ -281,12 +315,14 @@ public class RedactionLogMergeService {
|
|||||||
private OffsetDateTime date;
|
private OffsetDateTime date;
|
||||||
private Object item;
|
private Object item;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(ManualRedactionWrapper o) {
|
public int compareTo(ManualRedactionWrapper o) {
|
||||||
|
|
||||||
return this.date.compareTo(o.date);
|
return this.date.compareTo(o.date);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user