Search in sources :

Example 16 with DecisionNode

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);
}
Also used : FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Matchers.anyString(org.mockito.Matchers.anyString) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) DMNType(org.kie.dmn.api.core.DMNType)

Example 17 with DecisionNode

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);
}
Also used : DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DMNType(org.kie.dmn.api.core.DMNType)

Example 18 with DecisionNode

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;
}
Also used : DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DMNType(org.kie.dmn.api.core.DMNType)

Example 19 with DecisionNode

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;
}
Also used : FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) WrongDMNTypeException(org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DMNModel(org.kie.dmn.api.core.DMNModel) DMNType(org.kie.dmn.api.core.DMNType)

Example 20 with DecisionNode

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());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) DMNContext(org.kie.dmn.api.core.DMNContext) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) DMNMessage(org.kie.dmn.api.core.DMNMessage) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)32 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)16 DMNType (org.kie.dmn.api.core.DMNType)12 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)10 DecisionServiceNode (org.kie.dmn.api.core.ast.DecisionServiceNode)9 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)9 DMNMessage (org.kie.dmn.api.core.DMNMessage)7 DMNModel (org.kie.dmn.api.core.DMNModel)7 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)6 DMNNode (org.kie.dmn.api.core.ast.DMNNode)6 Optional (java.util.Optional)5 DMNContext (org.kie.dmn.api.core.DMNContext)5 DMNResult (org.kie.dmn.api.core.DMNResult)5 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)5 DMNBaseNode (org.kie.dmn.core.ast.DMNBaseNode)5 DecisionServiceNodeImpl (org.kie.dmn.core.ast.DecisionServiceNodeImpl)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 List (java.util.List)4 HashMap (java.util.HashMap)3