Search in sources :

Example 51 with TypeNodeImpl

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

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionModifyMultipleFields.

@Test
public void testSingleRule_ActionModifyMultipleFields() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  $p : Person( )\n" + "then \n" + "  modify( $p ) {\n" + "    setAge( 25 ), \n" + "    setName( \"Michael\" )\n" + "  }\n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    expected.setRoot(type);
    final ActionUpdateNode action = new ActionUpdateNodeImpl(type);
    action.setModify(true);
    action.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
    action.getFieldValues().add(new ActionFieldValueImpl("name", new StringValue("Michael")));
    type.addChild(action);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "name", String.class.getName(), DataType.TYPE_STRING);
    addModelField("Person", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 0);
    assertEquals(expected.getTreeName(), model.getTreeName());
    assertNotNull(model.getRoot());
    assertEquals(type.getClassName(), model.getRoot().getClassName());
    assertTrue(model.getRoot().isBound());
    assertEquals(type.getBinding(), model.getRoot().getBinding());
    assertEquals(1, model.getRoot().getChildren().size());
    assertNotNull(model.getRoot().getChildren().get(0));
    assertTrue(model.getRoot().getChildren().get(0) instanceof ActionUpdateNode);
    final ActionUpdateNode _action = (ActionUpdateNode) model.getRoot().getChildren().get(0);
    assertEquals(action.getBoundNode().getBinding(), _action.getBoundNode().getBinding());
    assertEquals(action.isModify(), _action.isModify());
    assertEquals(action.getFieldValues().size(), _action.getFieldValues().size());
    assertEquals(2, _action.getFieldValues().size());
    assertEquals(action.getFieldValues().get(0).getFieldName(), _action.getFieldValues().get(0).getFieldName());
    assertEquals(action.getFieldValues().get(0).getValue().getValue().toString(), _action.getFieldValues().get(0).getValue().getValue().toString());
    assertEquals(action.getFieldValues().get(1).getFieldName(), _action.getFieldValues().get(1).getFieldName());
    assertEquals(action.getFieldValues().get(1).getValue().getValue().toString(), _action.getFieldValues().get(1).getValue().getValue().toString());
    assertEquals(0, _action.getChildren().size());
}
Also used : BigInteger(java.math.BigInteger) 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) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) Test(org.junit.Test)

Example 53 with TypeNodeImpl

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

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

the class EditTypePopup method cloneNode.

// Clone node whilst editing to preserve original node should User cancel the edit
private TypeNode cloneNode(final TypeNode node) {
    final TypeNode clone = new TypeNodeImpl(node.getClassName());
    clone.setParent(node.getParent());
    clone.setBinding(node.getBinding());
    return clone;
}
Also used : TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 55 with TypeNodeImpl

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl 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)109 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)109 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)105 Test (org.junit.Test)105 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)54 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)53 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)32 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)30 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)29 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)26 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)25 BigInteger (java.math.BigInteger)23 StringValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue)23 DataTypeConversionErrorParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeConversionErrorParserMessage)10 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)10 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)9 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)9 Calendar (java.util.Calendar)8 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)8 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)8