Pull request #100: RED-2751: Always set a value for paragraph
Merge in RED/redaction-report-service from RED-2751-port to master * commit '7167b1371332326b6b354312cb803d5fbba67b4b': RED-2751: Always set a value for paragraph
This commit is contained in:
commit
213826e8b8
@ -7,18 +7,22 @@ import com.iqser.red.service.redaction.v1.model.ChangeType;
|
||||
import com.iqser.red.service.redaction.v1.model.ManualRedactionType;
|
||||
import com.iqser.red.service.redaction.v1.model.Rectangle;
|
||||
import com.iqser.red.service.redaction.v1.model.RedactionLog;
|
||||
import com.iqser.red.service.redaction.v1.model.RedactionLogEntry;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
public class RedactionLogConverterService {
|
||||
|
||||
public List<ReportRedactionEntry> convertAndSort(RedactionLog redactionLog,
|
||||
List<LegalBasis> legalBasisMappings) {
|
||||
public List<ReportRedactionEntry> convertAndSort(RedactionLog redactionLog, List<LegalBasis> legalBasisMappings) {
|
||||
|
||||
List<ReportRedactionEntry> reportEntries = new ArrayList<>();
|
||||
|
||||
@ -26,7 +30,10 @@ public class RedactionLogConverterService {
|
||||
|
||||
if (entry.isRedacted()) {
|
||||
|
||||
if (entry.getChanges() != null && entry.getChanges().size() > 1 && entry.getChanges().get(entry.getChanges().size() - 1).getType().equals(ChangeType.REMOVED)) {
|
||||
if (entry.getChanges() != null && entry.getChanges().size() > 1 && entry.getChanges()
|
||||
.get(entry.getChanges().size() - 1)
|
||||
.getType()
|
||||
.equals(ChangeType.REMOVED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -55,7 +62,7 @@ public class RedactionLogConverterService {
|
||||
pages.add(position.getPage());
|
||||
reportEntries.add(new ReportRedactionEntry(position.getPage(), position.getTopLeft()
|
||||
.getX(), position.getTopLeft()
|
||||
.getY(), entry.getSection(), entry.getLegalBasis() + " " + legalBasisMappings.stream()
|
||||
.getY(), getSection(entry, position), entry.getLegalBasis() + " " + legalBasisMappings.stream()
|
||||
.filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis()))
|
||||
.findAny()
|
||||
.map(LegalBasis::getDescription)
|
||||
@ -63,7 +70,8 @@ public class RedactionLogConverterService {
|
||||
.filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis()))
|
||||
.findAny()
|
||||
.map(LegalBasis::getDescription)
|
||||
.orElse(""), checkTextForNull(entry.getTextBefore()) + entry.getValue() + checkTextForNull(entry.getTextAfter()), entry.getValue()));
|
||||
.orElse(""), checkTextForNull(entry.getTextBefore()) + entry.getValue() + checkTextForNull(entry
|
||||
.getTextAfter()), entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,7 +91,9 @@ public class RedactionLogConverterService {
|
||||
return reportEntries;
|
||||
}
|
||||
|
||||
|
||||
private String checkTextForNull(String text) {
|
||||
|
||||
if (text == null) {
|
||||
return "";
|
||||
}
|
||||
@ -91,4 +101,39 @@ public class RedactionLogConverterService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String humanize(String label) {
|
||||
|
||||
String str = label;
|
||||
str = str.replaceAll("-+?", " ");
|
||||
str = str.replaceAll("_+?", " ");
|
||||
str = str.replaceAll(" +", " ");
|
||||
|
||||
StringBuilder strbf = new StringBuilder();
|
||||
Matcher match = Pattern.compile("([a-z])([a-z]*)", Pattern.CASE_INSENSITIVE).matcher(str);
|
||||
while (match.find()) {
|
||||
match.appendReplacement(strbf, match.group(1).toUpperCase() + match.group(2));
|
||||
}
|
||||
return match.appendTail(strbf).toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getSection(RedactionLogEntry entry, Rectangle position) {
|
||||
|
||||
if (StringUtils.isNotBlank(entry.getSection())) {
|
||||
return entry.getSection();
|
||||
}
|
||||
|
||||
if (entry.isImage()) {
|
||||
return "Image: " + humanize(entry.getType());
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(entry.getValue())) {
|
||||
return "Non-readable content";
|
||||
}
|
||||
|
||||
return "Text on page " + position.getPage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user