RED-7834: fixes for migration
* remove color * fix manualChangeOverwrite * fix checkstyle
This commit is contained in:
parent
ad6e628e0d
commit
9d876a32ce
@ -2,7 +2,6 @@ package com.iqser.red.service.redaction.v1.server.model.drools;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public record RuleType(String name) {
|
||||
|
||||
static Pattern alphaNumeric = Pattern.compile("^[a-zA-Z0-9]+$");
|
||||
|
||||
@ -123,7 +123,7 @@ public class Main {
|
||||
private static String escapeRuleStringIfOptionIsSet(CommandLine finalCmd, String ruleFileString) {
|
||||
|
||||
if (finalCmd.hasOption("e")) {
|
||||
ruleFileString = RuleFileIO.escapeAndWrap(ruleFileString);
|
||||
return RuleFileIO.escapeAndWrap(ruleFileString);
|
||||
}
|
||||
return ruleFileString;
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ public class RuleFileParser {
|
||||
|
||||
|
||||
/**
|
||||
* Creates a BluePrint from all redact manager, documine and component rule files
|
||||
* Creates a BluePrint from all redact manager, documine and component rule files.
|
||||
*
|
||||
* @return RuleFileBluePrint containing all rules from any all rule files
|
||||
*/
|
||||
|
||||
@ -19,6 +19,7 @@ public record RuleIdentifier(@NonNull RuleType type, Integer unit, Integer id) {
|
||||
return fromString(identifier);
|
||||
}
|
||||
|
||||
|
||||
public static RuleIdentifier fromRuleType(RuleType ruleType) {
|
||||
|
||||
return new RuleIdentifier(ruleType, null, null);
|
||||
@ -26,6 +27,7 @@ public record RuleIdentifier(@NonNull RuleType type, Integer unit, Integer id) {
|
||||
|
||||
|
||||
public static RuleIdentifier fromString(String identifier) {
|
||||
|
||||
String[] values = identifier.split("\\.");
|
||||
RuleType type = RuleType.fromString(values[0]);
|
||||
Integer group = values.length > 1 ? parseIntOrStar(values[1]) : null;
|
||||
@ -33,6 +35,7 @@ public record RuleIdentifier(@NonNull RuleType type, Integer unit, Integer id) {
|
||||
return new RuleIdentifier(type, group, id);
|
||||
}
|
||||
|
||||
|
||||
public static Set<RuleIdentifier> fromListOfIdentifiersString(String input) {
|
||||
|
||||
return Arrays.stream(input.split(",")).map(String::trim).map(RuleIdentifier::fromString).collect(Collectors.toSet());
|
||||
@ -40,8 +43,10 @@ public record RuleIdentifier(@NonNull RuleType type, Integer unit, Integer id) {
|
||||
|
||||
|
||||
private static Integer parseIntOrStar(String value) {
|
||||
value = value.replaceAll("\r","");
|
||||
return !value.equals("*") ? Integer.parseInt(value) : null;
|
||||
|
||||
String cleanedValue = value;
|
||||
cleanedValue = cleanedValue.replaceAll("\r", "");
|
||||
return !cleanedValue.equals("*") ? Integer.parseInt(cleanedValue) : null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -28,8 +28,8 @@ public class RuleType {
|
||||
|
||||
public static RuleType fromString(String value) {
|
||||
|
||||
value = value.replaceAll("\r", "");
|
||||
return new RuleType(value);
|
||||
String cleanedValue = value.replaceAll("\r", "");
|
||||
return new RuleType(cleanedValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ import lombok.experimental.UtilityClass;
|
||||
@UtilityClass
|
||||
public class OldRulesParser {
|
||||
|
||||
final static List<String> HEADERS = List.of("id", "old rule names", "old rule code", "translates to");
|
||||
static List<String> HEADERS = List.of("id", "old rule names", "old rule code", "translates to");
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@ -117,7 +117,7 @@ public class OldRulesParser {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setHeader(HEADERS.toArray(String[]::new)).build();
|
||||
try (final CSVPrinter printer = new CSVPrinter(sw, csvFormat)) {
|
||||
try (CSVPrinter printer = new CSVPrinter(sw, csvFormat)) {
|
||||
for (OldRulesCsvRecord record : records) {
|
||||
printer.printRecord(Stream.of(record.id, RuleFileIO.escapeAndWrap(record.names), RuleFileIO.escapeAndWrap(record.code), record.translatesTo));
|
||||
}
|
||||
@ -162,17 +162,18 @@ public class OldRulesParser {
|
||||
|
||||
private List<RuleIdentifier> parseRuleIdentifiers(String value) {
|
||||
|
||||
if (value.startsWith("[")) {
|
||||
value = value.substring(1);
|
||||
String cleanedValue = value;
|
||||
if (cleanedValue.startsWith("[")) {
|
||||
cleanedValue = cleanedValue.substring(1);
|
||||
}
|
||||
if (value.endsWith("]")) {
|
||||
value = value.substring(0, value.length() - 1);
|
||||
if (cleanedValue.endsWith("]")) {
|
||||
cleanedValue = cleanedValue.substring(0, value.length() - 1);
|
||||
}
|
||||
if (value.isEmpty() || value.isBlank()) {
|
||||
if (cleanedValue.isEmpty() || cleanedValue.isBlank()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<RuleIdentifier> ruleIdentifiers = new LinkedList<>();
|
||||
for (String identifier : value.split(", ")) {
|
||||
for (String identifier : cleanedValue.split(", ")) {
|
||||
ruleIdentifiers.add(RuleIdentifier.fromString(identifier));
|
||||
}
|
||||
return ruleIdentifiers;
|
||||
|
||||
@ -20,9 +20,11 @@ public final class RuleFileIO {
|
||||
if (rulesString.isBlank() || rulesString.isEmpty()) {
|
||||
return rulesString;
|
||||
}
|
||||
rulesString = rulesString.substring(1, rulesString.length() - 1);
|
||||
rulesString = rulesString.translateEscapes();
|
||||
return rulesString;
|
||||
|
||||
String ruleStringToUnescape = rulesString;
|
||||
ruleStringToUnescape = ruleStringToUnescape.substring(1, ruleStringToUnescape.length() - 1);
|
||||
ruleStringToUnescape = ruleStringToUnescape.translateEscapes();
|
||||
return ruleStringToUnescape;
|
||||
}
|
||||
|
||||
|
||||
@ -43,9 +45,10 @@ public final class RuleFileIO {
|
||||
|
||||
public String escapeAndWrap(String rulesString) {
|
||||
|
||||
rulesString = StringEscapeUtils.escapeJava(rulesString);
|
||||
rulesString = "\"" + rulesString + "\"";
|
||||
return rulesString;
|
||||
String rulesStringToEscape = rulesString;
|
||||
rulesStringToEscape = StringEscapeUtils.escapeJava(rulesStringToEscape);
|
||||
rulesStringToEscape = "\"" + rulesStringToEscape + "\"";
|
||||
return rulesStringToEscape;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user