Search in sources :

Example 31 with ConstraintNodeImpl

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());
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) 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) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) Test(org.junit.Test)

Example 32 with ConstraintNodeImpl

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;
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) TypeFactoryHelper(org.drools.workbench.screens.guided.dtree.client.widget.factories.TypeFactoryHelper) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) ConstraintFactoryHelper(org.drools.workbench.screens.guided.dtree.client.widget.factories.ConstraintFactoryHelper)

Example 33 with ConstraintNodeImpl

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;
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)

Example 34 with ConstraintNodeImpl

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);
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) DoubleValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DoubleValue) 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)

Example 35 with ConstraintNodeImpl

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);
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) 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

ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)56 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)56 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)54 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)53 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)52 Test (org.junit.Test)52 StringValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue)20 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)17 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)15 BigInteger (java.math.BigInteger)9 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)5 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)4 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)4 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)3 BigDecimalValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigDecimalValue)3 BooleanValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BooleanValue)3 ByteValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.ByteValue)3 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)3 DoubleValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DoubleValue)3 EnumValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.EnumValue)3