Search in sources :

Example 16 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTablePropertyConverterTest method testWBFromDMNMultipleOutputClauseTypeRef.

@Test
public void testWBFromDMNMultipleOutputClauseTypeRef() {
    final org.kie.dmn.model.api.DecisionTable dmn = new TDecisionTable();
    final org.kie.dmn.model.api.OutputClause dmnOutputClause1 = new TOutputClause();
    final org.kie.dmn.model.api.OutputClause dmnOutputClause2 = new TOutputClause();
    dmn.setId(UUID);
    dmn.setDescription(DESCRIPTION);
    dmn.setTypeRef(new QName(QNAME_LOCALPART));
    dmnOutputClause1.setName(NAME + "-oc1");
    dmnOutputClause2.setName(NAME + "-oc2");
    dmnOutputClause1.setTypeRef(new QName(QNAME_LOCALPART + "-oc1"));
    dmnOutputClause2.setTypeRef(new QName(QNAME_LOCALPART + "-oc2"));
    dmn.getOutput().add(dmnOutputClause1);
    dmn.getOutput().add(dmnOutputClause2);
    final DecisionTable wb = DecisionTablePropertyConverter.wbFromDMN(dmn);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(UUID);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(DESCRIPTION);
    assertThat(wb.getTypeRef()).isNotNull();
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART);
    assertThat(wb.getOutput()).hasSize(2);
    final OutputClause wbOutputClause1 = wb.getOutput().get(0);
    final OutputClause wbOutputClause2 = wb.getOutput().get(1);
    assertThat(wbOutputClause1.getName()).isEqualTo(NAME + "-oc1");
    assertThat(wbOutputClause2.getName()).isEqualTo(NAME + "-oc2");
    assertThat(wbOutputClause1.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc1");
    assertThat(wbOutputClause2.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc2");
}
Also used : TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) QName(javax.xml.namespace.QName) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) Test(org.junit.Test)

Example 17 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTablePropertyConverterTest method testDMNFromWBSingleOutputClauseTypeRef.

@Test
public void testDMNFromWBSingleOutputClauseTypeRef() {
    final DecisionTable wb = new DecisionTable();
    final OutputClause outputClause1 = new OutputClause();
    wb.getId().setValue(UUID);
    wb.getDescription().setValue(DESCRIPTION);
    wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART));
    outputClause1.setName(NAME);
    outputClause1.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART + "-oc1"));
    wb.getOutput().add(outputClause1);
    final org.kie.dmn.model.api.DecisionTable dmn = DecisionTablePropertyConverter.dmnFromWB(wb);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART);
    assertThat(dmn.getOutput()).hasSize(1);
    final org.kie.dmn.model.api.OutputClause dmnOutputClause1 = dmn.getOutput().get(0);
    assertThat(dmnOutputClause1.getName()).isNull();
    assertThat(dmnOutputClause1.getTypeRef()).isNull();
}
Also used : TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) Test(org.junit.Test)

Example 18 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricher method buildOutputClausesByDataType.

void buildOutputClausesByDataType(final HasExpression hasExpression, final DecisionTable dTable, final DecisionRule decisionRule) {
    final HasTypeRef hasTypeRef = getHasTypeRef(hasExpression, dTable);
    final QName typeRef = !Objects.isNull(hasTypeRef) ? hasTypeRef.getTypeRef() : BuiltInType.UNDEFINED.asQName();
    final String name = DecisionTableDefaultValueUtilities.getNewOutputClauseName(dTable);
    final List<ClauseRequirement> outputClausesRequirement = generateOutputClauseRequirements(dmnGraphUtils.getModelDefinitions(), typeRef, name);
    if (outputClausesRequirement.isEmpty()) {
        dTable.getOutput().add(buildOutputClause(dTable, typeRef, name));
        populateOutputEntries(decisionRule);
    } else {
        outputClausesRequirement.stream().sorted(Comparator.comparing(outputClauseRequirement -> outputClauseRequirement.text)).map(outputClauseRequirement -> buildOutputClause(dTable, outputClauseRequirement.typeRef, outputClauseRequirement.text)).forEach(outputClause -> {
            dTable.getOutput().add(outputClause);
            populateOutputEntries(decisionRule);
        });
    }
}
Also used : DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DecisionTableOrientation(org.kie.workbench.common.dmn.api.definition.model.DecisionTableOrientation) ANY(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType.ANY) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) ItemDefinitionUtils(org.kie.workbench.common.dmn.client.editors.types.common.ItemDefinitionUtils) TypeRefUtils(org.kie.workbench.common.dmn.client.editors.expressions.util.TypeRefUtils) HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) Predicate(java.util.function.Predicate) NULL_NS_URI(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) HitPolicy(org.kie.workbench.common.dmn.api.definition.model.HitPolicy) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Node(org.kie.workbench.common.stunner.core.graph.Node) BuiltInTypeUtils.isBuiltInType(org.kie.workbench.common.dmn.api.editors.types.BuiltInTypeUtils.isBuiltInType) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) ExpressionEditorModelEnricher(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorModelEnricher) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) Comparator(java.util.Comparator) Collections(java.util.Collections) HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) QName(org.kie.workbench.common.dmn.api.property.dmn.QName)

Example 19 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricher method buildOutputClause.

private OutputClause buildOutputClause(final DecisionTable dtable, final QName typeRef, final String text) {
    final OutputClause outputClause = new OutputClause();
    outputClause.setName(text);
    outputClause.setTypeRef(typeRef);
    outputClause.setParent(dtable);
    return outputClause;
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause)

Example 20 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricher method enrichOutputClauses.

void enrichOutputClauses(final DecisionTable dtable) {
    if (dtable.getParent() instanceof ContextEntry && dtable.getOutput().isEmpty()) {
        final ContextEntry contextEntry = (ContextEntry) dtable.getParent();
        final OutputClause outputClause = new OutputClause();
        outputClause.setName(getOutputClauseName(contextEntry).orElse(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable)));
        outputClause.setTypeRef(getOutputClauseTypeRef(contextEntry).orElse(BuiltInType.UNDEFINED.asQName()));
        dtable.getOutput().add(outputClause);
        dtable.getRule().stream().forEach(decisionRule -> {
            final LiteralExpression decisionRuleLiteralExpression = new LiteralExpression();
            decisionRuleLiteralExpression.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT);
            decisionRule.getOutputEntry().add(decisionRuleLiteralExpression);
            decisionRuleLiteralExpression.setParent(decisionRule);
        });
        outputClause.setParent(dtable);
    }
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Aggregations

OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)40 Test (org.junit.Test)24 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)14 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)12 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)10 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)9 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)7 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)7 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)6 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)6 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)5 Before (org.junit.Before)4 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)4 TOutputClause (org.kie.dmn.model.v1_2.TOutputClause)4 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)4