use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelXMLPersistenceImpl method unmarshal.
/*
* (non-Javadoc)
* @see
* org.drools.ide.common.server.util.RuleModelPersistence#toModel(java.lang.String
* )
*/
@Override
public TemplateModel unmarshal(final String xml) {
if (xml == null || xml.trim().length() == 0) {
return createEmptyModel();
}
TemplateModel model = (TemplateModel) this.xt.fromXML(xml);
// Upgrade model changes to legacy artifacts
ruleModelUpgrader1.upgrade(model);
ruleModelUpgrader2.upgrade(model);
ruleModelUpgrader3.upgrade(model);
ruleTemplateModelUpgrader1.upgrade(model);
model.putInSync();
return model;
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionModifyTwoFieldsFirstTemplateSecondTemplate3.
@Test
public void testActionModifyTwoFieldsFirstTemplateSecondTemplate3() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionUpdateField auf1 = new ActionUpdateField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
auf1.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
auf1.addFieldValue(afv1);
m.addRhsItem(auf1);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " modify( $p ) {\n" + " setField2(\"bar\")\n" + " }\n" + "end";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints5ThirdValue.
@Test
public void testNestedCompositeConstraints5ThirdValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
m.addLhsItem(p);
final SingleFieldConstraint comp1sfc1 = new SingleFieldConstraint();
comp1sfc1.setFieldName("field1");
comp1sfc1.setFieldType(DataType.TYPE_STRING);
comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc1.setValue("$f1");
comp1sfc1.setOperator("==");
comp.addConstraint(comp1sfc1);
final SingleFieldConstraint comp1sfc2 = new SingleFieldConstraint();
comp1sfc2.setFieldName("field2");
comp1sfc2.setFieldType(DataType.TYPE_STRING);
comp1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc2.setValue("$f2");
comp1sfc2.setOperator("==");
comp.addConstraint(comp1sfc2);
final SingleFieldConstraint comp1sfc3 = new SingleFieldConstraint();
comp1sfc3.setFieldName("field3");
comp1sfc3.setFieldType(DataType.TYPE_STRING);
comp1sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc3.setValue("$f3");
comp1sfc3.setOperator("==");
comp.addConstraint(comp1sfc3);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field3 == \"goo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, null, "goo" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testCompositeFactPatternSecondValue.
@Test
public void testCompositeFactPatternSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
FactPattern p1 = new FactPattern("Person");
SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFieldName("field1");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc1.setValue("$f1");
sfc1.setOperator("==");
p1.addConstraint(sfc1);
FactPattern p2 = new FactPattern("Person");
SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFieldName("field2");
sfc2.setFieldType(DataType.TYPE_STRING);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
sfc2.setValue("$f2");
sfc2.setOperator("==");
p2.addConstraint(sfc2);
cp.addFactPattern(p1);
cp.addFactPattern(p2);
m.addLhsItem(cp);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "(\n" + "Person( )\n" + "or\n" + "Person( field2 == \"bar\" )\n" + ")\n" + "then\n" + "end\n";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintSecondValue.
@Test
public void testConnectiveConstraintSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p1 = new FactPattern("Person");
m.addLhsItem(p1);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("field1");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
X.setValue("$f1");
X.setOperator("==");
p1.addConstraint(X);
ConnectiveConstraint connective = new ConnectiveConstraint();
connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
connective.setFieldType(DataType.TYPE_STRING);
connective.setOperator("|| ==");
connective.setValue("$f2");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = connective;
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"bar\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
Aggregations