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