Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,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 @@ -2701,6 +2711,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 @@ -4348,12 +4362,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
manstis marked this conversation as resolved.
Show resolved Hide resolved
}

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));
}
}