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);
}
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations