Search in sources :

Example 36 with ContextEntry

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntry.

@Test
public void testModelEnrichmentWhenParentIsContextEntry() {
    final Decision decision = mock(Decision.class);
    final String name = "context-entry";
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    context.getContextEntry().add(contextEntry);
    contextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(contextEntry);
    contextEntry.setParent(context);
    context.setParent(decision);
    when(decision.asDMNModelInstrumentedBase()).thenReturn(contextEntry);
    definition.enrich(Optional.empty(), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 37 with ContextEntry

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

the class PMMLIncludedModelHandlerTest method makeTopLevelPMMLFunctionDefinition.

private FunctionDefinition makeTopLevelPMMLFunctionDefinition(final String documentName, final String modelName) {
    final FunctionDefinition function = new FunctionDefinition();
    function.setKind(FunctionDefinition.Kind.PMML);
    final Context functionExpression = new Context();
    function.setExpression(functionExpression);
    final ContextEntry functionContextEntry1 = new ContextEntry();
    final InformationItem functionContextEntry1Variable = new InformationItem();
    final LiteralExpressionPMMLDocument functionContextEntry1Value = new LiteralExpressionPMMLDocument();
    functionContextEntry1Variable.getName().setValue(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT);
    functionContextEntry1.setVariable(functionContextEntry1Variable);
    functionContextEntry1Value.getText().setValue("\"" + documentName + "\"");
    functionContextEntry1.setExpression(functionContextEntry1Value);
    final ContextEntry functionContextEntry2 = new ContextEntry();
    final InformationItem functionContextEntry2Variable = new InformationItem();
    final LiteralExpressionPMMLDocumentModel functionContextEntry2Value = new LiteralExpressionPMMLDocumentModel();
    functionContextEntry2Variable.getName().setValue(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL);
    functionContextEntry2.setVariable(functionContextEntry2Variable);
    functionContextEntry2Value.getText().setValue("\"" + modelName + "\"");
    functionContextEntry2.setExpression(functionContextEntry2Value);
    functionExpression.getContextEntry().add(functionContextEntry1);
    functionExpression.getContextEntry().add(functionContextEntry2);
    return function;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 38 with ContextEntry

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

the class PMMLIncludedModelHandlerTest method makeNestedLiteralExpression.

private Context makeNestedLiteralExpression() {
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    final InformationItem variable = new InformationItem();
    variable.getName().setValue("variable");
    contextEntry.setVariable(variable);
    contextEntry.setExpression(new LiteralExpression());
    context.getContextEntry().add(contextEntry);
    return context;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 39 with ContextEntry

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

the class PMMLIncludedModelHandlerTest method assertNestedLiteralExpression.

private void assertNestedLiteralExpression(final Decision decision) {
    assertThat(decision.getExpression()).isInstanceOf(Context.class);
    final Context context = (Context) decision.getExpression();
    assertThat(context.getContextEntry()).hasSize(1);
    final ContextEntry contextEntry = context.getContextEntry().get(0);
    assertThat(contextEntry.getExpression()).isInstanceOf(LiteralExpression.class);
    assertThat(((LiteralExpression) contextEntry.getExpression()).getText().getValue()).isEmpty();
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 40 with ContextEntry

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

the class PMMLIncludedModelHandlerTest method assertNestedFunctionDefinition.

private void assertNestedFunctionDefinition(final BusinessKnowledgeModel bkm, final String expectedDocumentValue, final String expectedModelValue) {
    final FunctionDefinition function = bkm.getEncapsulatedLogic();
    assertThat(function.getExpression()).isInstanceOf(Context.class);
    final Context context = (Context) function.getExpression();
    assertThat(context.getContextEntry()).hasSize(1);
    final ContextEntry contextEntry = context.getContextEntry().get(0);
    assertThat(contextEntry.getExpression()).isInstanceOf(FunctionDefinition.class);
    assertPMMLContextDefinition((FunctionDefinition) contextEntry.getExpression(), expectedDocumentValue, expectedModelValue);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) 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