RED-9132 - Remove debug information from Paragraph/Location field

- check the section value for regex expression to identify and remove the leading numbering
- added junit test
This commit is contained in:
Corina Olariu 2024-05-09 13:06:24 +03:00
parent dba91f73b1
commit a19403dea1
2 changed files with 45 additions and 2 deletions

View File

@ -20,7 +20,6 @@ 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.EntryState;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.ManualChange;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.ManualRedactionType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Position;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.Type;
import com.iqser.red.service.redaction.report.v1.server.client.DictionaryClient;
@ -39,6 +38,7 @@ import lombok.extern.slf4j.Slf4j;
@RequiredArgsConstructor
public class EntityLogConverterService {
private final static String numericalIdentifierPatternForSection = "^.*\\d\\s*+\\]\\:";
private final DossierClient dossierClient;
private final DictionaryClient dictionaryClient;
@ -193,7 +193,7 @@ public class EntityLogConverterService {
private String getSection(EntityLogEntry entry, Position position) {
if (StringUtils.isNotBlank(entry.getSection())) {
return entry.getSection();
return removeNumericalIdentifierPatternFromSection(entry.getSection());
}
if (entry.getEntryType() == EntryType.IMAGE || entry.getEntryType() == EntryType.IMAGE_HINT) {
@ -208,6 +208,16 @@ public class EntityLogConverterService {
}
public String removeNumericalIdentifierPatternFromSection(String section) {
String[] sectionParts = section.split(numericalIdentifierPatternForSection);
if (sectionParts.length > 1) {
return sectionParts[1].trim();
}
return section.trim();
}
private String checkTextForNull(String text) {
if (text == null) {

View File

@ -86,4 +86,37 @@ public class EntityLogConverterServiceTest {
assertFalse(reportEntries.get(0).isSkipped());
}
@Test
public void testSection() {
String sectionResult = "Paragraph";
String section1 = "[1.1.1]: Paragraph";
String section2 = "[1. 1.1]: Paragraph";
String section3 = "[1,1.1]: Paragraph";
String section4 = "[1,1,1]: Paragraph";
String section5 = "[29]: Paragraph";
String section6 = "[29 ]: Paragraph";
String section7 = "[ 1, 1 . 2]: Paragraph";
String section8 = "[ 29]: Paragraph";
String section9 = "[ 1.1.1]: Paragraph";
String section10 = "[ 29 ]: Paragraph";
String section11 = "[ 1, 1. 1]: Paragraph";
String section12 = " Paragraph";
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section1), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section2), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section3), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section4), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section5), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section6), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section7), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section8), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section9), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section10), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section11), sectionResult);
assertEquals(entityLogConverterService.removeNumericalIdentifierPatternFromSection(section12), sectionResult);
}
}