Search in sources :

Example 1 with UnsupportedFieldConstraintParserMessage

use of org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage in project drools by kiegroup.

the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.

private List<Node> visit(final FieldConstraint fc, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
    final List<Node> nodes = new ArrayList<Node>();
    if (fc instanceof CompositeFieldConstraint) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    } else if (fc instanceof SingleFieldConstraintEBLeftSide) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    }
    if (!(fc instanceof SingleFieldConstraint)) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    }
    final SingleFieldConstraint sfc = (SingleFieldConstraint) fc;
    if (sfc.getConnectives() != null) {
        messages.add(new UnsupportedFieldConstraintParserMessage());
        return nodes;
    }
    ConstraintNode node = null;
    final String className = sfc.getFactType();
    final String fieldName = sfc.getFieldName();
    if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) {
        final String operator = sfc.getOperator();
        final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
        if (isValueRequired) {
            final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
            if (value != null) {
                node = new ConstraintNodeImpl(className, fieldName, operator, value);
            }
        } else {
            node = new ConstraintNodeImpl(className, fieldName);
        }
    } else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_ENUM) {
        final String operator = sfc.getOperator();
        final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
        if (isValueRequired) {
            final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
            if (value != null) {
                node = new ConstraintNodeImpl(className, fieldName, operator, value);
            }
        } else {
            node = new ConstraintNodeImpl(className, fieldName);
        }
    } else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_UNDEFINED) {
        final String operator = sfc.getOperator();
        final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
        if (isValueRequired) {
            node = new ConstraintNodeImpl(className, fieldName);
        } else {
            node = new ConstraintNodeImpl(className, fieldName, operator, null);
        }
    } else {
        messages.add(new UnsupportedFieldConstraintTypeParserMessage());
        return nodes;
    }
    if (node != null) {
        if (sfc.isBound()) {
            node.setBinding(sfc.getFieldBinding());
        }
        nodes.add(node);
    }
    return nodes;
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ArrayList(java.util.ArrayList) UnsupportedFieldConstraintTypeParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintTypeParserMessage) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) UnsupportedFieldConstraintParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ShortValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.ShortValue) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) FloatValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.FloatValue) BigDecimalValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigDecimalValue) ByteValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.ByteValue) Value(org.drools.workbench.models.guided.dtree.shared.model.values.Value) DoubleValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DoubleValue) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) BooleanValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BooleanValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) LongValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.LongValue) ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue) EnumValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.EnumValue)

Example 2 with UnsupportedFieldConstraintParserMessage

use of org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testSingleRule_UnsupportedFieldConstraintExpression.

@Test
public void testSingleRule_UnsupportedFieldConstraintExpression() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( this.name == \"Michael\" )\n" + "then \n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    expected.setRoot(type);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "name", String.class.getName(), DataType.TYPE_STRING);
    final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 1);
    assertEquals(expected.getTreeName(), model.getTreeName());
    assertNull(model.getRoot());
    assertEquals("test_0", model.getParserErrors().get(0).getOriginalRuleName());
    assertEqualsIgnoreWhitespace(drl, model.getParserErrors().get(0).getOriginalDrl());
    assertNotNull(model.getParserErrors().get(0).getMessages());
    assertEquals(1, model.getParserErrors().get(0).getMessages().size());
    assertTrue(model.getParserErrors().get(0).getMessages().get(0) instanceof UnsupportedFieldConstraintParserMessage);
    final String drl2 = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
    assertEqualsIgnoreWhitespace(drl, drl2);
}
Also used : UnsupportedFieldConstraintParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Test(org.junit.Test)

Example 3 with UnsupportedFieldConstraintParserMessage

use of org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage in project drools-wb by kiegroup.

the class ParserMessagesPopup method getMessage.

