diff --git a/drools-workbench-models/drools-workbench-models-commons/src/main/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceImpl.java b/drools-workbench-models/drools-workbench-models-commons/src/main/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceImpl.java index 0afed30c56e..51385d973ce 100644 --- a/drools-workbench-models/drools-workbench-models-commons/src/main/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceImpl.java +++ b/drools-workbench-models/drools-workbench-models-commons/src/main/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceImpl.java @@ -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 attributes) { boolean isJavaDialect = false; @@ -2701,6 +2711,10 @@ private CompositeFactPattern parseExistentialElementDescr(final RuleModel m, final boolean isJavaDialect, final Map 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); @@ -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 + } + + final Pattern rulePattern = Pattern.compile(".*\\s?rule\\s+\"(.+?)\"\\s+.*", Pattern.DOTALL); final Pattern lhsPattern = Pattern.compile(".*\\s+when\\s+(.+?)\\s+then.*", Pattern.DOTALL); diff --git a/drools-workbench-models/drools-workbench-models-commons/src/test/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceUnmarshallingTest.java b/drools-workbench-models/drools-workbench-models-commons/src/test/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceUnmarshallingTest.java index 8d75c98e268..bca5f9b9055 100644 --- a/drools-workbench-models/drools-workbench-models-commons/src/test/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceUnmarshallingTest.java +++ b/drools-workbench-models/drools-workbench-models-commons/src/test/java/org/drools/workbench/models/commons/backend/rule/RuleModelDRLPersistenceUnmarshallingTest.java @@ -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)); + } }