Search in sources :

Example 1 with TLiteralExpression

use of org.kie.dmn.model.v1_2.TLiteralExpression in project drools by kiegroup.

the class XLS2DMNParser method appendDecisionDT.

private void appendDecisionDT(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
    for (DTHeaderInfo hi : headerInfos.values()) {
        Decision decision = new TDecision();
        decision.setName(hi.getSheetName());
        decision.setId("d_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        InformationItem variable = new TInformationItem();
        variable.setName(hi.getSheetName());
        variable.setId("dvar_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        variable.setTypeRef(new QName("Any"));
        decision.setVariable(variable);
        for (String ri : hi.getRequiredInput()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#id_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredInput(er);
            decision.getInformationRequirement().add(ir);
        }
        for (String ri : hi.getRequiredDecision()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#d_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredDecision(er);
            decision.getInformationRequirement().add(ir);
        }
        DecisionTable dt = new TDecisionTable();
        dt.setOutputLabel(hi.getSheetName());
        dt.setId("ddt_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        dt.setHitPolicy(HitPolicy.ANY);
        for (String ri : hi.getRequiredInput()) {
            InputClause ic = new TInputClause();
            ic.setLabel(ri);
            LiteralExpression le = new TLiteralExpression();
            le.setText(ri);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        for (String rd : hi.getRequiredDecision()) {
            InputClause ic = new TInputClause();
            ic.setLabel(rd);
            LiteralExpression le = new TLiteralExpression();
            le.setText(rd);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        OutputClause oc = new TOutputClause();
        dt.getOutput().add(oc);
        decision.setExpression(dt);
        definitions.getDrgElement().add(decision);
    }
}
Also used : TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) Decision(org.kie.dmn.model.api.Decision) TDecision(org.kie.dmn.model.v1_2.TDecision) OutputClause(org.kie.dmn.model.api.OutputClause) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TInputClause(org.kie.dmn.model.v1_2.TInputClause) TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) InformationRequirement(org.kie.dmn.model.api.InformationRequirement) TDecision(org.kie.dmn.model.v1_2.TDecision) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) TInputClause(org.kie.dmn.model.v1_2.TInputClause) InputClause(org.kie.dmn.model.api.InputClause)

Example 2 with TLiteralExpression

use of org.kie.dmn.model.v1_2.TLiteralExpression in project drools by kiegroup.

the class DTSheetListener method newCell.

@Override
public void newCell(int row, int column, String value, int mergedColStart) {
    if (row == 0) {
        // TODO row 0 being the header.
        return;
    }
    if (curRule == null) {
        return;
    }
    if (value == null || value.isEmpty()) {
        LOG.trace("ignoring row {}, col {} having value {}", row, column, value);
        return;
    }
    if (column < headerInfo.gethIndex()) {
        valueCheck(row, column, value);
        UnaryTests ut = new TUnaryTests();
        ut.setText(eValue(value));
        curRule.getInputEntry().add(ut);
    } else if (column == headerInfo.gethIndex()) {
        valueCheck(row, column, value);
        LiteralExpression le = new TLiteralExpression();
        le.setText(eValue(value));
        curRule.getOutputEntry().add(le);
    } else {
        LOG.trace("ignoring row {}, col {} having value {}", row, column, value);
    }
}
Also used : TUnaryTests(org.kie.dmn.model.v1_2.TUnaryTests) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) TUnaryTests(org.kie.dmn.model.v1_2.TUnaryTests) UnaryTests(org.kie.dmn.model.api.UnaryTests)

Example 3 with TLiteralExpression

use of org.kie.dmn.model.v1_2.TLiteralExpression in project kie-wb-common by kiegroup.

the class BaseLiteralExpressionPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final LiteralExpression dmn = new TLiteralExpression();
    final QName typeRef = new QName(KIE.getUri(), LOCAL, KIE.getPrefix());
    final ImportedValues importedValues = new TImportedValues();
    importedValues.setImportedElement(IMPORTED_ELEMENT);
    dmn.setId(UUID);
    dmn.setDescription(DESCRIPTION);
    dmn.setTypeRef(typeRef);
    dmn.setText(TEXT);
    dmn.setImportedValues(importedValues);
    final T wb = convertWBFromDMN(dmn);
    assertThat(wb.getId().getValue()).isEqualTo(UUID);
    assertThat(wb.getDescription().getValue()).isEqualTo(DESCRIPTION);
    assertThat(wb.getTypeRef().getNamespaceURI()).isEqualTo(KIE.getUri());
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(LOCAL);
    assertThat(wb.getTypeRef().getPrefix()).isEqualTo(KIE.getPrefix());
    assertThat(wb.getText().getValue()).isEqualTo(TEXT);
    assertThat(wb.getImportedValues().getImportedElement()).isEqualTo(IMPORTED_ELEMENT);
    assertThat(wb.getImportedValues().getParent()).isEqualTo(wb);
}
Also used : QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) ImportedValues(org.kie.dmn.model.api.ImportedValues) TImportedValues(org.kie.dmn.model.v1_2.TImportedValues) TImportedValues(org.kie.dmn.model.v1_2.TImportedValues) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) Test(org.junit.Test)

