use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTest method testPriority_table_missing_output_values.
@Test
public void testPriority_table_missing_output_values() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DTABLE_PRIORITY_MISSING_OUTVALS.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "DTABLE_PRIORITY_MISSING_OUTVALS");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(true));
assertThat(dmnModel.getMessages().size(), is(1));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTest method testUnknownVariable1.
@Test
public void testUnknownVariable1() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("unknown_variable1.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9105d4a6-6049-4ace-a9cd-88f18d29bc8f", "Loan Recommendation - context");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.getMessages().size(), is(2));
assertEquals(1, dmnModel.getMessages().stream().filter(m -> m.getMessageType().equals(DMNMessageType.ERR_COMPILING_FEEL)).filter(m -> m.getMessage().contains("Unknown variable 'NonSalaryPct'")).count());
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTest method testVerifyExtendedKieFEELFunction_today.
@Test
public void testVerifyExtendedKieFEELFunction_today() {
// DROOLS-2322
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("just_today.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_56fd6445-ff6a-4c28-8206-71fce7f80436", "just today");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext emptyContext = DMNFactory.newContext();
DMNResult dmnResult = runtime.evaluateAll(dmnModel, emptyContext);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
assertThat(dmnResult.getDecisionResultByName("a decision just today").getResult(), notNullValue());
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNAssemblerService method addResources.
@Override
public void addResources(Object kbuilder, Collection<ResourceWithConfiguration> resources, ResourceType type) throws Exception {
KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
DMNCompilerImpl dmnCompiler = (DMNCompilerImpl) kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
DMNMarshaller dmnMarshaller = dmnCompiler.getMarshaller();
if (resources.size() == 1) {
// quick path:
internalAddResource(kbuilderImpl, dmnCompiler, resources.iterator().next(), Collections.emptyList());
return;
}
List<DMNResource> dmnResources = new ArrayList<>();
for (ResourceWithConfiguration r : resources) {
Definitions definitions = dmnMarshaller.unmarshal(r.getResource().getReader());
QName modelID = new QName(definitions.getNamespace(), definitions.getName());
DMNResource dmnResource = new DMNResource(modelID, r, definitions);
dmnResources.add(dmnResource);
}
// enrich with imports
for (DMNResource r : dmnResources) {
for (Import i : r.getDefinitions().getImport()) {
if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Either<String, DMNResource> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnResources, DMNResource::getModelID);
DMNResource located = resolvedResult.getOrElseThrow(RuntimeException::new);
r.addDependency(located.getModelID());
}
}
}
List<DMNResource> sortedDmnResources = DMNResourceDependenciesSorter.sort(dmnResources);
Collection<DMNModel> dmnModels = new ArrayList<>();
for (DMNResource dmnRes : sortedDmnResources) {
DMNModel dmnModel = internalAddResource(kbuilderImpl, dmnCompiler, dmnRes.getResAndConfig(), dmnModels);
dmnModels.add(dmnModel);
}
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNAssemblerService method addResource.
@Override
public void addResource(Object kbuilder, Resource resource, ResourceType type, ResourceConfiguration configuration) throws Exception {
logger.warn("invoked legacy addResource (no control on the order of the assembler compilation): " + resource.getSourcePath());
KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
DMNCompiler dmnCompiler = kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
Collection<DMNModel> dmnModels = new ArrayList<>();
for (PackageRegistry pr : kbuilderImpl.getPackageRegistry().values()) {
ResourceTypePackage resourceTypePackage = pr.getPackage().getResourceTypePackages().get(ResourceType.DMN);
if (resourceTypePackage != null) {
DMNPackageImpl dmnpkg = (DMNPackageImpl) resourceTypePackage;
dmnModels.addAll(dmnpkg.getAllModels().values());
}
}
compileResourceToModel(kbuilderImpl, dmnCompiler, resource, dmnModels);
}
Aggregations