Search in sources :

Example 6 with ActionRetractNode

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode 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);
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 7 with ActionRetractNode

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionModifyActionRetract.

@Test
public void testSingleRule_ActionModifyActionRetract() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  $p : Person( )\n" + "then\n" + "  modify( $p ) {\n" + "    setAge( 25 )\n" + "  }\n" + "  retract( $p );\n" + "end";
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    model.setRoot(type);
    final ActionUpdateNode action1 = new ActionUpdateNodeImpl(type);
    action1.setModify(true);
    action1.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
    type.addChild(action1);
    final ActionRetractNode action2 = new ActionRetractNodeImpl(type);
    action1.addChild(action2);
    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) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionUpdateNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl) ActionRetractNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl) 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 8 with ActionRetractNode

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionRetract.

@Test
public void testSingleRule_ActionRetract() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  $p : Person( )\n" + "then\n" + "  retract( $p );\n" + "end";
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    model.setRoot(type);
    final ActionRetractNode action = new ActionRetractNodeImpl(type);
    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) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionRetractNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl) 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 9 with ActionRetractNode

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionSetActionRetract.

@Test
public void testSingleRule_ActionSetActionRetract() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  $p : Person( )\n" + "then \n" + "  $p.setAge( 25 );\n" + "  retract( $p );\n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    expected.setRoot(type);
    final ActionUpdateNode action1 = new ActionUpdateNodeImpl(type);
    action1.setModify(false);
    action1.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
    type.addChild(action1);
    final ActionRetractNode action2 = new ActionRetractNodeImpl(type);
    action1.addChild(action2);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    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 _action1 = (ActionUpdateNode) model.getRoot().getChildren().get(0);
    assertEquals(action1.getBoundNode().getBinding(), _action1.getBoundNode().getBinding());
    assertEquals(action1.isModify(), _action1.isModify());
    assertEquals(action1.getFieldValues().size(), _action1.getFieldValues().size());
    assertEquals(1, _action1.getFieldValues().size());
    assertEquals(action1.getFieldValues().get(0).getFieldName(), _action1.getFieldValues().get(0).getFieldName());
    assertEquals(action1.getFieldValues().get(0).getValue().getValue().toString(), _action1.getFieldValues().get(0).getValue().getValue().toString());
    assertEquals(1, _action1.getChildren().size());
    assertNotNull(_action1.getChildren().get(0));
    assertTrue(_action1.getChildren().get(0) instanceof ActionRetractNode);
    final ActionRetractNode _action2 = (ActionRetractNode) _action1.getChildren().get(0);
    assertEquals(action2.getBoundNode().getBinding(), _action2.getBoundNode().getBinding());
}
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) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionUpdateNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl) ActionRetractNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl) 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 10 with ActionRetractNode

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionRetract.

@Test
public void testSingleRule_ActionRetract() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  $p : Person( )\n" + "then \n" + "  retract( $p );\n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    expected.setRoot(type);
    final ActionRetractNode action = new ActionRetractNodeImpl(type);
    type.addChild(action);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("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());
    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 ActionRetractNode);
    final ActionRetractNode _a1 = (ActionRetractNode) model.getRoot().getChildren().get(0);
    assertEquals(action.getBoundNode().getBinding(), _a1.getBoundNode().getBinding());
}
Also used : TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionRetractNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl) 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)

Aggregations

ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)14 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)12 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)11 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)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 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)6 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)6 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)5 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)5 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)5 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)5 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)3 BigInteger (java.math.BigInteger)2 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)2 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)2 ArrayList (java.util.ArrayList)1 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)1 ActionInsertLogicalFact (org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact)1