Skip to content

Commit

Permalink
RAP-93 Re-correct logic to set Drools UUID and Severity in DroolsRule…
Browse files Browse the repository at this point in the history
…sValidationService
  • Loading branch information
QuyenLy87 committed Jul 18, 2024
1 parent ec2d8bd commit 04963b6
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ private void loadAndConvertDroolsRulesToAssertions() {
private void convertDroolsRuleToAssertion(File droolsRulesSubfile) throws IOException {
try (final BufferedReader reader = Files.newBufferedReader(droolsRulesSubfile.toPath())) {
String line;
UUID uuid;
Assertion assertion = null;
boolean severityWarning = false;
boolean severityError = false;
UUID uuid = null;
String group = getAssertionGroup(droolsRulesSubfile.getAbsolutePath());
while ((line = reader.readLine()) != null) {
if (line.startsWith("rule") && !line.contains("Always passes")) {
Expand All @@ -125,20 +125,16 @@ private void convertDroolsRuleToAssertion(File droolsRulesSubfile) throws IOExce
assertions.add(assertion);
}
}
if (line.contains("new InvalidContent")) {
if (assertion != null && line.contains("new InvalidContent")) {
uuid = extractUuid(line);
assertion.setUuid(uuid);
}
// check for severity
if (line.contains("Severity.WARNING")) {
severityWarning = true;
severityWarning = severityWarning || detectSeverity(line, "Severity.WARNING");
severityError = severityError || detectSeverity(line, "Severity.ERROR");
if (assertion != null && "end".equals(line.trim())) {
assertion.setSeverity(buildSeverity(severityWarning, severityError));
}
if (line.contains("Severity.ERROR")) {
severityError = true;
}
}
if (assertion != null) {
assertion.setUuid(uuid);
assertion.setSeverity(buildSeverity(severityWarning, severityError));
}
}
}
Expand All @@ -151,6 +147,10 @@ private static UUID extractUuid(String line) {
return null;
}

private static boolean detectSeverity(String line, String type) {
return line.contains(type);
}

@NotNull
private static String buildSeverity(boolean severityWarning, boolean severityError) {
Set<String> severities = new HashSet<>();
Expand Down

0 comments on commit 04963b6

Please sign in to comment.