RED-9472: seperation of system rules

pmd fix
This commit is contained in:
yhampe 2024-11-13 12:01:07 +01:00
parent 65166751f1
commit 5ab0747d30
2 changed files with 11 additions and 17 deletions

View File

@ -22,12 +22,12 @@ import lombok.extern.slf4j.Slf4j;
@Service
public class RuleBuilderService {
private final List<RuleIdentifier> systemRules = new ArrayList<>(Arrays.asList(RuleIdentifier.fromName("AI.*.*"),
RuleIdentifier.fromName("MAN.*.*"),
RuleIdentifier.fromName("X.*.*"),
RuleIdentifier.fromName("DICT.*.*"),
RuleIdentifier.fromName("FA.*.*"),
RuleIdentifier.fromName("LDS.*.*")));
private final List<RuleIdentifier> systemRules = new ArrayList<>(Arrays.asList(RuleIdentifier.fromName("AI"),
RuleIdentifier.fromName("MAN"),
RuleIdentifier.fromName("X"),
RuleIdentifier.fromName("DICT"),
RuleIdentifier.fromName("FA"),
RuleIdentifier.fromName("LDS")));
public RuleBuilderModel getRuleBuilderModel() {
@ -58,7 +58,7 @@ public class RuleBuilderService {
if (systemRules.stream()
.toList().contains(RuleIdentifier.fromName(ruleClass.ruleType().name()))) {
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);
@ -81,19 +81,17 @@ public class RuleBuilderService {
mergedRuleFileBlueprint.getDeclarations()
.stream())
.toList());
RuleMergingResult mergingResult = RuleMergingResult.builder()
return RuleMergingResult.builder()
.mergedRules(RuleFileFactory.buildRuleString(ruleFileBluePrintExisting, false, false))
.addedGlobalsOffset(ruleFileBluePrintExisting.getGlobals().length())
.addedImportsOffset(ruleFileBluePrintExisting.getImports().length())
.build();
return mergingResult;
}
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 {
private final static Pattern ruleIdentifierInCodeFinder = Pattern.compile(
"\\b(?:redact|apply|skip|remove|ignore|applyWithLineBreaks|applyWithReferences|skipWithReferences)" +
"\\s*\\(\\s*" +
"\"([a-zA-Z0-9]+\\.\\d+\\.\\d+)\"" +
"\\s*,\\s*[^,\\)]*(?:\\s*,\\s*[^,\\)]*)*" +
"\\s*\\)"
);
"\\b(?:redact|apply|skip|remove|ignore|applyWithLineBreaks|applyWithReferences|skipWithReferences)\\s*\\(\\s*\"([a-zA-Z0-9]+.\\d+.\\d+)\"\\s*,\\s*.*(?:\\s*,\\s*.*)\\s*?\\)");
@SneakyThrows
public RuleCompilationResult buildRuleCompilationResultFromRuleString(String ruleString, boolean removedImports) {