RED-6835: clean incoming strings #132
@ -53,7 +53,7 @@ public class ManualRedactionMapper {
|
||||
public AddRedactionRequest toAddRedactionRequest(String dossierId, String dossierTemplateId, AddRedactionRequestModel addRedactionRequest) {
|
||||
|
||||
return AddRedactionRequest.builder()
|
||||
.value(addRedactionRequest.getValue())
|
||||
.value(StringCleaningUtility.cleanString(addRedactionRequest.getValue()))
|
||||
.legalBasis(addRedactionRequest.getLegalBasis())
|
||||
.user(KeycloakSecurity.getUserId())
|
||||
.dossierTemplateTypeId(toTypeId(addRedactionRequest.getType(), dossierTemplateId))
|
||||
@ -172,7 +172,7 @@ public class ManualRedactionMapper {
|
||||
.user(KeycloakSecurity.getUserId())
|
||||
.status(AnnotationStatus.APPROVED)
|
||||
.positions(resizeRedactionRequest.getPositions())
|
||||
.value(resizeRedactionRequest.getValue())
|
||||
.value(StringCleaningUtility.cleanString(resizeRedactionRequest.getValue()))
|
||||
.comment(resizeRedactionRequest.getComment())
|
||||
.updateDictionary(resizeRedactionRequest.getUpdateDictionary())
|
||||
.addToAllDossiers(resizeRedactionRequest.isAddToAllDossiers())
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.service.manualredactions;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class StringCleaningUtility {
|
||||
|
||||
public static final Pattern hyphenLineBreaks = Pattern.compile("[-~‐‒⁻−﹣゠⁓‑\\u00AD][\\r\\n]+");
|
||||
public static final Pattern linebreaks = Pattern.compile("[\\r\\n]+");
|
||||
public static final Pattern doubleWhitespaces = Pattern.compile("\\s{2,}");
|
||||
|
||||
|
||||
public String cleanString(String value) {
|
||||
|
||||
String noHyphenLinebreaks = removeHyphenLinebreaks(value);
|
||||
String noLinebreaks = removeLinebreaks(noHyphenLinebreaks);
|
||||
return removeMultipleWhitespaces(noLinebreaks);
|
||||
}
|
||||
|
||||
|
||||
private String removeHyphenLinebreaks(String value) {
|
||||
|
||||
return hyphenLineBreaks.matcher(value).replaceAll("");
|
||||
}
|
||||
|
||||
|
||||
private String removeMultipleWhitespaces(String value) {
|
||||
|
||||
return doubleWhitespaces.matcher(value).replaceAll(" ");
|
||||
}
|
||||
|
||||
|
||||
private String removeLinebreaks(String value) {
|
||||
|
||||
return linebreaks.matcher(value).replaceAll(" ");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.iqser.red.service.peristence.v1.server.integration.tests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.manualredactions.StringCleaningUtility;
|
||||
|
||||
public class StringCleaningUtilityTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveLinebreaks() {
|
||||
|
||||
String originalValue = "abc\ndef";
|
||||
assertEquals("abc def", StringCleaningUtility.cleanString(originalValue));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveHyphenLinebreaks() {
|
||||
|
||||
String originalValue = "abc-\ndef";
|
||||
assertEquals("abcdef", StringCleaningUtility.cleanString(originalValue));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDontRemoveHyphens() {
|
||||
|
||||
String originalValue = "abc-def";
|
||||
assertEquals("abc-def", StringCleaningUtility.cleanString(originalValue));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveDoubleWhiteSpace() {
|
||||
|
||||
String originalValue = "abc def";
|
||||
assertEquals("abc def", StringCleaningUtility.cleanString(originalValue));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAllAboveInOne() {
|
||||
|
||||
String originalValue = "abc\n def, ghi-jkl\n\nmno-\npqr";
|
||||
assertEquals("abc def, ghi-jkl mnopqr", StringCleaningUtility.cleanString(originalValue));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user