RED-9472: seperation of system rules

pmd fix
This commit is contained in:
yhampe 2024-11-13 12:01:07 +01:00
parent cb102a4e00
commit 7fcaaacded
2 changed files with 11 additions and 17 deletions

View File

@ -22,12 +22,12 @@ import lombok.extern.slf4j.Slf4j;
@Service @Service
public class RuleBuilderService { public class RuleBuilderService {
private final List<RuleIdentifier> systemRules = new ArrayList<>(Arrays.asList(RuleIdentifier.fromName("AI.*.*"), private final List<RuleIdentifier> systemRules = new ArrayList<>(Arrays.asList(RuleIdentifier.fromName("AI"),
RuleIdentifier.fromName("MAN.*.*"), RuleIdentifier.fromName("MAN"),
RuleIdentifier.fromName("X.*.*"), RuleIdentifier.fromName("X"),
RuleIdentifier.fromName("DICT.*.*"), RuleIdentifier.fromName("DICT"),
RuleIdentifier.fromName("FA.*.*"), RuleIdentifier.fromName("FA"),
RuleIdentifier.fromName("LDS.*.*"))); RuleIdentifier.fromName("LDS")));
public RuleBuilderModel getRuleBuilderModel() { public RuleBuilderModel getRuleBuilderModel() {
@ -58,7 +58,7 @@ public class RuleBuilderService {
if (systemRules.stream() if (systemRules.stream()
.toList().contains(RuleIdentifier.fromName(ruleClass.ruleType().name()))) { .toList().contains(RuleIdentifier.fromName(ruleClass.ruleType().name()))) {
log.warn("System rule in user rule update."); log.warn("System rule in user rule update.");
//throw new RuntimeException("No system rule updates allowed in user rule update."); throw new RuntimeException("No system rule updates allowed in user rule update.");
} }
}); });
removeAllRulesExceptSystemRules(ruleFileBluePrintExisting); removeAllRulesExceptSystemRules(ruleFileBluePrintExisting);
@ -81,19 +81,17 @@ public class RuleBuilderService {
mergedRuleFileBlueprint.getDeclarations() mergedRuleFileBlueprint.getDeclarations()
.stream()) .stream())
.toList()); .toList());
RuleMergingResult mergingResult = RuleMergingResult.builder() return RuleMergingResult.builder()
.mergedRules(RuleFileFactory.buildRuleString(ruleFileBluePrintExisting, false, false)) .mergedRules(RuleFileFactory.buildRuleString(ruleFileBluePrintExisting, false, false))
.addedGlobalsOffset(ruleFileBluePrintExisting.getGlobals().length()) .addedGlobalsOffset(ruleFileBluePrintExisting.getGlobals().length())
.addedImportsOffset(ruleFileBluePrintExisting.getImports().length()) .addedImportsOffset(ruleFileBluePrintExisting.getImports().length())
.build(); .build();
return mergingResult;
} }
private void removeAllRulesExceptSystemRules(RuleFileBluePrint ruleFileBluePrint) { private void removeAllRulesExceptSystemRules(RuleFileBluePrint ruleFileBluePrint) {
ruleFileBluePrint.buildFilteredBluePrintByRuleIdentifiers(new HashSet(systemRules)); ruleFileBluePrint.buildFilteredBluePrintByRuleIdentifiers(new HashSet<RuleIdentifier>(systemRules));
} }

View File

@ -32,12 +32,8 @@ import lombok.experimental.UtilityClass;
public class RuleCompilationResultParser { public class RuleCompilationResultParser {
private final static Pattern ruleIdentifierInCodeFinder = Pattern.compile( private final static Pattern ruleIdentifierInCodeFinder = Pattern.compile(
"\\b(?:redact|apply|skip|remove|ignore|applyWithLineBreaks|applyWithReferences|skipWithReferences)" + "\\b(?:redact|apply|skip|remove|ignore|applyWithLineBreaks|applyWithReferences|skipWithReferences)\\s*\\(\\s*\"([a-zA-Z0-9]+.\\d+.\\d+)\"\\s*,\\s*.*(?:\\s*,\\s*.*)\\s*?\\)");
"\\s*\\(\\s*" +
"\"([a-zA-Z0-9]+\\.\\d+\\.\\d+)\"" +
"\\s*,\\s*[^,\\)]*(?:\\s*,\\s*[^,\\)]*)*" +
"\\s*\\)"
);
@SneakyThrows @SneakyThrows
public RuleCompilationResult buildRuleCompilationResultFromRuleString(String ruleString, boolean removedImports) { public RuleCompilationResult buildRuleCompilationResultFromRuleString(String ruleString, boolean removedImports) {