Search in sources :

Example 16 with ContextEntry

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

the class PMMLFunctionEditorDefinition method enrich.

@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<Context> expression) {
    expression.ifPresent(context -> {
        final List<String> variableNames = getVariableNames();
        final ContextEntry contextEntryDocument = new ContextEntry();
        contextEntryDocument.setVariable(createVariable(variableNames.get(0)));
        contextEntryDocument.setExpression(new LiteralExpressionPMMLDocument());
        context.getContextEntry().add(contextEntryDocument);
        contextEntryDocument.setParent(context);
        final ContextEntry contextEntryDocumentModel = new ContextEntry();
        contextEntryDocumentModel.setVariable(createVariable(variableNames.get(1)));
        contextEntryDocumentModel.setExpression(new LiteralExpressionPMMLDocumentModel());
        context.getContextEntry().add(contextEntryDocumentModel);
        contextEntryDocumentModel.setParent(context);
    });
}
Also used : LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 17 with ContextEntry

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

the class DMNMarshallerStandaloneTest method testContextEntryDataType.

@Test
@SuppressWarnings("unchecked")
public void testContextEntryDataType() throws Exception {
    final DMNMarshallerStandalone marshaller = getDMNMarshaller();
    final Context context = new Context();
    context.setTypeRef(BuiltInType.DATE_TIME.asQName());
    final ContextEntry contextEntry = new ContextEntry();
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.setTypeRef(BuiltInType.BOOLEAN.asQName());
    literalExpression.getText().setValue("feel");
    contextEntry.setExpression(literalExpression);
    context.getContextEntry().add(contextEntry);
    final Diagram<Graph, Metadata> mockedDiagram = newDiagramDecisionWithExpression(context);
    final String marshalledSource = marshaller.marshall(mockedDiagram);
    final Graph<?, Node<View, ?>> unmarshalledGraph = marshaller.unmarshall(createMetadata(), new StringInputStream(marshalledSource));
    assertThat(unmarshalledGraph.nodes()).hasSize(2);
    checkDecisionExpression(unmarshalledGraph, context);
}
Also used : NamespaceContext(javax.xml.namespace.NamespaceContext) DMNContext(org.kie.dmn.api.core.DMNContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) StringInputStream(org.apache.tools.ant.filters.StringInputStream) Graph(org.kie.workbench.common.stunner.core.graph.Graph) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Test(org.junit.Test)

Example 18 with ContextEntry

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

the class ContextEntryPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.ContextEntry dmn = new TContextEntry();
    final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
    dmn.setVariable(informationItem);
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setExpression(literalExpression);
    final ContextEntry wb = ContextEntryPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getVariable()).isNotNull();
    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 : TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) Test(org.junit.Test)

Example 19 with ContextEntry

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

the class ContextEntryPropertyConverterTest method testDMNFromWBWithNullWBExpression.

@Test
public void testDMNFromWBWithNullWBExpression() {
    final ContextEntry wb = new ContextEntry();
    final InformationItem informationItem = new InformationItem();
    wb.setVariable(informationItem);
    wb.setExpression(null);
    final org.kie.dmn.model.api.ContextEntry dmn = ContextEntryPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getVariable()).isNotNull();
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression()).isInstanceOf(org.kie.dmn.model.api.LiteralExpression.class);
    final org.kie.dmn.model.api.LiteralExpression literalExpression = (org.kie.dmn.model.api.LiteralExpression) dmn.getExpression();
    assertThat(literalExpression.getText()).isEqualTo(ContextEntry.DEFAULT_EXPRESSION_VALUE);
}
Also used : TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) Test(org.junit.Test)

Example 20 with ContextEntry

use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry 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

ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)40 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)22 Context (org.kie.workbench.common.dmn.api.definition.model.Context)19 Test (org.junit.Test)16 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)6 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)5 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)5 TContextEntry (org.kie.dmn.model.v1_2.TContextEntry)4 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)4 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)4 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)4 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)3 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)3 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)3