Skip to content

Commit

Permalink
RHPAM-2617: [GSS](7.5.1) Rule logic in a RDRL file changes after impo…
Browse files Browse the repository at this point in the history
…rting the file as an Asset in RHPAM 7.5 (apache#2725)

* RHPAM-2617: [GSS](7.5.1) Rule logic in a RDRL file changes after importing the file as an Asset in RHPAM 7.5

* Updates following peer review.
  • Loading branch information
manstis authored Jan 27, 2020
1 parent 193255e commit ff514ea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,16 @@ private RuleDescr parseDrl(final ExpandedDRLInfo expandedDRLInfo) {
return packageDescr.getRules().get(0);
}

private RuleDescr parseDrl(final String drl) throws DroolsParserException {
final DrlParser drlParser = new DrlParser();
final PackageDescr packageDescr = drlParser.parse(true, drl);
if (drlParser.hasErrors()) {
throw new RuleModelUnmarshallingException();
}

return packageDescr.getRules().get(0);
}

private boolean parseAttributes(final RuleModel m,
final Map<String, AttributeDescr> attributes) {
boolean isJavaDialect = false;
Expand Down Expand Up @@ -2702,6 +2712,10 @@ private CompositeFactPattern parseExistentialElementDescr(final RuleModel m,
final boolean isJavaDialect,
final Map<String, String> boundParams,
final PackageDataModelOracle dmo) {
if (conditionalDescr.getDescrs().stream().anyMatch(d -> d instanceof ConditionalElementDescr)) {
throw new RuleModelUnmarshallingException();
}

CompositeFactPattern comp;
if (conditionalDescr instanceof NotDescr) {
comp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_NOT);
Expand Down Expand Up @@ -4371,12 +4385,18 @@ public static class RuleModelUnmarshallingException extends RuntimeException {
}

//Simple fall-back parser of DRL
public RuleModel getSimpleRuleModel(final String drl) {
private RuleModel getSimpleRuleModel(final String drl) {
final RuleModel rm = new RuleModel();
rm.setPackageName(PackageNameParser.parsePackageName(drl));
rm.setImports(ImportsParser.parseImports(drl));

final Pattern rulePattern = Pattern.compile(".*\\s?rule\\s+(.+?)\\s+.*",
try {
parseAttributes(rm, parseDrl(drl).getAttributes());
} catch (Exception e) {
//Discard. We're unable to retrieve the rule attributes from the DRL
}

final Pattern rulePattern = Pattern.compile(".*\\s?rule\\s+\"(.+?)\"\\s+.*",
Pattern.DOTALL);
final Pattern lhsPattern = Pattern.compile(".*\\s+when\\s+(.+?)\\s+then.*",
Pattern.DOTALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9696,4 +9696,33 @@ private void assertSingleFieldConstraintOperatorNoSpace(final String operator) {
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL,
sfp.getConstraintValueType());
}

@Test
public void testNestedOr() {
final String drl = "rule \"my rule\"\n" +
"dialect \"mvel\"\n" +
"when \n" +
"(\n" +
" (\n" +
" Term(effectiveDate < \"30-Sep-2018\") and \n" +
" Policy($state : state == \"KS\" || == \"MN\" || == \"NM\" || == \"UT\")\n" +
" )\n" +
" or\n" +
" (\n" +
" Term(effectiveDate < \"23-Jun-2019\") and\n" +
" ( \n" +
" Policy(state == \"AZ\" || == \"IA\" || == \"NE\" || == \"SD\" )\n" +
" ) \n" +
" )\n" +
") \n" +
"then \n" +
"end\n";

final RuleModel model = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl,
Collections.emptyList(),
dmo);

assertEqualsIgnoreWhitespace(drl,
RuleModelDRLPersistenceImpl.getInstance().marshal(model));
}
}

0 comments on commit ff514ea

Please sign in to comment.