Search in sources :

Example 41 with TemplateModel

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

the class GuidedRuleTemplateProviderImpl method loadFromInputStream.

@Override
public ResourceConversionResult loadFromInputStream(InputStream is) throws IOException {
    String xml = new String(IoUtils.readBytesFromInputStream(is), IoUtils.UTF8_CHARSET);
    TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(xml);
    String content = RuleTemplateModelDRLPersistenceImpl.getInstance().marshal(model);
    if (model.hasDSLSentences()) {
        return new ResourceConversionResult(content, ResourceType.DSLR);
    } else {
        return new ResourceConversionResult(content, ResourceType.DRL);
    }
}
Also used : TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) ResourceConversionResult(org.drools.compiler.compiler.ResourceConversionResult)

Example 42 with TemplateModel

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

the class GuidedRuleTemplateEditorServiceImplCDITest method testValidateAndLoad.

@Test
public void testValidateAndLoad() throws Exception {
    final Path testedPath = getPath(CARS);
    final TemplateModel testedModel = testedService.load(testedPath);
    final List<ValidationMessage> messages = testedService.validate(testedPath, testedModel);
    Assertions.assertThat(messages).isEmpty();
    Assertions.assertThat(testedModel.getColsCount()).isEqualTo(3);
    Assertions.assertThat(testedModel.getRowsCount()).isEqualTo(4);
}
Also used : Path(org.uberfire.backend.vfs.Path) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 43 with TemplateModel

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

the class GuidedRuleTemplateFactory method makeModelWithActions.

public static TemplateModel makeModelWithActions(final String packageName, final Collection<Import> imports, final String name) {
    final TemplateModel model = new TemplateModel();
    model.getImports().getImports().addAll(imports);
    model.setPackageName(packageName);
    model.name = name;
    final ActionInsertFact ifc1 = new ActionInsertFact();
    ifc1.setFactType("Applicant");
    ifc1.setBoundName("$a");
    final ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("age");
    afv1.setValue("f1");
    ifc1.addFieldValue(afv1);
    model.addRhsItem(ifc1);
    final ActionInsertFact ifc2 = new ActionInsertFact();
    ifc2.setFactType("Mortgage");
    ifc2.setBoundName("$m");
    final ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("amount");
    afv2.setValue("f2");
    ifc2.addFieldValue(afv2);
    model.addRhsItem(ifc2);
    final ActionSetField asf = new ActionSetField();
    asf.setVariable("$a");
    asf.addFieldValue(new ActionFieldValue("age", "33", DataType.TYPE_NUMERIC_INTEGER));
    model.addRhsItem(asf);
    final ActionUpdateField auf = new ActionUpdateField();
    asf.setVariable("$m");
    asf.addFieldValue(new ActionFieldValue("amount", "10000", DataType.TYPE_NUMERIC_INTEGER));
    model.addRhsItem(auf);
    model.addRow(new String[] { "33", null });
    return model;
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel)

Example 44 with TemplateModel

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

the class GuidedRuleTemplateFactory method makeModelWithConditions.

public static TemplateModel makeModelWithConditions(final String packageName, final Collection<Import> imports, final String name) {
    final TemplateModel model = new TemplateModel();
    model.getImports().getImports().addAll(imports);
    model.setPackageName(packageName);
    model.name = name;
    final FactPattern p1 = new FactPattern("Applicant");
    final SingleFieldConstraint con1 = new SingleFieldConstraint();
    con1.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    con1.setFactType("Applicant");
    con1.setFieldName("age");
    con1.setOperator("==");
    con1.setValue("f1");
    con1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    p1.addConstraint(con1);
    model.addLhsItem(p1);
    final FactPattern p2 = new FactPattern("Mortgage");
    final SingleFieldConstraint con2 = new SingleFieldConstraint();
    con2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    con1.setFactType("Mortgage");
    con2.setFieldName("amount");
    con2.setOperator("==");
    con2.setValue("f2");
    con2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    p2.addConstraint(con2);
    model.addLhsItem(p2);
    model.addRow(new String[] { "33", null });
    return model;
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel)

Example 45 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.getFileSystem()).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)

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)4 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