use of org.kie.dmn.api.core.ast.DecisionNode in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategyTest method getFactModelTuple.
private FactModelTuple getFactModelTuple(boolean hasInput, boolean hasOutput) throws IOException {
SortedMap<String, FactModelTree> visibleFacts = new TreeMap<>();
SortedMap<String, FactModelTree> hiddenFacts = new TreeMap<>();
if (hasInput) {
for (InputDataNode input : dmnModelLocal.getInputs()) {
DMNType type = input.getType();
visibleFacts.put(input.getName(), createFactModelTree(input.getName(), input.getName(), type, hiddenFacts, FactModelTree.Type.INPUT));
}
}
if (hasOutput) {
for (DecisionNode decision : dmnModelLocal.getDecisions()) {
DMNType type = decision.getResultType();
visibleFacts.put(decision.getName(), createFactModelTree(decision.getName(), decision.getName(), type, hiddenFacts, DECISION));
}
}
return new FactModelTuple(visibleFacts, hiddenFacts);
}
use of org.kie.dmn.api.core.ast.DecisionNode in project drools-wb by kiegroup.
the class DMNScenarioValidationTest method createDMNType.
private void createDMNType(String decisionName, String rootType, String... steps) {
DecisionNode decisionNodeMock = getOrCreateDecisionNode(decisionName, rootType);
DMNType currentType = decisionNodeMock.getResultType();
for (String step : steps) {
currentType = addStep(currentType, step);
}
mapOfMockDecisions.put(decisionName, decisionNodeMock);
}
use of org.kie.dmn.api.core.ast.DecisionNode in project drools-wb by kiegroup.
the class DMNScenarioValidationTest method getOrCreateDecisionNode.
private DecisionNode getOrCreateDecisionNode(String decisionName, String typeName) {
DecisionNode decisionNodeMock;
if (mapOfMockDecisions.containsKey(decisionName)) {
decisionNodeMock = mapOfMockDecisions.get(decisionName);
String decisionTypeName = decisionNodeMock.getResultType().getName();
if (!Objects.equals(decisionTypeName, createDMNTypeName(typeName))) {
throw new IllegalArgumentException("Decision with name " + decisionName + " already created of type " + decisionTypeName);
}
} else {
decisionNodeMock = mock(DecisionNode.class);
mapOfMockDecisions.put(decisionName, decisionNodeMock);
DMNType initDMNType = initDMNType(typeName);
when(decisionNodeMock.getResultType()).thenReturn(initDMNType);
}
return decisionNodeMock;
}
use of org.kie.dmn.api.core.ast.DecisionNode in project drools-wb by kiegroup.
the class DMNTypeServiceImpl method retrieveFactModelTuple.
@Override
public FactModelTuple retrieveFactModelTuple(Path path, String dmnPath) {
DMNModel dmnModel = getDMNModel(path, dmnPath);
SortedMap<String, FactModelTree> visibleFacts = new TreeMap<>();
SortedMap<String, FactModelTree> hiddenFacts = new TreeMap<>();
ErrorHolder errorHolder = new ErrorHolder();
Map<String, String> importedModelsMap = dmnModel.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
for (InputDataNode input : dmnModel.getInputs()) {
final DMNType type = input.getType();
final String importPrefix = importedModelsMap.getOrDefault(input.getModelNamespace(), null);
final String name = importedModelsMap.containsKey(input.getModelNamespace()) ? importedModelsMap.get(input.getModelNamespace()) + "." + input.getName() : input.getName();
checkTypeSupport(type, errorHolder, name);
try {
visibleFacts.put(name, createTopLevelFactModelTree(name, importPrefix, type, hiddenFacts, FactModelTree.Type.INPUT));
} catch (WrongDMNTypeException e) {
throw ExceptionUtilities.handleException(e);
}
}
for (DecisionNode decision : dmnModel.getDecisions()) {
DMNType type = decision.getResultType();
final String importPrefix = importedModelsMap.getOrDefault(decision.getModelNamespace(), null);
final String name = importedModelsMap.containsKey(decision.getModelNamespace()) ? importedModelsMap.get(decision.getModelNamespace()) + "." + decision.getName() : decision.getName();
checkTypeSupport(type, errorHolder, name);
try {
visibleFacts.put(name, createTopLevelFactModelTree(name, importPrefix, type, hiddenFacts, FactModelTree.Type.DECISION));
} catch (WrongDMNTypeException e) {
throw ExceptionUtilities.handleException(e);
}
}
FactModelTuple factModelTuple = new FactModelTuple(visibleFacts, hiddenFacts);
errorHolder.getMultipleNestedCollection().forEach(factModelTuple::addMultipleNestedCollectionError);
errorHolder.getMultipleNestedObject().forEach(factModelTuple::addMultipleNestedObjectError);
return factModelTuple;
}
use of org.kie.dmn.api.core.ast.DecisionNode in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method test_wrong_context.
@Test
public void test_wrong_context() throws IOException {
// DROOLS-2217
// SPECIAL CASE: to represent a partially edited DMN file.
// consider a LiteralExpression with null text as missing expression altogether.
final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/wrong_context.dmn"));
DMNModel dmnModel = runtime.getModels().get(0);
// the DMN file is schema valid but is not a valid-DMN (a context-entry value is a literal expression missing text, which is null)
assertTrue(dmnModel.hasErrors());
// identify the error message for context-entry "ciao":
DMNMessage m0 = dmnModel.getMessages(DMNMessage.Severity.ERROR).get(0);
assertTrue("expected a message identifying the problem on a context entry for 'ciao'", m0.getMessage().startsWith("No expression defined for name 'ciao'"));
DecisionNode d0 = dmnModel.getDecisionById("_653b3426-933a-4050-9568-ab2a66b43c36");
// the identified DMN Decision is composed of a DMN Context where the first context-entry value is a literal expression missing text (text is null).
org.kie.dmn.model.v1_1.Context d0c = (org.kie.dmn.model.v1_1.Context) d0.getDecision().getExpression();
org.kie.dmn.model.v1_1.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
assertTrue(contextEntryValue instanceof org.kie.dmn.model.v1_1.LiteralExpression);
assertEquals(null, ((org.kie.dmn.model.v1_1.LiteralExpression) contextEntryValue).getText());
// -- Stunner side.
DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/wrong_context.dmn"));
DiagramImpl diagram = new DiagramImpl("", null);
Node<?, ?> decisionNode = g.getNode("_653b3426-933a-4050-9568-ab2a66b43c36");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
View<Decision> view = ((View<Decision>) decisionNode.getContent());
// the identified DMN Decision is composed of a DMN Context where the first context-entry has missing Expression.
Context expression = (Context) view.getDefinition().getExpression();
assertEquals("a literalexpression with null text is threated as a missing expression altogether.", null, expression.getContextEntry().get(0).getExpression());
}
Aggregations