You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by gi...@apache.org on 2025/05/20 10:05:17 UTC
(incubator-kie-drools) branch main updated: [incubator-kie-issues#1891] DMN: adapt to engine-framework (#6310)
This is an automated email from the ASF dual-hosted git repository.
gitgabrio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git
The following commit(s) were added to refs/heads/main by this push:
new 1137a9bf01 [incubator-kie-issues#1891] DMN: adapt to engine-framework (#6310)
1137a9bf01 is described below
commit 1137a9bf01406a95bdd8a244df71790a43d88784
Author: Gabriele Cardosi <ga...@gmail.com>
AuthorDate: Tue May 20 12:05:13 2025 +0200
[incubator-kie-issues#1891] DMN: adapt to engine-framework (#6310)
* [efesto_DMN_integration] IMplemented integration - tested PMML invocation via Efesto
* [efesto_DMN_integration] WIP
* [efesto_DMN_integration] Sync with main branch
* [efesto_DMN_integration] WIP - partially broken
* [efesto_DMN_integration] WIP - broken
* [efesto_DMN_integration] WIP - build. Efesto test succeed
* [efesto_DMN_integration] WIP - Fix PMML
* [efesto_DMN_integration] WIP
* [efesto_DMN_integration] WIP
* [efesto_DMN_integration] WIP
* [efesto_DMN_integration] WIP - working and tested.
* [efesto_DMN_integration] License formatting
* [efesto_DMN_integration] WIP - build status. Not tested
* [engine_framework_fixes] Fixing the engine framework
* [incubator-kie-issues#1890] Add missing license headers
* [incubator-kie-issues#1890] Fix file name
* [incubator-kie-issues#1891] Implemented EfestoPMMLUtils with tests
* [incubator-kie-issues#1891] Implemented EfestoPMMLUtils with tests
* [incubator-kie-issues#1891] Implemented EfestoPMMLUtils with tests
* [incubator-kie-issues#1891] Implemented EfestoPMMLUtils with tests
* [incubator-kie-issues#1890] Fixed as per PR suggestion
* [incubator-kie-issues#1891] Working with tests
* [incubator-kie-issues#1890] Fixed as per PR review
* [incubator-kie-issues#1890] Fix test
* [incubator-kie-issues#1891] Refactoring - WIP - broken tests
* [incubator-kie-issues#1891] Working status - tests included
* [incubator-kie-issues#1891] Removing direct binding with pmml-trusty - kie-dmn-pmml-tests-trusty broken
* [incubator-kie-issues#1891] Restoring scesim integration tests. Add/modify unit tests. Add very short development guide, to be expanded/updated over time
* [incubator-kie-issues#1891] Adding missing license headers. Minor cleanup
* [incubator-kie-issues#1891] Adding required methods. Fixing scenario-simulation. Cleanup
* [incubator-kie-issues#1891] Fixing paths for windows
* [incubator-kie-issues#1891] Fixing paths for windows
* [incubator-kie-issues#1891] Cleanup
* [incubator-kie-issues#1891] Managing set of DMN resources
* [incubator-kie-issues#1891] Managing set of DMN resources
* [incubator-kie-issues#1891] Cleanup
* [incubator-kie-issues#1891] Fixing file reading from jar
* [incubator-kie-issues#1891] Remove unneeded method from FIleUtils
* [incubator-kie-issues#1891] Experimenting with Identifiers
* Revert "[incubator-kie-issues#1891] Experimenting with Identifiers"
This reverts commit cb7d95e5482c672f29ffb43dabf76ef43483e59f.
* [incubator-kie-issues#1891] Populating GeneratedModelResource at application start
* [incubator-kie-issues#1891] Fixing OS-related path issue
* [incubator-kie-issues#1891] Fixing filename cleanup
* [incubator-kie-issues#1891] Remove looping instantiation
* [incubator-kie-issues#1891] Fix as per PR suggestion
---------
Co-authored-by: Gabriele-Cardosi <ga...@ibm.com>
---
build-parent/pom.xml | 16 +
.../commands/impl/CommandFactoryServiceImpl.java | 3 +-
.../runtime/pmml/ApplyPmmlModelCommand.java | 31 +-
.../Developer_Guide.md | 44 +++
.../drools-scenario-simulation-backend/pom.xml | 24 ++
.../fluent/DMNScenarioExecutableBuilder.java | 81 +++--
.../backend/runner/DMNScenarioRunnerHelper.java | 12 +-
.../backend/util/DMNSimulationUtils.java | 72 +++-
.../fluent/DMNScenarioExecutableBuilderTest.java | 162 +++++++++
.../runner/DMNScenarioRunnerHelperTest.java | 15 +-
.../pom.xml | 19 +
.../integrationtest/ScenarioTest.java | 2 +-
.../test/resources/dmnPmml/KiePMMLTreeTest.scesim | 2 +-
.../src/main/java/org/drools/util/FileUtils.java | 7 +-
.../test/java/org/drools/util/FileUtilsTest.java | 2 +-
.../efesto/common/api/identifiers/LocalUri.java | 12 +-
.../common/api/identifiers/ModelLocalUriId.java | 3 +-
.../org/kie/efesto/common/api/io/IndexFile.java | 2 +-
.../common/api/model/GeneratedModelResource.java | 6 +-
.../kie/efesto/common/api/utils/FileNameUtils.java | 21 +-
.../common/api/identifiers/LocalUriTest.java | 1 -
.../efesto/common/core/storage/ContextStorage.java | 9 +
.../exceptions/KieCompilerServiceException.java | 7 +-
.../EfestoStringResource.java} | 33 +-
.../core/model/EfestoCompilationContextImpl.java | 55 ++-
.../core/model/EfestoCompilationContextUtils.java | 4 +
.../runtimemanager/api/service/RuntimeManager.java | 1 +
.../api/utils/GeneratedResourceUtils.java | 2 +-
efesto/pom.xml | 6 -
.../main/java/org/kie/api/command/KieCommands.java | 3 +-
.../src/main/resources/archetype-resources/pom.xml | 21 ++
.../integrationtestDefaults/reference/pom.xml | 21 ++
kie-dmn/kie-dmn-api/pom.xml | 4 -
kie-dmn/kie-dmn-core/pom.xml | 10 +
.../org/kie/dmn/core/compiler/DMNCompilerImpl.java | 54 +--
.../dmn/core/compiler/DMNEvaluatorCompiler.java | 26 +-
.../org/kie/dmn/core/compiler/DMNImportsUtil.java | 212 +++++++++--
.../AbstractDMNKiePMMLInvocationEvaluator.java | 46 ++-
.../core/pmml/AbstractPMMLInvocationEvaluator.java | 102 +-----
.../org/kie/dmn/core/pmml/DMNImportPMMLInfo.java | 9 +-
.../pmml/DMNKiePMMLTrustyInvocationEvaluator.java | 144 +++-----
.../core/pmml/DummyPMMLInvocationEvaluator.java | 55 +++
.../org/kie/dmn/core/pmml/EfestoPMMLUtils.java | 284 +++++++++++++++
.../core/pmml/PMMLInvocationEvaluatorFactory.java | 126 +++++++
.../kie/dmn/core/runtime/service/DMNEvaluator.java | 75 ++++
.../kie/dmn/core/compiler/DMNCompilerImplTest.java | 6 +-
.../kie/dmn/core/compiler/DMNImportsUtilTest.java | 386 ++++++++++++++++++---
.../DMNKiePMMLTrustyInvocationEvaluatorTest.java | 108 +++---
.../org/kie/dmn/core/pmml/EfestoPMMLUtilsTest.java | 223 ++++++++++++
.../java/org/kie/dmn/core/util/DMNTestUtil.java | 7 +
.../src/test/resources/0001-input-data-string.dmn | 38 ++
.../src/test/resources/IndexFile.dmn_json | 11 +
.../{kie-dmn-api => kie-dmn-efesto-api}/pom.xml | 50 +--
.../identifiers/AbstractModelLocalUriIdDmn.java | 8 +-
.../org/kie/dmn/api/identifiers/DecisionIds.java | 2 +-
.../dmn/api/identifiers/DecisionServiceIds.java | 2 +-
.../kie/dmn/api/identifiers/DmnComponentRoot.java} | 9 +-
.../org/kie/dmn/api/identifiers/DmnIdFactory.java | 24 +-
.../dmn/api/identifiers/DmnIdRedirectFactory.java} | 9 +-
.../dmn/api/identifiers/KieDmnComponentRoot.java} | 22 +-
.../identifiers/LocalCompilationSourceIdDmn.java | 26 +-
.../dmn/api/identifiers/LocalComponentIdDmn.java | 23 +-
.../identifiers/LocalComponentIdRedirectDmn.java | 29 +-
.../kie/dmn/api/identifiers/LocalDecisionId.java | 2 +-
.../api/identifiers/LocalDecisionServiceId.java | 2 +-
.../org.kie/kie-dmn-efesto-api/reflect-config.json | 65 ++++
.../org.kie.dmn.api.identifiers.DmnComponentRoot | 6 +-
...esto.common.api.identifiers.EfestoComponentRoot | 5 +-
kie-dmn/kie-dmn-efesto-compilation/pom.xml | 185 ++++++++++
.../compiler/model/DMNResourceSetResource.java | 20 +-
.../compiler/model/DmnCompilationContext.java | 57 +++
.../compiler/model/DmnCompilationContextImpl.java | 66 ++++
.../compiler/model/EfestoCallableOutputDMN.java | 52 +++
.../compiler/model/EfestoValidationOutput.java | 37 +-
.../service/AbstractKieCompilerServiceDMN.java | 62 ++++
.../service/KieCompilerServiceDMNFile.java | 101 ++++++
.../service/KieCompilerServiceDMNFileSet.java | 107 ++++++
.../service/KieCompilerServiceDMNInputStream.java | 92 +++++
.../service/KieCompilerServiceDMNResourceSet.java | 111 ++++++
.../service/KieCompilerServiceDMNString.java | 90 +++++
.../efesto/compiler/utils/DmnCompilerUtils.java | 164 +++++++++
...mpilationmanager.api.service.KieCompilerService | 9 +-
.../service/AbstractKieCompilerServiceDMNTest.java | 109 ++++++
.../service/KieCompilerServiceDMNFileTest.java | 132 +++++++
.../KieCompilerServiceDMNInputStreamTest.java | 96 +++++
.../service/KieCompilerServiceDMNResourceTest.java | 107 ++++++
.../compiler/utils/DmnCompilerUtilsTest.java | 92 +++++
.../src/test/resources/0001-input-data-string.dmn | 37 ++
kie-dmn/kie-dmn-efesto-runtime/pom.xml | 113 ++++++
.../dmn/efesto/runtime/model/EfestoOutputDMN.java} | 17 +-
.../dmn/efesto/runtime/service/DMNEvaluator.java | 82 +++++
.../service/KieRuntimeServiceDMNMapInput.java | 75 ++++
.../dmn/efesto/runtime/utils/DmnRuntimeHelper.java | 84 +++++
...to.runtimemanager.api.service.KieRuntimeService | 5 +-
.../service/KieRuntimeServiceDMNMapInputTest.java | 99 ++++++
.../src/test/resources/IndexFile.dmn_json | 11 +
.../kie-dmn-pmml-tests-trusty/pom.xml | 7 +
.../pmml/trusty/DMNRegressionTrustyPMMLTest.java | 2 +-
.../kie/dmn/pmml/trusty/DMNTreeTrustyPMMLTest.java | 2 +-
...ImportTest.java => NoPMMLTrustyImportTest.java} | 19 +-
.../kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java | 2 +-
.../pmml/trusty/TrustyPMMLValidatorImportTest.java | 2 +-
.../DMNv1_x/pmml/KiePMMLRegression.dmn | 193 +++++++++++
.../valid_models/DMNv1_x/pmml/test_regression.pmml | 49 +++
.../java/org/kie/dmn/validation/ValidatorTest.java | 2 +-
kie-dmn/pom.xml | 23 +-
.../KieRuntimeServiceDrlKieSessionLocal.java | 5 +-
.../service/KieRuntimeServiceDrlMapInput.java | 4 +-
.../runtime/mapinput/utils/DrlRuntimeHelper.java | 5 +-
.../mapinput/utils/DrlRuntimeHelperTest.java | 5 +-
.../engine/runtime/utils/EfestoKieSessionUtil.java | 2 +-
.../runtime/utils/EfestoKieSessionUtilTest.java | 2 +-
.../org/kie/internal/pmml/PMMLCommandExecutor.java | 8 +-
.../identifiers/AbstractModelLocalUriIdPmml.java | 2 +-
.../pmml/api/identifiers/LocalComponentIdPmml.java | 2 +-
.../kie/pmml/api/identifiers/PmmlIdFactory.java | 2 +-
.../pmml/compiler/PMMLCompilationContextImpl.java | 2 +-
.../serialization/PMMLRequestDataDeserializer.java | 3 +-
.../PMMLRequestDataDeserializerService.java | 3 +-
...to.runtimemanager.api.service.KieRuntimeService | 1 +
.../src/test/java/org/kie/pmml/TestingHelper.java | 2 +
.../service/KieRuntimeServicePMMLMapInputTest.java | 1 +
kie-pmml-trusty/pom.xml | 6 -
123 files changed, 4733 insertions(+), 744 deletions(-)
diff --git a/build-parent/pom.xml b/build-parent/pom.xml
index 34df972409..2ab5cc61d8 100644
--- a/build-parent/pom.xml
+++ b/build-parent/pom.xml
@@ -223,6 +223,9 @@
<!-- download-maven-plugin used to download arbitrary files at compile time -->
<version.download-maven-plugin>2.0.0</version.download-maven-plugin>
+ <!-- plugin used to enforce architectural constraints -->
+ <archunit.maven.plugin.version>2.9.1</archunit.maven.plugin.version>
+ <version.archunit.junit5>1.4.0</version.archunit.junit5>
</properties>
<dependencyManagement>
@@ -1191,6 +1194,13 @@
<artifactId>jboss-logging</artifactId>
<version>${version.org.jboss.logging}</version>
</dependency>
+
+ <dependency>
+ <groupId>com.tngtech.archunit</groupId>
+ <artifactId>archunit-junit5</artifactId>
+ <version>${version.archunit.junit5}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -1864,6 +1874,12 @@
<artifactId>frontend-maven-plugin</artifactId>
<version>${version.com.github.eirslett}</version>
</plugin>
+
+ <plugin>
+ <groupId>com.societegenerale.commons</groupId>
+ <artifactId>arch-unit-maven-plugin</artifactId>
+ <version>${archunit.maven.plugin.version}</version>
+ </plugin>
</plugins>
</pluginManagement>
diff --git a/drools-commands/src/main/java/org/drools/commands/impl/CommandFactoryServiceImpl.java b/drools-commands/src/main/java/org/drools/commands/impl/CommandFactoryServiceImpl.java
index 0c747b7354..34e044415d 100644
--- a/drools-commands/src/main/java/org/drools/commands/impl/CommandFactoryServiceImpl.java
+++ b/drools-commands/src/main/java/org/drools/commands/impl/CommandFactoryServiceImpl.java
@@ -62,7 +62,6 @@ import org.drools.commands.runtime.ExecutionResultImpl;
import org.kie.api.command.BatchExecutionCommand;
import org.kie.api.command.Command;
import org.kie.api.command.Setter;
-import org.kie.api.pmml.PMMLRequestData;
import org.kie.api.runtime.ExecutionResults;
import org.kie.api.runtime.ObjectFilter;
import org.kie.api.runtime.process.WorkItemHandler;
@@ -368,7 +367,7 @@ public class CommandFactoryServiceImpl implements ExtendedKieCommands {
}
@Override
- public Command newApplyPmmlModel(PMMLRequestData request) {
+ public Command newApplyPmmlModel(Map<String, Object> request) {
return new ApplyPmmlModelCommand(request);
}
diff --git a/drools-commands/src/main/java/org/drools/commands/runtime/pmml/ApplyPmmlModelCommand.java b/drools-commands/src/main/java/org/drools/commands/runtime/pmml/ApplyPmmlModelCommand.java
index 0afdc97077..246fced07a 100644
--- a/drools-commands/src/main/java/org/drools/commands/runtime/pmml/ApplyPmmlModelCommand.java
+++ b/drools-commands/src/main/java/org/drools/commands/runtime/pmml/ApplyPmmlModelCommand.java
@@ -20,18 +20,17 @@ package org.drools.commands.runtime.pmml;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
+
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElements;
import jakarta.xml.bind.annotation.XmlRootElement;
-
import org.drools.commands.IdentifiableResult;
import org.kie.api.command.ExecutableCommand;
-import org.kie.api.pmml.PMML4Result;
-import org.kie.api.pmml.PMMLRequestData;
import org.kie.api.runtime.Context;
import org.kie.api.runtime.ExecutionResults;
import org.kie.internal.command.RegistryContext;
@@ -41,7 +40,7 @@ import org.slf4j.LoggerFactory;
@XmlRootElement(name = "apply-pmml-model-command")
@XmlAccessorType(XmlAccessType.FIELD)
-public class ApplyPmmlModelCommand implements ExecutableCommand<PMML4Result>,
+public class ApplyPmmlModelCommand implements ExecutableCommand<Map<String, Object>>,
IdentifiableResult {
private static Logger logger = LoggerFactory.getLogger(ApplyPmmlModelCommand.class);
@@ -54,7 +53,7 @@ public class ApplyPmmlModelCommand implements ExecutableCommand<PMML4Result>,
@XmlAttribute(name = "hasMining")
private Boolean hasMining;
@XmlElement(name = "requestData")
- private PMMLRequestData requestData;
+ private Map<String, Object> requestData;
@XmlElements(
@XmlElement(name = "complexInputObject", type = Object.class)
)
@@ -65,29 +64,29 @@ public class ApplyPmmlModelCommand implements ExecutableCommand<PMML4Result>,
super();
}
- public ApplyPmmlModelCommand(PMMLRequestData requestData) {
+ public ApplyPmmlModelCommand(Map<String, Object> requestData) {
initialize(requestData, null, null);
}
- public ApplyPmmlModelCommand(PMMLRequestData requestData, List<Object> complexInputList) {
+ public ApplyPmmlModelCommand(Map<String, Object> requestData, List<Object> complexInputList) {
initialize(requestData, complexInputList, null);
}
- public ApplyPmmlModelCommand(PMMLRequestData requestData, List<Object> complexInputList, Boolean hasMining) {
+ public ApplyPmmlModelCommand(Map<String, Object> requestData, List<Object> complexInputList, Boolean hasMining) {
initialize(requestData, complexInputList, hasMining);
}
- private void initialize(PMMLRequestData requestData, List<Object> complexInputList, Boolean hasMining) {
+ private void initialize(Map<String, Object> requestData, List<Object> complexInputList, Boolean hasMining) {
this.requestData = requestData;
this.complexInputObjects = complexInputList != null ? new ArrayList(complexInputList) : new ArrayList<>();
this.hasMining = hasMining != null ? hasMining : Boolean.FALSE;
}
- public PMMLRequestData getRequestData() {
+ public Map<String, Object> getRequestData() {
return requestData;
}
- public void setRequestData(PMMLRequestData requestData) {
+ public void setRequestData(Map<String, Object> requestData) {
this.requestData = requestData;
}
@@ -128,16 +127,18 @@ public class ApplyPmmlModelCommand implements ExecutableCommand<PMML4Result>,
}
@Override
- public PMML4Result execute(Context context) {
+ public Map<String, Object> execute(Context context) {
if (requestData == null) {
- throw new IllegalStateException("ApplyPmmlModelCommand requires request data (PMMLRequestData) to execute");
+ throw new IllegalStateException("ApplyPmmlModelCommand requires request data (Map<String, Object>) to " +
+ "execute");
}
RegistryContext registryContext = (RegistryContext) context;
- PMML4Result toReturn = PMMLCommandExecutorFactory.get().newPMMLCommandExecutor().execute(requestData, context);
+ Map<String, Object> toReturn = PMMLCommandExecutorFactory.get().newPMMLCommandExecutor().execute(requestData,
+ context);
// Needed to update the ExecutionResultImpl and the Registry context,
// as done inside legacy implementation
Optional<ExecutionResults> execRes = Optional.ofNullable(registryContext.lookup(ExecutionResults.class));
- registryContext.register(PMML4Result.class, toReturn);
+ registryContext.register(Map.class, toReturn);
execRes.ifPresent(result -> result.setResult("results", toReturn));
return toReturn;
}
diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/Developer_Guide.md b/drools-scenario-simulation/drools-scenario-simulation-backend/Developer_Guide.md
new file mode 100644
index 0000000000..aa3ebb80ae
--- /dev/null
+++ b/drools-scenario-simulation/drools-scenario-simulation-backend/Developer_Guide.md
@@ -0,0 +1,44 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+# SCESIM BACKEND
+
+Currently, SCESIM engine is based on JUnit 4, and it is fired annotating a test class with
+
+```java
+@org.junit.runner.RunWith(ScenarioJunitActivator.class)
+```
+
+It provides two runners, one for Decision engine and one for Rules engine.
+
+For both runners there is `RunnerHelper` implementing `AbstractRunnerHelper`, namely:
+
+1. `DMNScenarioRunnerHelper`
+2. `RuleScenarioRunnerHelper`
+
+Scope of the `RunnerHelper`s is to
+1. instantiate an `ExecutableBuilder`, that contains all the required data to execute a model
+2. invoke methods on the above, to fire engine execution and retrieve results
+
+For `ExecutableBuilder` instantiation, the `RuleScenarioRunnerHelper` uses the tradition approach, based on KieContainer and related APIs.
+`DMNScenarioRunnerHelper`, on the other side, features the Efesto APIs, thus not requiring the KieContainer instantiation and usage.
+
+
+
+
+
diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/pom.xml b/drools-scenario-simulation/drools-scenario-simulation-backend/pom.xml
index 03b8f5abfe..2b679d27e8 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-backend/pom.xml
+++ b/drools-scenario-simulation/drools-scenario-simulation-backend/pom.xml
@@ -94,6 +94,14 @@
<groupId>org.kie</groupId>
<artifactId>kie-dmn-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ </dependency>
<!-- Test dependencies -->
<dependency>
@@ -115,6 +123,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-compiler-core</artifactId>
+ </dependency>
</dependencies>
@@ -127,6 +139,18 @@
<type>pom</type>
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/fluent/DMNScenarioExecutableBuilder.java b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/fluent/DMNScenarioExecutableBuilder.java
index cc20746de9..d870d225ea 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/fluent/DMNScenarioExecutableBuilder.java
+++ b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/fluent/DMNScenarioExecutableBuilder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,57 +18,80 @@
*/
package org.drools.scenariosimulation.backend.fluent;
+import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
import org.drools.scenariosimulation.backend.util.DMNSimulationUtils;
+import org.drools.util.ResourceHelper;
import org.kie.api.runtime.ExecutableRunner;
-import org.kie.api.runtime.KieContainer;
-import org.kie.api.runtime.KieRuntimeFactory;
import org.kie.api.runtime.RequestContext;
-import org.kie.dmn.api.core.DMNContext;
import org.kie.dmn.api.core.DMNModel;
-import org.kie.dmn.api.core.DMNResult;
-import org.kie.dmn.api.core.DMNRuntime;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.efesto.runtime.model.EfestoOutputDMN;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.GeneratedModelResource;
+import org.kie.efesto.common.api.model.GeneratedResources;
+
+import static org.drools.scenariosimulation.backend.util.DMNSimulationUtils.compileModels;
public class DMNScenarioExecutableBuilder {
- public static final String DEFAULT_APPLICATION = "defaultApplication";
public static final String DMN_RESULT = "dmnResult";
public static final String DMN_MODEL = "dmnModel";
- private final DMNRuntime dmnRuntime;
- private final DMNContext dmnContext;
- private DMNModel dmnModel;
-
- private DMNScenarioExecutableBuilder(KieContainer kieContainer, String applicationName) {
- dmnRuntime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
- dmnContext = dmnRuntime.newContext();
- }
-
- private DMNScenarioExecutableBuilder(KieContainer kieContainer) {
- this(kieContainer, DEFAULT_APPLICATION);
- }
+ private final Map<String, Object> dmnContext;
+ // default access for testing purpose
+ DMNModel dmnModel;
+ // default access for testing purpose
+ ModelLocalUriId dmnModelLocalUriId;
+ // default access for testing purpose
+ final Map<String, GeneratedResources> generatedResourcesMap;
- public static DMNScenarioExecutableBuilder createBuilder(KieContainer kieContainer, String applicationName) {
- return new DMNScenarioExecutableBuilder(kieContainer, applicationName);
+ private DMNScenarioExecutableBuilder(Map<String, GeneratedResources> generatedResourcesMap) {
+ dmnContext = new HashMap<>();
+ this.generatedResourcesMap = generatedResourcesMap;
}
- public static DMNScenarioExecutableBuilder createBuilder(KieContainer kieContainer) {
- return new DMNScenarioExecutableBuilder(kieContainer);
+ public static DMNScenarioExecutableBuilder createBuilder() {
+ try {
+ Collection<File> dmnFiles = ResourceHelper.getFileResourcesByExtension("dmn");
+ Map<String, GeneratedResources> generatedResourcesMap = compileModels(dmnFiles);
+ return new DMNScenarioExecutableBuilder(generatedResourcesMap);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
}
- public void setActiveModel(String path) {
- dmnModel = DMNSimulationUtils.extractDMNModel(dmnRuntime, path);
+ @SuppressWarnings( "rawtypes")
+ public void setActiveModel(String fileName, String modelName) {
+ GeneratedResources dmnGeneratedResources = generatedResourcesMap.get("dmn");
+ ModelLocalUriId targetModelLocalUriId = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName, modelName);
+ GeneratedModelResource generatedModelResource = dmnGeneratedResources.stream()
+ .filter(GeneratedModelResource.class::isInstance)
+ .map(GeneratedModelResource.class::cast)
+ .filter(genRes -> genRes.getModelLocalUriId().equals(targetModelLocalUriId))
+ .findFirst()
+ .orElseThrow(() -> new IllegalStateException("Could not find generated model resource for " + targetModelLocalUriId));
+ dmnModelLocalUriId = generatedModelResource.getModelLocalUriId();
+ dmnModel = (DMNModel) generatedModelResource.getCompiledModel();
}
public void setValue(String key, Object value) {
- dmnContext.set(key, value);
+ dmnContext.put(key, value);
}
public RequestContext run() {
- DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, dmnContext);
+ EfestoOutputDMN efestoOutput = (EfestoOutputDMN) DMNSimulationUtils.getEfestoOutput(generatedResourcesMap, dmnModelLocalUriId, dmnContext);
RequestContext requestContext = ExecutableRunner.create().createContext();
- requestContext.setResult(dmnResult);
+ requestContext.setResult(efestoOutput.getOutputData());
requestContext.setOutput(DMN_MODEL, dmnModel);
- requestContext.setOutput(DMN_RESULT, dmnResult);
+ requestContext.setOutput(DMN_RESULT, efestoOutput.getOutputData());
return requestContext;
}
}
diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelper.java b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelper.java
index 72dc6e63ab..dc777569f5 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelper.java
+++ b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelper.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -49,6 +49,7 @@ import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNModel;
import org.kie.dmn.api.core.DMNResult;
import org.kie.dmn.api.core.ast.DecisionNode;
+import org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils;
import static org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithMessage;
import static org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus.FAILED;
@@ -66,8 +67,9 @@ public class DMNScenarioRunnerHelper extends AbstractRunnerHelper {
if (!ScenarioSimulationModel.Type.DMN.equals(settings.getType())) {
throw new ScenarioException("Impossible to run a not-DMN simulation with DMN runner");
}
- DMNScenarioExecutableBuilder executableBuilder = createBuilderWrapper(kieContainer);
- executableBuilder.setActiveModel(settings.getDmnFilePath());
+ DMNScenarioExecutableBuilder executableBuilder = createBuilderWrapper();
+ String fileName = DmnCompilerUtils.getCleanedFilenameForURI(settings.getDmnFilePath());
+ executableBuilder.setActiveModel(fileName, settings.getDmnName());
defineInputValues(scenarioRunnerData.getBackgrounds(), scenarioRunnerData.getGivens()).forEach(executableBuilder::setValue);
@@ -289,7 +291,7 @@ public class DMNScenarioRunnerHelper extends AbstractRunnerHelper {
return toReturn;
}
- protected DMNScenarioExecutableBuilder createBuilderWrapper(KieContainer kieContainer) {
- return DMNScenarioExecutableBuilder.createBuilder(kieContainer);
+ protected DMNScenarioExecutableBuilder createBuilderWrapper() {
+ return DMNScenarioExecutableBuilder.createBuilder();
}
}
diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/util/DMNSimulationUtils.java b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/util/DMNSimulationUtils.java
index 80ae5e221d..67f9b6f49b 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/util/DMNSimulationUtils.java
+++ b/drools-scenario-simulation/drools-scenario-simulation-backend/src/main/java/org/drools/scenariosimulation/backend/util/DMNSimulationUtils.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,47 +18,81 @@
*/
package org.drools.scenariosimulation.backend.util;
+import java.io.File;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
-import org.kie.api.runtime.KieContainer;
-import org.kie.api.runtime.KieRuntimeFactory;
+import java.util.Map;
import org.kie.dmn.api.core.DMNModel;
-import org.kie.dmn.api.core.DMNRuntime;
+import org.kie.dmn.efesto.compiler.model.DmnCompilationContext;
+import org.kie.efesto.common.api.identifiers.LocalUri;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.api.model.GeneratedResources;
+import org.kie.efesto.compilationmanager.api.model.EfestoFileSetResource;
+import org.kie.efesto.compilationmanager.api.service.CompilationManager;
+import org.kie.efesto.compilationmanager.api.utils.SPIUtils;
+import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
+import org.kie.efesto.runtimemanager.api.model.EfestoInput;
+import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
+import org.kie.efesto.runtimemanager.api.model.EfestoOutput;
+import org.kie.efesto.runtimemanager.api.service.RuntimeManager;
+import org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils;
+import org.kie.memorycompiler.KieMemoryCompiler;
public class DMNSimulationUtils {
- private static String delimiter = "/";
+ private static final String SLASH = "/";
+ private static final KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader =
+ new KieMemoryCompiler.MemoryCompilerClassLoader(Thread.currentThread().getContextClassLoader());
+ private static final CompilationManager compilationManager =
+ SPIUtils.getCompilationManager(true).orElseThrow(() -> new RuntimeException("Compilation Manager not " +
+ "available"));
+ private static final RuntimeManager runtimeManager =
+ org.kie.efesto.runtimemanager.api.utils.SPIUtils.getRuntimeManager(true).orElseThrow(() -> new RuntimeException("Runtime Manager not available"));
private DMNSimulationUtils() {
}
- public static DMNModel extractDMNModel(DMNRuntime dmnRuntime, String path) {
- List<String> pathSplit = Arrays.asList(new StringBuilder(path).reverse().toString().split(delimiter));
- List<DMNModel> dmnModels = dmnRuntime.getModels();
-
- return findDMNModel(dmnModels, pathSplit, 1);
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static Map<String, GeneratedResources> compileModels(Collection<File> dmnFiles) {
+ ModelLocalUriId dmnModelLocalUriId = new ModelLocalUriId(LocalUri.Root.append("dmn").append("scesim"));
+ EfestoFileSetResource toProcessDmn = new EfestoFileSetResource(new HashSet<>(dmnFiles), dmnModelLocalUriId);
+ EfestoCompilationContext dmnCompilationContext = DmnCompilationContext.buildWithParentClassLoader(memoryCompilerClassLoader);
+ compilationManager.processResource(dmnCompilationContext, toProcessDmn);
+ return dmnCompilationContext.getGeneratedResourcesMap();
}
- public static DMNRuntime extractDMNRuntime(KieContainer kieContainer) {
- return KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
+ @SuppressWarnings("rawtypes")
+ public static EfestoOutput getEfestoOutput(Map<String, GeneratedResources> generatedResourcesMap,
+ ModelLocalUriId modelLocalUriId, Map<String, Object> inputData) {
+ EfestoLocalRuntimeContext runtimeContext =
+ EfestoRuntimeContextUtils.buildWithParentClassLoader(memoryCompilerClassLoader, generatedResourcesMap);
+ EfestoInput<Map<String, Object>> inputDMN = new BaseEfestoInput<>(modelLocalUriId, inputData);
+ Collection<EfestoOutput> efestoOutputs = runtimeManager.evaluateInput(runtimeContext, inputDMN);
+ return efestoOutputs.iterator().next();
}
public static DMNModel findDMNModel(List<DMNModel> dmnModels, List<String> pathToFind, int step) {
List<DMNModel> result = new ArrayList<>();
- String pathToCompare = String.join(delimiter, pathToFind.subList(0, step));
+ String pathToCompare = String.join(SLASH, pathToFind.subList(0, step));
for (DMNModel dmnModel : dmnModels) {
String modelPath = new StringBuilder(dmnModel.getResource().getSourcePath()).reverse().toString();
if (modelPath.startsWith(pathToCompare)) {
result.add(dmnModel);
}
}
- if (result.size() == 0) {
- throw new ImpossibleToFindDMNException("Retrieving the DMNModel has failed. Make sure the used DMN asset does not " +
- "produce any compilation errors and that the project does not " +
- "contain multiple DMN assets with the same name and namespace. " +
- "In addition, check if the reference to the DMN file is correct " +
+ if (result.isEmpty()) {
+ throw new ImpossibleToFindDMNException("Retrieving the DMNModel has failed. Make sure the used DMN asset " +
+ "does not " +
+ "produce any compilation errors and that the project does " +
+ "not " +
+ "contain multiple DMN assets with the same name and " +
+ "namespace. " +
+ "In addition, check if the reference to the DMN file is " +
+ "correct " +
"in the Settings panel. " +
"After addressing the issues, build the project again.");
} else if (result.size() == 1) {
diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/fluent/DMNScenarioExecutableBuilderTest.java b/drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/fluent/DMNScenarioExecutableBuilderTest.java
new file mode 100644
index 0000000000..861fd30ed9
--- /dev/null
+++ b/drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/fluent/DMNScenarioExecutableBuilderTest.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.scenariosimulation.backend.fluent;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.drools.scenariosimulation.backend.util.DMNSimulationUtils;
+import org.drools.util.ResourceHelper;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.GeneratedModelResource;
+import org.kie.efesto.common.api.model.GeneratedResources;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings("rawtypes")
+public class DMNScenarioExecutableBuilderTest {
+
+ public static final Logger LOG = LoggerFactory.getLogger(DMNScenarioExecutableBuilderTest.class);
+
+ @Test
+ public void testCreateBuilderNoException() {
+ Map<String, GeneratedResources> generatedResourcesMap = new HashMap<>();
+ Collection<File> dmnFiles = new ArrayList<>();
+ Collection<File> pmmlFiles = new ArrayList<>();
+ try (MockedStatic<DMNSimulationUtils> mockDMNSimulationUtils = Mockito.mockStatic(DMNSimulationUtils.class);
+ MockedStatic<ResourceHelper> mockResourceHelper = Mockito.mockStatic(ResourceHelper.class)) {
+ mockResourceHelper.when(() -> ResourceHelper.getFileResourcesByExtension("dmn")).thenAnswer(invocation -> {
+ LOG.debug("Mocked static Collection<File> getFileResourcesByExtension dmn!");
+ return dmnFiles;
+ });
+ mockResourceHelper.when(() -> ResourceHelper.getFileResourcesByExtension("pmml")).thenAnswer(invocation -> {
+ LOG.debug("Mocked static Collection<File> getFileResourcesByExtension pmml!");
+ return pmmlFiles;
+ });
+ mockDMNSimulationUtils.when(() -> DMNSimulationUtils.compileModels(dmnFiles)).thenAnswer(invocation -> {
+ LOG.debug("Mocked static Map compileModels!");
+ return generatedResourcesMap;
+ });
+ DMNScenarioExecutableBuilder builder = DMNScenarioExecutableBuilder.createBuilder();
+ mockResourceHelper.verify(() -> ResourceHelper.getFileResourcesByExtension("dmn"), times(1));
+ mockDMNSimulationUtils.verify(() -> DMNSimulationUtils.compileModels(dmnFiles), times(1));
+ assertThat(builder).isNotNull();
+ assertThat(builder.generatedResourcesMap).isEqualTo(generatedResourcesMap);
+ }
+ }
+
+ @Test
+ public void testCreateBuilderException() {
+ Collection<File> dmnFiles = new ArrayList<>();
+ Collection<File> pmmlFiles = new ArrayList<>();
+ try (MockedStatic<DMNSimulationUtils> mockDMNSimulationUtils = Mockito.mockStatic(DMNSimulationUtils.class);
+ MockedStatic<ResourceHelper> mockResourceHelper = Mockito.mockStatic(ResourceHelper.class)) {
+ mockResourceHelper.when(() -> ResourceHelper.getFileResourcesByExtension("dmn")).thenAnswer(invocation -> {
+ LOG.debug("Mocked static Collection<File> getFileResourcesByExtension dmn!");
+ return dmnFiles;
+ });
+ mockResourceHelper.when(() -> ResourceHelper.getFileResourcesByExtension("pmml")).thenAnswer(invocation -> {
+ LOG.debug("Mocked static Collection<File> getFileResourcesByExtension pmml!");
+ return pmmlFiles;
+ });
+ mockDMNSimulationUtils.when(() -> DMNSimulationUtils.compileModels(dmnFiles)).thenThrow(RuntimeException.class);
+ assertThrows(IllegalStateException.class, DMNScenarioExecutableBuilder::createBuilder);
+ mockResourceHelper.verify(() -> ResourceHelper.getFileResourcesByExtension("dmn"), times(1));
+ mockDMNSimulationUtils.verify(() -> DMNSimulationUtils.compileModels(dmnFiles), times(1));
+ }
+ }
+
+ @Test
+ public void testSetActiveModelNoException() {
+ String fileName = "/this/is/filename";
+ String modelName = "modelName";
+ ModelLocalUriId modelLocalUriId = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName, modelName);
+ GeneratedModelResource mockGeneratedModelResource = mock(GeneratedModelResource.class);
+ DMNModel mockDMNModel = mock(DMNModel.class);
+ when(mockGeneratedModelResource.getModelLocalUriId()).thenReturn(modelLocalUriId);
+ when(mockGeneratedModelResource.getCompiledModel()).thenReturn(mockDMNModel);
+
+ GeneratedResources generatedResources = new GeneratedResources();
+ generatedResources.add(mockGeneratedModelResource);
+ Map<String, GeneratedResources> generatedResourcesMap = new HashMap<>();
+ generatedResourcesMap.put("dmn", generatedResources);
+ try (MockedStatic<DMNSimulationUtils> mockDMNSimulationUtils = Mockito.mockStatic(DMNSimulationUtils.class)) {
+ mockDMNSimulationUtils.when(() -> DMNSimulationUtils.compileModels(Mockito.any())).thenAnswer(invocation -> {
+ LOG.debug("Mocked static Map compileModels!");
+ return generatedResourcesMap;
+ });
+ DMNScenarioExecutableBuilder builder = DMNScenarioExecutableBuilder.createBuilder();
+ assertThat(builder).isNotNull();
+ assertThat(builder.generatedResourcesMap).isEqualTo(generatedResourcesMap);
+ builder.setActiveModel(fileName, modelName);
+ assertThat(builder.dmnModelLocalUriId).isEqualTo(modelLocalUriId);
+ assertThat(builder.dmnModel).isEqualTo(mockDMNModel);
+ }
+ }
+
+ @Test
+ public void testSetActiveModelException() {
+ String fileName = "/this/is/filename";
+ String modelName = "modelName";
+ ModelLocalUriId modelLocalUriId = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName, modelName);
+ GeneratedModelResource mockGeneratedModelResource = mock(GeneratedModelResource.class);
+ when(mockGeneratedModelResource.getModelLocalUriId()).thenReturn(modelLocalUriId);
+
+ GeneratedResources generatedResources = new GeneratedResources();
+ generatedResources.add(mockGeneratedModelResource);
+ Map<String, GeneratedResources> generatedResourcesMap = new HashMap<>();
+ generatedResourcesMap.put("dmn", generatedResources);
+ try (MockedStatic<DMNSimulationUtils> mockDMNSimulationUtils = Mockito.mockStatic(DMNSimulationUtils.class)) {
+ mockDMNSimulationUtils.when(() -> DMNSimulationUtils.compileModels(Mockito.any())).thenAnswer(invocation -> {
+ LOG.debug("Mocked static Map compileModels!");
+ return generatedResourcesMap;
+ });
+ DMNScenarioExecutableBuilder builder = DMNScenarioExecutableBuilder.createBuilder();
+ assertThat(builder).isNotNull();
+ assertThat(builder.generatedResourcesMap).isEqualTo(generatedResourcesMap);
+ assertThrows(IllegalStateException.class, () -> builder.setActiveModel("not-filename", "not-model-name"));
+ assertThat(builder.dmnModelLocalUriId).isNull();
+ assertThat(builder.dmnModel).isNull();
+ }
+ }
+}
\ No newline at end of file
diff --git a/drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelperTest.java b/drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelperTest.java
index c40bb806d1..42de179213 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelperTest.java
+++ b/drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/runner/DMNScenarioRunnerHelperTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -89,13 +89,15 @@ public class DMNScenarioRunnerHelperTest {
private static final String FEEL_EXPRESSION_NAME = "\"" + NAME + "\"";
private static final BigDecimal AMOUNT = BigDecimal.valueOf(10);
private static final String DMN_FILE_PATH = "dmnFilePath";
+ private static final String DMN_NAMESPACE = "dmnNamespace";
private static final String TEST_DESCRIPTION = "Test description";
private static final ClassLoader classLoader = RuleScenarioRunnerHelperTest.class.getClassLoader();
private static final ExpressionEvaluatorFactory expressionEvaluatorFactory = ExpressionEvaluatorFactory.create(classLoader, ScenarioSimulationModel.Type.DMN);
private static final ExpressionEvaluator expressionEvaluator = new DMNFeelExpressionEvaluator(classLoader);
private final DMNScenarioRunnerHelper runnerHelper = new DMNScenarioRunnerHelper() {
+
@Override
- protected DMNScenarioExecutableBuilder createBuilderWrapper(KieContainer kieContainer) {
+ protected DMNScenarioExecutableBuilder createBuilderWrapper() {
return dmnScenarioExecutableBuilderMock;
}
};
@@ -141,6 +143,8 @@ public class DMNScenarioRunnerHelperTest {
settings = new Settings();
settings.setType(ScenarioSimulationModel.Type.DMN);
settings.setDmnFilePath(DMN_FILE_PATH);
+ settings.setDmnName(NAME);
+ settings.setDmnNamespace(DMN_NAMESPACE);
personFactIdentifier = FactIdentifier.create("Fact 1", "Fact 1");
firstNameGivenExpressionIdentifier = ExpressionIdentifier.create("First Name Given", FactMappingType.GIVEN);
firstNameGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameGivenExpressionIdentifier);
@@ -440,7 +444,7 @@ public class DMNScenarioRunnerHelperTest {
runnerHelper.executeScenario(kieContainerMock, scenarioRunnerData, expressionEvaluatorFactory, simulation.getScesimModelDescriptor(), settings);
- verify(dmnScenarioExecutableBuilderMock, times(1)).setActiveModel(DMN_FILE_PATH);
+ verify(dmnScenarioExecutableBuilderMock, times(1)).setActiveModel(DMN_FILE_PATH, NAME);
verify(dmnScenarioExecutableBuilderMock, times(inputObjects)).setValue(keyCaptor.capture(), valueCaptor.capture());
assertThat(keyCaptor.getAllValues()).containsAll(expectedInputDataToLoad);
for (int i = 0; i < inputObjects; i++) {
@@ -531,7 +535,8 @@ public class DMNScenarioRunnerHelperTest {
assertThat(subValuePerson).hasSize(2).contains(givenImportedPersonFactData, givenImportedPersonFactData2);
}
- public void commonExtractResultMetadata(List<DMNMessage> messages) {
+
+ private void commonExtractResultMetadata(List<DMNMessage> messages) {
Set<DecisionNode> decisions = new HashSet<>();
IntStream.range(0, 5).forEach(index -> decisions.add(createDecisionMock("decision" + index)));
when(dmnModelMock.getDecisions()).thenReturn(decisions);
@@ -564,7 +569,7 @@ public class DMNScenarioRunnerHelperTest {
}
}
- public void commonExtractResultMetadata() {
+ private void commonExtractResultMetadata() {
Set<DecisionNode> decisions = new HashSet<>();
IntStream.range(0, 5).forEach(index -> decisions.add(createDecisionMock("decision" + index)));
when(dmnModelMock.getDecisions()).thenReturn(decisions);
diff --git a/drools-scenario-simulation/drools-scenario-simulation-integrationtest/pom.xml b/drools-scenario-simulation/drools-scenario-simulation-integrationtest/pom.xml
index f66ab6a315..b7dae34ec5 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-integrationtest/pom.xml
+++ b/drools-scenario-simulation/drools-scenario-simulation-integrationtest/pom.xml
@@ -49,6 +49,16 @@
<artifactId>kie-drl-map-input-runtime</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -61,6 +71,15 @@
<groupId>org.drools</groupId>
<artifactId>drools-xml-support</artifactId>
</dependency>
+ <!-- DMN EFESTO -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ </dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-pmml-dependencies</artifactId>
diff --git a/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/java/org/drools/scenariosimulation/integrationtest/ScenarioTest.java b/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/java/org/drools/scenariosimulation/integrationtest/ScenarioTest.java
index 411bf82c5c..d59913ee8f 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/java/org/drools/scenariosimulation/integrationtest/ScenarioTest.java
+++ b/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/java/org/drools/scenariosimulation/integrationtest/ScenarioTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/resources/dmnPmml/KiePMMLTreeTest.scesim b/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/resources/dmnPmml/KiePMMLTreeTest.scesim
index c3a204b819..c0a578deb2 100644
--- a/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/resources/dmnPmml/KiePMMLTreeTest.scesim
+++ b/drools-scenario-simulation/drools-scenario-simulation-integrationtest/src/test/resources/dmnPmml/KiePMMLTreeTest.scesim
@@ -274,7 +274,7 @@
</scesimData>
</background>
<settings>
- <dmnFilePath>src/main/resources/com/myspace/puppa/KiePMMLTree.dmn</dmnFilePath>
+ <dmnFilePath>src/main/resources/dmnPmml/KiePMMLTree.dmn</dmnFilePath>
<type>DMN</type>
<dmnNamespace>https://kiegroup.org/dmn/_FAA4232D-9D61-4089-BB05-5F5D7C1AECE1</dmnNamespace>
<dmnName>TestTreeDMN</dmnName>
diff --git a/drools-util/src/main/java/org/drools/util/FileUtils.java b/drools-util/src/main/java/org/drools/util/FileUtils.java
index 799d746498..22f4abc86e 100644
--- a/drools-util/src/main/java/org/drools/util/FileUtils.java
+++ b/drools-util/src/main/java/org/drools/util/FileUtils.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -29,13 +29,16 @@ import java.util.Comparator;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility to access files
*/
public class FileUtils {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
+
private FileUtils() {
// Avoid instantiating class
}
diff --git a/drools-util/src/test/java/org/drools/util/FileUtilsTest.java b/drools-util/src/test/java/org/drools/util/FileUtilsTest.java
index 79012a9e42..b2dccee9e1 100644
--- a/drools-util/src/test/java/org/drools/util/FileUtilsTest.java
+++ b/drools-util/src/test/java/org/drools/util/FileUtilsTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/LocalUri.java b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/LocalUri.java
index 916ab22c8d..74c6ecef33 100644
--- a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/LocalUri.java
+++ b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/LocalUri.java
@@ -18,10 +18,10 @@
*/
package org.kie.efesto.common.api.identifiers;
-import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.StringTokenizer;
@@ -129,11 +129,7 @@ public abstract class LocalUri {
private LocalUriPathComponent(LocalUri parent, String component) {
this.parent = parent;
- try {
- this.component = URLEncoder.encode(component, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
+ this.component = URLEncoder.encode(component, StandardCharsets.UTF_8);
}
@Override
@@ -141,6 +137,10 @@ public abstract class LocalUri {
return parent;
}
+ public String getComponent() {
+ return component;
+ }
+
/**
* Returns true when the path starts with the given argument.
* <p>
diff --git a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/ModelLocalUriId.java b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/ModelLocalUriId.java
index bd44d4a55e..32cf1afbca 100644
--- a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/ModelLocalUriId.java
+++ b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/identifiers/ModelLocalUriId.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -35,7 +35,6 @@ public class ModelLocalUriId extends LocalUriId implements Serializable {
private final String fullPath;
-
public ModelLocalUriId(LocalUri path) {
super(path);
model = getModel(path);
diff --git a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/io/IndexFile.java b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/io/IndexFile.java
index ecef13ebe5..22bb875c4a 100644
--- a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/io/IndexFile.java
+++ b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/io/IndexFile.java
@@ -100,7 +100,7 @@ public final class IndexFile extends File {
}
public String getModel() {
- return getModel(getSuffix());
+ return getModel(this.getName());
}
@Override
diff --git a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/model/GeneratedModelResource.java b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/model/GeneratedModelResource.java
index bf5e0651d0..32958a7b78 100644
--- a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/model/GeneratedModelResource.java
+++ b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/model/GeneratedModelResource.java
@@ -18,15 +18,17 @@
*/
package org.kie.efesto.common.api.model;
-import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
-
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Objects;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
/**
* A <code>GeneratedResource</code> meant to be directly executed, with a <b>full reference name (frn)</b> identifier
*/
+@JsonIgnoreProperties(value = { "compiledModel" })
public final class GeneratedModelResource<T> implements GeneratedResource {
+
private static final long serialVersionUID = 6588314882989626752L;
/**
* the full reference identifier (e.g. "bar/resource/some_final_model")
diff --git a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/utils/FileNameUtils.java b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/utils/FileNameUtils.java
index ac30ce8764..cf337ee10e 100644
--- a/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/utils/FileNameUtils.java
+++ b/efesto/efesto-core/efesto-common-api/src/main/java/org/kie/efesto/common/api/utils/FileNameUtils.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,22 +18,33 @@
*/
package org.kie.efesto.common.api.utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.File;
+import java.net.URI;
public class FileNameUtils {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(FileNameUtils.class);
private FileNameUtils() {
}
public static String getFileName(String source) {
- return source.contains(File.separator) ?
- source.substring(source.lastIndexOf(File.separatorChar) + 1) : source;
+ String sourceToUse = source;
+ try {
+ sourceToUse = new URI(source).toURL().getFile();
+ } catch (Exception e) {
+ LOGGER.debug("Can't parse the given source {} as URI", source);
+ }
+ return new File(sourceToUse).getName();
}
public static String getSuffix(String fileName) {
- return fileName.substring(fileName.lastIndexOf('.') + 1);
+ return fileName.contains(".") ? fileName.substring(fileName.lastIndexOf('.') + 1) : "";
}
public static String removeSuffix(String fileName) {
- return fileName.substring(0, fileName.lastIndexOf('.'));
+ return fileName.contains(".") ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName;
}
}
diff --git a/efesto/efesto-core/efesto-common-api/src/test/java/org/kie/efesto/common/api/identifiers/LocalUriTest.java b/efesto/efesto-core/efesto-common-api/src/test/java/org/kie/efesto/common/api/identifiers/LocalUriTest.java
index 2b89ae8c9c..c9d892baa5 100644
--- a/efesto/efesto-core/efesto-common-api/src/test/java/org/kie/efesto/common/api/identifiers/LocalUriTest.java
+++ b/efesto/efesto-core/efesto-common-api/src/test/java/org/kie/efesto/common/api/identifiers/LocalUriTest.java
@@ -42,7 +42,6 @@ public class LocalUriTest {
LocalUri hpath = LocalUri.Root.append("example").append("some-id").append("instances").append("some-instance-id");
LocalUri parsedHPath = LocalUri.parse(path);
assertThat(parsedHPath).isEqualTo(hpath);
-
}
@Test
diff --git a/efesto/efesto-core/efesto-common-core/src/main/java/org/kie/efesto/common/core/storage/ContextStorage.java b/efesto/efesto-core/efesto-common-core/src/main/java/org/kie/efesto/common/core/storage/ContextStorage.java
index 044ffe3983..a90c05efd5 100644
--- a/efesto/efesto-core/efesto-common-core/src/main/java/org/kie/efesto/common/core/storage/ContextStorage.java
+++ b/efesto/efesto-core/efesto-common-core/src/main/java/org/kie/efesto/common/core/storage/ContextStorage.java
@@ -26,12 +26,21 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+@SuppressWarnings("rawtypes")
public class ContextStorage {
private static final Map<ModelLocalUriId, EfestoCompilationContext> COMPILATION_CONTEXT_MAP = new HashMap<>();
private static final Map<ModelLocalUriId, String> COMPILATION_SOURCE_MAP = new HashMap<>();
private static final Map<ModelLocalUriId, EfestoRuntimeContext> RUNTIME_CONTEXT_MAP = new HashMap<>();
+ /**
+ * Method used to clean up all data currently stored.
+ */
+ public static void reset() {
+ COMPILATION_CONTEXT_MAP.clear();
+ COMPILATION_SOURCE_MAP.clear();
+ RUNTIME_CONTEXT_MAP.clear();
+ }
public static void putEfestoCompilationContext(ModelLocalUriId modelLocalUriId, EfestoCompilationContext compilationContext) {
COMPILATION_CONTEXT_MAP.put(modelLocalUriId, compilationContext);
diff --git a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java
index 50cf9f7a9a..350b405dcc 100644
--- a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java
+++ b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,8 +18,13 @@
*/
package org.kie.efesto.compilationmanager.api.exceptions;
+import java.io.Serial;
+
public class KieCompilerServiceException extends RuntimeException {
+ @Serial
+ private static final long serialVersionUID = 8287001272309028060L;
+
public KieCompilerServiceException() {
}
diff --git a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/model/EfestoStringResource.java
similarity index 55%
copy from efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java
copy to efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/model/EfestoStringResource.java
index 50cf9f7a9a..12c15a11c8 100644
--- a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java
+++ b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/model/EfestoStringResource.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,26 +16,31 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.efesto.compilationmanager.api.exceptions;
+package org.kie.efesto.compilationmanager.api.model;
-public class KieCompilerServiceException extends RuntimeException {
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
- public KieCompilerServiceException() {
- }
+public final class EfestoStringResource implements EfestoResource<String> {
- public KieCompilerServiceException(String message) {
- super(message);
- }
+ private final String content;
+ private final ModelLocalUriId modelLocalUriId;
- public KieCompilerServiceException(String message, Throwable cause) {
- super(message, cause);
+ /**
+ *
+ * @param content
+ * @param modelLocalUriId
+ */
+ public EfestoStringResource(String content, ModelLocalUriId modelLocalUriId) {
+ this.content = content;
+ this.modelLocalUriId = modelLocalUriId;
}
- public KieCompilerServiceException(Throwable cause) {
- super(cause);
+ @Override
+ public String getContent() {
+ return content;
}
- public KieCompilerServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
+ public ModelLocalUriId getModelLocalUriId() {
+ return modelLocalUriId;
}
}
diff --git a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextImpl.java b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextImpl.java
index 636f5b5f42..e88fc3d9e9 100644
--- a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextImpl.java
+++ b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextImpl.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,6 +18,7 @@
*/
package org.kie.efesto.compilationmanager.core.model;
+import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
@@ -27,10 +28,13 @@ import java.util.Set;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.kie.efesto.common.api.io.IndexFile;
import org.kie.efesto.common.api.listener.EfestoListener;
+import org.kie.efesto.common.api.model.GeneratedModelResource;
import org.kie.efesto.common.api.model.GeneratedResources;
import org.kie.efesto.common.core.utils.JSONUtils;
import org.kie.efesto.compilationmanager.api.exceptions.EfestoCompilationManagerException;
import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.compilationmanager.api.model.EfestoStringResource;
+import org.kie.efesto.compilationmanager.api.service.CompilationManager;
import org.kie.efesto.compilationmanager.api.service.KieCompilerService;
import org.kie.efesto.compilationmanager.api.utils.SPIUtils;
import org.kie.memorycompiler.JavaConfiguration;
@@ -42,6 +46,10 @@ import static org.kie.efesto.common.core.utils.JSONUtils.writeGeneratedResources
public class EfestoCompilationContextImpl<T extends EfestoListener> implements EfestoCompilationContext<T> {
+ private static final CompilationManager compilationManager =
+ SPIUtils.getCompilationManager(true).orElseThrow(() -> new RuntimeException("Compilation Manager not " +
+ "available"));
+
protected final KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader;
protected final Map<String, GeneratedResources> generatedResourcesMap = new HashMap<>();
@@ -52,6 +60,14 @@ public class EfestoCompilationContextImpl<T extends EfestoListener> implements E
populateGeneratedResourcesMap();
}
+ protected EfestoCompilationContextImpl(KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader, boolean setup) {
+ this.memoryCompilerClassLoader = memoryCompilerClassLoader;
+ if (setup) {
+ prepareClassLoader();
+ populateGeneratedResourcesMap();
+ }
+ }
+
private void prepareClassLoader() {
for (ModelLocalUriId modelLocalUriId : localUriIdKeySet()) {
Map<String, byte[]> generatedClasses = getGeneratedClasses(modelLocalUriId);
@@ -61,10 +77,11 @@ public class EfestoCompilationContextImpl<T extends EfestoListener> implements E
private void populateGeneratedResourcesMap() {
Set<String> modelTypes = SPIUtils.collectModelTypes(this);
- Map<String, IndexFile> indexFileMap = IndexFile.findIndexFilesFromClassLoader(memoryCompilerClassLoader, modelTypes);
+ Map<String, IndexFile> indexFileMap = IndexFile.findIndexFilesFromClassLoader(memoryCompilerClassLoader,
+ modelTypes);
indexFileMap.forEach((model, indexFile) -> {
try {
- GeneratedResources generatedResources = JSONUtils.getGeneratedResourcesObject(indexFile);
+ GeneratedResources generatedResources = getInstantiatedResources(indexFile);
generatedResourcesMap.put(model, generatedResources);
} catch (Exception e) {
throw new EfestoCompilationManagerException("Failed to read IndexFile content : " + indexFile.getAbsolutePath(), e);
@@ -84,7 +101,8 @@ public class EfestoCompilationContextImpl<T extends EfestoListener> implements E
@Override
public Map<String, byte[]> compileClasses(Map<String, String> sourcesMap) {
- return KieMemoryCompiler.compileNoLoad(sourcesMap, memoryCompilerClassLoader, JavaConfiguration.CompilerType.NATIVE);
+ return KieMemoryCompiler.compileNoLoad(sourcesMap, memoryCompilerClassLoader,
+ JavaConfiguration.CompilerType.NATIVE);
}
@Override
@@ -129,4 +147,33 @@ public class EfestoCompilationContextImpl<T extends EfestoListener> implements E
}
return indexFiles;
}
+
+ private GeneratedResources getInstantiatedResources(IndexFile indexFile) throws IOException {
+ GeneratedResources readResources = JSONUtils.getGeneratedResourcesObject(indexFile);
+ GeneratedResources toReturn = new GeneratedResources();
+ readResources.forEach(resource -> {
+ if (resource instanceof GeneratedModelResource generatedModelResource && generatedModelResource.getCompiledModel() == null) {
+ GeneratedModelResource toAdd =
+ compileGeneratedModelResource(generatedModelResource);
+ toReturn.add(toAdd);
+ } else {
+ toReturn.add(resource);
+ }
+ }
+ );
+ return toReturn;
+ }
+
+ private GeneratedModelResource compileGeneratedModelResource(GeneratedModelResource toCompile) {
+ EfestoStringResource resource = new EfestoStringResource(toCompile.getModelSource(), toCompile.getModelLocalUriId());
+ compilationManager.processResource(this, resource);
+ Map<String, GeneratedResources> generatedResourcesMap = this.getGeneratedResourcesMap();
+ Map.Entry<String, GeneratedResources> generatedResourcesEntry = generatedResourcesMap.entrySet().stream()
+ .filter(entry -> entry.getKey().equals("dmn"))
+ .findFirst().orElseThrow(() -> new EfestoCompilationManagerException());
+ return generatedResourcesEntry.getValue().stream()
+ .filter(GeneratedModelResource.class::isInstance)
+ .map(GeneratedModelResource.class::cast)
+ .findFirst().orElseThrow(() -> new EfestoCompilationManagerException());
+ }
}
diff --git a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextUtils.java b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextUtils.java
index eccb43b976..fd05483fa9 100644
--- a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextUtils.java
+++ b/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-core/src/main/java/org/kie/efesto/compilationmanager/core/model/EfestoCompilationContextUtils.java
@@ -31,6 +31,10 @@ public class EfestoCompilationContextUtils {
return new EfestoCompilationContextImpl(new KieMemoryCompiler.MemoryCompilerClassLoader(parentClassLoader));
}
+ public static EfestoCompilationContext buildWithParentClassLoaderWithoutSetup(ClassLoader parentClassLoader) {
+ return new EfestoCompilationContextImpl(new KieMemoryCompiler.MemoryCompilerClassLoader(parentClassLoader), false);
+ }
+
public static EfestoCompilationContext buildFromContext(EfestoCompilationContextImpl original, Class<?
extends EfestoCompilationContext> toInstantiate) {
try {
diff --git a/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/service/RuntimeManager.java b/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/service/RuntimeManager.java
index 07c299a133..9cd4e7b5c5 100644
--- a/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/service/RuntimeManager.java
+++ b/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/service/RuntimeManager.java
@@ -24,6 +24,7 @@ import org.kie.efesto.runtimemanager.api.model.EfestoInput;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoOutput;
+@SuppressWarnings("rawtypes")
public interface RuntimeManager {
/**
diff --git a/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/utils/GeneratedResourceUtils.java b/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/utils/GeneratedResourceUtils.java
index 7be9f4c0ba..cb09b4ddd6 100644
--- a/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/utils/GeneratedResourceUtils.java
+++ b/efesto/efesto-core/efesto-runtime-manager/efesto-runtime-manager-api/src/main/java/org/kie/efesto/runtimemanager/api/utils/GeneratedResourceUtils.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/efesto/pom.xml b/efesto/pom.xml
index 697c654c2f..0a5d4e884c 100644
--- a/efesto/pom.xml
+++ b/efesto/pom.xml
@@ -39,7 +39,6 @@
<properties>
<rewrite.maven.plugin.version>4.42.0</rewrite.maven.plugin.version>
<rewrite.testing.frameworks.version>1.22.0</rewrite.testing.frameworks.version>
- <archunit.maven.plugin.version>2.9.1</archunit.maven.plugin.version>
<jdepend.maven.plugin.version>2.0</jdepend.maven.plugin.version>
<skip.jdepend>true</skip.jdepend>
</properties>
@@ -89,11 +88,6 @@
<artifactId>rewrite-maven-plugin</artifactId>
<version>${rewrite.maven.plugin.version}</version>
</plugin>
- <plugin>
- <groupId>com.societegenerale.commons</groupId>
- <artifactId>arch-unit-maven-plugin</artifactId>
- <version>${archunit.maven.plugin.version}</version>
- </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
diff --git a/kie-api/src/main/java/org/kie/api/command/KieCommands.java b/kie-api/src/main/java/org/kie/api/command/KieCommands.java
index 9cb50473ad..3504076910 100644
--- a/kie-api/src/main/java/org/kie/api/command/KieCommands.java
+++ b/kie-api/src/main/java/org/kie/api/command/KieCommands.java
@@ -23,7 +23,6 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.kie.api.internal.utils.KieService;
-import org.kie.api.pmml.PMMLRequestData;
import org.kie.api.runtime.ExecutionResults;
import org.kie.api.runtime.ObjectFilter;
import org.kie.api.runtime.process.WorkItemHandler;
@@ -152,7 +151,7 @@ public interface KieCommands extends KieService {
Command<Long> newAdvanceSessionTime(long amount, TimeUnit unit);
Command<Long> newAdvanceSessionTime(long amount, TimeUnit unit, String outIdentifier);
- Command newApplyPmmlModel(PMMLRequestData request);
+ Command newApplyPmmlModel(Map<String, Object> request);
ExecutionResults newExecutionResults();
}
diff --git a/kie-archetypes/kie-drools-dmn-archetype/src/main/resources/archetype-resources/pom.xml b/kie-archetypes/kie-drools-dmn-archetype/src/main/resources/archetype-resources/pom.xml
index f36395450e..364e7cf515 100644
--- a/kie-archetypes/kie-drools-dmn-archetype/src/main/resources/archetype-resources/pom.xml
+++ b/kie-archetypes/kie-drools-dmn-archetype/src/main/resources/archetype-resources/pom.xml
@@ -50,6 +50,16 @@
<scope>import</scope>
<type>pom</type>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ <version>${drools-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ <version>${drools-version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -67,6 +77,17 @@
<artifactId>drools-model-compiler</artifactId>
</dependency>
+ <!-- Efesto -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ </dependency>
+
+ <!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git a/kie-archetypes/kie-drools-dmn-archetype/src/test/resources/projects/integrationtestDefaults/reference/pom.xml b/kie-archetypes/kie-drools-dmn-archetype/src/test/resources/projects/integrationtestDefaults/reference/pom.xml
index f10ade50f2..06913363db 100644
--- a/kie-archetypes/kie-drools-dmn-archetype/src/test/resources/projects/integrationtestDefaults/reference/pom.xml
+++ b/kie-archetypes/kie-drools-dmn-archetype/src/test/resources/projects/integrationtestDefaults/reference/pom.xml
@@ -47,6 +47,16 @@
<scope>import</scope>
<type>pom</type>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ <version>${dollar}{drools-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ <version>${dollar}{drools-version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -64,6 +74,17 @@
<artifactId>drools-model-compiler</artifactId>
</dependency>
+ <!-- Efesto -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+ </dependency>
+
+ <!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git a/kie-dmn/kie-dmn-api/pom.xml b/kie-dmn/kie-dmn-api/pom.xml
index 6f179cff3a..777c4660cd 100644
--- a/kie-dmn/kie-dmn-api/pom.xml
+++ b/kie-dmn/kie-dmn-api/pom.xml
@@ -43,10 +43,6 @@
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.kie</groupId>
- <artifactId>efesto-common-api</artifactId>
- </dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-internal</artifactId>
diff --git a/kie-dmn/kie-dmn-core/pom.xml b/kie-dmn/kie-dmn-core/pom.xml
index 977df690c4..617d0663c8 100644
--- a/kie-dmn/kie-dmn-core/pom.xml
+++ b/kie-dmn/kie-dmn-core/pom.xml
@@ -264,6 +264,16 @@
<artifactId>kie-pmml-models-regression-evaluator</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-models-tree-compiler</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-models-tree-evaluator</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java
index 8dca2a57ad..f5e2c8560e 100644
--- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java
@@ -18,8 +18,6 @@ package org.kie.dmn.core.compiler;
import java.io.IOException;
import java.io.Reader;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -38,7 +36,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;
-import org.drools.io.FileSystemResource;
import org.kie.api.io.Resource;
import org.kie.dmn.api.core.DMNCompiler;
import org.kie.dmn.api.core.DMNCompilerConfiguration;
@@ -94,14 +91,10 @@ import org.kie.dmn.model.api.OutputClause;
import org.kie.dmn.model.api.UnaryTests;
import org.kie.dmn.model.v1_1.TInformationItem;
import org.kie.dmn.model.v1_1.extensions.DecisionServices;
-import org.kie.internal.io.ResourceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import static org.kie.dmn.core.compiler.DMNImportsUtil.resolveDMNImportType;
import static org.kie.dmn.core.compiler.DMNImportsUtil.logErrorMessage;
-import static org.kie.dmn.core.compiler.DMNImportsUtil.resolvePMMLImportType;
import static org.kie.dmn.core.compiler.UnnamedImportUtils.processMergedModel;
public class DMNCompilerImpl implements DMNCompiler {
@@ -248,10 +241,10 @@ public class DMNCompilerImpl implements DMNCompiler {
ImportType importType = DMNImportsUtil.whichImportType(i);
switch(importType) {
case DMN :
- resolveDMNImportType(i, dmnModels, model, toMerge);
+ DMNImportsUtil.resolveDMNImportType(i, dmnModels, model, toMerge);
break;
case PMML:
- resolvePMMLImportType(model, i, relativeResolver, (DMNCompilerConfigurationImpl) dmnCompilerConfig);
+ DMNImportsUtil.resolvePMMLImportType(model, dmndefs, i, relativeResolver, (DMNCompilerConfigurationImpl) dmnCompilerConfig);
model.setImportAliasForNS(i.getName(), i.getNamespace(), i.getName());
break;
default :
@@ -290,51 +283,8 @@ public class DMNCompilerImpl implements DMNCompiler {
Msg.FUNC_DEF_PMML_ERR_LOCATIONURI,
i.getLocationURI());
}
-
- }
- protected static Resource resolveRelativeResource(ClassLoader classLoader, DMNModelImpl model, Import i, DMNModelInstrumentedBase node, Function<String, Reader> relativeResolver) {
- if (relativeResolver != null) {
- Reader reader = relativeResolver.apply(i.getLocationURI());
- return ResourceFactory.newReaderResource(reader);
- } else if (model.getResource() != null) {
- return pmmlImportResource(classLoader, model, i, node);
- }
- throw new UnsupportedOperationException("Unable to determine relative Resource for import named: " + i.getName());
}
- protected static Resource pmmlImportResource(ClassLoader classLoader, DMNModelImpl model, Import i, DMNModelInstrumentedBase node) {
- String locationURI = i.getLocationURI();
- logger.trace("locationURI: {}", locationURI);
- Resource pmmlResource = null;
- try {
- URI resolveRelativeURI = DMNCompilerImpl.resolveRelativeURI(model, locationURI);
- pmmlResource = resolveRelativeURI.isAbsolute() ?
- ResourceFactory.newFileResource(resolveRelativeURI.getPath()) :
- ResourceFactory.newClassPathResource(resolveRelativeURI.getPath(), classLoader);
- } catch (URISyntaxException | IOException e) {
- new PMMLImportErrConsumer(model, i, node).accept(e);
- }
- logger.trace("pmmlResource: {}", pmmlResource);
- return pmmlResource;
- }
-
- protected static URI resolveRelativeURI(DMNModelImpl model, String relative) throws URISyntaxException, IOException {
- URI relativeAsURI = new URI(null, null, relative, null);
- if (model.getResource() instanceof FileSystemResource) {
- FileSystemResource fsr = (FileSystemResource) model.getResource();
- logger.trace("fsr: {}", fsr.getURL());
- URI resolve = fsr.getURL().toURI().resolve(relativeAsURI);
- return resolve;
- } else {
- URI dmnModelURI = new URI(null, null, model.getResource().getSourcePath(), null);
- logger.trace("dmnModelURI: {}", dmnModelURI);
- URI relativeURI = dmnModelURI.resolve(relativeAsURI);
- return relativeURI;
- }
- }
-
-
-
private void processItemDefinitions(DMNCompilerContext ctx, DMNModelImpl model, Definitions dmndefs) {
dmndefs.normalize();
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNEvaluatorCompiler.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNEvaluatorCompiler.java
index 72d636056a..2d8604eb9f 100644
--- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNEvaluatorCompiler.java
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNEvaluatorCompiler.java
@@ -33,7 +33,6 @@ import java.util.stream.Collectors;
import javax.xml.namespace.QName;
-import org.kie.api.io.Resource;
import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNType;
import org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode;
@@ -58,7 +57,8 @@ import org.kie.dmn.core.impl.BaseDMNTypeImpl;
import org.kie.dmn.core.impl.CompositeTypeImpl;
import org.kie.dmn.core.impl.DMNModelImpl;
import org.kie.dmn.core.pmml.AbstractPMMLInvocationEvaluator;
-import org.kie.dmn.core.pmml.AbstractPMMLInvocationEvaluator.PMMLInvocationEvaluatorFactory;
+import org.kie.dmn.core.pmml.EfestoPMMLUtils;
+import org.kie.dmn.core.pmml.PMMLInvocationEvaluatorFactory;
import org.kie.dmn.core.pmml.DMNImportPMMLInfo;
import org.kie.dmn.core.pmml.PMMLModelInfo;
import org.kie.dmn.core.util.Msg;
@@ -101,6 +101,7 @@ import org.kie.dmn.model.api.OutputClause;
import org.kie.dmn.model.api.Quantified;
import org.kie.dmn.model.api.Relation;
import org.kie.dmn.model.api.UnaryTests;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -541,7 +542,7 @@ public class DMNEvaluatorCompiler implements DMNDecisionLogicCompiler {
if (funcDef.getExpression() instanceof Context) {
Context context = (Context) funcDef.getExpression();
String pmmlDocument = null;
- String pmmlModel = null;
+ String pmmlModelName = null;
for (ContextEntry ce : context.getContextEntry()) {
if (ce.getVariable() != null && ce.getVariable().getName() != null && ce.getExpression() instanceof LiteralExpression) {
LiteralExpression ceLitExpr = (LiteralExpression) ce.getExpression();
@@ -551,7 +552,7 @@ public class DMNEvaluatorCompiler implements DMNDecisionLogicCompiler {
}
} else if (ce.getVariable().getName().equals("model")) {
if (ceLitExpr.getText() != null) {
- pmmlModel = stripQuotes(ceLitExpr.getText().trim());
+ pmmlModelName = stripQuotes(ceLitExpr.getText().trim());
}
}
}
@@ -562,19 +563,18 @@ public class DMNEvaluatorCompiler implements DMNDecisionLogicCompiler {
if (lookupImport.isPresent()) {
Import theImport = lookupImport.get();
logger.trace("theImport: {}", theImport);
- Resource pmmlResource = DMNCompilerImpl.resolveRelativeResource(getRootClassLoader(), model,
- theImport, funcDef,
- ctx.getRelativeResolver());
- logger.trace("pmmlResource: {}", pmmlResource);
+ ModelLocalUriId pmmlModelLocalUriID = EfestoPMMLUtils.getPmmlModelLocalUriId(theImport,pmmlModelName,
+ ctx.getRelativeResolver());
+ logger.trace("pmmlResource: {}", pmmlModelLocalUriID);
DMNImportPMMLInfo pmmlInfo = model.getPmmlImportInfo().get(pmmlDocument);
logger.trace("pmmlInfo: {}", pmmlInfo);
- if (pmmlModel == null || pmmlModel.isEmpty()) {
+ if (pmmlModelName == null || pmmlModelName.isEmpty()) {
List<String> pmmlModelNames = pmmlInfo.getModels()
.stream()
.map(PMMLModelInfo::getName)
.filter(x -> x != null)
- .collect(Collectors.toList());
- if (pmmlModelNames.size() > 0) {
+ .toList();
+ if (!pmmlModelNames.isEmpty()) {
MsgUtil.reportMessage(logger,
DMNMessage.Severity.WARN,
funcDef,
@@ -588,8 +588,8 @@ public class DMNEvaluatorCompiler implements DMNDecisionLogicCompiler {
AbstractPMMLInvocationEvaluator invoker = PMMLInvocationEvaluatorFactory.newInstance(model,
getRootClassLoader(),
funcDef,
- pmmlResource,
- pmmlModel,
+ pmmlModelLocalUriID,
+ pmmlModelName,
pmmlInfo);
DMNFunctionDefinitionEvaluator func = new DMNFunctionDefinitionEvaluator(node, funcDef);
for (InformationItem p : funcDef.getFormalParameter()) {
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java
index ce5c6f09aa..39a39fe0a2 100644
--- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java
@@ -16,38 +16,58 @@
*/
package org.kie.dmn.core.compiler;
+import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.Collection;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import javax.xml.namespace.QName;
-import org.kie.api.io.Resource;
+import org.drools.util.FileUtils;
import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNModel;
import org.kie.dmn.api.core.ast.*;
import org.kie.dmn.core.impl.DMNModelImpl;
import org.kie.dmn.core.pmml.DMNImportPMMLInfo;
+import org.kie.dmn.core.pmml.EfestoPMMLUtils;
import org.kie.dmn.core.util.Msg;
import org.kie.dmn.core.util.MsgUtil;
import org.kie.dmn.feel.util.Either;
+import org.kie.dmn.model.api.BusinessKnowledgeModel;
+import org.kie.dmn.model.api.Context;
+import org.kie.dmn.model.api.ContextEntry;
import org.kie.dmn.model.api.Definitions;
+import org.kie.dmn.model.api.FunctionDefinition;
+import org.kie.dmn.model.api.FunctionKind;
import org.kie.dmn.model.api.Import;
+import org.kie.dmn.model.api.LiteralExpression;
import org.kie.dmn.model.api.NamespaceConsts;
import org.kie.dmn.model.v1_1.TImport;
+import org.kie.efesto.common.api.identifiers.LocalUri;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.kie.dmn.core.compiler.DMNCompilerImpl.resolveRelativeResource;
public class DMNImportsUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(DMNImportsUtil.class);
+ public enum ImportType {
+ UNKNOWN,
+ DMN,
+ PMML
+ }
+
private DMNImportsUtil() {
// No constructor for util class.
}
@@ -115,31 +135,23 @@ public class DMNImportsUtil {
}
}
- public enum ImportType {
- UNKNOWN,
- DMN,
- PMML;
- }
public static ImportType whichImportType(Import importElement) {
- switch (importElement.getImportType()) {
- case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN:
- case "http://www.omg.org/spec/DMN1-2Alpha/20160929/MODEL":
- case org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN:
- case org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase.URI_DMN:
- case org.kie.dmn.model.v1_4.KieDMNModelInstrumentedBase.URI_DMN:
- case org.kie.dmn.model.v1_5.KieDMNModelInstrumentedBase.URI_DMN:
- return ImportType.DMN;
- case NamespaceConsts.PMML_3_0:
- case NamespaceConsts.PMML_3_1:
- case NamespaceConsts.PMML_3_2:
- case NamespaceConsts.PMML_4_0:
- case NamespaceConsts.PMML_4_1:
- case NamespaceConsts.PMML_4_2:
- case NamespaceConsts.PMML_4_3:
- return ImportType.PMML;
- default:
- return ImportType.UNKNOWN;
- }
+ return switch (importElement.getImportType()) {
+ case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN,
+ "http://www.omg.org/spec/DMN1-2Alpha/20160929/MODEL",
+ org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN,
+ org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase.URI_DMN,
+ org.kie.dmn.model.v1_4.KieDMNModelInstrumentedBase.URI_DMN,
+ org.kie.dmn.model.v1_5.KieDMNModelInstrumentedBase.URI_DMN -> ImportType.DMN;
+ case NamespaceConsts.PMML_3_0,
+ NamespaceConsts.PMML_3_1,
+ NamespaceConsts.PMML_3_2,
+ NamespaceConsts.PMML_4_0,
+ NamespaceConsts.PMML_4_1,
+ NamespaceConsts.PMML_4_2,
+ NamespaceConsts.PMML_4_3 -> ImportType.PMML;
+ default -> ImportType.UNKNOWN;
+ };
}
/**
@@ -189,17 +201,35 @@ public class DMNImportsUtil {
}
}
+ /**
+ * The method is using for handling imports related to PMML models, allowing the DMN model to incorporate external PMML-based resources.
+ *
+ * @param model : Instance of the DMNModelImpl into which the resolved import will be incorporated.
+ * @param anImport : The Import object representing the PMML import to be resolved.
+ * @param relativeResolver: FUnction used to retrieve the actual PMML source
+ * @param dmnCompilerConfig: Instance of the DMNCompilerConfigurationImpl that holds configuration details, including the root class loader.
+ */
+ static void resolvePMMLImportType(DMNModelImpl model, Definitions dmndefs, Import anImport, Function<String, Reader> relativeResolver, DMNCompilerConfigurationImpl dmnCompilerConfig) {
+ if (relativeResolver != null) {
+ resolvePMMLImportTypeFromRelativeResolver(model, dmndefs, anImport, relativeResolver, dmnCompilerConfig);
+ } else {
+ String pmmlModelName = getPMMLModelName(dmndefs, anImport.getName());
+ ModelLocalUriId pmmlModelLocalUriId = EfestoPMMLUtils.getRelativePmmlModelLocalUriIdFromImport(anImport, pmmlModelName, model.getResource());
+ resolvePMMLImportTypeFromModelLocalUriId(model, anImport, pmmlModelLocalUriId, dmnCompilerConfig);
+ }
+ }
+
/**
* The method is using for handling imports related to PMML models, allowing the DMN model to incorporate external PMML-based resources.
* @param model : Represents a DMN model that requires the PMML import resolution.
- * @param i : Object that specifies the import details for the PMML resource.
+ * @param anImport : Object that specifies the import details for the PMML resource.
* @param relativeResolver : A function that resolves relative paths to resources.
* @param dmnCompilerConfig : Instance of the DMNCompilerConfigurationImpl that holds configuration details, including the root class loader.
*/
- static void resolvePMMLImportType(DMNModelImpl model, Import i, Function<String, Reader> relativeResolver, DMNCompilerConfigurationImpl dmnCompilerConfig) {
- ClassLoader rootClassLoader = dmnCompilerConfig.getRootClassLoader();
- Resource relativeResource = resolveRelativeResource(rootClassLoader, model, i, i, relativeResolver);
- resolvePMMLImportType(model, i, relativeResource, dmnCompilerConfig);
+ static void resolvePMMLImportTypeFromRelativeResolver(DMNModelImpl model, Definitions dmndefs, Import anImport, Function<String, Reader> relativeResolver, DMNCompilerConfigurationImpl dmnCompilerConfig) {
+ String pmmlModelName = getPMMLModelName(dmndefs, anImport.getName());
+ ModelLocalUriId relativeResource = EfestoPMMLUtils.getPmmlModelLocalUriId(anImport, pmmlModelName, relativeResolver);
+ resolvePMMLImportTypeFromModelLocalUriId(model, anImport, relativeResource, dmnCompilerConfig);
}
/**
@@ -207,19 +237,35 @@ public class DMNImportsUtil {
* If an error occurs while reading the PMML resource, the exception is handled and passed to the error consumer for appropriate processing.
* @param model : represents a DMN model where the PMML import information will be added.
* @param i : The Import object that specifies the PMML import details.
- * @param relativeResource : The resource representing the relative resource containing the PMML data.
+ * @param pmmlModelLocalUriId : The ModelLocalUriId pointing at the PMML data.
* @param dmnCompilerConfig : The DMNCompilerConfigurationImpl providing configuration details for the DMN compiler.
- * @throws IOException If an error occurs while reading the PMML resource input stream.
*/
- static void resolvePMMLImportType(DMNModelImpl model, Import i, Resource relativeResource, DMNCompilerConfigurationImpl dmnCompilerConfig) {
- try (InputStream pmmlIS = relativeResource.getInputStream()) {
- DMNImportPMMLInfo.from(pmmlIS, dmnCompilerConfig, model, i).consume(new DMNCompilerImpl.PMMLImportErrConsumer(model, i),
+ static void resolvePMMLImportTypeFromModelLocalUriId(DMNModelImpl model, Import i, ModelLocalUriId pmmlModelLocalUriId, DMNCompilerConfigurationImpl dmnCompilerConfig) {
+ String pmmlSource = getPmmlSource(pmmlModelLocalUriId, dmnCompilerConfig.getRootClassLoader());
+ try (InputStream pmmlInputStream = new ByteArrayInputStream(pmmlSource.getBytes(StandardCharsets.UTF_8))) {
+ DMNImportPMMLInfo.from(pmmlInputStream, dmnCompilerConfig, model, i).consume(new DMNCompilerImpl.PMMLImportErrConsumer(model, i),
model::addPMMLImportInfo);
} catch (IOException e) {
new DMNCompilerImpl.PMMLImportErrConsumer(model, i).accept(e);
}
}
+ /**
+ * Method to retrieve the original Pmml model from Efesto storage, eventually storing it if not already present
+ * @param pmmlModelLocalUriId
+ * @param classLoader
+ * @return
+ */
+ static String getPmmlSource(ModelLocalUriId pmmlModelLocalUriId, ClassLoader classLoader) {
+ String toReturn = EfestoPMMLUtils.getPmmlSourceFromContextStorage(pmmlModelLocalUriId);
+ if (toReturn == null) {
+ String pmmlFileName = ((LocalUri.LocalUriPathComponent)pmmlModelLocalUriId.asLocalUri().parent()).getComponent() + ".pmml";
+ toReturn = getPmmlFileContent(pmmlFileName, classLoader);
+ EfestoPMMLUtils.setPmmlSourceToContextStorage(pmmlModelLocalUriId, toReturn);
+ }
+ return toReturn;
+ }
+
/**
* Logs an error message when an unsupported or unknown import type is encountered during DMN model compilation.
* @param model : Instance of the DMNModelImpl that represents the DMN model where the error occurred.
@@ -261,4 +307,98 @@ public class DMNImportsUtil {
model.addDecisionService(dsn);
}
}
+
+ /**
+ * Method used to retrieve the name of the PMML model invoked inside a BusinessKnowledgeModel
+ * @param dmndefs
+ * @param pmmlImportedName the name used, inside the DMN file, for the pmml import
+ * @return
+ */
+ static String getPMMLModelName(Definitions dmndefs, String pmmlImportedName) {
+ return dmndefs.findAllChildren(BusinessKnowledgeModel.class).stream()
+ .map(BusinessKnowledgeModel::getEncapsulatedLogic)
+ .filter(encapsulatedLogic -> encapsulatedLogic.getKind().equals(FunctionKind.PMML))
+ .map(encapsulatedLogic -> getPMMLModelName(encapsulatedLogic, pmmlImportedName))
+ .filter(Objects::nonNull)
+ .findFirst()
+ .orElse(null);
+ }
+
+ static String getPMMLModelName(FunctionDefinition functionDefinition, String pmmlImportedName) {
+ return functionDefinition.getChildren().stream()
+ .filter(Context.class::isInstance)
+ .map(Context.class::cast)
+ .filter(context -> referToPMMLImportedName(context, pmmlImportedName))
+ .map(DMNImportsUtil::getModelName)
+ .findFirst()
+ .orElse(null);
+ }
+
+ static String getModelName(Context context) {
+ return context.getContextEntry().stream()
+ .filter(DMNImportsUtil::isModelContextEntry)
+ .map(contextEntry -> ((LiteralExpression)contextEntry.getExpression()).getText().replace("\"", ""))
+ .findFirst()
+ .orElse(null);
+ }
+
+ static boolean referToPMMLImportedName(Context context, String pmmlImportedName) {
+ return context.getContextEntry().stream()
+ .anyMatch(contextEntry -> isDocumentContextEntry(contextEntry, pmmlImportedName));
+ }
+
+ static boolean isDocumentContextEntry(ContextEntry contextEntry, String pmmlImportedName) {
+ return hasVariableName(contextEntry, "document") &&
+ contextEntry.getExpression() instanceof LiteralExpression literalExpression &&
+ literalExpression.getText().replace("\"", "").equals(pmmlImportedName.replace("\"", ""));
+ }
+
+ static boolean isModelContextEntry(ContextEntry contextEntry) {
+ return hasVariableName(contextEntry, "model") &&
+ contextEntry.getExpression() instanceof LiteralExpression;
+ }
+
+ static boolean hasVariableName(ContextEntry contextEntry, String expectedVariableName) {
+ return contextEntry.getVariable().getName().equals(expectedVariableName);
+ }
+
+ /**
+ * Retrieve the file with the given name scanning first the classpath, then the given classloader
+ * @param pmmlFileName
+ * @param classLoader
+ * @return
+ * @throws IllegalStateException if the file can not be found
+ */
+ static String getPmmlFileContent(String pmmlFileName, ClassLoader classLoader) {
+ return getPmmlFileContentFromClasspath(pmmlFileName).or(() -> getPmmlFileContentFromClassloader(pmmlFileName, classLoader))
+ .orElseThrow(() -> new IllegalStateException("Could not find PMML file: " + pmmlFileName));
+ }
+
+ static Optional<String> getPmmlFileContentFromClasspath(String pmmlFileName) {
+ String toReturn = null;
+ try {
+ File foundFile = FileUtils.getFile(pmmlFileName);
+ if (foundFile.exists()) {
+ toReturn = Files.readString(foundFile.toPath(), StandardCharsets.UTF_8);
+ }
+ } catch (Exception e) {
+ LOGGER.warn("Unable to find PMML file {} from Classpath", pmmlFileName);
+ }
+ return Optional.ofNullable(toReturn);
+ }
+
+ static Optional<String> getPmmlFileContentFromClassloader(String pmmlFileName, ClassLoader classLoader) {
+ String toReturn = null;
+ try {
+ URL resource = classLoader.getResource(pmmlFileName);
+ if (resource != null) {
+ try (InputStream is = resource.openStream()) {
+ toReturn = new String(is.readAllBytes(), StandardCharsets.UTF_8);
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.warn("Unable to find PMML file {} from Classloader {}", pmmlFileName, classLoader);
+ }
+ return Optional.ofNullable(toReturn);
+ }
}
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractDMNKiePMMLInvocationEvaluator.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractDMNKiePMMLInvocationEvaluator.java
index 414d1efbc4..2d5804df96 100644
--- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractDMNKiePMMLInvocationEvaluator.java
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractDMNKiePMMLInvocationEvaluator.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -20,10 +20,9 @@ package org.kie.dmn.core.pmml;
import java.util.Collection;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
-import org.kie.api.io.Resource;
-import org.kie.api.pmml.PMML4Result;
import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNResult;
import org.kie.dmn.api.core.DMNType;
@@ -36,9 +35,12 @@ import org.kie.dmn.core.impl.DMNResultImpl;
import org.kie.dmn.core.util.Msg;
import org.kie.dmn.core.util.MsgUtil;
import org.kie.dmn.model.api.DMNElement;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.kie.dmn.core.pmml.DMNKiePMMLTrustyInvocationEvaluator.RESULT_CODE;
+
/**
* Abstract <code>DMNKiePMMLInvocationEvaluator</code> to delegate actual <code>PMML4Result</code> retrieval to specific
* kie-pmml implementation (legacy or new)
@@ -48,19 +50,28 @@ public abstract class AbstractDMNKiePMMLInvocationEvaluator extends AbstractPMML
private static final Logger LOG = LoggerFactory.getLogger(AbstractDMNKiePMMLInvocationEvaluator.class);
protected final PMMLInfo<?> pmmlInfo;
- public AbstractDMNKiePMMLInvocationEvaluator(String dmnNS, DMNElement node, Resource pmmlResource, String model, PMMLInfo<?> pmmlInfo) {
- super(dmnNS, node, pmmlResource, model);
+ public AbstractDMNKiePMMLInvocationEvaluator(String dmnNS, DMNElement node, ModelLocalUriId pmmlModelLocalUriID, String model, PMMLInfo<?> pmmlInfo) {
+ super(dmnNS, node, pmmlModelLocalUriID, model);
this.pmmlInfo = pmmlInfo;
}
@Override
public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult dmnr) {
- PMML4Result resultHolder = getPMML4Result(eventManager, dmnr);
-
- Map<String, Object> resultVariables = resultHolder.getResultVariables();
- Map<String, Object> result = getOutputFieldValues(resultHolder, resultVariables, dmnr);
+ Map<String, Object> resultVariables = getPMMLResult(eventManager, dmnr);
+ if (!Objects.equals(resultVariables.get(RESULT_CODE),"OK")) {
+ MsgUtil.reportMessage(LOG,
+ DMNMessage.Severity.ERROR,
+ node,
+ ((DMNResultImpl) dmnr),
+ null,
+ null,
+ Msg.UNABLE_TO_RETRIEVE_PMML_RESULT,
+ model);
+ return new EvaluatorResultImpl(null, ResultType.FAILURE);
+ }
+ Map<String, Object> result = getOutputFieldValues(resultVariables, dmnr);
if (result.isEmpty()) {
- result = getPredictedValues(resultHolder, dmnr);
+ result = getPredictedValues(resultVariables, dmnr);
}
if (result.isEmpty()) {
MsgUtil.reportMessage(LOG,
@@ -79,29 +90,30 @@ public abstract class AbstractDMNKiePMMLInvocationEvaluator extends AbstractPMML
}
/**
- * Returns the <code>PMML4Result</code>
+ * Returns the <code>PMML</code> results
* @param eventManager
* @param dmnr
* @return
*/
- protected abstract PMML4Result getPMML4Result(DMNRuntimeEventManager eventManager, DMNResult dmnr);
+ protected abstract Map<String, Object> getPMMLResult(DMNRuntimeEventManager eventManager, DMNResult dmnr);
/**
* Returns a <code>Map<String, Object></code> of values identified by <b>Output</b> definition
- * @param pmml4Result
* @param resultVariables
* @param dmnr
* @return
*/
- protected abstract Map<String, Object> getOutputFieldValues(PMML4Result pmml4Result, Map<String, Object> resultVariables, DMNResult dmnr);
+ protected abstract Map<String, Object> getOutputFieldValues(Map<String, Object>
+ resultVariables, DMNResult dmnr);
/**
- * Returns a <code>Map<String, Object></code> of predicted values identified by <b>MiningSchema/Targets</b> definitions
- * @param pmml4Result
+ * Returns a <code>Map<String, Object></code> of predicted values identified by
+ <b>MiningSchema/Targets</b> definitions
+ * @param resultVariables
* @param dmnr
* @return
*/
- protected abstract Map<String, Object> getPredictedValues(PMML4Result pmml4Result, DMNResult dmnr);
+ protected abstract Map<String, Object> getPredictedValues(Map<String, Object> resultVariables, DMNResult dmnr);
protected Optional<String> getOutputFieldNameFromInfo(String resultName) {
Optional<String> toReturn;
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractPMMLInvocationEvaluator.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractPMMLInvocationEvaluator.java
index fb07f4708a..6c9c4b5724 100644
--- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractPMMLInvocationEvaluator.java
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/AbstractPMMLInvocationEvaluator.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -19,26 +19,18 @@
package org.kie.dmn.core.pmml;
import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
-import org.kie.api.io.Resource;
-import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNResult;
import org.kie.dmn.api.core.DMNType;
-import org.kie.dmn.api.core.event.DMNRuntimeEventManager;
import org.kie.dmn.core.api.DMNExpressionEvaluator;
-import org.kie.dmn.api.core.EvaluatorResult;
-import org.kie.dmn.api.core.EvaluatorResult.ResultType;
import org.kie.dmn.core.ast.DMNFunctionDefinitionEvaluator.FormalParameter;
-import org.kie.dmn.core.ast.EvaluatorResultImpl;
-import org.kie.dmn.core.impl.DMNModelImpl;
-import org.kie.dmn.core.impl.DMNResultImpl;
-import org.kie.dmn.core.util.Msg;
-import org.kie.dmn.core.util.MsgUtil;
import org.kie.dmn.model.api.DMNElement;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,14 +41,14 @@ public abstract class AbstractPMMLInvocationEvaluator implements DMNExpressionEv
protected final String dmnNS;
protected final DMNElement node;
protected final List<FormalParameter> parameters = new ArrayList<>();
- protected final Resource documentResource;
+ protected final ModelLocalUriId pmmlModelLocalUriID;
protected final String model;
- public AbstractPMMLInvocationEvaluator(String dmnNS, DMNElement node, Resource resource, String model) {
+ public AbstractPMMLInvocationEvaluator(String dmnNS, DMNElement node, ModelLocalUriId pmmlModelLocalUriID, String model) {
this.dmnNS = dmnNS;
this.node = node;
- this.documentResource = resource;
+ this.pmmlModelLocalUriID = pmmlModelLocalUriID;
this.model = model;
}
@@ -89,86 +81,4 @@ public abstract class AbstractPMMLInvocationEvaluator implements DMNExpressionEv
this.parameters.add(new FormalParameter(name, dmnType));
}
- public static class DummyPMMLInvocationEvaluator extends AbstractPMMLInvocationEvaluator {
-
- public DummyPMMLInvocationEvaluator(String dmnNS, DMNElement node, Resource url, String model) {
- super(dmnNS, node, url, model);
- }
-
- @Override
- public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult result) {
- MsgUtil.reportMessage(LOG,
- DMNMessage.Severity.ERROR,
- node,
- ((DMNResultImpl) result),
- null,
- null,
- Msg.FUNC_DEF_PMML_NOT_SUPPORTED,
- node.getIdentifierString());
- return new EvaluatorResultImpl(null, ResultType.FAILURE);
- }
- }
-
- public static class PMMLInvocationEvaluatorFactory {
-
- private PMMLInvocationEvaluatorFactory() {
- // Constructing instances is not allowed for this Factory
- }
-
- public static AbstractPMMLInvocationEvaluator newInstance(DMNModelImpl model, ClassLoader classLoader, DMNElement funcDef, Resource pmmlResource, String pmmlModel, PMMLInfo<?> pmmlInfo) {
- try {
- @SuppressWarnings("unchecked")
- Class<AbstractPMMLInvocationEvaluator> cl = (Class<AbstractPMMLInvocationEvaluator>) classLoader.loadClass("org.kie.dmn.jpmml.DMNjPMMLInvocationEvaluator");
- return cl.getDeclaredConstructor(String.class,
- DMNElement.class,
- Resource.class,
- String.class)
- .newInstance(model.getNamespace(),
- funcDef,
- pmmlResource,
- pmmlModel);
- } catch (NoClassDefFoundError | ClassNotFoundException e) {
- LOG.warn("Tried binding org.kie:kie-dmn-jpmml, failed.");
- } catch (Throwable e) {
- LOG.warn("Binding org.kie:kie-dmn-jpmml succeded but initialization failed, with:", e);
- }
- DMNKiePMMLTrustyInvocationEvaluator toReturn = getDMNKiePMMLTrustyInvocationEvaluator(model.getNamespace(), funcDef, pmmlResource, pmmlModel, pmmlInfo);
- if (toReturn != null) {
- return toReturn;
- } else {
- MsgUtil.reportMessage(LOG,
- DMNMessage.Severity.WARN,
- funcDef,
- model,
- null,
- null,
- Msg.FUNC_DEF_PMML_NOT_SUPPORTED,
- funcDef.getIdentifierString());
- }
- return new AbstractPMMLInvocationEvaluator.DummyPMMLInvocationEvaluator(model.getNamespace(), funcDef, pmmlResource, pmmlModel);
- }
- }
-
- /**
- * Retrieve the required <code>DMNKiePMMLTrustyInvocationEvaluator</code>. It may return <code>null</code>
- * if <code>org.drools:kie-pmml-trusty</code> is not in the classpath
- *
- * @param nameSpace
- * @param funcDef
- * @param pmmlResource
- * @param pmmlModel
- * @param pmmlInfo
- * @return
- */
- private static DMNKiePMMLTrustyInvocationEvaluator getDMNKiePMMLTrustyInvocationEvaluator(String nameSpace, DMNElement funcDef, Resource pmmlResource, String pmmlModel, PMMLInfo<?> pmmlInfo) {
- try {
- return new DMNKiePMMLTrustyInvocationEvaluator(nameSpace, funcDef, pmmlResource, pmmlModel, pmmlInfo);
- } catch (NoClassDefFoundError e) {
- LOG.warn("Tried binding org.drools:kie-pmml-trusty, failed.");
- } catch (Throwable e) {
- throw new RuntimeException("Binding org.drools:kie-pmml-trusty succeeded but initialization failed, with:", e);
- }
- return null;
- }
-
}
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNImportPMMLInfo.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNImportPMMLInfo.java
index a99be1abf8..a623c9918f 100644
--- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNImportPMMLInfo.java
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNImportPMMLInfo.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -40,7 +40,6 @@ import org.kie.dmn.core.compiler.DMNFEELHelper;
import org.kie.dmn.core.impl.CompositeTypeImpl;
import org.kie.dmn.core.impl.DMNModelImpl;
import org.kie.dmn.core.impl.SimpleTypeImpl;
-import org.kie.dmn.feel.lang.FEELDialect;
import org.kie.dmn.feel.lang.FEELProfile;
import org.kie.dmn.feel.lang.types.BuiltInType;
import org.kie.dmn.feel.runtime.UnaryTest;
@@ -60,9 +59,9 @@ public class DMNImportPMMLInfo extends PMMLInfo<DMNPMMLModelInfo> {
this.i = i;
}
- public static Either<Exception, DMNImportPMMLInfo> from(InputStream is, DMNCompilerConfigurationImpl cc, DMNModelImpl model, Import i) {
+ public static Either<Exception, DMNImportPMMLInfo> from(InputStream pmmlInputStream, DMNCompilerConfigurationImpl cc, DMNModelImpl model, Import i) {
try {
- final PMML pmml = org.jpmml.model.PMMLUtil.unmarshal(is);
+ final PMML pmml = org.jpmml.model.PMMLUtil.unmarshal(pmmlInputStream);
PMMLHeaderInfo h = PMMLInfo.pmmlToHeaderInfo(pmml, pmml.getHeader());
for (DataField df : pmml.getDataDictionary().getDataFields()) {
String dfName =df.getName();
@@ -99,7 +98,7 @@ public class DMNImportPMMLInfo extends PMMLInfo<DMNPMMLModelInfo> {
model.getTypeRegistry().registerType(type);
}
- pmml.getModels().stream().forEach(m -> registerOutputFieldType(m, model, i));
+ pmml.getModels().forEach(m -> registerOutputFieldType(m, model, i));
List<DMNPMMLModelInfo> models = pmml.getModels()
.stream()
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluator.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluator.java
index e00d34cfef..f3b56a67d7 100644
--- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluator.java
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluator.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,9 +24,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.UUID;
-import org.kie.api.io.Resource;
-import org.kie.api.pmml.PMML4Result;
-import org.kie.api.pmml.PMMLRequestData;
import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNResult;
import org.kie.dmn.api.core.event.DMNRuntimeEventManager;
@@ -40,11 +37,7 @@ import org.kie.efesto.common.api.identifiers.LocalUri;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.kie.efesto.common.api.model.EfestoCompilationContext;
import org.kie.efesto.common.api.model.GeneratedResources;
-import org.kie.efesto.compilationmanager.api.exceptions.EfestoCompilationManagerException;
-import org.kie.efesto.compilationmanager.api.exceptions.KieCompilerServiceException;
-import org.kie.efesto.compilationmanager.api.model.EfestoInputStreamResource;
-import org.kie.efesto.compilationmanager.api.service.CompilationManager;
-import org.kie.efesto.compilationmanager.core.model.EfestoCompilationContextUtils;
+import org.kie.efesto.common.core.storage.ContextStorage;
import org.kie.efesto.runtimemanager.api.exceptions.EfestoRuntimeManagerException;
import org.kie.efesto.runtimemanager.api.exceptions.KieRuntimeServiceException;
import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
@@ -56,38 +49,34 @@ import org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.kie.efesto.common.api.identifiers.LocalUri.SLASH;
-import static org.kie.efesto.common.utils.PackageClassNameUtils.getSanitizedClassName;
-import static org.kie.efesto.runtimemanager.api.utils.GeneratedResourceUtils.isPresentExecutableOrRedirect;
-
-
+@SuppressWarnings({"unchecked", "rawtypes"})
public class DMNKiePMMLTrustyInvocationEvaluator extends AbstractDMNKiePMMLInvocationEvaluator {
private static final RuntimeManager runtimeManager =
org.kie.efesto.runtimemanager.api.utils.SPIUtils.getRuntimeManager(false).orElseThrow(() -> new EfestoRuntimeManagerException("Failed to find an instance of RuntimeManager: please check classpath and dependencies"));
- private static final CompilationManager compilationManager =
- org.kie.efesto.compilationmanager.api.utils.SPIUtils.getCompilationManager(false).orElseThrow(() -> new EfestoCompilationManagerException("Failed to find an instance of CompilationManager: please check classpath and dependencies"));
private static final Logger LOG = LoggerFactory.getLogger(DMNKiePMMLTrustyInvocationEvaluator.class);
private static final String CHECK_CLASSPATH = "check classpath and dependencies!";
- public DMNKiePMMLTrustyInvocationEvaluator(String dmnNS, DMNElement node, Resource pmmlResource, String model,
+ static final String PMML_FILE_NAME = "_pmml_file_name_";
+ static final String PMML_MODEL_NAME = "_model_name_";
+ static final String RESULT_OBJECT_NAME = "_result_object_name_";
+ static final String RESULT_CODE = "_result_code_";
+
+ public DMNKiePMMLTrustyInvocationEvaluator(String dmnNS, DMNElement node, ModelLocalUriId pmmlModelLocalUriID, String model,
PMMLInfo<?> pmmlInfo) {
- super(dmnNS, node, pmmlResource, model, pmmlInfo);
+ super(dmnNS, node, pmmlModelLocalUriID, model, pmmlInfo);
}
@Override
- protected PMML4Result getPMML4Result(DMNRuntimeEventManager eventManager, DMNResult dmnr) {
- String pmmlFilePath = documentResource.getSourcePath();
- String pmmlFileName = pmmlFilePath.contains("/") ? pmmlFilePath.substring(pmmlFilePath.lastIndexOf('/') + 1)
- : pmmlFilePath;
- return evaluate(model, pmmlFileName, dmnr, eventManager.getRuntime().getRootClassLoader());
+ protected Map<String, Object> getPMMLResult(DMNRuntimeEventManager eventManager, DMNResult dmnr) {
+ return evaluate(model, pmmlModelLocalUriID, dmnr, eventManager.getRuntime().getRootClassLoader());
}
@Override
- protected Map<String, Object> getOutputFieldValues(PMML4Result pmml4Result, Map<String, Object> resultVariables,
- DMNResult dmnr) {
+ protected Map<String, Object> getOutputFieldValues(Map<String, Object> resultVariables,
+ DMNResult dmnResult) {
Map<String, Object> toReturn = new HashMap<>();
for (Map.Entry<String, Object> kv : resultVariables.entrySet()) {
String resultName = kv.getKey();
@@ -95,21 +84,21 @@ public class DMNKiePMMLTrustyInvocationEvaluator extends AbstractDMNKiePMMLInvoc
continue;
}
Object r = kv.getValue();
- populateWithObject(toReturn, kv.getKey(), r, dmnr);
+ populateWithObject(toReturn, kv.getKey(), r, dmnResult);
}
return toReturn;
}
@Override
- protected Map<String, Object> getPredictedValues(PMML4Result pmml4Result, DMNResult dmnr) {
+ protected Map<String, Object> getPredictedValues(Map<String, Object> resultVariables, DMNResult dmnr) {
Map<String, Object> toReturn = new HashMap<>();
- String resultName = pmml4Result.getResultObjectName();
- Object value = pmml4Result.getResultVariables().get(resultName);
+ String resultName = (String) resultVariables.get(RESULT_OBJECT_NAME);
+ Object value = resultVariables.get(resultName);
toReturn.put(resultName, NumberEvalHelper.coerceNumber(value));
return toReturn;
}
- private void populateWithObject(Map<String, Object> toPopulate, String resultName, Object r, DMNResult dmnr) {
+ private void populateWithObject(Map<String, Object> toPopulate, String resultName, Object r, DMNResult dmnResult) {
Optional<String> outputFieldNameFromInfo = getOutputFieldNameFromInfo(resultName);
if (outputFieldNameFromInfo.isPresent()) {
String name = outputFieldNameFromInfo.get();
@@ -119,7 +108,7 @@ public class DMNKiePMMLTrustyInvocationEvaluator extends AbstractDMNKiePMMLInvoc
MsgUtil.reportMessage(LOG,
DMNMessage.Severity.WARN,
node,
- ((DMNResultImpl) dmnr),
+ ((DMNResultImpl) dmnResult),
e,
null,
Msg.INVALID_NAME,
@@ -130,43 +119,51 @@ public class DMNKiePMMLTrustyInvocationEvaluator extends AbstractDMNKiePMMLInvoc
}
}
- protected PMML4Result evaluate(String modelName, String pmmlFileName, DMNResult dmnr,
+ protected Map<String, Object> evaluate(String modelName, ModelLocalUriId pmmlModelLocalUriID, DMNResult dmnr,
ClassLoader parentClassloader) {
- EfestoLocalRuntimeContext runtimeContext = getEfestoRuntimeContext(parentClassloader);
- ModelLocalUriId modelLocalUriId = getModelLocalUriId(pmmlFileName, modelName);
-
- Collection<EfestoOutput> retrieved;
- if (!(isPresentExecutableOrRedirect(modelLocalUriId, runtimeContext))) {
- LOG.warn("GeneratedResources for {}@{} are not present: trying to invoke compilation....",
- pmmlFileName,
- modelName);
- Map<String, GeneratedResources> generatedResourcesMap = compileFile(pmmlFileName,
- parentClassloader);
- runtimeContext.getGeneratedResourcesMap().putAll(generatedResourcesMap);
- }
- PMMLRequestData pmmlRequestData = getPMMLRequestData(UUID.randomUUID().toString(), modelName, pmmlFileName,
+ String pmmlFileName = ((LocalUri.LocalUriPathComponent)pmmlModelLocalUriID.asLocalUri().parent()).getComponent() + ".pmml";
+ EfestoCompilationContext efestoCompilationContext = getEfestoCompilationContext(pmmlModelLocalUriID, pmmlFileName, parentClassloader);
+
+ EfestoLocalRuntimeContext runtimeContext = getEfestoRuntimeContext(parentClassloader, efestoCompilationContext.getGeneratedResourcesMap());
+
+ Map<String, Object> pmmlRequestData = getPMMLRequestData(UUID.randomUUID().toString(), modelName, pmmlFileName,
dmnr);
- EfestoInput<PMMLRequestData> inputPMML = new BaseEfestoInput<>(modelLocalUriId, pmmlRequestData);
- retrieved = evaluateInput(inputPMML, runtimeContext);
+ EfestoInput<Map<String, Object>> inputPMML = new BaseEfestoInput<>(pmmlModelLocalUriID, pmmlRequestData);
+ Collection<EfestoOutput> retrieved = evaluateInput(inputPMML, runtimeContext);
if (retrieved.isEmpty()) {
- String errorMessage = String.format("Failed to get result for %s@%s: please %s",
+ String errorMessage = String.format("Failed to get result for %s: please %s",
inputPMML.getModelLocalUriId(),
- inputPMML.getInputData().getModelName(),
CHECK_CLASSPATH);
LOG.error(errorMessage);
throw new KieRuntimeServiceException(errorMessage);
}
- return (PMML4Result) retrieved.iterator().next().getOutputData();
+ return (Map) retrieved.iterator().next().getOutputData();
}
- private Collection<EfestoOutput> evaluateInput(EfestoInput<PMMLRequestData> inputPMML,
+ /**
+ * This method retrieves the previously built <code>EfestoCompilationContext</code> for the given <code>ModelLocalUriId</code> or, eventually, recompile the model from scratch
+ * @param pmmlModelLocalUriID
+ * @param parentClassloader
+ * @return
+ */
+ private EfestoCompilationContext getEfestoCompilationContext(ModelLocalUriId pmmlModelLocalUriID, String pmmlFileName, ClassLoader parentClassloader) {
+ EfestoCompilationContext toReturn = ContextStorage.getEfestoCompilationContext(pmmlModelLocalUriID);
+ if (toReturn == null) {
+ String pmmlFileContent = EfestoPMMLUtils.getPmmlSourceFromContextStorage(pmmlModelLocalUriID);
+ EfestoPMMLUtils.compilePMMLAtGivenLocalComponentIdPmml(pmmlFileContent, pmmlFileName, pmmlModelLocalUriID, parentClassloader);
+ toReturn = ContextStorage.getEfestoCompilationContext(pmmlModelLocalUriID);
+ }
+ return toReturn;
+ }
+
+
+ private Collection<EfestoOutput> evaluateInput(EfestoInput<Map<String, Object>> inputPMML,
EfestoLocalRuntimeContext runtimeContext) {
try {
return runtimeManager.evaluateInput(runtimeContext, inputPMML);
} catch (Exception t) {
- String errorMessage = String.format("Evaluation error for %s@%s using %s due to %s: please %s",
+ String errorMessage = String.format("Evaluation error for %s using %s due to %s: please %s",
inputPMML.getModelLocalUriId(),
- inputPMML.getInputData().getModelName(),
inputPMML,
t.getMessage(),
CHECK_CLASSPATH);
@@ -175,47 +172,20 @@ public class DMNKiePMMLTrustyInvocationEvaluator extends AbstractDMNKiePMMLInvoc
}
}
- protected Map<String, GeneratedResources> compileFile(String fileName,
- ClassLoader parentClassLoader) {
- try {
- EfestoCompilationContext compilationContext =
- EfestoCompilationContextUtils.buildWithParentClassLoader(parentClassLoader);
- EfestoInputStreamResource toProcess = new EfestoInputStreamResource(documentResource.getInputStream(),
- fileName);
- compilationManager.processResource(compilationContext, toProcess);
- return compilationContext.getGeneratedResourcesMap();
- } catch (Exception t) {
- String errorMessage = String.format("Compilation error for %s due to %s: please %s",
- fileName,
- t.getMessage(),
- CHECK_CLASSPATH);
- LOG.error(errorMessage);
- throw new KieCompilerServiceException(errorMessage, t);
- }
- }
-
- protected PMMLRequestData getPMMLRequestData(String correlationId, String modelName, String fileName,
+ protected Map<String, Object> getPMMLRequestData(String correlationId, String modelName, String fileName,
DMNResult dmnr) {
- PMMLRequestData toReturn = new PMMLRequestData(correlationId, modelName);
+ Map<String, Object> toReturn = new HashMap<>();
for (DMNFunctionDefinitionEvaluator.FormalParameter p : parameters) {
Object pValue = getValueForPMMLInput(dmnr, p.name);
- toReturn.addRequestParam(p.name, pValue);
+ toReturn.put(p.name, pValue);
}
- toReturn.addRequestParam("_pmml_file_name_", fileName);
+ toReturn.put(PMML_FILE_NAME, fileName);
+ toReturn.put(PMML_MODEL_NAME, modelName);
return toReturn;
}
- private EfestoLocalRuntimeContext getEfestoRuntimeContext(final ClassLoader parentClassloader) {
- return EfestoRuntimeContextUtils.buildWithParentClassLoader(parentClassloader);
+ private EfestoLocalRuntimeContext getEfestoRuntimeContext(final ClassLoader parentClassloader, final Map<String, GeneratedResources> generatedResourcesMap) {
+ return EfestoRuntimeContextUtils.buildWithParentClassLoader(parentClassloader, generatedResourcesMap);
}
- private ModelLocalUriId getModelLocalUriId(String fileName, String modelName) {
- String path = "/pmml/" + getFileNameNoSuffix(fileName) + SLASH + getSanitizedClassName(modelName);
- LocalUri parsed = LocalUri.parse(path);
- return new ModelLocalUriId(parsed);
- }
-
- private String getFileNameNoSuffix(String fileName) {
- return fileName.contains(".") ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName;
- }
}
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DummyPMMLInvocationEvaluator.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DummyPMMLInvocationEvaluator.java
new file mode 100644
index 0000000000..be6a097a7c
--- /dev/null
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/DummyPMMLInvocationEvaluator.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.core.pmml;
+
+import org.kie.dmn.api.core.DMNMessage;
+import org.kie.dmn.api.core.DMNResult;
+import org.kie.dmn.api.core.EvaluatorResult;
+import org.kie.dmn.api.core.event.DMNRuntimeEventManager;
+import org.kie.dmn.core.ast.EvaluatorResultImpl;
+import org.kie.dmn.core.impl.DMNResultImpl;
+import org.kie.dmn.core.util.Msg;
+import org.kie.dmn.core.util.MsgUtil;
+import org.kie.dmn.model.api.DMNElement;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DummyPMMLInvocationEvaluator extends AbstractPMMLInvocationEvaluator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DummyPMMLInvocationEvaluator.class);
+
+ public DummyPMMLInvocationEvaluator(String dmnNS, DMNElement node, ModelLocalUriId pmmlModelLocalUriID, String model) {
+ super(dmnNS, node, pmmlModelLocalUriID, model);
+ }
+
+ @Override
+ public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult result) {
+ MsgUtil.reportMessage(LOG,
+ DMNMessage.Severity.ERROR,
+ node,
+ ((DMNResultImpl) result),
+ null,
+ null,
+ Msg.FUNC_DEF_PMML_NOT_SUPPORTED,
+ node.getIdentifierString());
+ return new EvaluatorResultImpl(null, EvaluatorResult.ResultType.FAILURE);
+ }
+
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/EfestoPMMLUtils.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/EfestoPMMLUtils.java
new file mode 100644
index 0000000000..7b58eee3b0
--- /dev/null
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/EfestoPMMLUtils.java
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.core.pmml;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.function.Function;
+import org.drools.io.ClassPathResource;
+import org.drools.io.FileSystemResource;
+import org.kie.api.io.Resource;
+import org.kie.dmn.model.api.Import;
+import org.kie.efesto.common.api.identifiers.LocalUri;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.api.model.GeneratedExecutableResource;
+import org.kie.efesto.common.api.model.GeneratedResources;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.model.EfestoInputStreamResource;
+import org.kie.efesto.compilationmanager.api.service.CompilationManager;
+import org.kie.efesto.compilationmanager.api.utils.SPIUtils;
+
+import org.kie.efesto.compilationmanager.core.model.EfestoCompilationContextUtils;
+import org.kie.internal.io.ResourceFactory;
+import org.kie.memorycompiler.KieMemoryCompiler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.kie.efesto.common.api.utils.FileNameUtils.getFileName;
+import static org.kie.efesto.common.api.utils.FileNameUtils.removeSuffix;
+import static org.kie.efesto.common.utils.PackageClassNameUtils.getSanitizedClassName;
+
+@SuppressWarnings("rawtypes")
+public class EfestoPMMLUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(EfestoPMMLUtils.class);
+
+ private static final CompilationManager compilationManager =
+ SPIUtils.getCompilationManager(true).orElseThrow(() -> new RuntimeException("Compilation Manager not " +
+ "available"));
+
+ private EfestoPMMLUtils() {
+ }
+
+ /**
+ * Compile the given <code>File</code> as PMML model and store it under automatically-generated
+ * <code>LocalComponentIdPmml</code>
+ * @param pmmlFile
+ * @param modelName
+ * @param classLoader
+ * @return
+ * @see EfestoPMMLUtils#getPmmlModelLocalUriId(String, String) for information about
+ * <code>LocalComponentIdPmml</code> generation
+ */
+ public static ModelLocalUriId compilePMML(File pmmlFile, String modelName, ClassLoader classLoader) {
+ ModelLocalUriId toReturn = getPmmlModelLocalUriId(pmmlFile.getName(), modelName);
+ compilePMMLAtGivenLocalComponentIdPmml(pmmlFile, toReturn, classLoader);
+ return toReturn;
+ }
+
+ /**
+ * Compile the given <b>pmml source</b> as PMML model and store it under automatically-generated
+ * <code>LocalComponentIdPmml</code>
+ *
+ * @param pmmlSource
+ * @param fileName
+ * @param modelName
+ * @param classLoader
+ * @return
+ * @see EfestoPMMLUtils#getPmmlModelLocalUriId(String, String) for information about
+ * <code>ModelLocalUriId</code> generation
+ */
+ public static ModelLocalUriId compilePMML(String pmmlSource, String fileName, String modelName,
+ ClassLoader classLoader) {
+ ModelLocalUriId toReturn = getPmmlModelLocalUriId(fileName, modelName);
+ compilePMMLAtGivenLocalComponentIdPmml(pmmlSource, fileName, toReturn, classLoader);
+ return toReturn;
+ }
+
+ /**
+ * Compile the given <code>File</code> as PMML model and store it under the provided
+ * <code>ModelLocalUriId</code>
+ * @param pmmlFile
+ * @param pmmlModelLocalUriId
+ * @param classLoader
+ */
+ public static void compilePMMLAtGivenLocalComponentIdPmml(File pmmlFile, ModelLocalUriId pmmlModelLocalUriId, ClassLoader classLoader) {
+ try {
+ compilePMMLAtGivenLocalComponentIdPmml(Files.readString(pmmlFile.toPath()), pmmlFile.getName(),
+ pmmlModelLocalUriId, classLoader);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Compile the given <b>pmml source</b> as PMML model and store it under the provided
+ * <code>LocalComponentIdPmml</code>
+ *
+ * @param pmmlSource
+ * @param fileName
+ * @param pmmlModelLocalUriId
+ * @param classLoader
+ */
+ public static void compilePMMLAtGivenLocalComponentIdPmml(String pmmlSource, String fileName,
+ ModelLocalUriId pmmlModelLocalUriId,
+ ClassLoader classLoader) {
+ KieMemoryCompiler.MemoryCompilerClassLoader toUse =
+ classLoader instanceof KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader ?
+ memoryCompilerClassLoader :
+ new KieMemoryCompiler.MemoryCompilerClassLoader(classLoader);
+ EfestoCompilationContext pmmlCompilationContext =
+ EfestoCompilationContextUtils.buildWithParentClassLoaderWithoutSetup(toUse);
+ EfestoInputStreamResource toProcess =
+ new EfestoInputStreamResource(new ByteArrayInputStream(pmmlSource.getBytes(StandardCharsets.UTF_8)),
+ fileName);
+ compilationManager.processResource(pmmlCompilationContext, toProcess);
+ GeneratedExecutableResource generatedExecutableResource =
+ ((GeneratedResources) pmmlCompilationContext.getGeneratedResourcesMap().get("pmml"))
+ .stream()
+ .filter(GeneratedExecutableResource.class::isInstance)
+ .map(GeneratedExecutableResource.class::cast)
+ .findFirst()
+ .orElse(null);
+ ContextStorage.putEfestoCompilationContext(pmmlModelLocalUriId, pmmlCompilationContext);
+ }
+
+ /**
+ * Retrieve a <code>LocalComponentIdPmml</code>
+ * @param anImport
+ * @param modelName
+ * @param relativeResolver
+ * @return
+ */
+ public static ModelLocalUriId getPmmlModelLocalUriId(Import anImport, String modelName, Function<String,
+ Reader> relativeResolver) {
+ ModelLocalUriId toReturn = getPmmlModelLocalUriIdFromImport(anImport, modelName);
+ if (relativeResolver != null && !isModelLocalUriIdPresent(toReturn)) {
+ toReturn = compilePmmlFromRelativeResolver(anImport, modelName, relativeResolver);
+ }
+ return toReturn;
+ }
+
+ public static ModelLocalUriId compilePmmlFromRelativeResolver(Import i, String modelName, Function<String,
+ Reader> relativeResolver) {
+ String pmmlSource = getStringFromRelativeResolver(i.getLocationURI(), relativeResolver);
+ return compilePMML(pmmlSource, i.getLocationURI(), modelName, Thread.currentThread().getContextClassLoader());
+ }
+
+ public static ModelLocalUriId getPmmlModelLocalUriIdFromImport(Import anImport, String modelName) {
+ String locationURI = anImport.getLocationURI();
+ logger.trace("locationURI: {}", locationURI);
+ return getPmmlModelLocalUriId(locationURI, modelName);
+ }
+
+ public static ModelLocalUriId getRelativePmmlModelLocalUriIdFromImport(Import anImport, String pmmlModelName, Resource dmnResource) {
+ String locationURI = anImport.getLocationURI();
+ if (isRelative(locationURI)) {
+ Path parentPath = getParentPath(dmnResource);
+ if (parentPath != null) {
+ locationURI = parentPath.resolve(locationURI).toString();
+ }
+ }
+ logger.trace("locationURI: {}", locationURI);
+ return getPmmlModelLocalUriId(locationURI, pmmlModelName);
+ }
+
+ /**
+ * This method consider the actual file name and the model name for <code>ModelLocalUriId</code> instantiation
+ * @param pathPart
+ * @return
+ */
+ public static ModelLocalUriId getPmmlModelLocalUriId(String pathPart, String modelName) {
+ String fileName = getFileName(pathPart);
+ fileName = removeSuffix(fileName);
+ String name = getFileName(modelName);
+ name = getSanitizedClassName(name);
+ LocalUri localUri = LocalUri.Root.append("pmml").append(fileName).append(name);
+ return new ModelLocalUriId(localUri);
+ }
+
+ /**
+ * Retrieves a <code>ByteArrayResource</code> of the <code>source</code> stored with the given
+ * <code>ModelLocalUriId</code>
+ * @param pmmlModelLocalUriID
+ * @return
+ */
+ public static Resource getPmmlResourceFromContextStorage(ModelLocalUriId pmmlModelLocalUriID) {
+ String pmmlSource = getPmmlSourceFromContextStorage(pmmlModelLocalUriID);
+ return ResourceFactory.newByteArrayResource(pmmlSource.getBytes(StandardCharsets.UTF_8));
+ }
+
+ /**
+ * Retrieves the <code>source</code> stored with the given <code>ModelLocalUriId</code>
+ * @param pmmlModelLocalUriID
+ * @return
+ */
+ public static String getPmmlSourceFromContextStorage(ModelLocalUriId pmmlModelLocalUriID) {
+ return ContextStorage.getEfestoCompilationSource(pmmlModelLocalUriID);
+ }
+
+ /**
+ * Retrieves the <code>source</code> stored with the given <code>ModelLocalUriId</code>
+ * @param pmmlModelLocalUriID
+ * @param pmmlSource
+ * @return
+ */
+ public static void setPmmlSourceToContextStorage(ModelLocalUriId pmmlModelLocalUriID, String pmmlSource) {
+ ContextStorage.putEfestoCompilationSource(pmmlModelLocalUriID, pmmlSource);
+ }
+
+ static boolean isModelLocalUriIdPresent(ModelLocalUriId toCheck) {
+ return ContextStorage.getAllModelLocalUriIdFromCompilationContext().contains(toCheck);
+ }
+
+ static Path getParentPath(Resource dmnResource) {
+ File parentDir = null;
+ if (dmnResource instanceof FileSystemResource fileSystemResource && fileSystemResource.getFile() != null) {
+ parentDir = fileSystemResource.getFile().getParentFile();
+ } else if (dmnResource instanceof ClassPathResource classPathResource) {
+ try {
+ URL resourceUrl = classPathResource.getURL();
+ if (resourceUrl != null && resourceUrl.getFile() != null) {
+ parentDir = new File(resourceUrl.getFile()).getParentFile();
+ }
+ } catch (Exception e) {
+ logger.warn("Failed to retrieve the URL from ClassPathResource {}", classPathResource, e);
+ }
+ }
+ return parentDir != null ? parentDir.toPath() : null;
+ }
+
+ /**
+ * Return <code>true</code> if the given <code>String</code> represent a relative path, <code>false</code> otherwise
+ * @param toParse
+ * @return
+ */
+ static boolean isRelative(String toParse) {
+ try {
+ URI uri = new URI(toParse);
+ return uri.getScheme() == null && !Paths.get(toParse).isAbsolute();
+ } catch (URISyntaxException e) {
+ return !Paths.get(toParse).isAbsolute();
+ }
+ }
+
+ static String getStringFromRelativeResolver(String key, Function<String, Reader> relativeResolver) {
+ try (Reader toRead = relativeResolver.apply(key)) {
+ char[] arr = new char[8 * 1024];
+ StringBuilder toReturn = new StringBuilder();
+ int numCharsRead;
+ while ((numCharsRead = toRead.read(arr, 0, arr.length)) != -1) {
+ toReturn.append(arr, 0, numCharsRead);
+ }
+ return toReturn.toString();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/PMMLInvocationEvaluatorFactory.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/PMMLInvocationEvaluatorFactory.java
new file mode 100644
index 0000000000..4f22fdadf8
--- /dev/null
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/pmml/PMMLInvocationEvaluatorFactory.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.core.pmml;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.kie.api.io.Resource;
+import org.kie.dmn.api.core.DMNMessage;
+import org.kie.dmn.core.impl.DMNModelImpl;
+import org.kie.dmn.core.util.Msg;
+import org.kie.dmn.core.util.MsgUtil;
+import org.kie.dmn.model.api.DMNElement;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PMMLInvocationEvaluatorFactory {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PMMLInvocationEvaluatorFactory.class);
+
+ private static final Map<ModelLocalUriId, AbstractPMMLInvocationEvaluator> MAPPED_INSTANCES = new HashMap<>();
+
+ private PMMLInvocationEvaluatorFactory() {
+ // Constructing instances is not allowed for this Factory
+ }
+
+ public static AbstractPMMLInvocationEvaluator newInstance(DMNModelImpl model, ClassLoader classLoader, DMNElement funcDef, ModelLocalUriId pmmlModelLocalUriID, String pmmlModelName, PMMLInfo<?> pmmlInfo) {
+ if (MAPPED_INSTANCES.containsKey(pmmlModelLocalUriID)) {
+ return MAPPED_INSTANCES.get(pmmlModelLocalUriID);
+ } else {
+ AbstractPMMLInvocationEvaluator toReturn = createNewInstance(model, classLoader, funcDef, pmmlModelLocalUriID, pmmlModelName, pmmlInfo);
+ MAPPED_INSTANCES.put(pmmlModelLocalUriID, toReturn);
+ return toReturn;
+ }
+ }
+
+ static AbstractPMMLInvocationEvaluator createNewInstance(DMNModelImpl model, ClassLoader classLoader, DMNElement funcDef, ModelLocalUriId pmmlModelLocalUriID, String pmmlModelName, PMMLInfo<?> pmmlInfo) {
+ AbstractPMMLInvocationEvaluator toReturn = getDMNjPMMLInvocationEvaluator(classLoader, funcDef, pmmlModelLocalUriID, model, pmmlModelName);
+ if (toReturn == null) {
+ toReturn = getDMNKiePMMLTrustyInvocationEvaluator(model.getNamespace(), funcDef, pmmlModelLocalUriID, pmmlModelName, pmmlInfo);
+ }
+ if (toReturn != null) {
+ return toReturn;
+ } else {
+ MsgUtil.reportMessage(LOG,
+ DMNMessage.Severity.WARN,
+ funcDef,
+ model,
+ null,
+ null,
+ Msg.FUNC_DEF_PMML_NOT_SUPPORTED,
+ funcDef.getIdentifierString());
+ }
+ return new DummyPMMLInvocationEvaluator(model.getNamespace(), funcDef, pmmlModelLocalUriID, pmmlModelName);
+ }
+
+ /**
+ * Retrieve the required <code>DMNjPMMLInvocationEvaluator</code>. It may return <code>null</code>
+ * if <code>org.kie.dmn.jpmml.DMNjPMMLInvocationEvaluator</code> is not in the classpath
+ *
+ * @param classLoader
+ * @param funcDef
+ * @param pmmlModelLocalUriID
+ * @param model
+ * @param pmmlModelName
+ * @return
+ */
+ private static AbstractPMMLInvocationEvaluator getDMNjPMMLInvocationEvaluator(ClassLoader classLoader, DMNElement funcDef, ModelLocalUriId pmmlModelLocalUriID, DMNModelImpl model, String pmmlModelName) {
+ try {
+ @SuppressWarnings("unchecked")
+ Class<AbstractPMMLInvocationEvaluator> cl = (Class<AbstractPMMLInvocationEvaluator>) classLoader.loadClass("org.kie.dmn.jpmml.DMNjPMMLInvocationEvaluator");
+ return cl.getDeclaredConstructor(String.class,
+ DMNElement.class,
+ Resource.class,
+ String.class)
+ .newInstance(model.getNamespace(),
+ funcDef,
+ EfestoPMMLUtils.getPmmlResourceFromContextStorage(pmmlModelLocalUriID),
+ pmmlModelName);
+ } catch (NoClassDefFoundError | ClassNotFoundException e) {
+ LOG.warn("Tried binding org.kie:kie-dmn-jpmml, failed.");
+ } catch (Throwable e) {
+ LOG.warn("Binding org.kie:kie-dmn-jpmml succeded but initialization failed, with:", e);
+ }
+ return null;
+ }
+
+ /**
+ * Retrieve the required <code>DMNKiePMMLTrustyInvocationEvaluator</code>. It may return <code>null</code>
+ * if <code>org.drools:kie-pmml-trusty</code> is not in the classpath
+ *
+ * @param nameSpace
+ * @param funcDef
+ * @param pmmlModelLocalUriID
+ * @param pmmlModel
+ * @param pmmlInfo
+ * @return
+ */
+ private static DMNKiePMMLTrustyInvocationEvaluator getDMNKiePMMLTrustyInvocationEvaluator(String nameSpace, DMNElement funcDef, ModelLocalUriId pmmlModelLocalUriID, String pmmlModel, PMMLInfo<?> pmmlInfo) {
+ try {
+ return new DMNKiePMMLTrustyInvocationEvaluator(nameSpace, funcDef, pmmlModelLocalUriID, pmmlModel, pmmlInfo);
+ } catch (NoClassDefFoundError e) {
+ LOG.warn("Tried binding org.drools:kie-pmml-trusty, failed.");
+ } catch (Throwable e) {
+ throw new RuntimeException("Binding org.drools:kie-pmml-trusty succeeded but initialization failed, with:", e);
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/runtime/service/DMNEvaluator.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/runtime/service/DMNEvaluator.java
new file mode 100644
index 0000000000..34711a7859
--- /dev/null
+++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/runtime/service/DMNEvaluator.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.kie.dmn.core.runtime.service;
+
+import org.kie.api.io.Resource;
+import org.kie.dmn.api.core.DMNContext;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.core.DMNResult;
+import org.kie.dmn.api.core.DMNRuntime;
+import org.kie.dmn.core.internal.utils.DMNRuntimeBuilder;
+import org.kie.dmn.core.internal.utils.DynamicDMNContextBuilder;
+import org.kie.internal.io.ResourceFactory;
+
+import java.io.StringReader;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class DMNEvaluator {
+
+ private final DMNModel dmnModel;
+ private final DMNRuntime dmnRuntime;
+
+ public static DMNEvaluator fromXML(String modelXML) {
+ Resource modelResource = ResourceFactory.newReaderResource(new StringReader(modelXML), "UTF-8");
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ DMNModel dmnModel = dmnRuntime.getModels().get(0);
+ return new DMNEvaluator(dmnModel, dmnRuntime);
+ }
+
+ private DMNEvaluator(DMNModel dmnModel, DMNRuntime dmnRuntime) {
+ this.dmnModel = dmnModel;
+ this.dmnRuntime = dmnRuntime;
+ }
+
+ public DMNModel getDmnModel() {
+ return dmnModel;
+ }
+
+ public String getNamespace() {
+ return dmnModel.getNamespace();
+ }
+
+ public String getName() {
+ return dmnModel.getName();
+ }
+
+ public Collection<DMNModel> getAllDMNModels() {
+ return dmnRuntime.getModels();
+ }
+
+ public DMNResult evaluate(Map<String, Object> context) {
+ DMNContext dmnContext = new DynamicDMNContextBuilder(dmnRuntime.newContext(), dmnModel).populateContextWith(context);
+ return dmnRuntime.evaluateAll(dmnModel, dmnContext);
+ }
+
+}
diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java
index e45048502a..f6e45483e6 100644
--- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java
+++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java
@@ -17,6 +17,7 @@
*/
package org.kie.dmn.core.compiler;
+import java.util.ArrayList;
import org.drools.io.ClassPathResource;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -33,10 +34,7 @@ import org.mockito.verification.VerificationMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.Reader;
-import java.util.*;
import java.util.List;
-import java.util.function.Function;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
@@ -216,7 +214,7 @@ class DMNCompilerImplTest {
dMNCompiler.iterateImports(dmnDefs, null, model, null );
mockDMNImportsUtil.verify(() -> DMNImportsUtil.resolveDMNImportType(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()), dmnInvocation);
mockDMNImportsUtil.verify(() -> DMNImportsUtil.whichImportType(Mockito.any()), times(1));
- mockDMNImportsUtil.verify(() -> DMNImportsUtil.resolvePMMLImportType(Mockito.any(), Mockito.any(), (Function<String, Reader>) Mockito.any(), Mockito.any()), pmmlInvocation);
+ mockDMNImportsUtil.verify(() -> DMNImportsUtil.resolvePMMLImportType(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()), pmmlInvocation);
mockDMNImportsUtil.verify(() -> DMNImportsUtil.logErrorMessage(Mockito.any(), Mockito.any()), logErrorInvocation);
}
}
diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNImportsUtilTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNImportsUtilTest.java
index 21d4d66fe0..28b12107bf 100644
--- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNImportsUtilTest.java
+++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNImportsUtilTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,28 +16,71 @@
*/
package org.kie.dmn.core.compiler;
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.net.URL;
+import java.nio.file.Files;
import java.util.*;
import java.util.function.Function;
import javax.xml.namespace.QName;
+import java.util.stream.Stream;
import org.drools.io.ClassPathResource;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.kie.api.io.Resource;
import org.kie.dmn.api.core.DMNCompiler;
import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode;
+import org.kie.dmn.core.ast.BusinessKnowledgeModelNodeImpl;
import org.kie.dmn.core.impl.DMNModelImpl;
+import org.kie.dmn.core.pmml.EfestoPMMLUtils;
import org.kie.dmn.feel.util.Either;
+import org.kie.dmn.model.api.BusinessKnowledgeModel;
+import org.kie.dmn.model.api.Context;
+import org.kie.dmn.model.api.ContextEntry;
import org.kie.dmn.model.api.Definitions;
+import org.kie.dmn.model.api.Expression;
+import org.kie.dmn.model.api.FunctionDefinition;
+import org.kie.dmn.model.api.FunctionKind;
import org.kie.dmn.model.api.Import;
+import org.kie.dmn.model.api.InformationItem;
+import org.kie.dmn.model.api.LiteralExpression;
import org.kie.dmn.model.v1_1.TImport;
+import org.kie.dmn.model.v1_5.TBusinessKnowledgeModel;
+import org.kie.dmn.model.v1_5.TConditional;
+import org.kie.dmn.model.v1_5.TContext;
+import org.kie.dmn.model.v1_5.TContextEntry;
+import org.kie.dmn.model.v1_5.TFunctionDefinition;
+import org.kie.dmn.model.v1_5.TInformationItem;
+import org.kie.dmn.model.v1_5.TLiteralExpression;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.core.storage.ContextStorage;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.kie.dmn.core.util.DMNTestUtil.getRelativeResolver;
import static org.mockito.Mockito.mock;
class DMNImportsUtilTest {
+ private static final String dmnPmmlModelName = "TestRegressionDMN";
+ private static final String dmnPmmlFileName = "KiePMMLRegression";
+
+ private static final String dmnPmmlNameSpace = "https://kiegroup.org/dmn/_51A1FD67-8A67-4332-9889-B718BE8B7456";
+ private static final String dmnPmmlFullFileName = String.format("%s.dmn", dmnPmmlFileName);
+ private static final String dmnPmmlFullPathFileName = String.format("valid_models/DMNv1_x/pmml/%s", dmnPmmlFullFileName);
+
+ private static final String pmmlImportedName = "TestRegression";
+ protected static final String pmmlModelName = "LinReg";
+ protected static final String pmmlFileName = "test_regression";
+ protected static final String pmmlFullFileName = String.format("%s.pmml", pmmlFileName);
+ protected static final String pmmlFullPathFileName = String.format("valid_models/DMNv1_x/pmml/%s", pmmlFullFileName);
+
private static DMNCompiler dMNCompiler;
@BeforeAll
@@ -45,6 +88,11 @@ class DMNImportsUtilTest {
dMNCompiler = new DMNCompilerImpl();
}
+ @BeforeEach
+ public void init() {
+ ContextStorage.reset();
+ }
+
@Test
void nSonly() {
final Import i = makeImport("ns1", null, null);
@@ -179,50 +227,12 @@ class DMNImportsUtilTest {
assertThat(result.isLeft()).isTrue();
}
- private Import makeImport(final String namespace, final String name, final String modelName) {
- final Import i = new TImport();
- i.setNamespace(namespace);
- final Map<QName, String> addAttributes = new HashMap<>();
- if (name != null) {
- addAttributes.put(TImport.NAME_QNAME, name);
- }
- if (modelName != null) {
- addAttributes.put(TImport.MODELNAME_QNAME, modelName);
- }
- i.setAdditionalAttributes(addAttributes);
- final Definitions definitions = mock(Definitions.class);
- definitions.setNamespace("ParentDMNNamespace");
- definitions.setName("ParentDMN");
- i.setParent(definitions);
- return i;
- }
-
- @Test
- void checkLocatedDMNModel() {
- List<DMNModel> toMerge = new ArrayList<>();
- List<DMNModel> dmnModels = new ArrayList<>();
- String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
- Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
- this.getClass());
- DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
- assertThat(importingModel).isNotNull();
- assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
-
- Import input = importingModel.getDefinitions().getImport().get(0);
- DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
- DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
- DMNImportsUtil.checkLocatedDMNModel(input, located, model, toMerge);
- assertThat(importingModel).isNotNull();
- assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
- assertThat(toMerge).isEmpty();
- }
-
@Test
void resolveDMNImportType() {
List<DMNModel> toMerge = new ArrayList<>();
List<DMNModel> dmnModels = new ArrayList<>();
Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
- this.getClass());
+ this.getClass());
DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
assertThat(importedModel).isNotNull();
dmnModels.add(importedModel);
@@ -230,7 +240,7 @@ class DMNImportsUtilTest {
//imported model - Importing_Named_Model.dmn
String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
- this.getClass());
+ this.getClass());
DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
assertThat(importingModel).isNotNull();
assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
@@ -246,7 +256,25 @@ class DMNImportsUtilTest {
}
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNImportsUtil.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge).isEmpty();
+ }
@Test
void checkLocatedDMNModelWithAliasNull() {
@@ -270,23 +298,275 @@ class DMNImportsUtilTest {
}
@Test
- void resolvePMMLImportType() {
- List<DMNModel> dmnModels = new ArrayList<>();
- Resource dmnResource = new ClassPathResource( "../pmml/KiePMMLNewTree.dmn",
- this.getClass());
- DMNModel importingModel = dMNCompiler.compile( dmnResource, dmnModels);
- assertThat(importingModel).isNotNull();
+ void resolvePMMLImportTypeWithRelativeResolver() throws IOException {
+ DMNModelImpl model = getDMNModelWithUnresolvedPMMLImport();
+ Import anImport =getImportForUnresolvedPMMLImport();
+ Function<String, Reader> relativeResolver = getRelativeResolverForPMMLImport();
+ DMNCompilerConfigurationImpl dmnCompilerConfig = (DMNCompilerConfigurationImpl)((DMNCompilerImpl)dMNCompiler).getDmnCompilerConfig();
+ assertThat(model.getPmmlImportInfo()).isEmpty();
+ DMNImportsUtil.resolvePMMLImportType(model, getDMNDefinitionsForDMNWithPMMLImport(), anImport, relativeResolver, dmnCompilerConfig);
+ assertThat(model.getPmmlImportInfo()).hasSize(1).containsOnlyKeys(anImport.getName());
+ }
+ @Test
+ void resolvePMMLImportTypeWithoutRelativeResolver() throws IOException {
+ DMNModelImpl model = getDMNModelWithUnresolvedPMMLImport();
+ Import anImport = getImportForUnresolvedPMMLImport();
+ DMNCompilerConfigurationImpl dmnCompilerConfig = (DMNCompilerConfigurationImpl)((DMNCompilerImpl)dMNCompiler).getDmnCompilerConfig();
+ assertThat(model.getPmmlImportInfo()).isEmpty();
+ DMNImportsUtil.resolvePMMLImportType(model, getDMNDefinitionsForDMNWithPMMLImport(), anImport, null, dmnCompilerConfig);
+ assertThat(model.getPmmlImportInfo()).hasSize(1).containsOnlyKeys(pmmlImportedName);
+ }
- Import input = importingModel.getDefinitions().getImport().get(0);
- DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), dmnResource);
- Resource relativeResource = new ClassPathResource( "../pmml/test_tree_new.pmml",
- this.getClass());
+ @Test
+ void resolvePMMLImportTypeFromRelativeResolver() throws IOException {
+ DMNModelImpl model = getDMNModelWithUnresolvedPMMLImport();
+ Import anImport = getImportForUnresolvedPMMLImport();
+ Function<String, Reader> relativeResolver = getRelativeResolverForPMMLImport();
+ DMNCompilerConfigurationImpl dmnCompilerConfig = (DMNCompilerConfigurationImpl)((DMNCompilerImpl)dMNCompiler).getDmnCompilerConfig();
assertThat(model.getPmmlImportInfo()).isEmpty();
+ DMNImportsUtil.resolvePMMLImportTypeFromRelativeResolver(model, getDMNDefinitionsForDMNWithPMMLImport(), anImport, relativeResolver, dmnCompilerConfig);
+ assertThat(model.getPmmlImportInfo()).hasSize(1).containsOnlyKeys(anImport.getName());
+ }
+
+ @Test
+ void resolvePMMLImportTypeFromModelLocalUriId() throws IOException {
+ String pmmlFilePath = "../pmml/test_tree_new.pmml";
+ URL resource = DMNImportsUtilTest.class.getResource(pmmlFilePath);
+ assertThat(resource).isNotNull();
+ File pmmlFile = new File(resource.getFile());
+ assertThat(pmmlFile).isNotNull().exists();
+
+ String pmmlFileContent = Files.readString(pmmlFile.toPath());
+ ModelLocalUriId modelLocalUriId = EfestoPMMLUtils.compilePMML(pmmlFileContent, pmmlFile.getName(), "SampleMineNew" , Thread.currentThread().getContextClassLoader());
+
+ DMNModelImpl model = getDMNModelWithUnresolvedPMMLImport();
+ Import anImport =getImportForUnresolvedPMMLImport();
DMNCompilerConfigurationImpl dmnCompilerConfig = (DMNCompilerConfigurationImpl)((DMNCompilerImpl)dMNCompiler).getDmnCompilerConfig();
- DMNImportsUtil.resolvePMMLImportType(model, input, relativeResource, dmnCompilerConfig);
- assertThat(model.getPmmlImportInfo()).hasSize(1).containsOnlyKeys("test_tree");
+ assertThat(model.getPmmlImportInfo()).isEmpty();
+ DMNImportsUtil.resolvePMMLImportTypeFromModelLocalUriId(model, anImport, modelLocalUriId, dmnCompilerConfig);
+ assertThat(model.getPmmlImportInfo()).hasSize(1).containsOnlyKeys(anImport.getName());
+ }
+
+ @ParameterizedTest
+ @MethodSource("getExpectedResult")
+ void getPMMLModelFromDefinitions(Map.Entry<String, String> expectedResult) throws IOException {
+ Definitions defs = getDMNDefinitionsForDMNWithPMMLImport();
+ assertThat(DMNImportsUtil.getPMMLModelName(defs, expectedResult.getKey())).isEqualTo(expectedResult.getValue());
+ }
+
+ @ParameterizedTest
+ @MethodSource("getExpectedResult")
+ void getPMMLModelFromFunctionDef(Map.Entry<String, String> expectedResult) {
+ FunctionDefinition functionDefinition = getFunctionDefinitionForPMMLImport();
+ assertThat(DMNImportsUtil.getPMMLModelName(functionDefinition, expectedResult.getKey())).isEqualTo(expectedResult.getValue());
+ }
+
+ @Test
+ void getPMMLModelFromFunctionDefNameFails() {
+ FunctionDefinition functionDefinition = getFunctionDefinitionForPMMLImport();
+ assertThat(DMNImportsUtil.getPMMLModelName(functionDefinition, "NOT_PMML_IMPORTED_NAME")).isNull();
+ }
+
+ @Test
+ void getModelNameSuccess() {
+ ContextEntry contextEntry = getPmmlModelNameContextEntry("model");
+ Context context = getContext(contextEntry);
+ assertThat(DMNImportsUtil.getModelName(context)).isEqualTo(pmmlModelName);
+ }
+
+ @Test
+ void getModelNameFails() {
+ ContextEntry contextEntry = getPmmlModelNameContextEntry("not-model");
+ Context context = getContext(contextEntry);
+ assertThat(DMNImportsUtil.getModelName(context)).isNull();
+ //
+ contextEntry = getContextEntry("not-model", new TConditional());
+ context = getContext(contextEntry);
+ assertThat(DMNImportsUtil.getModelName(context)).isNull();
+ }
+
+ @Test
+ void referToPMMLImportedName() {
+ ContextEntry contextEntry = getPmmlModelNameContextEntry("document");
+ Context context = getContext(contextEntry);
+ assertThat(DMNImportsUtil.referToPMMLImportedName(context, pmmlModelName)).isTrue();
+ //
+ assertThat(DMNImportsUtil.referToPMMLImportedName(context, "NOT_MODEL_NAME")).isFalse();
+ //
+ contextEntry = getPmmlModelNameContextEntry("not-document");
+ context = getContext(contextEntry);
+ assertThat(DMNImportsUtil.referToPMMLImportedName(context, pmmlModelName)).isFalse();
+ }
+
+ @Test
+ void isDocumentContextEntry() {
+ ContextEntry contextEntry = getPmmlModelNameContextEntry("document");
+ assertThat(DMNImportsUtil.isDocumentContextEntry(contextEntry, pmmlModelName)).isTrue();
+ //
+ assertThat(DMNImportsUtil.isDocumentContextEntry(contextEntry, "NOT_MODEL_NAME")).isFalse();
+ //
+ contextEntry = getPmmlModelNameContextEntry("not-document");
+ assertThat(DMNImportsUtil.isDocumentContextEntry(contextEntry, pmmlModelName)).isFalse();
+ }
+
+ @Test
+ void isModelContextEntry() {
+ ContextEntry contextEntry = getContextEntry("model", new TLiteralExpression());
+ assertThat(DMNImportsUtil.isModelContextEntry(contextEntry)).isTrue();
+ contextEntry = getContextEntry("not-model", new TLiteralExpression());
+ assertThat(DMNImportsUtil.isModelContextEntry(contextEntry)).isFalse();
+ }
+
+ @Test
+ void hasVariableName() {
+ ContextEntry contextEntry = getContextEntry("variable");
+ assertThat(DMNImportsUtil.hasVariableName(contextEntry, "variable")).isTrue();
+ assertThat(DMNImportsUtil.hasVariableName(contextEntry, "not-variable")).isFalse();
+ }
+
+ private static Definitions getDMNDefinitionsForDMNWithPMMLImport() throws IOException {
+ Resource resource = new ClassPathResource( dmnPmmlFullPathFileName,
+ DMNImportsUtilTest.class);
+ return ((DMNCompilerImpl)dMNCompiler).getMarshaller().unmarshal(resource.getReader());
+ }
+
+ private static DMNModelImpl getDMNModelWithUnresolvedPMMLImport() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource dmnResource = new ClassPathResource( "valid_models/DMNv1_5/Sample.dmn",
+ DMNImportsUtilTest.class);
+ DMNModel simpleModel = dMNCompiler.compile( dmnResource, dmnModels);
+ assertThat(simpleModel).isNotNull();
+
+
+ String pmmlFilePath = "../pmml/test_tree_new.pmml";
+ URL resource = DMNImportsUtilTest.class.getResource(pmmlFilePath);
+ assertThat(resource).isNotNull();
+
+ DMNModelImpl toReturn = new DMNModelImpl(simpleModel.getDefinitions(), dmnResource);
+ assertThat(toReturn.getPmmlImportInfo()).isEmpty();
+ // encapsulatedLogic
+ FunctionDefinition encapsulatedLogic = getFunctionDefinitionForPMMLImport();
+ // businessKnowledgeModel
+ BusinessKnowledgeModel businessKnowledgeModel = new TBusinessKnowledgeModel();
+ businessKnowledgeModel.setEncapsulatedLogic(encapsulatedLogic);
+ businessKnowledgeModel.setName("BKM");
+ businessKnowledgeModel.setParent(simpleModel.getDefinitions());
+ // BusinessKnowledgeModelNode
+ BusinessKnowledgeModelNode businessKnowledgeModelNode = new BusinessKnowledgeModelNodeImpl(businessKnowledgeModel);
+ toReturn.addBusinessKnowledgeModel(businessKnowledgeModelNode);
+ return toReturn;
+ }
+
+ private static FunctionDefinition getFunctionDefinitionForPMMLImport() {
+ // document context entry
+ ContextEntry documentContextEntry = getPmmlImportedNameContextEntry("document");
+ // model context entry
+ ContextEntry modelContextEntry = getPmmlModelNameContextEntry("model");
+ // context
+ Context context = getContext(documentContextEntry, modelContextEntry);
+ FunctionDefinition toReturn = new TFunctionDefinition();
+ toReturn.setKind(FunctionKind.PMML);
+ toReturn.addChildren(context);
+ return toReturn;
+ }
+
+ private static Import getImportForUnresolvedPMMLImport() {
+ String pmmlFilePath = "../pmml/test_tree_new.pmml";
+ URL resource = DMNImportsUtilTest.class.getResource(pmmlFilePath);
+ assertThat(resource).isNotNull();
+ File pmmlFile = new File(resource.getFile());
+ Import anImport = new org.kie.dmn.model.v1_5.TImport();
+ anImport.setLocationURI(pmmlFile.toURI().toString());
+ anImport.setImportType("pmml");
+ anImport.setName(pmmlImportedName);
+ return anImport;
+ }
+
+ private static Function<String, Reader> getRelativeResolverForPMMLImport() throws IOException {
+ String pmmlFilePath = "../pmml/test_tree_new.pmml";
+ URL resource = DMNImportsUtilTest.class.getResource(pmmlFilePath);
+ assertThat(resource).isNotNull();
+ File pmmlFile = new File(resource.getFile());
+ String pmmlFileContent = Files.readString(pmmlFile.toPath());
+ return getRelativeResolver(pmmlFile.toURI().toString(), pmmlFileContent);
+ }
+
+ private static Import makeImport(final String namespace, final String name, final String modelName) {
+ final Import i = new TImport();
+ i.setNamespace(namespace);
+ final Map<QName, String> addAttributes = new HashMap<>();
+ if (name != null) {
+ addAttributes.put(TImport.NAME_QNAME, name);
+ }
+ if (modelName != null) {
+ addAttributes.put(TImport.MODELNAME_QNAME, modelName);
+ }
+ i.setAdditionalAttributes(addAttributes);
+ final Definitions definitions = mock(Definitions.class);
+ definitions.setNamespace("ParentDMNNamespace");
+ definitions.setName("ParentDMN");
+ i.setParent(definitions);
+ return i;
+ }
+
+ private static Stream<Map.Entry<String, String>> getExpectedResult() {
+ Map<String, String> toReturn = new HashMap<>();
+ toReturn.put(pmmlImportedName, pmmlModelName);
+ toReturn.put("NOT_IMPORTED_NAME", null);
+ return toReturn.entrySet().stream();
+ }
+
+ private static Context getContext(ContextEntry ... contextEntries) {
+ Context toReturn = new TContext();
+ for (ContextEntry contextEntry : contextEntries) {
+ toReturn.getContextEntry().add(contextEntry);
+ }
+ return toReturn;
+ }
+
+ private static ContextEntry getPmmlImportedNameContextEntry(String variableName) {
+ ContextEntry toReturn = getContextEntry(variableName);
+ toReturn.setExpression(getPmmlImportedNameLiteralExpression());
+ return toReturn;
+ }
+
+ private static ContextEntry getPmmlModelNameContextEntry(String variableName) {
+ ContextEntry toReturn = getContextEntry(variableName);
+ toReturn.setExpression(getPmmlModelNameLiteralExpression());
+ return toReturn;
+ }
+
+ private static ContextEntry getContextEntry(String variableName, Expression expression) {
+ ContextEntry toReturn = getContextEntry(variableName);
+ toReturn.setExpression(expression);
+ return toReturn;
+ }
+
+ private static ContextEntry getContextEntry(String variableName) {
+ InformationItem variable = getInformationItem(variableName);
+ ContextEntry toReturn = new TContextEntry();
+ toReturn.setVariable(variable);
+ return toReturn;
+ }
+
+ private static InformationItem getInformationItem(String name) {
+ InformationItem toReturn = new TInformationItem();
+ toReturn.setName(name);
+ return toReturn;
+ }
+
+ private static LiteralExpression getPmmlModelNameLiteralExpression() {
+ LiteralExpression toReturn = new TLiteralExpression();
+ toReturn.setText(String.format("\"%s\"", pmmlModelName));
+ return toReturn;
+ }
+
+ private static LiteralExpression getPmmlImportedNameLiteralExpression() {
+ LiteralExpression toReturn = new TLiteralExpression();
+ toReturn.setText(String.format("\"%s\"", pmmlImportedName));
+ return toReturn;
}
}
diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluatorTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluatorTest.java
index 343f81eeee..e035a5a97a 100644
--- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluatorTest.java
+++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/pmml/DMNKiePMMLTrustyInvocationEvaluatorTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,7 +18,7 @@
*/
package org.kie.dmn.core.pmml;
-import java.io.IOException;
+import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;
@@ -27,23 +27,22 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.kie.api.io.Resource;
-import org.kie.api.pmml.PMML4Result;
-import org.kie.api.pmml.PMMLRequestData;
import org.kie.dmn.api.core.DMNResult;
import org.kie.dmn.api.core.DMNRuntime;
import org.kie.dmn.api.core.event.DMNRuntimeEventManager;
import org.kie.dmn.feel.util.NumberEvalHelper;
import org.kie.dmn.model.api.DMNElement;
-import org.kie.efesto.common.api.model.GeneratedResources;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.mockito.Mockito;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.kie.dmn.core.pmml.DMNKiePMMLTrustyInvocationEvaluator.RESULT_OBJECT_NAME;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -54,35 +53,31 @@ class DMNKiePMMLTrustyInvocationEvaluatorTest {
private static DMNKiePMMLTrustyInvocationEvaluator dmnKiePMMLTrustyInvocationEvaluator;
- private static final String pmmlFileNameNoSuffix ="LogisticRegression";
- private static final String pmmlFileName = pmmlFileNameNoSuffix + ".pmml";
- private static final String model = "LogisticRegression";
+ private static final String PMML_FILE_NAME_NO_SUFFIX ="LogisticRegression";
+ private static final String PMML_FILE_NAME = PMML_FILE_NAME_NO_SUFFIX + ".pmml";
+ private static final String PMML_MODEL_NAME = "LogisticRegression";
+ private static ModelLocalUriId pmmlModelLocalUriId;
@BeforeEach
- void setup() throws IOException {
- URL pmmlUrl = DMNKiePMMLTrustyInvocationEvaluatorTest.class.getResource(pmmlFileName);
- assertThat(pmmlUrl).isNotNull();
- String pmmlFilePath = pmmlUrl.getPath();
+ void setup() {
+ pmmlModelLocalUriId = compilePmml();
String dmnNS = "dmnNS";
DMNElement nodeMock = Mockito.mock(DMNElement.class);
- Resource pmmlResourceMock = Mockito.mock(Resource.class);
- when(pmmlResourceMock.getSourcePath()).thenReturn(pmmlFilePath);
- when(pmmlResourceMock.getInputStream()).thenReturn(pmmlUrl.openStream());
PMMLInfo pmmlInfoMock = Mockito.mock(PMMLInfo.class);
+
dmnKiePMMLTrustyInvocationEvaluator = spy(new DMNKiePMMLTrustyInvocationEvaluator(dmnNS,
nodeMock,
- pmmlResourceMock,
- model,
+ pmmlModelLocalUriId,
+ PMML_MODEL_NAME,
pmmlInfoMock) {
protected Optional<String> getOutputFieldNameFromInfo(String resultName) {
return Optional.of(resultName);
}
-
- protected PMMLRequestData getPMMLRequestData(String correlationId, String modelName, String fileName,
+ protected Map<String, Object> getPMMLRequestData(String correlationId, String modelName, String fileName,
DMNResult dmnr) {
- return getPMMLRequestDataCommon(correlationId, modelName, fileName);
+ return getPMMLRequestDataCommon(modelName, fileName);
}
});
}
@@ -95,20 +90,16 @@ class DMNKiePMMLTrustyInvocationEvaluatorTest {
DMNRuntimeEventManager eventManagerMock = mock(DMNRuntimeEventManager.class);
when(eventManagerMock.getRuntime()).thenReturn(dmnRuntimeMock);
DMNResult dmnrMock = mock(DMNResult.class);
- dmnKiePMMLTrustyInvocationEvaluator.getPMML4Result(eventManagerMock, dmnrMock);
+ dmnKiePMMLTrustyInvocationEvaluator.getPMMLResult(eventManagerMock, dmnrMock);
verify(dmnKiePMMLTrustyInvocationEvaluator,
- times(1)).evaluate(model, pmmlFileName, dmnrMock, classLoader);
+ times(1)).evaluate(PMML_MODEL_NAME, pmmlModelLocalUriId, dmnrMock, classLoader);
}
@Test
- void getOutputFieldValues() {
- List<Object> values = getValues();
- Map<String, Object> resultVariables = new HashMap<>();
- for (int i = 0; i < values.size(); i++) {
- resultVariables.put("Element-" + i, values.get(i));
- }
- Map<String, Object> retrieved = dmnKiePMMLTrustyInvocationEvaluator.getOutputFieldValues(new PMML4Result(),
- resultVariables, null);
+ public void getOutputFieldValues() {
+ Map<String, Object> resultVariables = getMappedValues();
+ Map<String, Object> retrieved = dmnKiePMMLTrustyInvocationEvaluator.getOutputFieldValues(resultVariables,
+ null);
resultVariables.forEach((s, value) -> {
assertThat(retrieved).containsKey(s);
Object retObject = retrieved.get(s);
@@ -118,13 +109,14 @@ class DMNKiePMMLTrustyInvocationEvaluatorTest {
}
@Test
- void getPredictedValues() {
- List<Object> values = getValues();
- values.forEach(value -> {
- PMML4Result result = getPMML4Result(value);
- Map<String, Object> retrieved = dmnKiePMMLTrustyInvocationEvaluator.getPredictedValues(result, null);
- assertThat(retrieved).containsKey(result.getResultObjectName());
- Object retObject = retrieved.get(result.getResultObjectName());
+ public void getPredictedValues() {
+ final Map<String, Object> values = getMappedValues();
+ values.forEach((key, value) -> {
+ Map<String, Object> resultVariables = new HashMap<>(values);
+ resultVariables.put(RESULT_OBJECT_NAME, key);
+ Map<String, Object> retrieved = dmnKiePMMLTrustyInvocationEvaluator.getPredictedValues(resultVariables, null);
+ assertThat(retrieved).containsKey(key);
+ Object retObject = retrieved.get(key);
Object expected = NumberEvalHelper.coerceNumber(value);
assertThat(retObject).isEqualTo(expected);
});
@@ -138,29 +130,40 @@ class DMNKiePMMLTrustyInvocationEvaluatorTest {
DMNRuntimeEventManager eventManagerMock = mock(DMNRuntimeEventManager.class);
when(eventManagerMock.getRuntime()).thenReturn(dmnRuntimeMock);
DMNResult dmnrMock = mock(DMNResult.class);
- PMML4Result retrieved = dmnKiePMMLTrustyInvocationEvaluator.evaluate(model, pmmlFileName, dmnrMock, classLoader);
- assertThat(retrieved).isNotNull();
+ Map<String, Object> retrieved = dmnKiePMMLTrustyInvocationEvaluator.evaluate(PMML_MODEL_NAME, pmmlModelLocalUriId, dmnrMock,
+ classLoader);
+ assertThat(retrieved).isNotNull().isNotEmpty();
}
- @Test
- void compileFile() {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Map<String, GeneratedResources> retrieved = dmnKiePMMLTrustyInvocationEvaluator.compileFile(pmmlFileName, classLoader);
- assertThat(retrieved).isNotNull().isNotEmpty().containsKey("pmml");
+ private static ModelLocalUriId compilePmml() {
+ URL pmmlUrl = DMNKiePMMLTrustyInvocationEvaluatorTest.class.getResource(PMML_FILE_NAME);
+ assertThat(pmmlUrl).isNotNull();
+ File pmmlFile = new File(pmmlUrl.getFile());
+ assertThat(pmmlFile).isNotNull().exists();
+ return EfestoPMMLUtils.compilePMML(pmmlFile, PMML_MODEL_NAME, Thread.currentThread().getContextClassLoader());
}
- private static PMMLRequestData getPMMLRequestDataCommon(String correlationId, String modelName, String fileName) {
- PMMLRequestData toReturn = new PMMLRequestData(correlationId, modelName);
+ private static Map<String, Object> getPMMLRequestDataCommon(String modelName,
+ String fileName) {
+ Map<String, Object> toReturn = new HashMap<>();
List<String> fields = Arrays.asList("variance", "skewness", "curtosis", "entropy");
Random random = new Random();
fields.forEach(field -> {
double value = (double)random.nextInt(100)/10;
- toReturn.addRequestParam(field, value);
+ toReturn.put(field, value);
});
- toReturn.addRequestParam("_pmml_file_name_", fileName);
+ toReturn.put(DMNKiePMMLTrustyInvocationEvaluator.PMML_FILE_NAME, fileName);
+ toReturn.put(DMNKiePMMLTrustyInvocationEvaluator.PMML_MODEL_NAME, modelName);
return toReturn;
}
+ private Map<String, Object> getMappedValues() {
+ List<Object> values = getValues();
+ AtomicInteger counter = new AtomicInteger(0);
+ return values.stream().collect(Collectors.toMap(o -> "Element-" + counter.getAndAdd(1),
+ o -> o));
+ }
+
private List<Object> getValues() {
Random random = new Random();
return Stream.of(random.nextInt(),
@@ -171,11 +174,4 @@ class DMNKiePMMLTrustyInvocationEvaluatorTest {
.collect(Collectors.toList());
}
- private PMML4Result getPMML4Result(Object value) {
- PMML4Result toReturn = new PMML4Result();
- String resultName = "resultName";
- toReturn.setResultObjectName(resultName);
- toReturn.addResultVariable(resultName, value);
- return toReturn;
- }
}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/pmml/EfestoPMMLUtilsTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/pmml/EfestoPMMLUtilsTest.java
new file mode 100644
index 0000000000..000249bd4e
--- /dev/null
+++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/pmml/EfestoPMMLUtilsTest.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.core.pmml;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Function;
+import org.assertj.core.util.TriFunction;
+import org.drools.io.ClassPathResource;
+import org.drools.io.FileSystemResource;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.api.io.Resource;
+import org.kie.dmn.model.api.Import;
+import org.kie.dmn.model.v1_5.TImport;
+import org.kie.efesto.common.api.identifiers.LocalUri;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.api.model.GeneratedResources;
+import org.kie.efesto.common.core.storage.ContextStorage;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.kie.dmn.core.util.DMNTestUtil.getRelativeResolver;
+
+@SuppressWarnings({"unchecked", "rawtypes"})
+class EfestoPMMLUtilsTest {
+
+ private static final String DMN_FILE_PATH = "../pmml/KiePMMLNewTree.dmn";
+ private static File DMN_FILE;
+ private static final String PMML_FILE_NAME = "test_tree_new.pmml";
+ private static final String PMML_MODEL_NAME = "SampleMineNew";
+ private static final String PMML_FILE_PATH = "../pmml/" + PMML_FILE_NAME;
+ private static File PMML_FILE;
+ private static String PMML_SOURCE;
+
+ @BeforeAll
+ static void setUp() throws IOException {
+ URL dmnUrl = EfestoPMMLUtilsTest.class.getResource(DMN_FILE_PATH);
+ assertThat(dmnUrl).isNotNull();
+ DMN_FILE = new File(dmnUrl.getFile());
+ assertThat(DMN_FILE).isNotNull().exists();
+ URL pmmlUrl = EfestoPMMLUtilsTest.class.getResource(PMML_FILE_PATH);
+ assertThat(pmmlUrl).isNotNull();
+ PMML_FILE = new File(pmmlUrl.getFile());
+ assertThat(PMML_FILE).isNotNull().exists();
+ PMML_SOURCE = Files.readString(PMML_FILE.toPath());
+ assertThat(PMML_SOURCE).isNotNull().isNotEmpty();
+ }
+
+ @BeforeEach
+ void init() {
+ ContextStorage.reset();
+ }
+
+ @Test
+ void compilePMMLFromFile() {
+ ModelLocalUriId retrieved = EfestoPMMLUtils.compilePMML(PMML_FILE,
+ PMML_MODEL_NAME,
+ Thread.currentThread().getContextClassLoader());
+ commonCompilePMML(retrieved);
+ }
+
+ @Test
+ void compilePMMLFromSource() {
+ ModelLocalUriId retrieved = EfestoPMMLUtils.compilePMML(PMML_SOURCE,
+ PMML_FILE_NAME,
+ PMML_MODEL_NAME,
+ Thread.currentThread().getContextClassLoader());
+ commonCompilePMML(retrieved);
+ }
+
+ @Test
+ void getPmmlModelLocalUriIdWithResolver() {
+ commonCompileFromResolver(EfestoPMMLUtils::getPmmlModelLocalUriId);
+ }
+
+ @ParameterizedTest
+ @MethodSource("pmmlPaths")
+ void getPmmlModelLocalUriIdWithoutResolver(String fullFileNamePath, ModelLocalUriId expected) {
+ Import anImport = new TImport();
+ anImport.setLocationURI(fullFileNamePath);
+ ModelLocalUriId retrieved = EfestoPMMLUtils.getPmmlModelLocalUriId(anImport, ((LocalUri.LocalUriPathComponent)expected.asLocalUri()).getComponent(), null);
+ assertThat(retrieved).isNotNull().isEqualTo(expected);
+ }
+
+ @Test
+ void compilePmmlFromRelativeResolver() {
+ commonCompileFromResolver(EfestoPMMLUtils::compilePmmlFromRelativeResolver);
+ }
+
+ @ParameterizedTest
+ @MethodSource("pmmlPaths")
+ void getPmmlModelLocalUriIdFromImportWithoutResource(String fullFileNamePath, ModelLocalUriId expected) {
+ Import anImport = new TImport();
+ anImport.setLocationURI(fullFileNamePath);
+ ModelLocalUriId retrieved = EfestoPMMLUtils.getPmmlModelLocalUriIdFromImport(anImport, ((LocalUri.LocalUriPathComponent)expected.asLocalUri()).getComponent());
+ assertThat(retrieved).isNotNull().isEqualTo(expected);
+ }
+
+ @Test
+ void getPmmlModelLocalUriIdFromImportWithResource() {
+ ModelLocalUriId expected = EfestoPMMLUtils.getPmmlModelLocalUriId(PMML_FILE.getAbsolutePath(), PMML_MODEL_NAME);
+ Import anImport = new TImport();
+ anImport.setLocationURI(PMML_FILE_NAME);
+
+ Resource fileSystemResource = new FileSystemResource(DMN_FILE);
+ ModelLocalUriId retrieved = EfestoPMMLUtils.getRelativePmmlModelLocalUriIdFromImport(anImport, PMML_MODEL_NAME, fileSystemResource);
+ assertThat(retrieved).isEqualTo(expected);
+
+ Resource classPathResource = new ClassPathResource(DMN_FILE_PATH, EfestoPMMLUtilsTest.class);
+ retrieved = EfestoPMMLUtils.getRelativePmmlModelLocalUriIdFromImport(anImport, PMML_MODEL_NAME, classPathResource);
+ assertThat(retrieved).isEqualTo(expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("pmmlPaths")
+ void getPmmlModelLocalUriId(String fullFileNamePath, ModelLocalUriId expected) {
+ ModelLocalUriId retrieved = EfestoPMMLUtils.getPmmlModelLocalUriId(fullFileNamePath, ((LocalUri.LocalUriPathComponent)expected.asLocalUri()).getComponent());
+ assertThat(retrieved).isNotNull().isEqualTo(expected);
+ }
+
+ @Test
+ void getParentPath() {
+ Path expected = PMML_FILE.getParentFile().toPath();
+ Resource fileSystemResource = new FileSystemResource(PMML_FILE);
+ Path retrieved = EfestoPMMLUtils.getParentPath(fileSystemResource);
+ assertThat(retrieved).isEqualTo(expected);
+
+ Resource classPathResource = new ClassPathResource(PMML_FILE_PATH, EfestoPMMLUtilsTest.class);
+ retrieved = EfestoPMMLUtils.getParentPath(classPathResource);
+ assertThat(retrieved).isEqualTo(expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("filePaths")
+ void isRelative(String filePath, boolean expected) {
+ assertThat(EfestoPMMLUtils.isRelative(filePath)).isEqualTo(expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("pmmlPaths")
+ void getStringFromRelativeResolver(String fullFileNamePath, ModelLocalUriId modelLocalUriId) {
+ String content = UUID.randomUUID().toString();
+ Function<String, Reader> relativeResolver = getRelativeResolver(fullFileNamePath, content);
+ assertThat(EfestoPMMLUtils.getStringFromRelativeResolver(fullFileNamePath, relativeResolver)).isNotNull().isEqualTo(content);
+ }
+
+ private void commonCompilePMML(ModelLocalUriId retrieved) {
+ assertThat(retrieved).isNotNull();
+ EfestoCompilationContext efestoCompilationContext = ContextStorage.getEfestoCompilationContext(retrieved);
+ assertThat(efestoCompilationContext).isNotNull();
+ Map<String, GeneratedResources> generatedResourcesMap = efestoCompilationContext.getGeneratedResourcesMap();
+ assertThat(generatedResourcesMap).isNotNull().hasSize(1).containsOnlyKeys("pmml");
+ GeneratedResources generatedResources = generatedResourcesMap.get("pmml");
+ }
+
+ private void commonCompileFromResolver(TriFunction<Import, String, Function<String, Reader>, ModelLocalUriId> methodToCall) {
+ Import anImport = new TImport();
+ anImport.setLocationURI(PMML_FILE.toURI().toString());
+ Function<String, Reader> relativeResolver = getRelativeResolver(anImport.getLocationURI(), PMML_SOURCE);
+ ModelLocalUriId retrieved = methodToCall.apply(anImport, PMML_MODEL_NAME, relativeResolver);
+ assertThat(retrieved).isNotNull();
+ }
+
+ private static Object[][] pmmlPaths() {
+ return new Object[][]{
+ {fileFormattedPath("this", "is", "a", "path", "to", "model.pmml"), getModelLocalUriId("model", "RegressionModel")},
+ {fileFormattedPath("this", "is", "a", "path", "to", "model"), getModelLocalUriId("model", "TreeModel")},
+ {"model.pmml", getModelLocalUriId("model", "ClusterModel")}
+ };
+ }
+
+ private static Object[][] filePaths() {
+ return new Object[][]{
+ {"http://some.place/file", false},
+ {fileFormattedUri("some", "place", "file"), false},
+ {fileFormattedPath(".", "file"), true},
+ {fileFormattedPath("..", "some", "place", "file"), true}
+ };
+ }
+
+ private static String fileFormattedPath(String... elements) {
+ assertThat(elements).isNotNull().hasSizeGreaterThan(0);
+ return String.join(File.separator, elements);
+ }
+
+ private static String fileFormattedUri(String... elements) {
+ String path = fileFormattedPath(elements);
+ assertThat(path).isNotNull();
+ return new File(path).toURI().toString();
+ }
+
+ private static ModelLocalUriId getModelLocalUriId(String fileName, String modelName) {
+ LocalUri localUri = LocalUri.Root.append("pmml").append(fileName).append(modelName);
+ return new ModelLocalUriId(localUri);
+ }
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/DMNTestUtil.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/DMNTestUtil.java
index 0ebca7a8e1..5832332efe 100644
--- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/DMNTestUtil.java
+++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/util/DMNTestUtil.java
@@ -18,6 +18,9 @@
*/
package org.kie.dmn.core.util;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.function.Function;
import org.kie.dmn.api.core.DMNModel;
import org.kie.dmn.api.core.DMNRuntime;
@@ -35,4 +38,8 @@ public class DMNTestUtil {
assertThat(dmnModel.hasErrors()).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).isFalse();
return dmnModel;
}
+
+ public static Function<String, Reader> getRelativeResolver(String key, String content) {
+ return s -> s.equals(key) ? new StringReader(content) : null;
+ }
}
diff --git a/kie-dmn/kie-dmn-core/src/test/resources/0001-input-data-string.dmn b/kie-dmn/kie-dmn-core/src/test/resources/0001-input-data-string.dmn
new file mode 100644
index 0000000000..e36bbf9d96
--- /dev/null
+++ b/kie-dmn/kie-dmn-core/src/test/resources/0001-input-data-string.dmn
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+<dmn:definitions xmlns="https://github.com/kiegroup/drools/kie-dmn"
+ xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/"
+ id="_0001-input-data-string"
+ name="_0001-input-data-string"
+ namespace="https://github.com/kiegroup/drools/kie-dmn">
+ <dmn:decision name="Greeting Message" id="d_GreetingMessage">
+ <dmn:variable name="Greeting Message" typeRef="string"/>
+ <dmn:informationRequirement>
+ <dmn:requiredInput href="#i_FullName"/>
+ </dmn:informationRequirement>
+ <dmn:literalExpression>
+ <dmn:text>"Hello " + Full Name</dmn:text>
+ </dmn:literalExpression>
+ </dmn:decision>
+ <dmn:inputData name="Full Name" id="i_FullName">
+ <dmn:variable name="Full Name" typeRef="string"/>
+ </dmn:inputData>
+</dmn:definitions>
diff --git a/kie-dmn/kie-dmn-core/src/test/resources/IndexFile.dmn_json b/kie-dmn/kie-dmn-core/src/test/resources/IndexFile.dmn_json
new file mode 100644
index 0000000000..4e7dd0c201
--- /dev/null
+++ b/kie-dmn/kie-dmn-core/src/test/resources/IndexFile.dmn_json
@@ -0,0 +1,11 @@
+[
+ {
+ "step-type": "model",
+ "modelLocalUriId": {
+ "model": "dmn",
+ "basePath": "/0001-input-data-string/_0001-input-data-string",
+ "fullPath": "/dmn/0001-input-data-string/_0001-input-data-string"
+ },
+ "modelSource": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--\n ~ Copyright 2016 Red Hat, Inc. and/or its affiliates.\n ~\n ~ Licensed under the Apache License, Version 2.0 (the \"License\");\n ~ you may not use this file except in compliance with the License.\n ~ You may obtain a copy of the License at\n ~\n ~ http://www.apache.org/licenses/LICENSE-2.0\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is [...]
+ }
+]
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-api/pom.xml b/kie-dmn/kie-dmn-efesto-api/pom.xml
similarity index 56%
copy from kie-dmn/kie-dmn-api/pom.xml
copy to kie-dmn/kie-dmn-efesto-api/pom.xml
index 6f179cff3a..209b7079a6 100644
--- a/kie-dmn/kie-dmn-api/pom.xml
+++ b/kie-dmn/kie-dmn-efesto-api/pom.xml
@@ -23,44 +23,26 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
-
<parent>
<groupId>org.kie</groupId>
<artifactId>kie-dmn</artifactId>
<version>999-SNAPSHOT</version>
</parent>
- <artifactId>kie-dmn-api</artifactId>
+ <artifactId>kie-dmn-efesto-api</artifactId>
- <name>KIE :: Decision Model Notation :: API</name>
+ <name>KIE :: Decision Model Notation :: Efesto API</name>
<properties>
- <java.module.name>org.kie.dmn.api</java.module.name>
+ <java.module.name>org.kie.dmn.efesto.api</java.module.name>
</properties>
-
- <dependencies>
- <dependency>
- <groupId>org.kie</groupId>
- <artifactId>kie-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.kie</groupId>
- <artifactId>efesto-common-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.kie</groupId>
- <artifactId>kie-internal</artifactId>
- </dependency>
- <dependency>
- <groupId>org.kie</groupId>
- <artifactId>kie-dmn-model</artifactId>
- </dependency>
- <dependency>
- <groupId>com.thoughtworks.xstream</groupId>
- <artifactId>xstream</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
+
+<dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>efesto-common-api</artifactId>
+ </dependency>
+</dependencies>
<build>
<plugins>
@@ -74,14 +56,4 @@
</plugins>
</build>
- <profiles>
- <profile>
- <id>sonarcloud-analysis</id>
- <properties>
- <!-- Excluding the entire module from coverage statistics. API modules like this one contain only interfaces
- and enums, thus nothing JaCoCo can measure. -->
- <sonar.coverage.exclusions>**/*.java</sonar.coverage.exclusions>
- </properties>
- </profile>
- </profiles>
-</project>
+</project>
\ No newline at end of file
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/AbstractModelLocalUriIdDmn.java
similarity index 89%
copy from kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/AbstractModelLocalUriIdDmn.java
index 6c291c261d..7dc002862a 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/AbstractModelLocalUriIdDmn.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.pmml.api.identifiers;
+package org.kie.dmn.api.identifiers;
import java.util.Objects;
@@ -25,13 +25,13 @@ import org.kie.efesto.common.api.identifiers.LocalId;
import org.kie.efesto.common.api.identifiers.LocalUri;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
-public class AbstractModelLocalUriIdPmml extends ModelLocalUriId implements Id {
+public class AbstractModelLocalUriIdDmn extends ModelLocalUriId implements Id {
private static final long serialVersionUID = -4610916178245973385L;
protected final String fileName;
protected final String name;
- public AbstractModelLocalUriIdPmml(LocalUri path, String fileName, String name) {
+ public AbstractModelLocalUriIdDmn(LocalUri path, String fileName, String name) {
super(path);
this.fileName = fileName;
this.name = name;
diff --git a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
similarity index 99%
copy from kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
index 77478cc9e4..598856f48e 100644
--- a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java
similarity index 99%
copy from kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java
index 5014dadd22..53134cedfe 100644
--- a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnComponentRoot.java
similarity index 83%
copy from kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnComponentRoot.java
index fb7e788151..78504736e3 100644
--- a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnComponentRoot.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,9 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.dmn.pmml.trusty;
+package org.kie.dmn.api.identifiers;
-import org.kie.dmn.pmml.PMMLInfoTest;
+import org.kie.efesto.common.api.identifiers.ComponentRoot;
+
+public interface DmnComponentRoot extends ComponentRoot {
-public class TrustyPMMLInfoTest extends PMMLInfoTest {
}
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnIdFactory.java
similarity index 55%
copy from kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnIdFactory.java
index b276160eb0..f849f241d9 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnIdFactory.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -16,17 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.pmml.api.identifiers;
+package org.kie.dmn.api.identifiers;
import org.kie.efesto.common.api.identifiers.LocalUri;
-public class LocalComponentIdPmml extends AbstractModelLocalUriIdPmml {
- public static final String PREFIX = "pmml";
- private static final long serialVersionUID = 8621199867598971641L;
+public class DmnIdFactory implements DmnComponentRoot {
-
- public LocalComponentIdPmml(String fileName, String name) {
- super(LocalUri.Root.append(PREFIX).append(fileName).append(name), fileName, name);
+ public LocalComponentIdDmn get(String fileName, String modelName) {
+ return new LocalComponentIdDmn(fileName, modelName);
}
+ public LocalCompilationSourceIdDmn get(String fileName) {
+ if (fileName.contains(LocalUri.SLASH)) {
+ fileName = fileName.substring(fileName.lastIndexOf(LocalUri.SLASH) + 1);
+ }
+ if (fileName.contains(".")) {
+ fileName = fileName.substring(0, fileName.lastIndexOf('.'));
+ }
+ return new LocalCompilationSourceIdDmn(fileName);
+ }
}
diff --git a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnIdRedirectFactory.java
similarity index 77%
copy from kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnIdRedirectFactory.java
index 77478cc9e4..6eb3892388 100644
--- a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/DmnIdRedirectFactory.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,10 +18,9 @@
*/
package org.kie.dmn.api.identifiers;
-import org.kie.efesto.common.api.identifiers.ComponentRoot;
+public class DmnIdRedirectFactory implements DmnComponentRoot {
-public class DecisionIds implements ComponentRoot {
- public LocalDecisionId get(String namespace, String name) {
- return new LocalDecisionId(namespace, name);
+ public LocalComponentIdRedirectDmn get(String redirectModel, String fileName, String name) {
+ return new LocalComponentIdRedirectDmn(redirectModel, fileName, name);
}
}
diff --git a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/KieDmnComponentRoot.java
similarity index 59%
rename from kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
rename to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/KieDmnComponentRoot.java
index 77478cc9e4..c7eec43e44 100644
--- a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionIds.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/KieDmnComponentRoot.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,10 +18,24 @@
*/
package org.kie.dmn.api.identifiers;
+import java.util.Map;
+
import org.kie.efesto.common.api.identifiers.ComponentRoot;
+import org.kie.efesto.common.api.identifiers.EfestoComponentRoot;
+import org.kie.efesto.common.api.utils.EfestoAppRootHelper;
+
+import static org.kie.efesto.common.api.utils.EfestoAppRootHelper.getComponentRootBySPI;
+
+public class KieDmnComponentRoot implements EfestoComponentRoot {
+
+ private static final Map<Class<? extends ComponentRoot>, ComponentRoot> INSTANCES;
+
+ static {
+ INSTANCES = EfestoAppRootHelper.getComponentRootBySPI(DmnComponentRoot.class);
+ }
-public class DecisionIds implements ComponentRoot {
- public LocalDecisionId get(String namespace, String name) {
- return new LocalDecisionId(namespace, name);
+ @Override
+ public <T extends ComponentRoot> T get(Class<T> providerId) {
+ return (T) INSTANCES.get(providerId);
}
}
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalCompilationSourceIdDmn.java
similarity index 76%
copy from kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalCompilationSourceIdDmn.java
index 6c291c261d..177a2f332c 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalCompilationSourceIdDmn.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -16,34 +16,30 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.pmml.api.identifiers;
-
-import java.util.Objects;
+package org.kie.dmn.api.identifiers;
import org.kie.efesto.common.api.identifiers.Id;
import org.kie.efesto.common.api.identifiers.LocalId;
import org.kie.efesto.common.api.identifiers.LocalUri;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
-public class AbstractModelLocalUriIdPmml extends ModelLocalUriId implements Id {
+import java.util.Objects;
- private static final long serialVersionUID = -4610916178245973385L;
- protected final String fileName;
- protected final String name;
+public class LocalCompilationSourceIdDmn extends ModelLocalUriId implements Id {
+ public static final String PREFIX = "dmn";
+ private static final long serialVersionUID = 8621199867598971641L;
- public AbstractModelLocalUriIdPmml(LocalUri path, String fileName, String name) {
- super(path);
+ private final String fileName;
+
+ public LocalCompilationSourceIdDmn(String fileName) {
+ super(LocalUri.Root.append(PREFIX).append(fileName));
this.fileName = fileName;
- this.name = name;
}
public String getFileName() {
return fileName;
}
- public String name() {
- return name;
- }
@Override
public LocalId toLocalId() {
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalComponentIdDmn.java
similarity index 75%
copy from kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalComponentIdDmn.java
index 6c291c261d..60846691ae 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalComponentIdDmn.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.pmml.api.identifiers;
+package org.kie.dmn.api.identifiers;
import java.util.Objects;
@@ -25,14 +25,16 @@ import org.kie.efesto.common.api.identifiers.LocalId;
import org.kie.efesto.common.api.identifiers.LocalUri;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
-public class AbstractModelLocalUriIdPmml extends ModelLocalUriId implements Id {
+public class LocalComponentIdDmn extends ModelLocalUriId implements Id {
- private static final long serialVersionUID = -4610916178245973385L;
- protected final String fileName;
- protected final String name;
+ public static final String PREFIX = "dmn";
+ private static final long serialVersionUID = 8621199867598971641L;
- public AbstractModelLocalUriIdPmml(LocalUri path, String fileName, String name) {
- super(path);
+ private final String fileName;
+ private final String name;
+
+ public LocalComponentIdDmn(String fileName, String name) {
+ super(LocalUri.Root.append(PREFIX).append(fileName).append(name));
this.fileName = fileName;
this.name = name;
}
@@ -41,7 +43,7 @@ public class AbstractModelLocalUriIdPmml extends ModelLocalUriId implements Id {
return fileName;
}
- public String name() {
+ public String getName() {
return name;
}
@@ -63,5 +65,4 @@ public class AbstractModelLocalUriIdPmml extends ModelLocalUriId implements Id {
public int hashCode() {
return super.hashCode();
}
-
}
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalComponentIdRedirectDmn.java
similarity index 55%
copy from kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
copy to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalComponentIdRedirectDmn.java
index b276160eb0..5dfcdc06ee 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalComponentIdRedirectDmn.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,17 +16,32 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.pmml.api.identifiers;
+package org.kie.dmn.api.identifiers;
import org.kie.efesto.common.api.identifiers.LocalUri;
-public class LocalComponentIdPmml extends AbstractModelLocalUriIdPmml {
- public static final String PREFIX = "pmml";
- private static final long serialVersionUID = 8621199867598971641L;
+public class LocalComponentIdRedirectDmn extends AbstractModelLocalUriIdDmn {
+ private static final long serialVersionUID = -4610916178245973385L;
- public LocalComponentIdPmml(String fileName, String name) {
- super(LocalUri.Root.append(PREFIX).append(fileName).append(name), fileName, name);
+ private final String redirectModel;
+
+ public LocalComponentIdRedirectDmn(String redirectModel, String fileName, String name) {
+ super(LocalUri.Root.append(redirectModel).append(fileName).append(name), fileName, name);
+ this.redirectModel = redirectModel;
+ }
+
+ public String getRedirectModel() {
+ return redirectModel;
}
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
}
diff --git a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionId.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionId.java
similarity index 99%
rename from kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionId.java
rename to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionId.java
index 12c03f34a7..d6e16884cb 100644
--- a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionId.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionId.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionServiceId.java b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionServiceId.java
similarity index 99%
rename from kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionServiceId.java
rename to kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionServiceId.java
index 41e8e670c3..dc51f6c149 100644
--- a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionServiceId.java
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/java/org/kie/dmn/api/identifiers/LocalDecisionServiceId.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/native-image/org.kie/kie-dmn-efesto-api/reflect-config.json b/kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/native-image/org.kie/kie-dmn-efesto-api/reflect-config.json
new file mode 100644
index 0000000000..0ed5d33b26
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/native-image/org.kie/kie-dmn-efesto-api/reflect-config.json
@@ -0,0 +1,65 @@
+[
+ {
+ "name" : "org.kie.dmn.api.identifiers.KieDmnComponentRoot",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name" : "org.kie.dmn.api.identifiers.DmnIdFactory",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name" : "org.kie.dmn.api.identifiers.DmnIdRedirectFactory",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name" : "org.kie.dmn.api.identifiers.LocalComponentIdDmn",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name" : "org.kie.dmn.api.identifiers.LocalComponentIdRedirectDmn",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name" : "org.kie.dmn.api.identifiers.LocalDecisionId",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ },
+ {
+ "name" : "org.kie.dmn.api.identifiers.DecisionIds",
+ "allDeclaredConstructors" : true,
+ "allPublicConstructors" : true,
+ "allDeclaredMethods" : true,
+ "allPublicMethods" : true,
+ "allDeclaredFields" : true,
+ "allPublicFields" : true
+ }
+]
\ No newline at end of file
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService b/kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/services/org.kie.dmn.api.identifiers.DmnComponentRoot
similarity index 80%
copy from kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
copy to kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/services/org.kie.dmn.api.identifiers.DmnComponentRoot
index 662843a940..67d38940db 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/services/org.kie.dmn.api.identifiers.DmnComponentRoot
@@ -17,6 +17,6 @@
# under the License.
#
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMML
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLRequestData
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLMapInput
\ No newline at end of file
+# SPI implementations
+org.kie.dmn.api.identifiers.DmnIdFactory
+org.kie.dmn.api.identifiers.DmnIdRedirectFactory
\ No newline at end of file
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService b/kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/services/org.kie.efesto.common.api.identifiers.EfestoComponentRoot
similarity index 80%
copy from kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
copy to kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/services/org.kie.efesto.common.api.identifiers.EfestoComponentRoot
index 662843a940..fe1884203f 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
+++ b/kie-dmn/kie-dmn-efesto-api/src/main/resources/META-INF/services/org.kie.efesto.common.api.identifiers.EfestoComponentRoot
@@ -17,6 +17,5 @@
# under the License.
#
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMML
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLRequestData
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLMapInput
\ No newline at end of file
+# SPI implementations
+org.kie.dmn.api.identifiers.KieDmnComponentRoot
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-compilation/pom.xml b/kie-dmn/kie-dmn-efesto-compilation/pom.xml
new file mode 100644
index 0000000000..479a916dc4
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/pom.xml
@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn</artifactId>
+ <version>999-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>kie-dmn-efesto-compilation</artifactId>
+
+ <name>KIE :: Decision Model Notation :: Efesto Compilation</name>
+
+ <properties>
+ <java.module.name>org.kie.dmn.efesto.compilation</java.module.name>
+ <dependency-plugin.version>3.6.1</dependency-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-test-resources</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-compiler-core</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-models-regression-compiler</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-models-regression-evaluator</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+
+ <dependencies>
+ <!-- DMN -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-validation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-api</artifactId>
+ </dependency>
+ <!-- End DMN -->
+ <!-- Efesto -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>efesto-compilation-manager-core</artifactId>
+ </dependency>
+ <!-- End Efesto -->
+ <!-- TEST -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-test-resources</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-compiler-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-models-regression-compiler</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-pmml-models-regression-evaluator</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-test-util</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <!-- Unpack DMN resources from from org.kie:kie-dmn-test-resources -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>${dependency-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-test-resources</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <type>jar</type>
+ <overWrite>true</overWrite>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <includes>**/*.dmn,**/*.pmml</includes>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DMNResourceSetResource.java
similarity index 62%
copy from kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
copy to kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DMNResourceSetResource.java
index b276160eb0..3c0d6db87f 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DMNResourceSetResource.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,17 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.pmml.api.identifiers;
+package org.kie.dmn.efesto.compiler.model;
-import org.kie.efesto.common.api.identifiers.LocalUri;
+import java.util.Set;
+import org.kie.api.io.Resource;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.compilationmanager.api.model.EfestoSetResource;
-public class LocalComponentIdPmml extends AbstractModelLocalUriIdPmml {
- public static final String PREFIX = "pmml";
- private static final long serialVersionUID = 8621199867598971641L;
+/**
+ * Resource set for "dmn" files
+ */
+public class DMNResourceSetResource extends EfestoSetResource<Resource> {
- public LocalComponentIdPmml(String fileName, String name) {
- super(LocalUri.Root.append(PREFIX).append(fileName).append(name), fileName, name);
+ public DMNResourceSetResource(Set<Resource> dmnResources, ModelLocalUriId modelLocalUriId) {
+ super(dmnResources, modelLocalUriId);
}
}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DmnCompilationContext.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DmnCompilationContext.java
new file mode 100644
index 0000000000..305c7b2b9f
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DmnCompilationContext.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.model;
+
+import java.util.Set;
+import org.kie.dmn.core.compiler.DMNProfile;
+import org.kie.dmn.core.compiler.RuntimeTypeCheckOption;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.compilationmanager.core.model.EfestoCompilationContextImpl;
+import org.kie.efesto.compilationmanager.core.model.EfestoCompilationContextUtils;
+import org.kie.internal.builder.KnowledgeBuilderConfiguration;
+import org.kie.memorycompiler.KieMemoryCompiler;
+
+@SuppressWarnings("rawtypes")
+public interface DmnCompilationContext extends EfestoCompilationContext {
+
+ static DmnCompilationContext buildWithParentClassLoader(ClassLoader parentClassLoader) {
+ return new DmnCompilationContextImpl(new KieMemoryCompiler.MemoryCompilerClassLoader(parentClassLoader));
+ }
+
+ static DmnCompilationContext buildWithMemoryCompilerClassLoader(KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader) {
+ return new DmnCompilationContextImpl(memoryCompilerClassLoader);
+ }
+
+ static DmnCompilationContext buildWithEfestoCompilationContext(EfestoCompilationContextImpl context) {
+ return (DmnCompilationContext) EfestoCompilationContextUtils.buildFromContext(context, DmnCompilationContextImpl.class);
+ }
+
+ static DmnCompilationContext buildWithParentClassLoader(ClassLoader parentClassLoader, Set<DMNProfile> customDMNProfiles,
+ RuntimeTypeCheckOption runtimeTypeCheckOption) {
+ return new DmnCompilationContextImpl(new KieMemoryCompiler.MemoryCompilerClassLoader(parentClassLoader), customDMNProfiles, runtimeTypeCheckOption);
+ }
+
+ KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration();
+
+ Set<DMNProfile> getCustomDMNProfiles();
+
+ RuntimeTypeCheckOption getRuntimeTypeCheckOption();
+
+ ClassLoader getContextClassloader();
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DmnCompilationContextImpl.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DmnCompilationContextImpl.java
new file mode 100644
index 0000000000..a5abcefdf2
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/DmnCompilationContextImpl.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.model;
+
+import java.util.Set;
+import org.kie.dmn.core.compiler.DMNProfile;
+import org.kie.dmn.core.compiler.RuntimeTypeCheckOption;
+import org.kie.efesto.compilationmanager.core.model.EfestoCompilationContextImpl;
+import org.kie.internal.builder.KnowledgeBuilderConfiguration;
+import org.kie.internal.builder.KnowledgeBuilderFactory;
+import org.kie.memorycompiler.KieMemoryCompiler;
+
+@SuppressWarnings("rawtypes")
+
+public class DmnCompilationContextImpl extends EfestoCompilationContextImpl implements DmnCompilationContext {
+
+ private Set<DMNProfile> customDMNProfiles;
+ private RuntimeTypeCheckOption runtimeTypeCheckOption;
+
+ public DmnCompilationContextImpl(KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader) {
+ this(memoryCompilerClassLoader, null, null);
+ }
+
+ public DmnCompilationContextImpl(KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader, Set<DMNProfile> customDMNProfiles,
+ RuntimeTypeCheckOption runtimeTypeCheckOption) {
+ super(memoryCompilerClassLoader, false);
+ this.customDMNProfiles = customDMNProfiles;
+ this.runtimeTypeCheckOption = runtimeTypeCheckOption;
+ }
+
+ @Override
+ public KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration() {
+ return KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(memoryCompilerClassLoader);
+ }
+
+ @Override
+ public Set<DMNProfile> getCustomDMNProfiles() {
+ return customDMNProfiles;
+ }
+
+ @Override
+ public RuntimeTypeCheckOption getRuntimeTypeCheckOption() {
+ return runtimeTypeCheckOption;
+ }
+
+ @Override
+ public ClassLoader getContextClassloader() {
+ return memoryCompilerClassLoader;
+ }
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/EfestoCallableOutputDMN.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/EfestoCallableOutputDMN.java
new file mode 100644
index 0000000000..0a4c9c7c99
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/EfestoCallableOutputDMN.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.model;
+
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.compilationmanager.api.model.EfestoCallableOutputModelContainer;
+
+import java.util.Collections;
+import java.util.List;
+
+public class EfestoCallableOutputDMN extends EfestoCallableOutputModelContainer<DMNModel> {
+
+ public EfestoCallableOutputDMN(String fileName, String modelName, String modelSource, DMNModel dmnModel) {
+ super(new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName, modelName),
+ modelSource,
+ dmnModel);
+ }
+
+ public EfestoCallableOutputDMN(ModelLocalUriId modelLocalUriId, String modelSource, DMNModel dmnModel) {
+ super(modelLocalUriId,
+ modelSource,
+ dmnModel);
+ }
+
+ @Override
+ public List<String> getFullClassNames() {
+ return Collections.emptyList();
+ }
+}
diff --git a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/EfestoValidationOutput.java
similarity index 53%
copy from efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java
copy to kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/EfestoValidationOutput.java
index 50cf9f7a9a..e3e7dbb7df 100644
--- a/efesto/efesto-core/efesto-compilation-manager/efesto-compilation-manager-api/src/main/java/org/kie/efesto/compilationmanager/api/exceptions/KieCompilerServiceException.java
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/model/EfestoValidationOutput.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,26 +16,39 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.efesto.compilationmanager.api.exceptions;
+package org.kie.dmn.efesto.compiler.model;
-public class KieCompilerServiceException extends RuntimeException {
+import java.util.Collection;
- public KieCompilerServiceException() {
+public class EfestoValidationOutput {
+
+ public enum STATUS {
+ OK,
+ FAIL
+ }
+
+ private String modelIdentifier;
+ private STATUS status;
+ private Collection<String> messages;
+
+ public EfestoValidationOutput() {
}
- public KieCompilerServiceException(String message) {
- super(message);
+ public EfestoValidationOutput(String modelIdentifier, STATUS status, Collection<String> messages) {
+ this.modelIdentifier = modelIdentifier;
+ this.status = status;
+ this.messages = messages;
}
- public KieCompilerServiceException(String message, Throwable cause) {
- super(message, cause);
+ public String getModelIdentifier() {
+ return modelIdentifier;
}
- public KieCompilerServiceException(Throwable cause) {
- super(cause);
+ public STATUS getStatus() {
+ return status;
}
- public KieCompilerServiceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
+ public Collection<String> getMessages() {
+ return messages;
}
}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/AbstractKieCompilerServiceDMN.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/AbstractKieCompilerServiceDMN.java
new file mode 100644
index 0000000000..dfb8a6a887
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/AbstractKieCompilerServiceDMN.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.util.Arrays;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.api.identifiers.LocalCompilationSourceIdDmn;
+import org.kie.dmn.core.compiler.profiles.ExtendedDMNProfile;
+import org.kie.dmn.validation.DMNValidator;
+import org.kie.dmn.validation.DMNValidatorFactory;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.service.KieCompilerService;
+
+
+public abstract class AbstractKieCompilerServiceDMN implements KieCompilerService<EfestoCompilationOutput, EfestoCompilationContext> {
+
+ static final DMNValidator validator = DMNValidatorFactory.newValidator(Arrays.asList(new ExtendedDMNProfile()));
+
+ @Override
+ public boolean hasCompilationSource(String fileName) {
+ LocalCompilationSourceIdDmn localCompilationSourceIdDmn = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName);
+ return ContextStorage.getEfestoCompilationSource(localCompilationSourceIdDmn) != null;
+ }
+
+ @Override
+ public String getCompilationSource(String fileName) {
+ LocalCompilationSourceIdDmn localCompilationSourceIdDmn = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName);
+ return ContextStorage.getEfestoCompilationSource(localCompilationSourceIdDmn);
+ }
+
+ @Override
+ public String getModelType() {
+ return "dmn";
+ }
+
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFile.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFile.java
new file mode 100644
index 0000000000..23b2ad3006
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFile.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import org.kie.dmn.api.core.DMNMessage;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.api.identifiers.LocalCompilationSourceIdDmn;
+import org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils;
+import org.kie.dmn.validation.DMNValidator;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.io.MemoryFile;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.exceptions.EfestoCompilationManagerException;
+import org.kie.efesto.compilationmanager.api.exceptions.KieCompilerServiceException;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoFileResource;
+import org.kie.efesto.compilationmanager.api.model.EfestoResource;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Collections;
+import java.util.List;
+
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getCleanedFilenameForURI;
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getDMNModel;
+
+
+public class KieCompilerServiceDMNFile extends AbstractKieCompilerServiceDMN {
+
+ @Override
+ @SuppressWarnings( "rawtypes")
+ public boolean canManageResource(EfestoResource toProcess) {
+ return toProcess instanceof EfestoFileResource efestoFileResource && efestoFileResource.getModelType().equalsIgnoreCase("dmn");
+ }
+
+ @Override
+ @SuppressWarnings( "rawtypes")
+ public List<EfestoCompilationOutput> processResource(EfestoResource toProcess, EfestoCompilationContext context) {
+ if (!canManageResource(toProcess)) {
+ throw new KieCompilerServiceException(String.format("%s can not process %s",
+ this.getClass().getName(),
+ toProcess.getClass().getName()));
+ }
+ EfestoFileResource fileResource = (EfestoFileResource) toProcess;
+ File dmnFile = fileResource.getContent();
+ String modelSource;
+ try {
+ modelSource = dmnFile instanceof MemoryFile memoryFile ? new String(memoryFile.getContent(), StandardCharsets.UTF_8) : ( Files.readString(dmnFile.toPath()));
+
+ } catch (IOException e) {
+ throw new KieCompilerServiceException(String.format("%s failed to read content of %s",
+ this.getClass().getName(),
+ fileResource.getContent()));
+ }
+ List<DMNMessage> messages = validator.validate(new StringReader(modelSource),
+ DMNValidator.Validation.VALIDATE_SCHEMA,
+ DMNValidator.Validation.VALIDATE_MODEL,
+ DMNValidator.Validation.VALIDATE_COMPILATION,
+ DMNValidator.Validation.ANALYZE_DECISION_TABLE);
+ // see https://github.com/apache/incubator-kie-issues/issues/1619
+// if (DmnCompilerUtils.hasError(messages)) {
+// return Collections.emptyList();
+// }
+ try {
+ String fileName = getCleanedFilenameForURI(dmnFile);
+ LocalCompilationSourceIdDmn localCompilationSourceIdDmn = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName);
+ ContextStorage.putEfestoCompilationSource(localCompilationSourceIdDmn, modelSource);
+ DMNModel dmnModel = getDMNModel(modelSource);
+ return Collections.singletonList(DmnCompilerUtils.getDefaultEfestoCompilationOutput(fileName,
+ dmnModel.getName(),
+ modelSource, dmnModel));
+ } catch (Exception e) {
+ throw new EfestoCompilationManagerException(e);
+ }
+ }
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFileSet.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFileSet.java
new file mode 100644
index 0000000000..9f4072a10e
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFileSet.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.Set;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.api.identifiers.LocalCompilationSourceIdDmn;
+import org.kie.dmn.efesto.compiler.model.DmnCompilationContext;
+import org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.exceptions.EfestoCompilationManagerException;
+import org.kie.efesto.compilationmanager.api.exceptions.KieCompilerServiceException;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoFileSetResource;
+import org.kie.efesto.compilationmanager.api.model.EfestoResource;
+
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getCleanedFilenameForURI;
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getDMNModelsFromFiles;
+
+public class KieCompilerServiceDMNFileSet extends AbstractKieCompilerServiceDMN {
+
+ @Override
+ @SuppressWarnings( "rawtypes")
+ public boolean canManageResource(EfestoResource toProcess) {
+ return toProcess instanceof EfestoFileSetResource efestoFileSetResource &&
+ efestoFileSetResource.getModelLocalUriId().model().equalsIgnoreCase("dmn");
+ }
+
+ @Override
+ @SuppressWarnings( "rawtypes")
+ public List<EfestoCompilationOutput> processResource(EfestoResource toProcess, EfestoCompilationContext context) {
+ if (!canManageResource(toProcess)) {
+ throw new KieCompilerServiceException(String.format("%s can not process %s",
+ this.getClass().getName(),
+ toProcess.getClass().getName()));
+ }
+ if (!(context instanceof DmnCompilationContext dmnContext)) {
+ throw new KieCompilerServiceException(String.format("Wrong %s context parameter for from %s",
+ context.getClass().getName(),
+ this.getClass().getName()));
+ }
+ EfestoFileSetResource fileSetResource = (EfestoFileSetResource) toProcess;
+ Set<File> dmnFiles = fileSetResource.getContent();
+ try {
+ List<DMNModel> dmnModels = getDMNModelsFromFiles(dmnFiles, dmnContext.getCustomDMNProfiles(), dmnContext.getRuntimeTypeCheckOption(), dmnContext.getContextClassloader());
+ storeSources(dmnFiles);
+ return dmnModels.stream()
+ .map(
+ dmnModel -> {
+ File dmnFile = new File(dmnModel.getResource().getSourcePath());
+ String modelSource = readFile(dmnFile);
+ return DmnCompilerUtils.getDefaultEfestoCompilationOutput(getCleanedFilenameForURI(dmnFile),
+ dmnModel.getName(),
+ modelSource,
+ dmnModel);
+ })
+ .toList();
+
+ } catch (Exception e) {
+ throw new EfestoCompilationManagerException(e);
+ }
+ }
+
+ private void storeSources(Set<File> dmnFiles) {
+ dmnFiles.forEach(file -> {
+ String fileName = file.getName();
+ LocalCompilationSourceIdDmn localCompilationSourceIdDmn = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName);
+ String modelSource = readFile(file);
+ ContextStorage.putEfestoCompilationSource(localCompilationSourceIdDmn, modelSource);
+ });
+ }
+
+ private String readFile(File toRead) {
+ try {
+ return Files.readString(toRead.toPath());
+ } catch (IOException e) {
+ throw new KieCompilerServiceException(e);
+ }
+ }
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNInputStream.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNInputStream.java
new file mode 100644
index 0000000000..f4c8c47f4c
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNInputStream.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import org.kie.dmn.api.core.DMNMessage;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.api.identifiers.LocalCompilationSourceIdDmn;
+import org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils;
+import org.kie.dmn.validation.DMNValidator;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.exceptions.KieCompilerServiceException;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoInputStreamResource;
+import org.kie.efesto.compilationmanager.api.model.EfestoResource;
+
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getCleanedFilenameForURI;
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getDMNModel;
+
+/**
+ * For the moment being, use this for DMN "validation", since DMN does not have a code-generation phase
+ */
+public class KieCompilerServiceDMNInputStream extends AbstractKieCompilerServiceDMN {
+
+ @Override
+ public boolean canManageResource(EfestoResource toProcess) {
+ return toProcess instanceof EfestoInputStreamResource efestoInputStreamResource && efestoInputStreamResource.getModelType().equalsIgnoreCase("dmn");
+ }
+
+ @Override
+ public List<EfestoCompilationOutput> processResource(EfestoResource toProcess, EfestoCompilationContext context) {
+ if (!canManageResource(toProcess)) {
+ throw new KieCompilerServiceException(String.format("%s can not process %s",
+ this.getClass().getName(),
+ toProcess.getClass().getName()));
+ }
+ EfestoInputStreamResource inputStreamResource = (EfestoInputStreamResource) toProcess;
+ String modelSource;
+ try {
+ modelSource = new String(inputStreamResource.getContent().readAllBytes(), StandardCharsets.UTF_8);
+ } catch (Exception e) {
+ throw new KieCompilerServiceException(String.format("Unable to read content from %s", toProcess), e);
+ }
+ List<DMNMessage> messages = validator.validate(new StringReader(modelSource),
+ DMNValidator.Validation.VALIDATE_SCHEMA,
+ DMNValidator.Validation.VALIDATE_MODEL,
+ DMNValidator.Validation.VALIDATE_COMPILATION,
+ DMNValidator.Validation.ANALYZE_DECISION_TABLE);
+ if (DmnCompilerUtils.hasError(messages)) {
+ String errors = messages.stream().map(DMNMessage::getText).collect(Collectors.joining("\n"));
+ throw new KieCompilerServiceException(String.format("Validation errors from %s:%n%s", ((EfestoInputStreamResource) toProcess).getFileName(), errors));
+
+ } else {
+ String fileName = getCleanedFilenameForURI(inputStreamResource.getFileName());
+ LocalCompilationSourceIdDmn localCompilationSourceIdDmn = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName);
+ ContextStorage.putEfestoCompilationSource(localCompilationSourceIdDmn, modelSource);
+ DMNModel dmnModel = getDMNModel(modelSource);
+ return Collections.singletonList(DmnCompilerUtils.getDefaultEfestoCompilationOutput(fileName,
+ dmnModel.getName(),
+ modelSource,
+ dmnModel));
+ }
+ }
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNResourceSet.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNResourceSet.java
new file mode 100644
index 0000000000..35eae06278
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNResourceSet.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.kie.api.io.Resource;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.api.identifiers.LocalCompilationSourceIdDmn;
+import org.kie.dmn.efesto.compiler.model.DMNResourceSetResource;
+import org.kie.dmn.efesto.compiler.model.DmnCompilationContext;
+import org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.exceptions.EfestoCompilationManagerException;
+import org.kie.efesto.compilationmanager.api.exceptions.KieCompilerServiceException;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getCleanedFilenameForURI;
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getDMNModelsFromResources;
+
+public class KieCompilerServiceDMNResourceSet extends AbstractKieCompilerServiceDMN {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(KieCompilerServiceDMNResourceSet.class);
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public boolean canManageResource(EfestoResource toProcess) {
+ return toProcess instanceof DMNResourceSetResource dmnFileSystemResourceSetResource &&
+ dmnFileSystemResourceSetResource.getModelLocalUriId().model().equalsIgnoreCase("dmn");
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public List<EfestoCompilationOutput> processResource(EfestoResource toProcess, EfestoCompilationContext context) {
+ if (!canManageResource(toProcess)) {
+ throw new KieCompilerServiceException(String.format("%s can not process %s",
+ this.getClass().getName(),
+ toProcess.getClass().getName()));
+ }
+ if (!(context instanceof DmnCompilationContext dmnContext)) {
+ throw new KieCompilerServiceException(String.format("Wrong %s context parameter for from %s",
+ context.getClass().getName(),
+ this.getClass().getName()));
+ }
+ DMNResourceSetResource dmnFileSystemResourceSetResource = (DMNResourceSetResource) toProcess;
+ Collection<Resource> dmnResources = dmnFileSystemResourceSetResource.getContent();
+ try {
+ List<DMNModel> dmnModels = getDMNModelsFromResources(dmnResources, dmnContext.getCustomDMNProfiles(),
+ dmnContext.getRuntimeTypeCheckOption(),
+ dmnContext.getContextClassloader());
+ List<EfestoCompilationOutput> toReturn = new ArrayList<>();
+ dmnModels.forEach(dmnModel -> {
+ String modelSource = readResource(dmnModel.getResource());
+ storeSource(modelSource, dmnModel.getName());
+ File dmnFile = new File(dmnModel.getResource().getSourcePath());
+ toReturn.add(DmnCompilerUtils.getDefaultEfestoCompilationOutput(getCleanedFilenameForURI(dmnFile),
+ dmnModel.getName(),
+ modelSource,
+ dmnModel));
+ });
+ return toReturn;
+ } catch (Exception e) {
+ LOGGER.error("ERROR", e);
+ throw new EfestoCompilationManagerException(e);
+ }
+ }
+
+ private void storeSource(String modelSource, String modelName) {
+ LocalCompilationSourceIdDmn localCompilationSourceIdDmn = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(modelName);
+ ContextStorage.putEfestoCompilationSource(localCompilationSourceIdDmn, modelSource);
+ }
+
+ private String readResource(Resource toRead) {
+ try (InputStream is = toRead.getInputStream()) {
+ return new String(is.readAllBytes(), StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ throw new KieCompilerServiceException(e);
+ }
+ }
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNString.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNString.java
new file mode 100644
index 0000000000..ba4b89e16e
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNString.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.io.StringReader;
+import java.util.Collections;
+import java.util.List;
+import org.kie.dmn.api.core.DMNMessage;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.api.identifiers.LocalCompilationSourceIdDmn;
+import org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils;
+import org.kie.dmn.validation.DMNValidator;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.exceptions.EfestoCompilationManagerException;
+import org.kie.efesto.compilationmanager.api.exceptions.KieCompilerServiceException;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoResource;
+import org.kie.efesto.compilationmanager.api.model.EfestoStringResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.getDMNModel;
+
+public class KieCompilerServiceDMNString extends AbstractKieCompilerServiceDMN {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(KieCompilerServiceDMNString.class);
+
+ @Override
+ @SuppressWarnings( "rawtypes")
+ public boolean canManageResource(EfestoResource toProcess) {
+ return toProcess instanceof EfestoStringResource && ((EfestoStringResource) toProcess).getModelLocalUriId().model().equalsIgnoreCase("dmn");
+ }
+
+ @Override
+ @SuppressWarnings( "rawtypes")
+ public List<EfestoCompilationOutput> processResource(EfestoResource toProcess, EfestoCompilationContext context) {
+ if (!canManageResource(toProcess)) {
+ throw new KieCompilerServiceException(String.format("%s can not process %s",
+ this.getClass().getName(),
+ toProcess.getClass().getName()));
+ }
+ EfestoStringResource stringResource = (EfestoStringResource) toProcess;
+ String modelSource = stringResource.getContent();
+ List<DMNMessage> messages = validator.validate(new StringReader(modelSource),
+ DMNValidator.Validation.VALIDATE_SCHEMA,
+ DMNValidator.Validation.VALIDATE_MODEL,
+ DMNValidator.Validation.VALIDATE_COMPILATION,
+ DMNValidator.Validation.ANALYZE_DECISION_TABLE);
+ // see https://github.com/apache/incubator-kie-issues/issues/1619
+// if (DmnCompilerUtils.hasError(messages)) {
+// return Collections.emptyList();
+// }
+ try {
+ ModelLocalUriId modelLocalUriId =stringResource.getModelLocalUriId();
+ String basePath = modelLocalUriId.basePath();
+ String fileName = basePath.substring(0, basePath.lastIndexOf("/"));
+ LocalCompilationSourceIdDmn localCompilationSourceIdDmn = new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName);
+ ContextStorage.putEfestoCompilationSource(localCompilationSourceIdDmn, modelSource);
+ DMNModel dmnModel = getDMNModel(modelSource);
+ return Collections.singletonList(DmnCompilerUtils.getDefaultEfestoCompilationOutput(modelLocalUriId,
+ modelSource, dmnModel));
+ } catch (Exception e) {
+ throw new EfestoCompilationManagerException(e);
+ }
+ }
+}
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/utils/DmnCompilerUtils.java b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/utils/DmnCompilerUtils.java
new file mode 100644
index 0000000000..d28bb6d0de
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/java/org/kie/dmn/efesto/compiler/utils/DmnCompilerUtils.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.utils;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+import org.kie.api.builder.Message;
+import org.kie.api.io.Resource;
+import org.kie.dmn.api.core.DMNMessage;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.core.DMNRuntime;
+import org.kie.dmn.core.compiler.DMNProfile;
+import org.kie.dmn.core.compiler.RuntimeTypeCheckOption;
+import org.kie.dmn.core.internal.utils.DMNRuntimeBuilder;
+import org.kie.dmn.efesto.compiler.model.EfestoCallableOutputDMN;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.internal.io.ResourceFactory;
+
+import java.io.StringReader;
+import java.util.Collections;
+import java.util.List;
+
+public class DmnCompilerUtils {
+
+ static final List<String> CLEANABLE_PATTERNS = Arrays.asList("main/resources",
+ "main/java",
+ "test/resources",
+ "test/java",
+ "target/generated-resources",
+ "target/classes",
+ "target/test-classes");
+
+ private DmnCompilerUtils() {
+ // avoid instantiation
+ }
+
+ public static boolean hasError(List<DMNMessage> dmnMessages) {
+ return dmnMessages.stream().anyMatch(dmnMessage -> dmnMessage.getLevel().equals(Message.Level.ERROR));
+ }
+
+ public static EfestoCompilationOutput getDefaultEfestoCompilationOutput(String fileName, String modelName, String modelSource, DMNModel dmnModel) {
+ return new EfestoCallableOutputDMN(fileName, modelName, modelSource, dmnModel);
+ }
+
+ public static EfestoCompilationOutput getDefaultEfestoCompilationOutput(ModelLocalUriId modelLocalUriId, String modelSource, DMNModel dmnModel) {
+ return new EfestoCallableOutputDMN(modelLocalUriId, modelSource, dmnModel);
+ }
+
+ public static DMNModel getDMNModel(String modelSource) {
+ Resource modelResource = ResourceFactory.newReaderResource(new StringReader(modelSource), "UTF-8");
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ return dmnRuntime.getModels().get(0);
+ }
+
+ public static List<DMNModel> getDMNModelsFromFiles(Set<File> modelFiles,
+ Set<DMNProfile> customDMNProfiles,
+ RuntimeTypeCheckOption runtimeTypeCheckOption,
+ ClassLoader classLoader) {
+ List<Resource> modelResources = modelFiles.stream().map(ResourceFactory::newFileResource)
+ .toList();
+ DMNRuntimeBuilder dmnRuntimeBuilder = DMNRuntimeBuilder.fromDefaults();
+ if (runtimeTypeCheckOption != null) {
+ dmnRuntimeBuilder.setOption(runtimeTypeCheckOption);
+ }
+ if (customDMNProfiles != null) {
+ customDMNProfiles.forEach(dmnRuntimeBuilder::addProfile);
+ }
+ DMNRuntime dmnRuntime = dmnRuntimeBuilder
+ .setRootClassLoader(classLoader)
+ .buildConfiguration()
+ .fromResources(modelResources)
+ .getOrElseThrow(RuntimeException::new);
+ return dmnRuntime.getModels();
+ }
+
+ public static List<DMNModel> getDMNModelsFromResources(Collection<Resource> dmnResources,
+ Set<DMNProfile> customDMNProfiles,
+ RuntimeTypeCheckOption runtimeTypeCheckOption,
+ ClassLoader classLoader) {
+ DMNRuntimeBuilder dmnRuntimeBuilder = DMNRuntimeBuilder.fromDefaults();
+ if (runtimeTypeCheckOption != null) {
+ dmnRuntimeBuilder.setOption(runtimeTypeCheckOption);
+ }
+ if (customDMNProfiles != null) {
+ customDMNProfiles.forEach(dmnRuntimeBuilder::addProfile);
+ }
+ DMNRuntime dmnRuntime = dmnRuntimeBuilder
+ .setRootClassLoader(classLoader)
+ .buildConfiguration()
+ .fromResources(dmnResources)
+ .getOrElseThrow(RuntimeException::new);
+ return dmnRuntime.getModels();
+ }
+
+ /**
+ * This method remove unwanted preceding paths from given <code>File</code>, and always returns a <b>/</b>-separated path,
+ * without leading <b>/</b>
+ * @param fileToClean
+ * @return
+ */
+ public static String getCleanedFilenameForURI(File fileToClean) {
+ return getCleanedFilenameForURI(fileToClean.getPath());
+ }
+
+ /**
+ * This method remove unwanted preceding paths from given <code>String</code>, and always returns a <b>/</b>-separated path,
+ * without leading <b>/</b>
+ * @param filenameToClean
+ * @return
+ */
+ public static String getCleanedFilenameForURI(String filenameToClean) {
+ if (filenameToClean == null) {
+ return filenameToClean;
+ }
+ String toReturn = filenameToClean;
+ for (String patternToClean : CLEANABLE_PATTERNS) {
+ toReturn = getCleanedFileNameForURIByPattern(toReturn, patternToClean);
+ }
+ if (toReturn != null && toReturn.startsWith("/")) {
+ toReturn = toReturn.substring(1);
+ }
+ return toReturn;
+ }
+
+ /**
+ * This method remove unwanted preceding paths from given <code>String</code> and always returns a <b>/</b>-separated path,
+ * @param filenameToClean
+ * @param patternToClean
+ * @return
+ */
+ static String getCleanedFileNameForURIByPattern(String filenameToClean, String patternToClean) {
+ if (filenameToClean == null) {
+ return filenameToClean;
+ }
+ String toReturn = filenameToClean.replace(File.separator, "/"); // needed because the path could come from a file (e.g. scesim) built on a different OS
+ if (toReturn.endsWith(".dmn")) {
+ toReturn = toReturn.substring(0, toReturn.lastIndexOf(".dmn"));
+ }
+ if (toReturn.contains(patternToClean)) {
+ toReturn = toReturn.substring(toReturn.indexOf(patternToClean) + patternToClean.length());
+ }
+ return toReturn;
+ }
+}
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService b/kie-dmn/kie-dmn-efesto-compilation/src/main/resources/META-INF/services/org.kie.efesto.compilationmanager.api.service.KieCompilerService
similarity index 69%
copy from kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
copy to kie-dmn/kie-dmn-efesto-compilation/src/main/resources/META-INF/services/org.kie.efesto.compilationmanager.api.service.KieCompilerService
index 662843a940..4e864986c8 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/main/resources/META-INF/services/org.kie.efesto.compilationmanager.api.service.KieCompilerService
@@ -17,6 +17,9 @@
# under the License.
#
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMML
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLRequestData
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLMapInput
\ No newline at end of file
+# SPI implementations
+org.kie.dmn.efesto.compiler.service.KieCompilerServiceDMNFile
+org.kie.dmn.efesto.compiler.service.KieCompilerServiceDMNFileSet
+org.kie.dmn.efesto.compiler.service.KieCompilerServiceDMNInputStream
+org.kie.dmn.efesto.compiler.service.KieCompilerServiceDMNResourceSet
+org.kie.dmn.efesto.compiler.service.KieCompilerServiceDMNString
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/AbstractKieCompilerServiceDMNTest.java b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/AbstractKieCompilerServiceDMNTest.java
new file mode 100644
index 0000000000..a8f7fdb9e3
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/AbstractKieCompilerServiceDMNTest.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.kie.dmn.core.pmml.EfestoPMMLUtils;
+import org.kie.dmn.efesto.compiler.model.DmnCompilationContext;
+import org.kie.dmn.efesto.compiler.model.DmnCompilationContextImpl;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.io.MemoryFile;
+import org.kie.efesto.common.api.model.EfestoCompilationContext;
+import org.kie.efesto.common.core.storage.ContextStorage;
+import org.kie.efesto.compilationmanager.api.exceptions.EfestoCompilationManagerException;
+import org.kie.efesto.compilationmanager.api.model.EfestoInputStreamResource;
+import org.kie.efesto.compilationmanager.api.service.CompilationManager;
+import org.kie.efesto.compilationmanager.api.service.KieCompilerService;
+import org.kie.efesto.compilationmanager.core.model.EfestoCompilationContextImpl;
+import org.kie.efesto.compilationmanager.core.model.EfestoCompilationContextUtils;
+
+
+@SuppressWarnings("rawtypes")
+public abstract class AbstractKieCompilerServiceDMNTest {
+
+ private static final String VALID_MODELS = "valid_models";
+ private static final String DMN_1 = "/DMNv1_x";
+ private static final String VALID_MODELS_DMN1 = String.format("%s%s", VALID_MODELS, DMN_1);
+ private static final String VALID_MODELS_DMN1_PMML = String.format("%s%s/pmml", VALID_MODELS, DMN_1);
+
+ protected static final String DMN_MODEL_NAME = "loan";
+ protected static final String DMN_FILE_NAME = "loan";
+ protected static final String DMN_NAMESPACE = "https://kiegroup.org/dmn/_79B69A7F-5A25-4B53-BD6A-3216EDC246ED";
+ protected static final String DMN_FULL_FILE_NAME = String.format("%s.dmn", DMN_FILE_NAME);
+ protected static final String DMN_FULL_PATH_FILE_NAME = String.format("%s/%s", VALID_MODELS_DMN1, DMN_FULL_FILE_NAME);
+ protected static final String DMN_FULL_PATH_FILE_NAME_NO_SUFFIX = String.format("%s/%s", VALID_MODELS_DMN1, DMN_FILE_NAME);
+ protected static MemoryFile dmnFile;
+
+ protected static final String DMN_PMML_MODEL_NAME = "TestRegressionDMN";
+ protected static final String DMN_PMML_FILE_NAME = "KiePMMLRegression";
+
+ protected static final String DMN_PMML_NAMESPACE = "https://kiegroup.org/dmn/_51A1FD67-8A67-4332-9889-B718BE8B7456";
+ protected static final String DMN_PMML_FULL_FILE_NAME = String.format("%s.dmn", DMN_PMML_FILE_NAME);
+ protected static final String DMN_PMML_FULL_PATH_FILE_NAME = String.format("%s/%s", VALID_MODELS_DMN1_PMML, DMN_PMML_FULL_FILE_NAME);
+ protected static final String DMN_PMML_FULL_PATH_FILE_NAME_NO_SUFFIX = String.format("%s/%s",VALID_MODELS_DMN1_PMML, DMN_PMML_FILE_NAME);
+ protected static MemoryFile dmnPmmlFile;
+
+ protected static final String PMML_MODEL_NAME = "TestRegression";
+ protected static final String PMML_FILE_NAME = "test_regression";
+ protected static final String PMML_FULL_FILE_NAME = String.format("%s.pmml", PMML_FILE_NAME);
+ protected static final String PMML_FULL_PATH_FILE_NAME = String.format("%s/%s", VALID_MODELS_DMN1_PMML, PMML_FULL_FILE_NAME);
+ protected static MemoryFile pmmlFile;
+
+ protected static KieCompilerService kieCompilationService;
+ protected static DmnCompilationContext dmnCompilationContext;
+ private static final CompilationManager compilationManager =
+ org.kie.efesto.compilationmanager.api.utils.SPIUtils.getCompilationManager(false).orElseThrow(() -> new EfestoCompilationManagerException("Failed to find an instance of CompilationManager: please check classpath and dependencies"));
+
+
+
+ protected static void commonSetUp() {
+ dmnFile = getMemoryFile(DMN_FULL_PATH_FILE_NAME);
+ pmmlFile = getMemoryFile(PMML_FULL_PATH_FILE_NAME);
+ dmnPmmlFile = getMemoryFile(DMN_PMML_FULL_PATH_FILE_NAME);
+ EfestoCompilationContext pmmlCompilationContext = EfestoCompilationContextUtils.buildWithParentClassLoader(Thread.currentThread().getContextClassLoader());
+
+ InputStream is = new ByteArrayInputStream(pmmlFile.getContent());
+ EfestoInputStreamResource pmmlFileResource = new EfestoInputStreamResource(is, PMML_FULL_PATH_FILE_NAME);
+ compilationManager.processResource(pmmlCompilationContext, pmmlFileResource);
+ ContextStorage.putEfestoCompilationContext(getPmmlModelLocalUriId(), pmmlCompilationContext);
+ ContextStorage.putEfestoCompilationSource(getPmmlModelLocalUriId(), new String( pmmlFile.getContent(), StandardCharsets.UTF_8));
+ dmnCompilationContext = (DmnCompilationContext) EfestoCompilationContextUtils.buildFromContext((EfestoCompilationContextImpl) pmmlCompilationContext, DmnCompilationContextImpl.class);
+ }
+
+ private static MemoryFile getMemoryFile(String fullFilePath) {
+ return org.kie.efesto.common.api.utils.MemoryFileUtils.getFileFromFileName(fullFilePath)
+ .map(file -> {
+ try {
+ return new MemoryFile(file.toPath());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ })
+ .orElseThrow(() -> new RuntimeException(String.format("Failed to get %s file", fullFilePath)));
+ }
+
+ private static ModelLocalUriId getPmmlModelLocalUriId() {
+ return EfestoPMMLUtils.getPmmlModelLocalUriId(PMML_FULL_FILE_NAME, PMML_MODEL_NAME);
+ }
+
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFileTest.java b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFileTest.java
new file mode 100644
index 0000000000..2f5277a6ae
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNFileTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.api.identifiers.LocalComponentIdDmn;
+import org.kie.dmn.efesto.compiler.model.EfestoCallableOutputDMN;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoFileResource;
+import org.kie.efesto.compilationmanager.api.model.EfestoInputStreamResource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+@SuppressWarnings("unchecked")
+class KieCompilerServiceDMNFileTest extends AbstractKieCompilerServiceDMNTest {
+
+ private static EfestoFileResource toProcessDmn;
+ private static EfestoFileResource toProcessDmnPmml;
+
+ @BeforeAll
+ static void setUp() {
+ kieCompilationService = new KieCompilerServiceDMNFile();
+ commonSetUp();
+ toProcessDmn = new EfestoFileResource(dmnFile);
+ toProcessDmnPmml = new EfestoFileResource(dmnPmmlFile);
+ }
+
+ @Test
+ void canManageResourceDmn() {
+ assertThat(kieCompilationService.canManageResource(toProcessDmn)).isTrue();
+ InputStream is = new ByteArrayInputStream(dmnFile.getContent());
+ EfestoInputStreamResource notToProcess = new EfestoInputStreamResource(is, DMN_FULL_PATH_FILE_NAME);
+ assertThat(kieCompilationService.canManageResource(notToProcess)).isFalse();
+ }
+
+ @Test
+ void canManageResourceDmnPmml() {
+ assertThat(kieCompilationService.canManageResource(toProcessDmnPmml)).isTrue();
+ InputStream is = new ByteArrayInputStream( dmnPmmlFile.getContent());
+ EfestoInputStreamResource notToProcess = new EfestoInputStreamResource(is, DMN_PMML_FULL_PATH_FILE_NAME);
+ assertThat(kieCompilationService.canManageResource(notToProcess)).isFalse();
+ }
+
+ @Test
+ void processResourceDmn() {
+ List<EfestoCompilationOutput> retrieved = kieCompilationService.processResource(toProcessDmn,
+ dmnCompilationContext);
+ assertThat(retrieved).isNotNull().hasSize(1);
+ EfestoCompilationOutput retrievedOutput = retrieved.get(0);
+ assertThat(retrievedOutput).isNotNull().isExactlyInstanceOf(EfestoCallableOutputDMN.class);
+ EfestoCallableOutputDMN callableOutput = (EfestoCallableOutputDMN) retrievedOutput;
+ ModelLocalUriId modelLocalUriId = callableOutput.getModelLocalUriId();
+ assertThat(modelLocalUriId).isExactlyInstanceOf(LocalComponentIdDmn.class);
+ LocalComponentIdDmn localComponentIdDmn = (LocalComponentIdDmn) modelLocalUriId;
+ assertThat(localComponentIdDmn.getFileName()).isEqualTo(DMN_FULL_PATH_FILE_NAME_NO_SUFFIX);
+ assertThat(localComponentIdDmn.getName()).isEqualTo(DMN_MODEL_NAME);
+ }
+
+ @Test
+ void processResourceDmnPmml() {
+ List<EfestoCompilationOutput> retrieved = kieCompilationService.processResource(toProcessDmnPmml,
+ dmnCompilationContext);
+ assertThat(retrieved).isNotNull().hasSize(1);
+ EfestoCompilationOutput retrievedOutput = retrieved.get(0);
+ assertThat(retrievedOutput).isNotNull().isExactlyInstanceOf(EfestoCallableOutputDMN.class);
+ EfestoCallableOutputDMN callableOutput = (EfestoCallableOutputDMN) retrievedOutput;
+ ModelLocalUriId modelLocalUriId = callableOutput.getModelLocalUriId();
+ assertThat(modelLocalUriId).isExactlyInstanceOf(LocalComponentIdDmn.class);
+ LocalComponentIdDmn localComponentIdDmn = (LocalComponentIdDmn) modelLocalUriId;
+ assertThat(localComponentIdDmn.getFileName()).isEqualTo(DMN_PMML_FULL_PATH_FILE_NAME_NO_SUFFIX);
+ assertThat(localComponentIdDmn.getName()).isEqualTo(DMN_PMML_MODEL_NAME);
+ }
+
+ @Test
+ void hasCompilationSourceDmn() {
+ kieCompilationService.processResource(toProcessDmn,
+ dmnCompilationContext);
+ assertThat(kieCompilationService.hasCompilationSource(DMN_FULL_PATH_FILE_NAME)).isTrue();
+ }
+
+ @Test
+ void hasCompilationSourceDmnPmml() {
+ kieCompilationService.processResource(toProcessDmnPmml,
+ dmnCompilationContext);
+ assertThat(kieCompilationService.hasCompilationSource(DMN_PMML_FULL_PATH_FILE_NAME)).isTrue();
+ }
+
+ @Test
+ void getCompilationSourceDmn() {
+ kieCompilationService.processResource(toProcessDmn,
+ dmnCompilationContext);
+ String retrieved = kieCompilationService.getCompilationSource(DMN_FULL_PATH_FILE_NAME);
+ assertThat(retrieved).isNotNull();
+ String expected = new String(dmnFile.getContent(), StandardCharsets.UTF_8);
+ assertThat(retrieved).isEqualTo(expected);
+ }
+
+ @Test
+ void getCompilationSourceDmnPmml() {
+ kieCompilationService.processResource(toProcessDmnPmml,
+ dmnCompilationContext);
+ String retrieved = kieCompilationService.getCompilationSource(DMN_PMML_FULL_PATH_FILE_NAME);
+ assertThat(retrieved).isNotNull();
+ String expected = new String(dmnPmmlFile.getContent(), StandardCharsets.UTF_8);
+ assertThat(retrieved).isEqualTo(expected);
+ }
+
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNInputStreamTest.java b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNInputStreamTest.java
new file mode 100644
index 0000000000..ac45b36f77
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNInputStreamTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.api.identifiers.LocalComponentIdDmn;
+import org.kie.dmn.efesto.compiler.model.DmnCompilationContext;
+import org.kie.dmn.efesto.compiler.model.EfestoCallableOutputDMN;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoFileResource;
+import org.kie.efesto.compilationmanager.api.model.EfestoInputStreamResource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SuppressWarnings("unchecked")
+class KieCompilerServiceDMNInputStreamTest extends AbstractKieCompilerServiceDMNTest {
+
+ private static EfestoInputStreamResource toProcess;
+
+ @BeforeAll
+ static void setUp() {
+ kieCompilationService = new KieCompilerServiceDMNInputStream();
+ commonSetUp();
+ }
+
+ @BeforeEach
+ void init() {
+ InputStream is = new ByteArrayInputStream(dmnFile.getContent());
+ toProcess = new EfestoInputStreamResource(is, DMN_FULL_PATH_FILE_NAME);
+ }
+
+ @Test
+ void canManageResource() {
+ assertThat(kieCompilationService.canManageResource(toProcess)).isTrue();
+ EfestoFileResource notToProcess = new EfestoFileResource(dmnFile);
+ assertThat(kieCompilationService.canManageResource(notToProcess)).isFalse();
+ }
+
+ @Test
+ void processResource() {
+ List<EfestoCompilationOutput> retrieved = kieCompilationService.processResource(toProcess,
+ DmnCompilationContext.buildWithParentClassLoader(Thread.currentThread().getContextClassLoader()));
+ assertThat(retrieved).isNotNull().hasSize(1);
+ EfestoCompilationOutput retrievedOutput = retrieved.get(0);
+ assertThat(retrievedOutput).isNotNull().isExactlyInstanceOf(EfestoCallableOutputDMN.class);
+ EfestoCallableOutputDMN callableOutput = (EfestoCallableOutputDMN) retrievedOutput;
+ ModelLocalUriId modelLocalUriId = callableOutput.getModelLocalUriId();
+ assertThat(modelLocalUriId).isExactlyInstanceOf(LocalComponentIdDmn.class);
+ LocalComponentIdDmn localComponentIdDmn = (LocalComponentIdDmn) modelLocalUriId;
+ assertThat(localComponentIdDmn.getFileName()).isEqualTo(DMN_FULL_PATH_FILE_NAME_NO_SUFFIX);
+ assertThat(localComponentIdDmn.getName()).isEqualTo(DMN_MODEL_NAME);
+ }
+
+ @Test
+ void hasCompilationSource() {
+ kieCompilationService.processResource(toProcess,
+ DmnCompilationContext.buildWithParentClassLoader(Thread.currentThread().getContextClassLoader()));
+ assertThat(kieCompilationService.hasCompilationSource(DMN_FULL_FILE_NAME)).isTrue();
+ }
+
+ @Test
+ void getCompilationSource() {
+ kieCompilationService.processResource(toProcess,
+ DmnCompilationContext.buildWithParentClassLoader(Thread.currentThread().getContextClassLoader()));
+ String retrieved = kieCompilationService.getCompilationSource(DMN_FULL_FILE_NAME);
+ assertThat(retrieved).isNotNull();
+ String expected = new String(dmnFile.getContent(), StandardCharsets.UTF_8);
+ assertThat(retrieved).isEqualTo(expected);
+ }
+
+
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNResourceTest.java b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNResourceTest.java
new file mode 100644
index 0000000000..94c1c310ff
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/service/KieCompilerServiceDMNResourceTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.service;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Set;
+import org.drools.io.ByteArrayResource;
+import org.drools.io.FileSystemResource;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.kie.api.io.Resource;
+import org.kie.dmn.api.identifiers.LocalComponentIdDmn;
+import org.kie.dmn.efesto.compiler.model.DMNResourceSetResource;
+import org.kie.dmn.efesto.compiler.model.EfestoCallableOutputDMN;
+import org.kie.efesto.common.api.identifiers.LocalUri;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.compilationmanager.api.model.EfestoCompilationOutput;
+import org.kie.efesto.compilationmanager.api.model.EfestoFileSetResource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SuppressWarnings("unchecked")
+class KieCompilerServiceDMNResourceTest extends AbstractKieCompilerServiceDMNTest {
+
+ private static Resource toProcessDmn;
+ private static Resource toProcessDmnPmml;
+ private static DMNResourceSetResource toProcess;
+ private static ModelLocalUriId dmnModelLocalUriId;
+
+ @BeforeAll
+ static void setUp() {
+ kieCompilationService = new KieCompilerServiceDMNResourceSet();
+ commonSetUp();
+ toProcessDmn = new FileSystemResource(dmnFile);
+ toProcessDmnPmml = new ByteArrayResource(dmnPmmlFile.getContent());
+ toProcessDmnPmml.setSourcePath(DMN_PMML_FULL_PATH_FILE_NAME_NO_SUFFIX);
+ dmnModelLocalUriId = new ModelLocalUriId(LocalUri.Root.append("dmn").append(DMN_MODEL_NAME));
+ toProcess = new DMNResourceSetResource(Set.of(toProcessDmn, toProcessDmnPmml), dmnModelLocalUriId);
+ }
+
+ @Test
+ void canManageResourceSet() {
+ assertThat(kieCompilationService.canManageResource(toProcess)).isTrue();
+ EfestoFileSetResource notToProcess = new EfestoFileSetResource(Set.of(dmnFile, dmnPmmlFile), dmnModelLocalUriId);
+ assertThat(kieCompilationService.canManageResource(notToProcess)).isFalse();
+ }
+
+
+ @Test
+ void processResourceSet() {
+ List<EfestoCompilationOutput> retrieved = kieCompilationService.processResource(toProcess,
+ dmnCompilationContext);
+ assertThat(retrieved).isNotNull().hasSize(2);
+ retrieved.forEach(retrievedOutput -> {
+ assertThat(retrievedOutput).isNotNull().isExactlyInstanceOf(EfestoCallableOutputDMN.class);
+ EfestoCallableOutputDMN callableOutput = (EfestoCallableOutputDMN) retrievedOutput;
+ ModelLocalUriId modelLocalUriId = callableOutput.getModelLocalUriId();
+ assertThat(modelLocalUriId).isExactlyInstanceOf(LocalComponentIdDmn.class);
+ LocalComponentIdDmn localComponentIdDmn = (LocalComponentIdDmn) modelLocalUriId;
+ String fileName = localComponentIdDmn.getFileName();
+ String name = localComponentIdDmn.getName();
+ assertThat((fileName.equals(DMN_FULL_PATH_FILE_NAME_NO_SUFFIX) && name.equals(DMN_MODEL_NAME)) ||
+ (fileName.equals(DMN_PMML_FULL_PATH_FILE_NAME_NO_SUFFIX) && name.equals(DMN_PMML_MODEL_NAME)))
+ .isTrue();
+ });
+ }
+
+ @Test
+ void hasCompilationSource() {
+ kieCompilationService.processResource(toProcess,
+ dmnCompilationContext);
+ assertThat(kieCompilationService.hasCompilationSource(DMN_FULL_PATH_FILE_NAME)).isTrue();
+ assertThat(kieCompilationService.hasCompilationSource(DMN_PMML_MODEL_NAME)).isTrue();
+ }
+
+ @Test
+ void getCompilationSource() {
+ kieCompilationService.processResource(toProcess,
+ dmnCompilationContext);
+ String retrieved = kieCompilationService.getCompilationSource(DMN_FULL_PATH_FILE_NAME);
+ assertThat(retrieved).isNotNull();
+ String expected = new String(dmnFile.getContent(), StandardCharsets.UTF_8);
+ assertThat(retrieved).isEqualTo(expected);
+ retrieved = kieCompilationService.getCompilationSource(DMN_PMML_MODEL_NAME);
+ assertThat(retrieved).isNotNull();
+ expected = new String(dmnPmmlFile.getContent(), StandardCharsets.UTF_8);
+ assertThat(retrieved).isEqualTo(expected);
+ }
+
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/utils/DmnCompilerUtilsTest.java b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/utils/DmnCompilerUtilsTest.java
new file mode 100644
index 0000000000..0bc15bb312
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/test/java/org/kie/dmn/efesto/compiler/utils/DmnCompilerUtilsTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.compiler.utils;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.kie.dmn.efesto.compiler.utils.DmnCompilerUtils.CLEANABLE_PATTERNS;
+
+class DmnCompilerUtilsTest {
+
+ @Test
+ void getCleanedFileNameForURIByFile() {
+ String fileNameWithPrefixAndSuffix = File.separator + Path.of("path", "to", "File.dmn");
+ String expected = "path/to/File";
+ CLEANABLE_PATTERNS.forEach(patternToClean -> {
+ File fileToClean = Path.of(patternToClean, fileNameWithPrefixAndSuffix).toFile();
+ assertThat(DmnCompilerUtils.getCleanedFilenameForURI(fileToClean)).isEqualTo(expected);
+ fileToClean = Path.of("..", "..", patternToClean, fileNameWithPrefixAndSuffix).toFile();
+ assertThat(DmnCompilerUtils.getCleanedFilenameForURI(fileToClean)).isEqualTo(expected);
+ });
+ }
+
+ @Test
+ void getCleanedFileNameForURIByStringOSDependent() {
+ String fileNameWithPrefixAndSuffix = File.separator + Path.of("path", "to", "File.dmn");
+ String expected = "path/to/File";
+ CLEANABLE_PATTERNS.forEach(patternToClean -> {
+ String filenameToClean = Path.of(patternToClean, fileNameWithPrefixAndSuffix).toString();
+ assertThat(DmnCompilerUtils.getCleanedFilenameForURI(filenameToClean)).isEqualTo(expected);
+ filenameToClean = Path.of("..", "..", patternToClean, fileNameWithPrefixAndSuffix).toString();
+ assertThat(DmnCompilerUtils.getCleanedFilenameForURI(filenameToClean)).isEqualTo(expected);
+ });
+ }
+
+ @Test
+ void getCleanedFileNameForURIByStringOSAgnostic() {
+ String fileNameWithPrefixAndSuffix = File.separator + Path.of("path", "to", "File.dmn");
+ String expected = "path/to/File";
+ CLEANABLE_PATTERNS.forEach(patternToClean -> {
+ String filenameToClean = Path.of(patternToClean, fileNameWithPrefixAndSuffix).toString().replace(File.separator, "/");
+ assertThat(DmnCompilerUtils.getCleanedFilenameForURI(filenameToClean)).isEqualTo(expected);
+ filenameToClean = Path.of("..", "..", patternToClean, fileNameWithPrefixAndSuffix).toString().replace(File.separator, "/");
+ assertThat(DmnCompilerUtils.getCleanedFilenameForURI(filenameToClean)).isEqualTo(expected);
+ });
+ }
+
+ @Test
+ void getCleanedFileNameForURIByPatternForURIOSDependent() {
+ String expected = (File.separator + Path.of("path", "to", "File")).replace(File.separator, "/");
+ String fileNameWithPrefixAndSuffix = File.separator + Path.of("path", "to", "File.dmn");
+ CLEANABLE_PATTERNS.forEach(patternToClean -> {
+ String filenameToClean = Path.of(patternToClean, fileNameWithPrefixAndSuffix).toString();
+ assertThat(DmnCompilerUtils.getCleanedFileNameForURIByPattern(filenameToClean, patternToClean)).isEqualTo(expected);
+ filenameToClean = Path.of("..", "..", patternToClean, fileNameWithPrefixAndSuffix).toString();
+ assertThat(DmnCompilerUtils.getCleanedFileNameForURIByPattern(filenameToClean, patternToClean)).isEqualTo(expected);
+ });
+ }
+
+ @Test
+ void getCleanedFileNameForURIByPatternForURIOSAgnostic() {
+ String expected = (File.separator + Path.of("path", "to", "File")).replace(File.separator, "/");
+ String fileNameWithPrefixAndSuffix = File.separator + Path.of("path", "to", "File.dmn");
+ CLEANABLE_PATTERNS.forEach(patternToClean -> {
+ String filenameToClean = Path.of(patternToClean, fileNameWithPrefixAndSuffix).toString().replace(File.separator, "/");
+ assertThat(DmnCompilerUtils.getCleanedFileNameForURIByPattern(filenameToClean, patternToClean)).isEqualTo(expected);
+ filenameToClean = Path.of("..", "..", patternToClean, fileNameWithPrefixAndSuffix).toString().replace(File.separator, "/");
+ assertThat(DmnCompilerUtils.getCleanedFileNameForURIByPattern(filenameToClean, patternToClean)).isEqualTo(expected);
+ });
+ }
+
+
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-compilation/src/test/resources/0001-input-data-string.dmn b/kie-dmn/kie-dmn-efesto-compilation/src/test/resources/0001-input-data-string.dmn
new file mode 100644
index 0000000000..53d8fd182e
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-compilation/src/test/resources/0001-input-data-string.dmn
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+<semantic:definitions xmlns="https://github.com/kiegroup/drools/kie-dmn"
+ xmlns:semantic="http://www.omg.org/spec/DMN/20180521/MODEL/"
+ id="_0001-input-data-string"
+ name="_0001-input-data-string"
+ namespace="https://github.com/kiegroup/drools/kie-dmn">
+ <semantic:decision name="Greeting Message" id="d_GreetingMessage">
+ <semantic:variable name="Greeting Message" typeRef="string"/>
+ <semantic:informationRequirement>
+ <semantic:requiredInput href="#i_FullName"/>
+ </semantic:informationRequirement>
+ <semantic:literalExpression>
+ <semantic:text>"Hello " + Full Name</semantic:text>
+ </semantic:literalExpression>
+ </semantic:decision>
+ <semantic:inputData name="Full Name" id="i_FullName">
+ <semantic:variable name="Full Name" typeRef="string"/>
+ </semantic:inputData>
+</semantic:definitions>
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-runtime/pom.xml b/kie-dmn/kie-dmn-efesto-runtime/pom.xml
new file mode 100644
index 0000000000..50d955cfd6
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-runtime/pom.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn</artifactId>
+ <version>999-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>kie-dmn-efesto-runtime</artifactId>
+
+ <name>KIE :: Decision Model Notation :: Efesto Runtime</name>
+
+ <properties>
+ <java.module.name>org.kie.dmn.efesto.runtime</java.module.name>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-api</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>efesto-runtime-manager-api</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>efesto-runtime-manager-core</artifactId>
+ <version>${version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- DMN -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-dmn-efesto-api</artifactId>
+ </dependency>
+ <!-- End DMN -->
+ <!-- Efesto -->
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>efesto-runtime-manager-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>efesto-runtime-manager-core</artifactId>
+ </dependency>
+ <!-- End Efesto -->
+ <!-- TEST -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.kie</groupId>
+ <artifactId>kie-test-util</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/model/EfestoOutputDMN.java
similarity index 66%
rename from kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java
rename to kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/model/EfestoOutputDMN.java
index 5014dadd22..770345f44b 100644
--- a/kie-dmn/kie-dmn-api/src/main/java/org/kie/dmn/api/identifiers/DecisionServiceIds.java
+++ b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/model/EfestoOutputDMN.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,16 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.kie.dmn.api.identifiers;
+package org.kie.dmn.efesto.runtime.model;
-public class DecisionServiceIds {
- private final LocalDecisionId parentId;
+import org.kie.dmn.api.core.DMNResult;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.runtimemanager.api.model.AbstractEfestoOutput;
- public DecisionServiceIds(LocalDecisionId parentId) {
- this.parentId = parentId;
- }
+public class EfestoOutputDMN extends AbstractEfestoOutput<DMNResult> {
- public LocalDecisionServiceId get(String serviceId) {
- return new LocalDecisionServiceId(parentId, serviceId);
+ public EfestoOutputDMN(ModelLocalUriId modelLocalUriId, DMNResult outputData) {
+ super(modelLocalUriId, outputData);
}
}
diff --git a/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/service/DMNEvaluator.java b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/service/DMNEvaluator.java
new file mode 100644
index 0000000000..669dda805e
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/service/DMNEvaluator.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.kie.dmn.efesto.runtime.service;
+
+import org.kie.api.io.Resource;
+import org.kie.dmn.api.core.DMNContext;
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.core.DMNResult;
+import org.kie.dmn.api.core.DMNRuntime;
+import org.kie.dmn.core.internal.utils.DMNRuntimeBuilder;
+import org.kie.dmn.core.internal.utils.DynamicDMNContextBuilder;
+import org.kie.internal.io.ResourceFactory;
+
+import java.io.StringReader;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class DMNEvaluator {
+
+ private final DMNModel dmnModel;
+ private final DMNRuntime dmnRuntime;
+
+ public static DMNEvaluator fromXML(String modelXML) {
+ Resource modelResource = ResourceFactory.newReaderResource(new StringReader(modelXML), "UTF-8");
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ DMNModel dmnModel = dmnRuntime.getModels().get(0);
+ return new DMNEvaluator(dmnModel, dmnRuntime);
+ }
+
+ public static DMNEvaluator fromDMNModel(DMNModel dmnModel) {
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.emptyList())
+ .getOrElseThrow(RuntimeException::new);
+ return new DMNEvaluator(dmnModel, dmnRuntime);
+ }
+
+ private DMNEvaluator(DMNModel dmnModel, DMNRuntime dmnRuntime) {
+ this.dmnModel = dmnModel;
+ this.dmnRuntime = dmnRuntime;
+ }
+
+ public DMNModel getDmnModel() {
+ return dmnModel;
+ }
+
+ public String getNamespace() {
+ return dmnModel.getNamespace();
+ }
+
+ public String getName() {
+ return dmnModel.getName();
+ }
+
+ public Collection<DMNModel> getAllDMNModels() {
+ return dmnRuntime.getModels();
+ }
+
+ public DMNResult evaluate(Map<String, Object> context) {
+ DMNContext dmnContext = new DynamicDMNContextBuilder(dmnRuntime.newContext(), dmnModel).populateContextWith(context);
+ return dmnRuntime.evaluateAll(dmnModel, dmnContext);
+ }
+
+}
diff --git a/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/service/KieRuntimeServiceDMNMapInput.java b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/service/KieRuntimeServiceDMNMapInput.java
new file mode 100644
index 0000000000..98ae5aaac0
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/service/KieRuntimeServiceDMNMapInput.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.runtime.service;
+
+import org.kie.dmn.api.core.DMNResult;
+import org.kie.dmn.efesto.runtime.model.EfestoOutputDMN;
+import org.kie.efesto.common.api.cache.EfestoClassKey;
+import org.kie.efesto.runtimemanager.api.exceptions.KieRuntimeServiceException;
+import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
+import org.kie.efesto.runtimemanager.api.model.EfestoInput;
+import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
+import org.kie.efesto.runtimemanager.api.service.KieRuntimeService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.kie.dmn.efesto.runtime.utils.DmnRuntimeHelper.canManage;
+import static org.kie.dmn.efesto.runtime.utils.DmnRuntimeHelper.execute;
+
+public class KieRuntimeServiceDMNMapInput implements KieRuntimeService<Map<String, Object>, DMNResult, EfestoInput<Map<String, Object>>, EfestoOutputDMN, EfestoLocalRuntimeContext> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(KieRuntimeServiceDMNMapInput.class);
+
+ @Override
+ public EfestoClassKey getEfestoClassKeyIdentifier() {
+ return new EfestoClassKey(BaseEfestoInput.class, HashMap.class);
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public boolean canManageInput(EfestoInput toEvaluate, EfestoLocalRuntimeContext context) {
+ return canManage(toEvaluate, context)
+ && toEvaluate.getModelLocalUriId().model().equals("dmn");
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Optional<EfestoOutputDMN> evaluateInput(EfestoInput<Map<String, Object>> toEvaluate,
+ EfestoLocalRuntimeContext context) {
+ if (!canManageInput(toEvaluate, context)) {
+ throw new KieRuntimeServiceException("Wrong parameters " + toEvaluate + " " + context);
+ }
+ return execute(toEvaluate, context);
+ }
+
+ @Override
+ public String getModelType() {
+ return "dmn";
+ }
+
+ @Override
+ public Optional<EfestoInput<Map<String, Object>>> parseJsonInput(String modelLocalUriIdString, String inputDataString) {
+ return Optional.empty();
+ }
+
+}
diff --git a/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/utils/DmnRuntimeHelper.java b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/utils/DmnRuntimeHelper.java
new file mode 100644
index 0000000000..506b54d87c
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-runtime/src/main/java/org/kie/dmn/efesto/runtime/utils/DmnRuntimeHelper.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.runtime.utils;
+
+import java.util.Map;
+import java.util.Optional;
+
+import org.kie.dmn.api.core.DMNModel;
+import org.kie.dmn.api.core.DMNResult;
+import org.kie.dmn.efesto.runtime.model.EfestoOutputDMN;
+import org.kie.dmn.efesto.runtime.service.DMNEvaluator;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.GeneratedModelResource;
+import org.kie.efesto.runtimemanager.api.model.EfestoInput;
+import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.kie.efesto.runtimemanager.api.utils.GeneratedResourceUtils.getGeneratedModelResource;
+import static org.kie.efesto.runtimemanager.api.utils.GeneratedResourceUtils.isPresentExecutableOrModelOrRedirect;
+
+@SuppressWarnings({"unchecked", "rawtypes"})
+public class DmnRuntimeHelper {
+
+ private static final Logger logger = LoggerFactory.getLogger(DmnRuntimeHelper.class.getName());
+
+ private DmnRuntimeHelper() {
+ }
+
+ public static boolean canManage(EfestoInput toEvaluate, EfestoLocalRuntimeContext context) {
+ return isPresentExecutableOrModelOrRedirect(toEvaluate.getModelLocalUriId(), context);
+ }
+
+ public static Optional<EfestoOutputDMN> execute(EfestoInput<Map<String, Object>> toEvaluate, EfestoLocalRuntimeContext runtimeContext) {
+ ModelLocalUriId modelLocalUriId = toEvaluate.getModelLocalUriId();
+ Optional<GeneratedModelResource> generatedModelResource = getGeneratedModelResource(modelLocalUriId, runtimeContext.getGeneratedResourcesMap());
+ return generatedModelResource.map(it -> {
+ if (it.getCompiledModel() != null) {
+ return execute((DMNModel) it.getCompiledModel(), modelLocalUriId, toEvaluate.getInputData());
+ } else {
+ return execute(it.getModelSource(), modelLocalUriId, toEvaluate.getInputData());
+ }
+ });
+ }
+
+ static EfestoOutputDMN execute(DMNModel model, ModelLocalUriId modelLocalUriId, Map<String, Object> inputData) {
+ try {
+ DMNEvaluator dmnEvaluator = DMNEvaluator.fromDMNModel(model);
+ DMNResult dmnResult = dmnEvaluator.evaluate(inputData);
+ return new EfestoOutputDMN(modelLocalUriId, dmnResult);
+ } catch (Exception e) {
+ logger.error("Failed to evaluate {}", inputData, e);
+ return null;
+ }
+ }
+
+ static EfestoOutputDMN execute(String modelSource, ModelLocalUriId modelLocalUriId, Map<String, Object> inputData) {
+ try {
+ DMNEvaluator dmnEvaluator = DMNEvaluator.fromXML(modelSource);
+ DMNResult dmnResult = dmnEvaluator.evaluate(inputData);
+ return new EfestoOutputDMN(modelLocalUriId, dmnResult);
+ } catch (Exception e) {
+ logger.error("Failed to evaluate {}", inputData, e);
+ return null;
+ }
+ }
+
+}
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService b/kie-dmn/kie-dmn-efesto-runtime/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
similarity index 80%
copy from kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
copy to kie-dmn/kie-dmn-efesto-runtime/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
index 662843a940..670319252c 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
+++ b/kie-dmn/kie-dmn-efesto-runtime/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
@@ -17,6 +17,5 @@
# under the License.
#
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMML
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLRequestData
-org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLMapInput
\ No newline at end of file
+# SPI implementations
+org.kie.dmn.efesto.runtime.service.KieRuntimeServiceDMNMapInput
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-runtime/src/test/java/org/kie/dmn/efesto/runtime/service/KieRuntimeServiceDMNMapInputTest.java b/kie-dmn/kie-dmn-efesto-runtime/src/test/java/org/kie/dmn/efesto/runtime/service/KieRuntimeServiceDMNMapInputTest.java
new file mode 100644
index 0000000000..14a8a93698
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-runtime/src/test/java/org/kie/dmn/efesto/runtime/service/KieRuntimeServiceDMNMapInputTest.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.efesto.runtime.service;
+
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.api.core.DMNResult;
+import org.kie.dmn.api.identifiers.DmnIdFactory;
+import org.kie.dmn.api.identifiers.KieDmnComponentRoot;
+import org.kie.dmn.api.identifiers.LocalComponentIdDmn;
+import org.kie.dmn.efesto.runtime.model.EfestoOutputDMN;
+import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.EfestoRuntimeContext;
+import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
+import org.kie.efesto.runtimemanager.api.model.EfestoInput;
+import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
+import org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils;
+import org.kie.memorycompiler.KieMemoryCompiler;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+@SuppressWarnings("rawtypes")
+public class KieRuntimeServiceDMNMapInputTest {
+
+ private static final String MODEL_NAME = "_0001-input-data-string";
+ private static final String FILE_NAME = "0001-input-data-string";
+ private static KieRuntimeServiceDMNMapInput kieRuntimeServiceDMNMapInput;
+ private static KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader;
+
+ private ModelLocalUriId modelLocalUriId;
+
+ private EfestoInput<Map<String, Object>> inputDMN;
+ private EfestoLocalRuntimeContext efestoRuntimeContext;
+
+ @BeforeAll
+ public static void setup() {
+ kieRuntimeServiceDMNMapInput = new KieRuntimeServiceDMNMapInput();
+ memoryCompilerClassLoader =
+ new KieMemoryCompiler.MemoryCompilerClassLoader(Thread.currentThread().getContextClassLoader());
+ }
+
+ @Test
+ public void canManageManageableInput() {
+ modelLocalUriId = getModelLocalUriIdFromDmnIdFactory(FILE_NAME, MODEL_NAME);
+ Map<String, Object> inputData = new HashMap<>();
+ inputDMN = new BaseEfestoInput<>(modelLocalUriId, inputData);
+ assertThat(kieRuntimeServiceDMNMapInput.canManageInput(inputDMN,
+ getEfestoContext(memoryCompilerClassLoader))).isTrue();
+ }
+
+ @Test
+ public void evaluateCorrectInput() {
+ modelLocalUriId = getModelLocalUriIdFromDmnIdFactory(FILE_NAME, MODEL_NAME);
+ Map<String, Object> inputData = Map.of("Full Name", "John Doe");
+ inputDMN = new BaseEfestoInput<>(modelLocalUriId, inputData);
+ efestoRuntimeContext = getEfestoContext(memoryCompilerClassLoader);
+ Optional<EfestoOutputDMN> retrieved = kieRuntimeServiceDMNMapInput.evaluateInput(inputDMN,
+ efestoRuntimeContext);
+ assertThat(retrieved).isNotNull().isPresent();
+ DMNResult dmnResult = retrieved.get().getOutputData();
+ Assertions.assertThat( dmnResult.getDecisionResults()).hasSize(1);
+ Assertions.assertThat( dmnResult.getDecisionResultByName( "Greeting Message" ).getResult()).isEqualTo("Hello John Doe" );
+ }
+
+
+ static LocalComponentIdDmn getModelLocalUriIdFromDmnIdFactory(String fileName, String modelName) {
+ return new EfestoAppRoot()
+ .get(KieDmnComponentRoot.class)
+ .get(DmnIdFactory.class)
+ .get(fileName, modelName);
+ }
+
+ static EfestoLocalRuntimeContext getEfestoContext(ClassLoader parenClassLoader) {
+ return EfestoRuntimeContextUtils.buildWithParentClassLoader(parenClassLoader);
+ }
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-efesto-runtime/src/test/resources/IndexFile.dmn_json b/kie-dmn/kie-dmn-efesto-runtime/src/test/resources/IndexFile.dmn_json
new file mode 100644
index 0000000000..4e7dd0c201
--- /dev/null
+++ b/kie-dmn/kie-dmn-efesto-runtime/src/test/resources/IndexFile.dmn_json
@@ -0,0 +1,11 @@
+[
+ {
+ "step-type": "model",
+ "modelLocalUriId": {
+ "model": "dmn",
+ "basePath": "/0001-input-data-string/_0001-input-data-string",
+ "fullPath": "/dmn/0001-input-data-string/_0001-input-data-string"
+ },
+ "modelSource": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--\n ~ Copyright 2016 Red Hat, Inc. and/or its affiliates.\n ~\n ~ Licensed under the Apache License, Version 2.0 (the \"License\");\n ~ you may not use this file except in compliance with the License.\n ~ You may obtain a copy of the License at\n ~\n ~ http://www.apache.org/licenses/LICENSE-2.0\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is [...]
+ }
+]
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/pom.xml b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/pom.xml
index 126cfd4e4b..3faff6dcd4 100644
--- a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/pom.xml
+++ b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/pom.xml
@@ -72,6 +72,7 @@
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-pmml-dependencies</artifactId>
+ <scope>test</scope>
<exclusions>
<!-- Tree -->
<exclusion>
@@ -178,6 +179,12 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
+ <!-- ArchUnit -->
+ <dependency>
+ <groupId>com.tngtech.archunit</groupId>
+ <artifactId>archunit-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNRegressionTrustyPMMLTest.java b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNRegressionTrustyPMMLTest.java
index 1980447200..4d76069175 100644
--- a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNRegressionTrustyPMMLTest.java
+++ b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNRegressionTrustyPMMLTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNTreeTrustyPMMLTest.java b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNTreeTrustyPMMLTest.java
index b46e7d2fad..43d3703861 100644
--- a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNTreeTrustyPMMLTest.java
+++ b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/DMNTreeTrustyPMMLTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLValidatorImportTest.java b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/NoPMMLTrustyImportTest.java
similarity index 62%
copy from kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLValidatorImportTest.java
copy to kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/NoPMMLTrustyImportTest.java
index 82323bb41d..866cc1ac73 100644
--- a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLValidatorImportTest.java
+++ b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/NoPMMLTrustyImportTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,7 +18,18 @@
*/
package org.kie.dmn.pmml.trusty;
-import org.kie.dmn.pmml.PMMLValidatorImportTest;
+import com.tngtech.archunit.junit.AnalyzeClasses;
+import com.tngtech.archunit.junit.ArchTest;
+import com.tngtech.archunit.lang.ArchRule;
-public class TrustyPMMLValidatorImportTest extends PMMLValidatorImportTest {
-}
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
+
+@AnalyzeClasses(packages = "org.kie.dmn")
+public class NoPMMLTrustyImportTest {
+
+ @ArchTest
+ public static final ArchRule myRule = noClasses()
+ .that().resideInAnyPackage("org.kie.dmn..")
+ .should().dependOnClassesThat().resideInAnyPackage("org.kie.pmml..");
+
+}
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java
index fb7e788151..c6f47e99c7 100644
--- a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java
+++ b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLInfoTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLValidatorImportTest.java b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLValidatorImportTest.java
index 82323bb41d..2ce5435fe1 100644
--- a/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLValidatorImportTest.java
+++ b/kie-dmn/kie-dmn-pmml-tests-parent/kie-dmn-pmml-tests-trusty/src/test/java/org/kie/dmn/pmml/trusty/TrustyPMMLValidatorImportTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_x/pmml/KiePMMLRegression.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_x/pmml/KiePMMLRegression.dmn
new file mode 100644
index 0000000000..4b4427a7ee
--- /dev/null
+++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_x/pmml/KiePMMLRegression.dmn
@@ -0,0 +1,193 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+<dmn:definitions xmlns:dmn="http://www.omg.org/spec/DMN/20180521/MODEL/" xmlns="https://kiegroup.org/dmn/_51A1FD67-8A67-4332-9889-B718BE8B7456" xmlns:included1="test_regression.pmml" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" xmlns:kie="http://www.drools.org/kie/dmn/1.2" xmlns:feel="http://www.omg.org/spec/DMN/20180521/FEEL/" xmlns:dmndi="http://www.omg.org/spec/DMN/20180521/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="_CA32FDFE-2E29-4026-AA95-08A290808FF7" na [...]
+ <dmn:extensionElements/>
+ <dmn:import id="_A0514F73-E427-4AF5-AED2-4CBC0A173A66" name="TestRegression" namespace="TestRegression" locationURI="test_regression.pmml" importType="http://www.dmg.org/PMML-4_2"/>
+ <dmn:inputData id="_B330C8AD-E87F-4B09-A3AB-5664E2284B1A" name="fld2">
+ <dmn:extensionElements/>
+ <dmn:variable id="_27781513-ED23-4E5A-9C8D-8C5CCCCF41B2" name="fld2" typeRef="number"/>
+ </dmn:inputData>
+ <dmn:businessKnowledgeModel id="_BB0D3D38-E0DA-4384-A9E1-25DDFFD89C68" name="RegressionModelBKM">
+ <dmn:extensionElements/>
+ <dmn:variable id="_359E98E1-9534-416E-83C3-A8C5AD65AC52" name="RegressionModelBKM"/>
+ <dmn:encapsulatedLogic id="_CCCE713B-D128-4BD7-A02B-4CA98A66533C" kind="PMML">
+ <dmn:formalParameter id="_234C5838-9546-484C-ACB2-3ACAD4656823" name="fld1" typeRef="Any"/>
+ <dmn:formalParameter id="_7F5745D1-DE0A-4DB1-BCA9-E8373E5C3F3A" name="fld2" typeRef="Any"/>
+ <dmn:formalParameter id="_FF36D657-F576-4E20-BAF5-F25413C97C79" name="fld3" typeRef="Any"/>
+ <dmn:context id="_991B62E3-C276-4521-80B1-BBD9C5EA1C1C">
+ <dmn:contextEntry>
+ <dmn:variable id="_832AAA1B-1765-480F-AFC1-C81C5062906B" name="document" typeRef="string"/>
+ <dmn:literalExpression id="_9B105002-44C3-4CBE-BB30-DA08D7348A6A">
+ <dmn:text>"TestRegression"</dmn:text>
+ </dmn:literalExpression>
+ </dmn:contextEntry>
+ <dmn:contextEntry>
+ <dmn:variable id="_7513F2BC-4A96-41DF-813F-647709390DAE" name="model" typeRef="string"/>
+ <dmn:literalExpression id="_BFCECD3D-A60C-4937-8440-4EFC5EFF5973">
+ <dmn:text>"LinReg"</dmn:text>
+ </dmn:literalExpression>
+ </dmn:contextEntry>
+ </dmn:context>
+ </dmn:encapsulatedLogic>
+ </dmn:businessKnowledgeModel>
+ <dmn:decision id="_97845D38-0E4C-41D0-9998-0D6B149751F3" name="Decision">
+ <dmn:extensionElements/>
+ <dmn:variable id="_0B606366-E2BE-422F-8F07-05245DD795D8" name="Decision" typeRef="Any"/>
+ <dmn:informationRequirement id="_EE5083E2-21EB-4203-AADA-A0B980C6BEE9">
+ <dmn:requiredInput href="#_96CF50A6-C3A9-4D14-A4D7-EBC0F35F4CB0"/>
+ </dmn:informationRequirement>
+ <dmn:informationRequirement id="_40AF9256-9EB2-445E-A30F-EFCB39C220D1">
+ <dmn:requiredInput href="#_B330C8AD-E87F-4B09-A3AB-5664E2284B1A"/>
+ </dmn:informationRequirement>
+ <dmn:informationRequirement id="_D88145A0-5976-42C2-8464-EC0930FD5921">
+ <dmn:requiredInput href="#_5EC9CC6D-7E1D-4C13-980C-DD904CCF3926"/>
+ </dmn:informationRequirement>
+ <dmn:knowledgeRequirement id="_39C45185-1E40-421F-9D3B-5F56D95CB2C5">
+ <dmn:requiredKnowledge href="#_BB0D3D38-E0DA-4384-A9E1-25DDFFD89C68"/>
+ </dmn:knowledgeRequirement>
+ <dmn:invocation id="_33828843-45AD-4993-B32A-DADEC37A681D">
+ <dmn:literalExpression id="_87CF8DF8-A31D-48CF-BD14-299E912F44B2">
+ <dmn:text>RegressionModelBKM</dmn:text>
+ </dmn:literalExpression>
+ <dmn:binding>
+ <dmn:parameter id="_9EE6DB90-9EA2-4AF4-8CDB-6BB23D7AC126" name="fld1" typeRef="number"/>
+ <dmn:literalExpression id="_7C37842F-5F27-441D-B2CC-124904AA92CF">
+ <dmn:text>fld1</dmn:text>
+ </dmn:literalExpression>
+ </dmn:binding>
+ <dmn:binding>
+ <dmn:parameter id="_C66D7CBE-EFCD-4CC3-B605-8171B4AEA608" name="fld2" typeRef="number"/>
+ <dmn:literalExpression id="_52031D8C-7952-4C68-B5C8-161F7626E0E7">
+ <dmn:text>fld2</dmn:text>
+ </dmn:literalExpression>
+ </dmn:binding>
+ <dmn:binding>
+ <dmn:parameter id="_5CEB6DE8-64E6-46AB-A0E9-BB80193DD415" name="fld3" typeRef="string"/>
+ <dmn:literalExpression id="_9C9A6DD0-AC19-4283-B0A4-F3DE0C86B2D3">
+ <dmn:text>fld3</dmn:text>
+ </dmn:literalExpression>
+ </dmn:binding>
+ </dmn:invocation>
+ </dmn:decision>
+ <dmn:inputData id="_96CF50A6-C3A9-4D14-A4D7-EBC0F35F4CB0" name="fld1">
+ <dmn:extensionElements/>
+ <dmn:variable id="_C9F1EC44-7489-4D66-A1A5-B1410BE546C4" name="fld1" typeRef="number"/>
+ </dmn:inputData>
+ <dmn:inputData id="_5EC9CC6D-7E1D-4C13-980C-DD904CCF3926" name="fld3">
+ <dmn:extensionElements/>
+ <dmn:variable id="_BCB5EA59-820E-40BE-8620-D11B92DFE6F1" name="fld3" typeRef="string"/>
+ </dmn:inputData>
+ <dmndi:DMNDI>
+ <dmndi:DMNDiagram>
+ <di:extension>
+ <kie:ComponentsWidthsExtension>
+ <kie:ComponentWidths dmnElementRef="_991B62E3-C276-4521-80B1-BBD9C5EA1C1C">
+ <kie:width>50.0</kie:width>
+ <kie:width>100.0</kie:width>
+ <kie:width>200.0</kie:width>
+ </kie:ComponentWidths>
+ <kie:ComponentWidths dmnElementRef="_9B105002-44C3-4CBE-BB30-DA08D7348A6A"/>
+ <kie:ComponentWidths dmnElementRef="_BFCECD3D-A60C-4937-8440-4EFC5EFF5973"/>
+ <kie:ComponentWidths dmnElementRef="_CCCE713B-D128-4BD7-A02B-4CA98A66533C">
+ <kie:width>50.0</kie:width>
+ <kie:width>370.0</kie:width>
+ </kie:ComponentWidths>
+ <kie:ComponentWidths dmnElementRef="_33828843-45AD-4993-B32A-DADEC37A681D">
+ <kie:width>50.0</kie:width>
+ <kie:width>100.0</kie:width>
+ <kie:width>150.0</kie:width>
+ </kie:ComponentWidths>
+ <kie:ComponentWidths dmnElementRef="_87CF8DF8-A31D-48CF-BD14-299E912F44B2"/>
+ <kie:ComponentWidths dmnElementRef="_7C37842F-5F27-441D-B2CC-124904AA92CF">
+ <kie:width>150.0</kie:width>
+ </kie:ComponentWidths>
+ <kie:ComponentWidths dmnElementRef="_52031D8C-7952-4C68-B5C8-161F7626E0E7">
+ <kie:width>150.0</kie:width>
+ </kie:ComponentWidths>
+ <kie:ComponentWidths dmnElementRef="_9C9A6DD0-AC19-4283-B0A4-F3DE0C86B2D3">
+ <kie:width>150.0</kie:width>
+ </kie:ComponentWidths>
+ </kie:ComponentsWidthsExtension>
+ </di:extension>
+ <dmndi:DMNShape id="dmnshape-_B330C8AD-E87F-4B09-A3AB-5664E2284B1A" dmnElementRef="_B330C8AD-E87F-4B09-A3AB-5664E2284B1A" isCollapsed="false">
+ <dmndi:DMNStyle>
+ <dmndi:FillColor red="255" green="255" blue="255"/>
+ <dmndi:StrokeColor red="0" green="0" blue="0"/>
+ <dmndi:FontColor red="0" green="0" blue="0"/>
+ </dmndi:DMNStyle>
+ <dc:Bounds x="373.29906542056074" y="117" width="100" height="50"/>
+ <dmndi:DMNLabel/>
+ </dmndi:DMNShape>
+ <dmndi:DMNShape id="dmnshape-_BB0D3D38-E0DA-4384-A9E1-25DDFFD89C68" dmnElementRef="_BB0D3D38-E0DA-4384-A9E1-25DDFFD89C68" isCollapsed="false">
+ <dmndi:DMNStyle>
+ <dmndi:FillColor red="255" green="255" blue="255"/>
+ <dmndi:StrokeColor red="0" green="0" blue="0"/>
+ <dmndi:FontColor red="0" green="0" blue="0"/>
+ </dmndi:DMNStyle>
+ <dc:Bounds x="680" y="261" width="100" height="50"/>
+ <dmndi:DMNLabel/>
+ </dmndi:DMNShape>
+ <dmndi:DMNShape id="dmnshape-_97845D38-0E4C-41D0-9998-0D6B149751F3" dmnElementRef="_97845D38-0E4C-41D0-9998-0D6B149751F3" isCollapsed="false">
+ <dmndi:DMNStyle>
+ <dmndi:FillColor red="255" green="255" blue="255"/>
+ <dmndi:StrokeColor red="0" green="0" blue="0"/>
+ <dmndi:FontColor red="0" green="0" blue="0"/>
+ </dmndi:DMNStyle>
+ <dc:Bounds x="373" y="261" width="100" height="50"/>
+ <dmndi:DMNLabel/>
+ </dmndi:DMNShape>
+ <dmndi:DMNShape id="dmnshape-_96CF50A6-C3A9-4D14-A4D7-EBC0F35F4CB0" dmnElementRef="_96CF50A6-C3A9-4D14-A4D7-EBC0F35F4CB0" isCollapsed="false">
+ <dmndi:DMNStyle>
+ <dmndi:FillColor red="255" green="255" blue="255"/>
+ <dmndi:StrokeColor red="0" green="0" blue="0"/>
+ <dmndi:FontColor red="0" green="0" blue="0"/>
+ </dmndi:DMNStyle>
+ <dc:Bounds x="182" y="117" width="100" height="50"/>
+ <dmndi:DMNLabel/>
+ </dmndi:DMNShape>
+ <dmndi:DMNShape id="dmnshape-_5EC9CC6D-7E1D-4C13-980C-DD904CCF3926" dmnElementRef="_5EC9CC6D-7E1D-4C13-980C-DD904CCF3926" isCollapsed="false">
+ <dmndi:DMNStyle>
+ <dmndi:FillColor red="255" green="255" blue="255"/>
+ <dmndi:StrokeColor red="0" green="0" blue="0"/>
+ <dmndi:FontColor red="0" green="0" blue="0"/>
+ </dmndi:DMNStyle>
+ <dc:Bounds x="565" y="117" width="100" height="50"/>
+ <dmndi:DMNLabel/>
+ </dmndi:DMNShape>
+ <dmndi:DMNEdge id="dmnedge-_EE5083E2-21EB-4203-AADA-A0B980C6BEE9" dmnElementRef="_EE5083E2-21EB-4203-AADA-A0B980C6BEE9">
+ <di:waypoint x="232" y="167"/>
+ <di:waypoint x="423" y="261"/>
+ </dmndi:DMNEdge>
+ <dmndi:DMNEdge id="dmnedge-_40AF9256-9EB2-445E-A30F-EFCB39C220D1" dmnElementRef="_40AF9256-9EB2-445E-A30F-EFCB39C220D1">
+ <di:waypoint x="423.29906542056074" y="167"/>
+ <di:waypoint x="423" y="261"/>
+ </dmndi:DMNEdge>
+ <dmndi:DMNEdge id="dmnedge-_D88145A0-5976-42C2-8464-EC0930FD5921" dmnElementRef="_D88145A0-5976-42C2-8464-EC0930FD5921">
+ <di:waypoint x="615" y="167"/>
+ <di:waypoint x="423" y="261"/>
+ </dmndi:DMNEdge>
+ <dmndi:DMNEdge id="dmnedge-_39C45185-1E40-421F-9D3B-5F56D95CB2C5" dmnElementRef="_39C45185-1E40-421F-9D3B-5F56D95CB2C5">
+ <di:waypoint x="680" y="286"/>
+ <di:waypoint x="473" y="286"/>
+ </dmndi:DMNEdge>
+ </dmndi:DMNDiagram>
+ </dmndi:DMNDI>
+</dmn:definitions>
diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_x/pmml/test_regression.pmml b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_x/pmml/test_regression.pmml
new file mode 100644
index 0000000000..8035fc427f
--- /dev/null
+++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_x/pmml/test_regression.pmml
@@ -0,0 +1,49 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+<PMML version="4.2" xsi:schemaLocation="http://www.dmg.org/PMML-4_2 http://www.dmg.org/v4-2-1/pmml-4-2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.dmg.org/PMML-4_2">
+ <Header copyright="Apache"/>
+ <DataDictionary numberOfFields="5">
+ <DataField dataType="double" name="fld1" optype="continuous"/>
+ <DataField dataType="double" name="fld2" optype="continuous"/>
+ <DataField dataType="string" name="fld3" optype="categorical">
+ <Value value="x"/>
+ <Value value="y"/>
+ </DataField>
+ <DataField dataType="double" name="fld4" optype="continuous"/>
+ <DataField dataType="double" name="fld5" optype="continuous"/>
+ </DataDictionary>
+ <RegressionModel algorithmName="linearRegression" functionName="regression" modelName="LinReg" targetFieldName="fld4">
+ <MiningSchema>
+ <MiningField name="fld1"/>
+ <MiningField name="fld2"/>
+ <MiningField name="fld3"/>
+ <MiningField name="fld4" usageType="predicted"/>
+ </MiningSchema>
+ <Output>
+ <OutputField name="result" targetField="fld4" />
+ </Output>
+ <RegressionTable intercept="0.5">
+ <NumericPredictor coefficient="5" exponent="2" name="fld1"/>
+ <NumericPredictor coefficient="2" exponent="1" name="fld2"/>
+ <CategoricalPredictor coefficient="-3" name="fld3" value="x"/>
+ <CategoricalPredictor coefficient="3" name="fld3" value="y"/>
+ </RegressionTable>
+ </RegressionModel>
+</PMML>
\ No newline at end of file
diff --git a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java
index 9cdf71a14f..997f5346c1 100644
--- a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java
+++ b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/ValidatorTest.java
@@ -625,7 +625,7 @@ class ValidatorTest extends AbstractValidatorTest {
private void testDirectoryInJar(JarFile jarFile, String directory) {
Resource[] resources = Collections.list(jarFile.entries())
.stream()
- .filter(entry -> entry.getName().startsWith(directory) && !entry.isDirectory())
+ .filter(entry -> entry.getName().startsWith(directory) && !entry.isDirectory() && entry.getName().endsWith(".dmn"))
.map(ZipEntry::getName)
.map(ClassPathResource::new)
.toArray(Resource[]::new);
diff --git a/kie-dmn/pom.xml b/kie-dmn/pom.xml
index 269618b98c..34d8d87698 100644
--- a/kie-dmn/pom.xml
+++ b/kie-dmn/pom.xml
@@ -36,10 +36,6 @@
<name>KIE :: Decision Model Notation</name>
<description>Top level pom for the KIE DMN support implementation</description>
- <properties>
- <archunit.maven.plugin.version>2.9.1</archunit.maven.plugin.version>
- </properties>
-
<modules>
<module>kie-dmn-xsd-resources</module>
<module>kie-dmn-api</module>
@@ -48,6 +44,9 @@
<module>kie-dmn-feel</module>
<module>kie-dmn-core</module>
<module>kie-dmn-backend</module>
+ <module>kie-dmn-efesto-api</module>
+ <module>kie-dmn-efesto-compilation</module>
+ <module>kie-dmn-efesto-runtime</module>
<module>kie-dmn-validation-bootstrap</module>
<module>kie-dmn-validation</module>
<module>kie-dmn-openapi</module>
@@ -75,15 +74,6 @@
</dependencyManagement>
<build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>com.societegenerale.commons</groupId>
- <artifactId>arch-unit-maven-plugin</artifactId>
- <version>${archunit.maven.plugin.version}</version>
- </plugin>
- </plugins>
- </pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -93,6 +83,8 @@
<bannedDependencies>
<excludes>
<exclude>junit:junit</exclude>
+ <exclude>org.kie:kie-pmml-api:*:*:compile</exclude>
+ <exclude>org.kie:kie-pmml-api:*:*:runtime</exclude>
</excludes>
</bannedDependencies>
</rules>
@@ -117,11 +109,6 @@
<!-- optional - you can avoid build fail if there is issue. True to avoid build failure, default is false -->
<!-- <noFailOnError>true</noFailOnError>-->
- <!-- optional - you can exclude classes that have a path containing any of the mentioned paths -->
- <!-- <excludedPaths>-->
- <!-- <excludedPath>my/package/to/exclude</excludedPath>-->
- <!-- </excludedPaths>-->
-
<rules>
<!-- using a rule available out of the box... -->
<preConfiguredRules>
diff --git a/kie-drl/kie-drl-implementations/kie-drl-kiesession-local/kie-drl-kiesession-local-runtime/src/main/java/org/kie/drl/engine/runtime/kiesession/local/service/KieRuntimeServiceDrlKieSessionLocal.java b/kie-drl/kie-drl-implementations/kie-drl-kiesession-local/kie-drl-kiesession-local-runtime/src/main/java/org/kie/drl/engine/runtime/kiesession/local/service/KieRuntimeServiceDrlKieSessionLocal.java
index da19503785..879f0be5fb 100644
--- a/kie-drl/kie-drl-implementations/kie-drl-kiesession-local/kie-drl-kiesession-local-runtime/src/main/java/org/kie/drl/engine/runtime/kiesession/local/service/KieRuntimeServiceDrlKieSessionLocal.java
+++ b/kie-drl/kie-drl-implementations/kie-drl-kiesession-local/kie-drl-kiesession-local-runtime/src/main/java/org/kie/drl/engine/runtime/kiesession/local/service/KieRuntimeServiceDrlKieSessionLocal.java
@@ -19,8 +19,6 @@
package org.kie.drl.engine.runtime.kiesession.local.service;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.Optional;
-
import org.kie.api.runtime.KieSession;
import org.kie.drl.engine.runtime.kiesession.local.model.EfestoInputDrlKieSessionLocal;
import org.kie.drl.engine.runtime.kiesession.local.model.EfestoOutputDrlKieSessionLocal;
@@ -34,8 +32,11 @@ import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.api.service.KieRuntimeService;
+import java.util.Optional;
+
import static org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils.buildWithParentClassLoader;
+@SuppressWarnings({"unchecked", "rawtypes"})
public class KieRuntimeServiceDrlKieSessionLocal implements KieRuntimeService<String, KieSession, EfestoInputDrlKieSessionLocal, EfestoOutputDrlKieSessionLocal, EfestoRuntimeContext> {
private static final ObjectMapper objectMapper = JSONUtils.getObjectMapper();
diff --git a/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/service/KieRuntimeServiceDrlMapInput.java b/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/service/KieRuntimeServiceDrlMapInput.java
index fe710818c9..cd9ed8e688 100644
--- a/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/service/KieRuntimeServiceDrlMapInput.java
+++ b/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/service/KieRuntimeServiceDrlMapInput.java
@@ -24,24 +24,24 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-
import org.kie.drl.engine.runtime.mapinput.model.EfestoOutputDrlMap;
import org.kie.drl.engine.runtime.mapinput.utils.DrlRuntimeHelper;
import org.kie.efesto.common.api.cache.EfestoClassKey;
import org.kie.efesto.common.api.exceptions.KieEfestoCommonException;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.common.core.utils.JSONUtils;
import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
import org.kie.efesto.runtimemanager.api.model.EfestoInput;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoMapInputDTO;
-import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoOriginalTypeGeneratedType;
import org.kie.efesto.runtimemanager.api.service.KieRuntimeService;
import static org.kie.efesto.common.core.utils.JSONUtils.getInputData;
import static org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils.buildWithParentClassLoader;
+@SuppressWarnings({"unchecked", "rawtypes"})
public class KieRuntimeServiceDrlMapInput implements KieRuntimeService<EfestoMapInputDTO, Map<String, Object>,
BaseEfestoInput<EfestoMapInputDTO>, EfestoOutputDrlMap, EfestoRuntimeContext> {
diff --git a/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelper.java b/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelper.java
index d4b27d03f8..ff401c27ad 100644
--- a/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelper.java
+++ b/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/main/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelper.java
@@ -26,12 +26,12 @@ import org.kie.drl.api.identifiers.KieDrlComponentRoot;
import org.kie.drl.api.identifiers.LocalComponentIdDrlSession;
import org.kie.drl.engine.runtime.mapinput.model.EfestoOutputDrlMap;
import org.kie.efesto.common.api.identifiers.EfestoAppRoot;
+import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.api.exceptions.KieRuntimeServiceException;
import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
import org.kie.efesto.runtimemanager.api.model.EfestoInput;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoMapInputDTO;
-import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,7 +49,8 @@ public class DrlRuntimeHelper {
return getGeneratedExecutableResource(toEvaluate.getModelLocalUriId(), context.getGeneratedResourcesMap()).isPresent();
}
- public static Optional<EfestoOutputDrlMap> execute(BaseEfestoInput<EfestoMapInputDTO> toEvaluate, EfestoLocalRuntimeContext context) {
+ public static Optional<EfestoOutputDrlMap> execute(BaseEfestoInput<EfestoMapInputDTO> toEvaluate,
+ EfestoLocalRuntimeContext context) {
KieSession kieSession;
try {
kieSession = loadKieSession(toEvaluate.getModelLocalUriId(), context);
diff --git a/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/test/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelperTest.java b/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/test/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelperTest.java
index 6c5446f85b..0123920ca8 100644
--- a/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/test/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelperTest.java
+++ b/kie-drl/kie-drl-implementations/kie-drl-map-input/kie-drl-map-input-runtime/src/test/java/org/kie/drl/engine/runtime/mapinput/utils/DrlRuntimeHelperTest.java
@@ -32,10 +32,10 @@ import org.kie.drl.engine.runtime.mapinput.model.EfestoInputDrlMap;
import org.kie.drl.engine.runtime.mapinput.model.EfestoOutputDrlMap;
import org.kie.efesto.common.api.identifiers.LocalUri;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
+import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoMapInputDTO;
-import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -74,7 +74,8 @@ class DrlRuntimeHelperTest {
EfestoInputDrlMap darInputDrlMap =
new EfestoInputDrlMap(new ModelLocalUriId(LocalUri.parse("/drl/" + basePath)), darMapInputDTO);
- EfestoLocalRuntimeContext context = EfestoRuntimeContextUtils.buildWithParentClassLoader(Thread.currentThread().getContextClassLoader());
+ EfestoLocalRuntimeContext context =
+ EfestoRuntimeContextUtils.buildWithParentClassLoader(Thread.currentThread().getContextClassLoader());
Optional<EfestoOutputDrlMap> retrieved = DrlRuntimeHelper.execute(darInputDrlMap, context);
assertThat(retrieved).isNotNull().isPresent();
assertThat(approvedApplications).hasSize(1);
diff --git a/kie-drl/kie-drl-runtime-common/src/main/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtil.java b/kie-drl/kie-drl-runtime-common/src/main/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtil.java
index 848b5b06e1..48df3619e4 100644
--- a/kie-drl/kie-drl-runtime-common/src/main/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtil.java
+++ b/kie-drl/kie-drl-runtime-common/src/main/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtil.java
@@ -29,12 +29,12 @@ import org.kie.api.runtime.KieSession;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
import org.kie.efesto.common.api.model.GeneratedExecutableResource;
import org.kie.efesto.runtimemanager.api.exceptions.KieRuntimeServiceException;
-import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.api.utils.GeneratedResourceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@SuppressWarnings({"unchecked", "rawtypes"})
public class EfestoKieSessionUtil {
private static final Logger logger = LoggerFactory.getLogger(EfestoKieSessionUtil.class.getName());
diff --git a/kie-drl/kie-drl-runtime-common/src/test/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtilTest.java b/kie-drl/kie-drl-runtime-common/src/test/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtilTest.java
index 2c4f44b686..6dad47b428 100644
--- a/kie-drl/kie-drl-runtime-common/src/test/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtilTest.java
+++ b/kie-drl/kie-drl-runtime-common/src/test/java/org/kie/drl/engine/runtime/utils/EfestoKieSessionUtilTest.java
@@ -24,12 +24,12 @@ import org.junit.jupiter.api.Test;
import org.kie.api.runtime.KieSession;
import org.kie.efesto.common.api.identifiers.LocalUri;
import org.kie.efesto.common.api.identifiers.ModelLocalUriId;
-import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils;
import static org.assertj.core.api.Assertions.assertThat;
+@SuppressWarnings("rawtypes")
class EfestoKieSessionUtilTest {
private static final String fullModelResourcesSourceClassName = "org.kie.drl.engine.compilation.model.test.Rulesefe9b92fdd254fbabc9e9002be0d51d6";
diff --git a/kie-internal/src/main/java/org/kie/internal/pmml/PMMLCommandExecutor.java b/kie-internal/src/main/java/org/kie/internal/pmml/PMMLCommandExecutor.java
index dad72646e0..6205c54875 100644
--- a/kie-internal/src/main/java/org/kie/internal/pmml/PMMLCommandExecutor.java
+++ b/kie-internal/src/main/java/org/kie/internal/pmml/PMMLCommandExecutor.java
@@ -18,17 +18,17 @@
*/
package org.kie.internal.pmml;
-import org.kie.api.pmml.PMML4Result;
-import org.kie.api.pmml.PMMLRequestData;
+import java.util.Map;
+
import org.kie.api.runtime.Context;
public interface PMMLCommandExecutor {
/**
- * Evaluate the given <code>PMMLRequestData<code>
+ * Evaluate the given <code>Map<String, Object><code>
* @param pmmlRequestData : it must contain the pmml file name (in the <i>source</i> property)
* and the model name
* @return
*/
- PMML4Result execute(final PMMLRequestData pmmlRequestData, final Context context);
+ Map<String, Object> execute(final Map<String, Object> pmmlRequestData, final Context context);
}
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java b/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
index 6c291c261d..2d007f725d 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
+++ b/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/AbstractModelLocalUriIdPmml.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java b/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
index b276160eb0..5f16444c7d 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
+++ b/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/LocalComponentIdPmml.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/PmmlIdFactory.java b/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/PmmlIdFactory.java
index 96789f84af..d657c7819d 100644
--- a/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/PmmlIdFactory.java
+++ b/kie-pmml-trusty/kie-pmml-api/src/main/java/org/kie/pmml/api/identifiers/PmmlIdFactory.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
diff --git a/kie-pmml-trusty/kie-pmml-compiler/kie-pmml-compiler-core/src/main/java/org/kie/pmml/compiler/PMMLCompilationContextImpl.java b/kie-pmml-trusty/kie-pmml-compiler/kie-pmml-compiler-core/src/main/java/org/kie/pmml/compiler/PMMLCompilationContextImpl.java
index 4125c90a4b..e980d1d483 100644
--- a/kie-pmml-trusty/kie-pmml-compiler/kie-pmml-compiler-core/src/main/java/org/kie/pmml/compiler/PMMLCompilationContextImpl.java
+++ b/kie-pmml-trusty/kie-pmml-compiler/kie-pmml-compiler-core/src/main/java/org/kie/pmml/compiler/PMMLCompilationContextImpl.java
@@ -50,7 +50,7 @@ public class PMMLCompilationContextImpl extends EfestoCompilationContextImpl<PMM
public PMMLCompilationContextImpl(final String fileName,
final KieMemoryCompiler.MemoryCompilerClassLoader memoryCompilerClassLoader) {
- super(memoryCompilerClassLoader);
+ super(memoryCompilerClassLoader, false);
name = "Context_" + ID_GENERATOR.incrementAndGet();
if (!fileName.endsWith(PMML_SUFFIX)) {
this.fileName = fileName + PMML_SUFFIX;
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializer.java b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializer.java
index 79c91cc801..3076b65516 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializer.java
+++ b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializer.java
@@ -18,6 +18,8 @@
*/
package org.kie.pmml.evaluator.core.serialization;
+import java.io.IOException;
+
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -26,7 +28,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.ArrayNode;
-import java.io.IOException;
import org.kie.api.pmml.PMMLRequestData;
import org.kie.pmml.api.exceptions.KiePMMLInternalException;
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializerService.java b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializerService.java
index 86e4429ef5..8ea1ec57d1 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializerService.java
+++ b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/java/org/kie/pmml/evaluator/core/serialization/PMMLRequestDataDeserializerService.java
@@ -18,9 +18,10 @@
*/
package org.kie.pmml.evaluator.core.serialization;
+
import com.fasterxml.jackson.databind.JsonDeserializer;
-import org.kie.efesto.common.core.serialization.DeserializerService;
import org.kie.api.pmml.PMMLRequestData;
+import org.kie.efesto.common.core.serialization.DeserializerService;
public class PMMLRequestDataDeserializerService implements DeserializerService<PMMLRequestData> {
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
index 662843a940..b44995fd9d 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
+++ b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/main/resources/META-INF/services/org.kie.efesto.runtimemanager.api.service.KieRuntimeService
@@ -17,6 +17,7 @@
# under the License.
#
+# SPI implementations
org.kie.pmml.evaluator.core.service.KieRuntimeServicePMML
org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLRequestData
org.kie.pmml.evaluator.core.service.KieRuntimeServicePMMLMapInput
\ No newline at end of file
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/TestingHelper.java b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/TestingHelper.java
index 0e657c3f48..10ff3d362a 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/TestingHelper.java
+++ b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/TestingHelper.java
@@ -24,10 +24,12 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.IntStream;
+import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.efesto.runtimemanager.api.model.EfestoLocalRuntimeContext;
import org.kie.api.pmml.PMML4Result;
import org.kie.api.pmml.PMMLRequestData;
import org.kie.efesto.runtimemanager.api.model.BaseEfestoInput;
+import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.efesto.runtimemanager.core.model.EfestoRuntimeContextUtils;
import org.kie.memorycompiler.KieMemoryCompiler;
import org.kie.pmml.api.enums.PMML_STEP;
diff --git a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/evaluator/core/service/KieRuntimeServicePMMLMapInputTest.java b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/evaluator/core/service/KieRuntimeServicePMMLMapInputTest.java
index d8abb79eeb..96d8694f79 100644
--- a/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/evaluator/core/service/KieRuntimeServicePMMLMapInputTest.java
+++ b/kie-pmml-trusty/kie-pmml-evaluator/kie-pmml-evaluator-core/src/test/java/org/kie/pmml/evaluator/core/service/KieRuntimeServicePMMLMapInputTest.java
@@ -30,6 +30,7 @@ import org.kie.efesto.runtimemanager.api.model.EfestoInput;
import org.kie.efesto.common.api.model.EfestoRuntimeContext;
import org.kie.memorycompiler.KieMemoryCompiler;
import org.kie.pmml.evaluator.core.model.EfestoOutputPMMLMap;
+import org.kie.pmml.evaluator.core.model.EfestoOutputPMMLMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.kie.pmml.TestingHelper.getEfestoContext;
diff --git a/kie-pmml-trusty/pom.xml b/kie-pmml-trusty/pom.xml
index e29272d561..1bf9a52d7c 100644
--- a/kie-pmml-trusty/pom.xml
+++ b/kie-pmml-trusty/pom.xml
@@ -39,7 +39,6 @@
<properties>
<rewrite.maven.plugin.version>4.42.0</rewrite.maven.plugin.version>
<rewrite.testing.frameworks.version>1.22.0</rewrite.testing.frameworks.version>
- <archunit.maven.plugin.version>2.9.1</archunit.maven.plugin.version>
</properties>
<modules>
@@ -98,11 +97,6 @@
<artifactId>rewrite-maven-plugin</artifactId>
<version>${rewrite.maven.plugin.version}</version>
</plugin>
- <plugin>
- <groupId>com.societegenerale.commons</groupId>
- <artifactId>arch-unit-maven-plugin</artifactId>
- <version>${archunit.maven.plugin.version}</version>
- </plugin>
</plugins>
</pluginManagement>
<plugins>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org