Search in sources :

Example 1 with TemplateModel

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;
}
Also used : TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel)

Example 2 with TemplateModel

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);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 3 with TemplateModel

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);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 4 with TemplateModel

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);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 5 with TemplateModel

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);
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Aggregations

TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)118 Test (org.junit.Test)103 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)89 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)88 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)85 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)64 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)63 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)34 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)26 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)16 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)11 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)8 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)7 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)6 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)5 Query (org.apache.lucene.search.Query)3 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)3 Path (org.uberfire.backend.vfs.Path)3 ArrayList (java.util.ArrayList)2 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)2