use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionModifyActionRetract.
@Test
public void testSingleRule_ActionModifyActionRetract() throws Exception {
final String drl = "rule \"test_0\"\n" + "when \n" + " $p : Person( )\n" + "then \n" + " modify( $p ) {\n" + " setAge( 25 )\n" + " }\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(true);
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());
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionRetractWithConstraint.
@Test
public void testSingleRule_ActionRetractWithConstraint() throws Exception {
final String drl = "rule \"test_0\"\n" + "when \n" + " $p : Person( $n : name )\n" + "then \n" + " retract( $p );\n" + "end";
final GuidedDecisionTree expected = new GuidedDecisionTree();
expected.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
type.setBinding("$p");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "name");
c1.setBinding("$n");
expected.setRoot(type);
type.addChild(c1);
final ActionRetractNode action = new ActionRetractNodeImpl(type);
c1.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 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());
assertNull(_c1.getValue());
assertEquals(1, _c1.getChildren().size());
assertNotNull(_c1.getChildren().get(0));
assertTrue(_c1.getChildren().get(0) instanceof ActionRetractNode);
final ActionRetractNode _a1 = (ActionRetractNode) _c1.getChildren().get(0);
assertEquals(action.getBoundNode().getBinding(), _a1.getBoundNode().getBinding());
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode in project drools by kiegroup.
the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.
private List<Node> visit(final IAction a, final List<TypeNode> types, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
final List<Node> nodes = new ArrayList<Node>();
if (a instanceof ActionRetractFact) {
final ActionRetractFact arf = (ActionRetractFact) a;
final String binding = arf.getVariableName();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionRetractNode arn = new ActionRetractNodeImpl(tn);
nodes.add(arn);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else if (a instanceof ActionInsertLogicalFact) {
final ActionInsertLogicalFact aif = (ActionInsertLogicalFact) a;
final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
aun.setLogicalInsertion(true);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
} else if (a instanceof ActionInsertFact) {
final ActionInsertFact aif = (ActionInsertFact) a;
final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
aun.setLogicalInsertion(false);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
} else if (a instanceof ActionUpdateField) {
final ActionUpdateField auf = (ActionUpdateField) a;
final String binding = auf.getVariable();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
aun.setModify(true);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : auf.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else if (a instanceof ActionSetField) {
final ActionSetField asf = (ActionSetField) a;
final String binding = asf.getVariable();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : asf.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else {
messages.add(new UnsupportedIActionParserMessage());
return nodes;
}
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionRetractWithConstraint.
@Test
public void testSingleRule_ActionRetractWithConstraint() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " $p : Person( $n : name )\n" + "then\n" + " retract( $p );\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 ActionRetractNode action = new ActionRetractNodeImpl(type);
c1.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode in project drools-wb by kiegroup.
the class GuidedDecisionTreeWidget method processChildren.
private void processChildren(final Node node, final WiresBaseTreeNode uiNode, final boolean isReadOnly) {
uiNode.setSelectionManager(this);
uiNode.setShapesManager(this);
uiNode.setLayoutManager(layoutManager);
if (uiNode instanceof BaseGuidedDecisionTreeShape) {
((BaseGuidedDecisionTreeShape) uiNode).setPresenter(presenter);
}
canvasLayer.add(uiNode);
shapesInCanvas.add(uiNode);
final Iterator<Node> itr = node.iterator();
while (itr.hasNext()) {
final Node child = itr.next();
WiresBaseTreeNode uiChildNode = null;
if (child instanceof TypeNode) {
uiChildNode = typeNodeFactory.getShape((TypeNode) child, isReadOnly);
} else if (child instanceof ConstraintNode) {
uiChildNode = constraintNodeFactory.getShape((ConstraintNode) child, isReadOnly);
} else if (child instanceof ActionInsertNode) {
uiChildNode = actionInsertNodeFactory.getShape((ActionInsertNode) child, isReadOnly);
} else if (child instanceof ActionUpdateNode) {
uiChildNode = actionUpdateNodeFactory.getShape((ActionUpdateNode) child, isReadOnly);
} else if (child instanceof ActionRetractNode) {
uiChildNode = actionRetractNodeFactory.getShape((ActionRetractNode) child, isReadOnly);
}
if (uiChildNode != null) {
uiNode.addChildNode(uiChildNode);
processChildren(child, uiChildNode, isReadOnly);
}
}
}
Aggregations