private String getMessage(final ParserMessage msg) {
    if (msg instanceof AmbiguousRootParserMessage) {
        final TypeNode tn = model.getRoot();
        final AmbiguousRootParserMessage m = (AmbiguousRootParserMessage) msg;
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageAmbiguousRootParserMessage(tn.getClassName(), m.getClassName());
    } else if (msg instanceof BindingNotFoundParserMessage) {
        final BindingNotFoundParserMessage m = (BindingNotFoundParserMessage) msg;
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageBindingNotFoundParserMessage(m.getBinding());
    } else if (msg instanceof DataTypeConversionErrorParserMessage) {
        final DataTypeConversionErrorParserMessage m = (DataTypeConversionErrorParserMessage) msg;
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageDataTypeConversionErrorParserMessage(m.getValue(), m.getDataTypeClassName());
    } else if (msg instanceof DataTypeNotFoundParserMessage) {
        final DataTypeNotFoundParserMessage m = (DataTypeNotFoundParserMessage) msg;
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageDataTypeNotFoundParserMessage(m.getClassName(), m.getFieldName());
    } else if (msg instanceof DefaultParserMessage) {
        final DefaultParserMessage m = (DefaultParserMessage) msg;
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageDefaultParserMessage(m.getMessage());
    } else if (msg instanceof InvalidRootParserMessage) {
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageInvalidRootParserMessage();
    } else if (msg instanceof UnsupportedFieldConstraintParserMessage) {
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageUnsupportedFieldConstraintParserMessage();
    } else if (msg instanceof UnsupportedFieldConstraintTypeParserMessage) {
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageUnsupportedFieldConstraintTypeParserMessage();
    } else if (msg instanceof UnsupportedFieldNatureTypeParserMessage) {
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageUnsupportedFieldNatureTypeParserMessage();
    } else if (msg instanceof UnsupportedIActionParserMessage) {
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageUnsupportedIActionParserMessage();
    } else if (msg instanceof UnsupportedIPatternParserMessage) {
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageUnsupportedIPatternParserMessage();
    } else {
        return GuidedDecisionTreeConstants.INSTANCE.parserMessageUnknownMessage();
    }
}
Also used : UnsupportedIPatternParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedIPatternParserMessage) DataTypeNotFoundParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeNotFoundParserMessage) BindingNotFoundParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.BindingNotFoundParserMessage) InvalidRootParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.InvalidRootParserMessage) UnsupportedFieldConstraintParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage) UnsupportedFieldNatureTypeParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldNatureTypeParserMessage) DataTypeConversionErrorParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeConversionErrorParserMessage) DefaultParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DefaultParserMessage) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) UnsupportedIActionParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedIActionParserMessage) AmbiguousRootParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.AmbiguousRootParserMessage) UnsupportedFieldConstraintTypeParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintTypeParserMessage)

Example 4 with UnsupportedFieldConstraintParserMessage

use of org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testSingleRule_UnsupportedFieldConstraintCompositeFieldConstraint.

@Test
public void testSingleRule_UnsupportedFieldConstraintCompositeFieldConstraint() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( name == \"Michael\" || name == \"John\" )\n" + "then \n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    expected.setRoot(type);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "name", String.class.getName(), DataType.TYPE_STRING);
    final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 1);
    assertEquals(expected.getTreeName(), model.getTreeName());
    assertNull(model.getRoot());
    assertEquals("test_0", model.getParserErrors().get(0).getOriginalRuleName());
    assertEqualsIgnoreWhitespace(drl, model.getParserErrors().get(0).getOriginalDrl());
    assertNotNull(model.getParserErrors().get(0).getMessages());
    assertEquals(1, model.getParserErrors().get(0).getMessages().size());
    assertTrue(model.getParserErrors().get(0).getMessages().get(0) instanceof UnsupportedFieldConstraintParserMessage);
    final String drl2 = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
    assertEqualsIgnoreWhitespace(drl, drl2);
}
Also used : UnsupportedFieldConstraintParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Test(org.junit.Test)

Aggregations

TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)4 UnsupportedFieldConstraintParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintParserMessage)4 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)2 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)2 UnsupportedFieldConstraintTypeParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldConstraintTypeParserMessage)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)1 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)1 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)1 ActionFieldValue (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue)1 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)1 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)1 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)1 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)1 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)1 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)1 AmbiguousRootParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.AmbiguousRootParserMessage)1 BindingNotFoundParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.BindingNotFoundParserMessage)1