Search in sources :

Example 61 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode 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 62 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools-wb by kiegroup.

the class ActionRetractShape method getNodeLabel.

@Override
public String getNodeLabel() {
    final StringBuilder sb = new StringBuilder();
    sb.append(ActionRetractNodeFactory.DESCRIPTION);
    final TypeNode boundNode = getModelNode().getBoundNode();
    if (boundNode != null) {
        if (boundNode.isBound()) {
            sb.append(" ").append(boundNode.getBinding());
        }
    }
    return sb.toString();
}
Also used : TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 63 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools-wb by kiegroup.

the class ActionUpdateShape method setParentNode.

@Override
public void setParentNode(final WiresBaseTreeNode parent) {
    super.setParentNode(parent);
    // Set binding to first bound parent TypeNode
    if (parent instanceof BaseGuidedDecisionTreeShape) {
        Node node = ((BaseGuidedDecisionTreeShape) parent).getModelNode();
        while (node != null) {
            if (node instanceof TypeNode) {
                final TypeNode tn = (TypeNode) node;
                if (tn.isBound()) {
                    getModelNode().setBoundNode(tn);
                    setNodeLabel(getNodeLabel());
                    break;
                }
            }
            node = node.getParent();
        }
    }
}
Also used : Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 64 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.

the class GuidedDecisionTreeModelMarshallingVisitor method generateRuleDRL.

protected void generateRuleDRL(final List<Node> path) {
    Node context = null;
    final StringBuilder drl = new StringBuilder();
    final boolean hasDateFieldValue = hasDateFieldValue(path);
    this.varCounter = 0;
    drl.append(generateRuleHeaderDRL());
    drl.append(INDENTATION).append("when \n");
    for (Node node : path) {
        if (node instanceof TypeNode) {
            generateTypeNodeDRL((TypeNode) node, context, drl);
        } else if (node instanceof ConstraintNode) {
            generateConstraintNodeDRL((ConstraintNode) node, context, drl);
        } else if (node instanceof ActionRetractNode) {
            generateActionRetractNodeDRL((ActionRetractNode) node, context, hasDateFieldValue, drl);
        } else if (node instanceof ActionUpdateNode) {
            generateActionUpdateNodeDRL((ActionUpdateNode) node, context, hasDateFieldValue, drl);
        } else if (node instanceof ActionInsertNode) {
            generateActionInsertNodeDRL((ActionInsertNode) node, context, hasDateFieldValue, drl);
        }
        context = node;
    }
    if (context == null) {
    // No previous context to close
    } else if (context instanceof ConstraintNode) {
        drl.append(")\n").append("then \n").append("end\n");
    } else if (context instanceof TypeNode) {
        drl.append(")\n").append("then \n").append("end\n");
    } else if (context instanceof ActionRetractNode) {
        drl.append("end\n");
    } else if (context instanceof ActionUpdateNode) {
        drl.append("end\n");
    } else if (context instanceof ActionInsertNode) {
        drl.append("end\n");
    }
    ruleCount++;
    rules.append(drl);
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 65 with TypeNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionSetDateFieldValue.

@Test
public void testSingleRule_ActionSetDateFieldValue() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  $p : Person()\n" + "then\n" + "  java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");\n" + "  $p.setDateOfBirth( sdf.parse(\"15-Jul-1985\") );\n" + "end";
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    model.setRoot(type);
    final ActionUpdateNode action = new ActionUpdateNodeImpl(type);
    action.setModify(false);
    final Calendar dob = Calendar.getInstance();
    dob.set(Calendar.YEAR, 1985);
    dob.set(Calendar.MONTH, 6);
    dob.set(Calendar.DATE, 15);
    action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
    type.addChild(action);
    final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
    assertEqualsIgnoreWhitespace(expected, drl);
}
Also used : TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) Calendar(java.util.Calendar) ActionUpdateNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) ActionFieldValueImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl) Test(org.junit.Test)

Aggregations

TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)125 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)109 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)106 Test (org.junit.Test)105 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)61 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)53 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)34 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)33 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)31 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)30 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)26 StringValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue)24 BigInteger (java.math.BigInteger)23 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)17 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)16 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)11 DataTypeConversionErrorParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeConversionErrorParserMessage)11 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)11 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)9 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)9