Search in sources :

Example 46 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools-wb by kiegroup.

the class IndexGuidedRuleTemplateActionsTest method testIndexGuidedRuleTemplateActions.

@Test
public void testIndexGuidedRuleTemplateActions() throws IOException, InterruptedException {
    // Add test files
    final Path path = basePath.resolve("template1.template");
    final TemplateModel model = GuidedRuleTemplateFactory.makeModelWithActions("org.drools.workbench.screens.guided.template.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant"));
            add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage"));
        }
    }, "template1");
    final String xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(model);
    ioService().write(path, xml);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) Import(org.kie.soup.project.datamodel.imports.Import) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 47 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools-wb by kiegroup.

the class IndexGuidedRuleTemplateConditionsTest method testIndexGuidedRuleTemplateConditions.

@Test
public void testIndexGuidedRuleTemplateConditions() throws IOException, InterruptedException {
    // Add test files
    final Path path = basePath.resolve("template1.template");
    final TemplateModel model = GuidedRuleTemplateFactory.makeModelWithConditions("org.drools.workbench.screens.guided.template.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant"));
            add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage"));
        }
    }, "template1");
    final String xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(model);
    ioService().write(path, xml);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) Import(org.kie.soup.project.datamodel.imports.Import) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 48 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped1.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped1() {
    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);
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("field3");
    afv2.setValue("$f3");
    auf1.addFieldValue(afv2);
    m.addRhsItem(auf1);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $p : Person()\n" + "then\n" + "  modify( $p ) {\n" + "    setField1(\"v1\"),\n" + "    setField2(\"v2\"),\n" + "    setField3(\"v3\")\n" + "  }\n" + "end";
    m.addRow(new String[] { "v1", "v2", "v3" });
    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 49 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintsFirstValue.

@Test
public void testCompositeConstraintsFirstValue() {
    TemplateModel m = new TemplateModel();
    m.name = "t1";
    FactPattern p1 = new FactPattern("Person");
    m.addLhsItem(p1);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p1.addConstraint(comp);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("field1");
    X.setFieldType(DataType.TYPE_STRING);
    X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    X.setValue("$f1");
    X.setOperator("==");
    comp.addConstraint(X);
    final SingleFieldConstraint Y = new SingleFieldConstraint();
    Y.setFieldName("field2");
    Y.setFieldType(DataType.TYPE_STRING);
    Y.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    Y.setValue("$f2");
    Y.setOperator("==");
    comp.addConstraint(Y);
    String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" )\n" + "then\n" + "end\n";
    m.addRow(new String[] { "foo", null });
    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 50 with TemplateModel

use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped2.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped2() {
    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);
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("field3");
    afv2.setValue("$f3");
    auf1.addFieldValue(afv2);
    m.addRhsItem(auf1);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $p : Person()\n" + "then\n" + "  modify( $p ) {\n" + "    setField2(\"v2\"),\n" + "    setField3(\"v3\")\n" + "  }\n" + "end";
    m.addRow(new String[] { null, "v2", "v3" });
    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)

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