Search in sources :

Example 1 with UnsupportedFieldNatureTypeParserMessage

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

the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.

private List<Node> visit(final IAction a, final List<TypeNode> types, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
    final List<Node> nodes = new ArrayList<Node>();
    if (a instanceof ActionRetractFact) {
        final ActionRetractFact arf = (ActionRetractFact) a;
        final String binding = arf.getVariableName();
        for (TypeNode tn : types) {
            if (tn.isBound()) {
                if (tn.getBinding().equals(binding)) {
                    final ActionRetractNode arn = new ActionRetractNodeImpl(tn);
                    nodes.add(arn);
                    return nodes;
                }
            }
        }
        messages.add(new BindingNotFoundParserMessage(binding));
        return nodes;
    } else if (a instanceof ActionInsertLogicalFact) {
        final ActionInsertLogicalFact aif = (ActionInsertLogicalFact) a;
        final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
        aun.setLogicalInsertion(true);
        for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
            if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                messages.add(new UnsupportedFieldNatureTypeParserMessage());
                return nodes;
            }
            final String fieldName = afv.getField();
            final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
            if (value != null) {
                final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                aun.getFieldValues().add(_afv);
            }
        }
        nodes.add(aun);
        return nodes;
    } else if (a instanceof ActionInsertFact) {
        final ActionInsertFact aif = (ActionInsertFact) a;
        final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
        aun.setLogicalInsertion(false);
        for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
            if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                messages.add(new UnsupportedFieldNatureTypeParserMessage());
                return nodes;
            }
            final String fieldName = afv.getField();
            final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
            if (value != null) {
                final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                aun.getFieldValues().add(_afv);
            }
        }
        nodes.add(aun);
        return nodes;
    } else if (a instanceof ActionUpdateField) {
        final ActionUpdateField auf = (ActionUpdateField) a;
        final String binding = auf.getVariable();
        for (TypeNode tn : types) {
            if (tn.isBound()) {
                if (tn.getBinding().equals(binding)) {
                    final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
                    aun.setModify(true);
                    for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : auf.getFieldValues()) {
                        if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                            messages.add(new UnsupportedFieldNatureTypeParserMessage());
                            return nodes;
                        }
                        final String fieldName = afv.getField();
                        final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
                        if (value != null) {
                            final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                            aun.getFieldValues().add(_afv);
                        }
                    }
                    nodes.add(aun);
                    return nodes;
                }
            }
        }
        messages.add(new BindingNotFoundParserMessage(binding));
        return nodes;
    } else if (a instanceof ActionSetField) {
        final ActionSetField asf = (ActionSetField) a;
        final String binding = asf.getVariable();
        for (TypeNode tn : types) {
            if (tn.isBound()) {
                if (tn.getBinding().equals(binding)) {
                    final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
                    for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : asf.getFieldValues()) {
                        if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
                            messages.add(new UnsupportedFieldNatureTypeParserMessage());
                            return nodes;
                        }
                        final String fieldName = afv.getField();
                        final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
                        if (value != null) {
                            final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
                            aun.getFieldValues().add(_afv);
                        }
                    }
                    nodes.add(aun);
                    return nodes;
                }
            }
        }
        messages.add(new BindingNotFoundParserMessage(binding));
        return nodes;
    } else {
        messages.add(new UnsupportedIActionParserMessage());
        return nodes;
    }
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) 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) ActionRetractNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) BindingNotFoundParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.BindingNotFoundParserMessage) ActionFieldValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) UnsupportedFieldNatureTypeParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldNatureTypeParserMessage) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) 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) ActionUpdateNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) ActionFieldValueImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl) UnsupportedIActionParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedIActionParserMessage) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)

Example 2 with UnsupportedFieldNatureTypeParserMessage

use of org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldNatureTypeParserMessage 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 3 with UnsupportedFieldNatureTypeParserMessage

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testSingleRule_UnsupportedFieldNatureType.

@Test
public void testSingleRule_UnsupportedFieldNatureType() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  $p : Person()\n" + "then \n" + "modify( $p ) { \n" + "  setAge( 25 + 10 ) \n" + "} \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", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    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 UnsupportedFieldNatureTypeParserMessage);
    final String drl2 = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
    assertEqualsIgnoreWhitespace(drl, drl2);
}
Also used : BigInteger(java.math.BigInteger) UnsupportedFieldNatureTypeParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldNatureTypeParserMessage) 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)3 UnsupportedFieldNatureTypeParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedFieldNatureTypeParserMessage)3 BindingNotFoundParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.BindingNotFoundParserMessage)2 UnsupportedIActionParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.UnsupportedIActionParserMessage)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 ActionInsertLogicalFact (org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)1 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)1 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)1 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)1 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)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 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)1 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)1