Search in sources :

Example 11 with ActionInsertNode

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionInsertDateFieldValue.

@Test
public void testSingleRule_ActionInsertDateFieldValue() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( )\n" + "then \n" + "  java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");\n" + "  Person $var0 = new Person();\n" + "  $var0.setDateOfBirth( sdf.parse(\"15-Jul-1985\") );\n" + "  insert( $var0 );\n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    expected.setRoot(type);
    final ActionInsertNode action = new ActionInsertNodeImpl("Person");
    action.setLogicalInsertion(false);
    final Calendar dob = Calendar.getInstance();
    dob.set(Calendar.YEAR, 1985);
    dob.set(Calendar.MONTH, 6);
    dob.set(Calendar.DATE, 15);
    dob.set(Calendar.HOUR_OF_DAY, 0);
    dob.set(Calendar.MINUTE, 0);
    dob.set(Calendar.SECOND, 0);
    action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
    type.addChild(action);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "dateOfBirth", Date.class.getName(), DataType.TYPE_DATE);
    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 ActionInsertNode);
    final ActionInsertNode _action = (ActionInsertNode) model.getRoot().getChildren().get(0);
    assertEquals(action.getClassName(), _action.getClassName());
    assertEquals(action.isLogicalInsertion(), _action.isLogicalInsertion());
    assertEquals(action.getFieldValues().size(), _action.getFieldValues().size());
    assertEquals(1, _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(0, _action.getChildren().size());
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) Calendar(java.util.Calendar) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl) 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) Date(java.util.Date) Test(org.junit.Test)

Example 12 with ActionInsertNode

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionInsertLogicalDateFieldValue.

@Test
public void testSingleRule_ActionInsertLogicalDateFieldValue() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( )\n" + "then \n" + "  java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");\n" + "  Person $var0 = new Person();\n" + "  $var0.setDateOfBirth( sdf.parse(\"15-Jul-1985\") );\n" + "  insertLogical( $var0 );\n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    expected.setRoot(type);
    final ActionInsertNode action = new ActionInsertNodeImpl("Person");
    action.setLogicalInsertion(true);
    final Calendar dob = Calendar.getInstance();
    dob.set(Calendar.YEAR, 1985);
    dob.set(Calendar.MONTH, 6);
    dob.set(Calendar.DATE, 15);
    dob.set(Calendar.HOUR_OF_DAY, 0);
    dob.set(Calendar.MINUTE, 0);
    dob.set(Calendar.SECOND, 0);
    action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
    type.addChild(action);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "dateOfBirth", Date.class.getName(), DataType.TYPE_DATE);
    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 ActionInsertNode);
    final ActionInsertNode _action = (ActionInsertNode) model.getRoot().getChildren().get(0);
    assertEquals(action.getClassName(), _action.getClassName());
    assertEquals(action.isLogicalInsertion(), _action.isLogicalInsertion());
    assertEquals(action.getFieldValues().size(), _action.getFieldValues().size());
    assertEquals(1, _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(0, _action.getChildren().size());
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) Calendar(java.util.Calendar) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl) 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) Date(java.util.Date) Test(org.junit.Test)

Example 13 with ActionInsertNode

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionInsert.

@Test
public void testSingleRule_ActionInsert() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  Person( )\n" + "then\n" + "  Person $var0 = new Person();\n" + "  $var0.setAge( 25 );\n" + "  insert( $var0 );\n" + "end";
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    model.setRoot(type);
    final ActionInsertNode action = new ActionInsertNodeImpl("Person");
    action.setLogicalInsertion(false);
    action.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
    type.addChild(action);
    final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
    assertEqualsIgnoreWhitespace(expected, drl);
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl) 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)

Example 14 with ActionInsertNode

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

the class GuidedDecisionTreeModelVisitor method visitNode.

private Set<String> visitNode(final Node node) {
    if (node == null) {
        return Collections.EMPTY_SET;
    }
    final Set<String> factTypes = new HashSet<String>();
    if (node instanceof TypeNode) {
        final TypeNode tn = (TypeNode) node;
        factTypes.add(tn.getClassName());
    } else if (node instanceof ActionInsertNode) {
        final ActionInsertNode an = (ActionInsertNode) node;
        factTypes.add(an.getClassName());
    }
    for (Node child : node.getChildren()) {
        factTypes.addAll(visitNode(child));
    }
    return factTypes;
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) HashSet(java.util.HashSet)

Example 15 with ActionInsertNode

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

the class GuidedDecisionTreeEditorPresenter method editModelNode.

public void editModelNode(final Node node, final Command callback) {
    if (node instanceof TypeNode) {
        final EditTypePopup popup = new EditTypePopup((TypeNode) node, new com.google.gwt.user.client.Command() {

            @Override
            public void execute() {
                callback.execute();
            }
        });
        popup.show();
    } else if (node instanceof ConstraintNode) {
        final EditConstraintPopup popup = new EditConstraintPopup((ConstraintNode) node, oracle, new com.google.gwt.user.client.Command() {

            @Override
            public void execute() {
                callback.execute();
            }
        });
        popup.show();
    } else if (node instanceof ActionInsertNode) {
        final EditActionInsertPopup popup = new EditActionInsertPopup((ActionInsertNode) node, oracle, new com.google.gwt.user.client.Command() {

            @Override
            public void execute() {
                callback.execute();
            }
        });
        popup.show();
    } else if (node instanceof ActionUpdateNode) {
        final EditActionUpdatePopup popup = new EditActionUpdatePopup((ActionUpdateNode) node, oracle, new com.google.gwt.user.client.Command() {

            @Override
            public void execute() {
                callback.execute();
            }
        });
        popup.show();
    } else if (node instanceof ActionRetractNode) {
        final EditActionRetractPopup popup = new EditActionRetractPopup((ActionRetractNode) node, new com.google.gwt.user.client.Command() {

            @Override
            public void execute() {
                callback.execute();
            }
        });
        popup.show();
    }
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) EditActionUpdatePopup(org.drools.workbench.screens.guided.dtree.client.widget.popups.EditActionUpdatePopup) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) EditTypePopup(org.drools.workbench.screens.guided.dtree.client.widget.popups.EditTypePopup) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) Command(org.uberfire.mvp.Command) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) EditActionInsertPopup(org.drools.workbench.screens.guided.dtree.client.widget.popups.EditActionInsertPopup) EditConstraintPopup(org.drools.workbench.screens.guided.dtree.client.widget.popups.EditConstraintPopup) EditActionRetractPopup(org.drools.workbench.screens.guided.dtree.client.widget.popups.EditActionRetractPopup)

Aggregations

ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)16 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)13 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)12 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)9 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)8 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)8 Test (org.junit.Test)8 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)5 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)5 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)5 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)5 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)5 Calendar (java.util.Calendar)4 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)4 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)4 BigInteger (java.math.BigInteger)2 Date (java.util.Date)2 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)2 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)2 ArrayList (java.util.ArrayList)1