use of org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_WithImport.
@Test
public void testSingleRule_WithImport() throws Exception {
final String drl = "package smurf; \n" + "import org.drools.workbench.models.guided.dtree.backend.Person; \n" + "rule \"test_0\"\n" + "when \n" + " Person( name == \"Michael\" )\n" + "then \n" + "end";
final GuidedDecisionTree expected = new GuidedDecisionTree();
expected.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "name", "==", new StringValue("Michael"));
expected.setRoot(type);
type.addChild(c1);
addModelField("org.drools.workbench.models.guided.dtree.backend.Person", "this", "org.drools.workbench.models.guided.dtree.backend.Person", DataType.TYPE_THIS);
addModelField("org.drools.workbench.models.guided.dtree.backend.Person", "name", String.class.getName(), DataType.TYPE_STRING);
final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 0);
assertEquals(expected.getTreeName(), model.getTreeName());
assertNotNull(model.getRoot());
assertEquals(type.getClassName(), model.getRoot().getClassName());
assertFalse(model.getRoot().isBound());
assertEquals(1, model.getRoot().getChildren().size());
assertNotNull(model.getRoot().getChildren().get(0));
assertTrue(model.getRoot().getChildren().get(0) instanceof ConstraintNode);
final ConstraintNode _c1 = (ConstraintNode) model.getRoot().getChildren().get(0);
assertEquals(c1.getClassName(), _c1.getClassName());
assertEquals(c1.getFieldName(), _c1.getFieldName());
assertEquals(c1.getOperator(), _c1.getOperator());
assertEquals(c1.getValue().getValue().toString(), _c1.getValue().getValue().toString());
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl in project drools-wb by kiegroup.
the class GuidedDecisionTreePalette method makeStencils.
private Widget makeStencils(final String className, final boolean isReadOnly) {
final GuidedDecisionTreePaletteGroup paletteGroup = new GuidedDecisionTreePaletteGroup();
if (className == null) {
return paletteGroup;
}
oracle.getFieldCompletions(className, new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] mfs) {
if (mfs == null || mfs.length == 0) {
return;
}
final TypeNode tn = new TypeNodeImpl(className);
paletteGroup.addStencil(typeNodeFactory, stencilBuilder, new TypeFactoryHelper(tn, isReadOnly), isReadOnly);
for (ModelField mf : mfs) {
final String fieldName = mf.getName();
if (!fieldName.equals(DataType.TYPE_THIS)) {
final ConstraintNode cn = new ConstraintNodeImpl(className, fieldName, "", new StringValue(""));
paletteGroup.addStencil(constraintNodeFactory, stencilBuilder, new ConstraintFactoryHelper(cn, isReadOnly), isReadOnly);
}
}
}
});
return paletteGroup;
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl in project drools-wb by kiegroup.
the class EditConstraintPopup method cloneNode.
// Clone node whilst editing to preserve original node should User cancel the edit
private ConstraintNode cloneNode(final ConstraintNode node) {
final ConstraintNode clone = new ConstraintNodeImpl(node.getClassName(), node.getFieldName());
if (node.getOperator() != null) {
clone.setOperator(node.getOperator());
}
if (node.getValue() != null) {
clone.setValue(node.getValue());
}
clone.setParent(node.getParent());
clone.setBinding(node.getBinding());
return clone;
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl 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.impl.ConstraintNodeImpl 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);
}
Aggregations