Example 4 with TLiteralExpression

use of org.kie.dmn.model.v1_2.TLiteralExpression in project kie-wb-common by kiegroup.

the class InvocationPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.Invocation dmn = new TInvocation();
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setId(INVOCATION_UUID);
    dmn.setDescription(INVOCATION_DESCRIPTION);
    dmn.setTypeRef(new QName(INVOCATION_QNAME_LOCALPART));
    dmn.setExpression(literalExpression);
    final Invocation wb = InvocationPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(INVOCATION_UUID);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(INVOCATION_DESCRIPTION);
    assertThat(wb.getTypeRef()).isNotNull();
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(INVOCATION_QNAME_LOCALPART);
    assertThat(wb.getExpression()).isNotNull();
    assertThat(wb.getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
    verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
    final HasComponentWidths hasComponentWidths = hasComponentWidthsCaptor.getValue();
    assertThat(hasComponentWidths).isNotNull();
    assertThat(hasComponentWidths).isEqualTo(wb.getExpression());
}
Also used : TInvocation(org.kie.dmn.model.v1_2.TInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) QName(javax.xml.namespace.QName) TInvocation(org.kie.dmn.model.v1_2.TInvocation) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Test(org.junit.Test)

Example 5 with TLiteralExpression

use of org.kie.dmn.model.v1_2.TLiteralExpression in project kie-wb-common by kiegroup.

the class FunctionDefinitionPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.FunctionDefinition dmn = new TFunctionDefinition();
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setId(FUNCTION_DEFINITION_UUID);
    dmn.setDescription(FUNCTION_DEFINITION_DESCRIPTION);
    dmn.setTypeRef(new QName(FUNCTION_DEFINITION_QNAME_LOCALPART));
    dmn.setKind(FunctionKind.JAVA);
    dmn.setExpression(literalExpression);
    final FunctionDefinition wb = FunctionDefinitionPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(FUNCTION_DEFINITION_UUID);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(FUNCTION_DEFINITION_DESCRIPTION);
    assertThat(wb.getTypeRef()).isNotNull();
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(FUNCTION_DEFINITION_QNAME_LOCALPART);
    assertThat(wb.getKind()).isNotNull();
    assertThat(wb.getKind()).isEqualTo(FunctionDefinition.Kind.JAVA);
    assertThat(wb.getExpression()).isNotNull();
    assertThat(wb.getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
    verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
    final HasComponentWidths hasComponentWidths = hasComponentWidthsCaptor.getValue();
    assertThat(hasComponentWidths).isNotNull();
    assertThat(hasComponentWidths).isEqualTo(wb.getExpression());
}
Also used : TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) QName(javax.xml.namespace.QName) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Test(org.junit.Test)

Aggregations

TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)13 Test (org.junit.Test)10 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)8 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)7 QName (javax.xml.namespace.QName)6 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)4 TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)3 UnaryTests (org.kie.dmn.model.api.UnaryTests)2 TContextEntry (org.kie.dmn.model.v1_2.TContextEntry)2 TDecision (org.kie.dmn.model.v1_2.TDecision)2 TList (org.kie.dmn.model.v1_2.TList)2 TUnaryTests (org.kie.dmn.model.v1_2.TUnaryTests)2 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)2 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)2 DMNElementReference (org.kie.dmn.model.api.DMNElementReference)1 Decision (org.kie.dmn.model.api.Decision)1 DecisionTable (org.kie.dmn.model.api.DecisionTable)1 ImportedValues (org.kie.dmn.model.api.ImportedValues)1