use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode 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.ConstraintNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testValue_Double.
@Test
public void testValue_Double() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( doubleField == 1000.56 )\n" + "then\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "doubleField", "==", new DoubleValue(1000.56));
model.setRoot(type);
type.addChild(c1);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionSetWithConstraint.
@Test
public void testSingleRule_ActionSetWithConstraint() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " $p : Person( $n : name )\n" + "then\n" + " $p.setAge( 25 );\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
type.setBinding("$p");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "name");
c1.setBinding("$n");
model.setRoot(type);
type.addChild(c1);
final ActionUpdateNode action = new ActionUpdateNodeImpl(type);
action.setModify(false);
action.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
c1.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testValue_BigInteger.
@Test
public void testValue_BigInteger() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( bigIntegerField == 1000000I )\n" + "then\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "bigIntegerField", "==", new BigIntegerValue(new BigInteger("1000000")));
model.setRoot(type);
type.addChild(c1);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_SingleConstraintJavaEnum.
@Test
public void testSingleRule_SingleConstraintJavaEnum() throws Exception {
final String expected = "rule \"test_0\"" + "when \n" + " Person( name == Names.FRED )\n" + "then \n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "name", "==", new EnumValue("Names.FRED"));
model.setRoot(type);
type.addChild(c1);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
Aggregations