Search in sources :

Example 31 with FunctionDefinition

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

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

the class PMMLIncludedModelHandlerTest method setupBusinessKnowledgeModelWithNestedFunction.

private List<BusinessKnowledgeModel> setupBusinessKnowledgeModelWithNestedFunction() {
    final List<DRGElement> drgElements = new ArrayList<>();
    final BusinessKnowledgeModel bkm1 = new BusinessKnowledgeModel();
    final FunctionDefinition bkm1Function = new FunctionDefinition();
    bkm1Function.setKind(FunctionDefinition.Kind.FEEL);
    bkm1Function.setExpression(makeNestedLiteralExpression());
    bkm1.setEncapsulatedLogic(bkm1Function);
    final BusinessKnowledgeModel bkm2 = new BusinessKnowledgeModel();
    final FunctionDefinition bkm2Function = new FunctionDefinition();
    bkm2Function.setKind(FunctionDefinition.Kind.FEEL);
    bkm2Function.setExpression(makeNestedPMMLFunctionDefinition(DOCUMENT_NAME_ORIGINAL, MODEL_NAME));
    bkm2.setEncapsulatedLogic(bkm2Function);
    final BusinessKnowledgeModel bkm3 = new BusinessKnowledgeModel();
    final FunctionDefinition bkm3Function = new FunctionDefinition();
    bkm3Function.setKind(FunctionDefinition.Kind.FEEL);
    bkm3Function.setExpression(makeNestedPMMLFunctionDefinition(UNAFFECTED_DOCUMENT, UNAFFECTED_MODEL));
    bkm3.setEncapsulatedLogic(bkm3Function);
    drgElements.add(bkm1);
    drgElements.add(bkm2);
    drgElements.add(bkm3);
    when(dmnGraphUtils.getModelDRGElements()).thenReturn(drgElements);
    return Arrays.asList(bkm1, bkm2, bkm3);
}
Also used : BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) ArrayList(java.util.ArrayList) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 33 with FunctionDefinition

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

Example 34 with FunctionDefinition

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

the class PMMLIncludedModelHandlerTest method setupBusinessKnowledgeModelWithTopLevelFunction.

private List<BusinessKnowledgeModel> setupBusinessKnowledgeModelWithTopLevelFunction() {
    final List<DRGElement> drgElements = new ArrayList<>();
    final BusinessKnowledgeModel bkm1 = new BusinessKnowledgeModel();
    final FunctionDefinition bkm1Function = new FunctionDefinition();
    bkm1Function.setKind(FunctionDefinition.Kind.FEEL);
    bkm1Function.setExpression(new LiteralExpression());
    bkm1.setEncapsulatedLogic(bkm1Function);
    final BusinessKnowledgeModel bkm2 = new BusinessKnowledgeModel();
    bkm2.setEncapsulatedLogic(makeTopLevelPMMLFunctionDefinition(DOCUMENT_NAME_ORIGINAL, MODEL_NAME));
    final BusinessKnowledgeModel bkm3 = new BusinessKnowledgeModel();
    bkm3.setEncapsulatedLogic(makeTopLevelPMMLFunctionDefinition(UNAFFECTED_DOCUMENT, UNAFFECTED_MODEL));
    bkm1.getId().setValue(NODE1_UUID);
    bkm2.getId().setValue(NODE2_UUID);
    bkm3.getId().setValue(NODE3_UUID);
    drgElements.add(bkm1);
    drgElements.add(bkm2);
    drgElements.add(bkm3);
    when(dmnGraphUtils.getModelDRGElements()).thenReturn(drgElements);
    return Arrays.asList(bkm1, bkm2, bkm3);
}
Also used : BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) ArrayList(java.util.ArrayList) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 35 with FunctionDefinition

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

the class DMNDeepCloneProcessTest method testCloneWhenSourceIsDecision.

@Test
public void testCloneWhenSourceIsDecision() {
    final Decision source = buildDecision();
    setLinks(source, FIRST_URL, SECOND_URL);
    final Decision cloned = dmnDeepCloneProcess.clone(source, new Decision());
    assertThat(cloned).isNotNull();
    assertThat(cloned.getId().getValue()).isNotEqualTo(SOURCE_ID);
    assertThat(cloned.getName().getValue()).isEqualTo(DECISION_SOURCE_NAME + FIRST_INDEX_IN_SUFFIX);
    assertThat(cloned.getLinksHolder().getValue().getLinks()).hasSize(2).extracting(DMNExternalLink::getUrl).contains(FIRST_URL, SECOND_URL);
    assertThat(cloned.getVariable().getTypeRef()).isEqualTo(BuiltInType.BOOLEAN.asQName());
    assertThat(cloned.getQuestion().getValue()).isEqualTo(QUESTION);
    assertThat(cloned.getAllowedAnswers().getValue()).isEqualTo(ANSWER);
    assertThat(cloned.getExpression()).isNotNull();
    assertThat(cloned.getExpression()).isInstanceOf(FunctionDefinition.class);
    assertThat(cloned.getExpression().getId().getValue()).isNotEqualTo(FUNCTION_ID);
    assertThat(cloned.getExpression().getTypeRef()).isEqualTo(BuiltInType.BOOLEAN.asQName());
    assertThat(((FunctionDefinition) cloned.getExpression()).getExpression()).isInstanceOf(Context.class);
    assertThat(((FunctionDefinition) cloned.getExpression()).getExpression().getId()).isNotEqualTo(CONTEXT_ID);
    assertThat(((FunctionDefinition) cloned.getExpression()).getExpression().getTypeRef()).isEqualTo(BuiltInType.NUMBER.asQName());
}
Also used : FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) AbstractCloneProcessTest(org.kie.workbench.common.stunner.core.definition.clone.AbstractCloneProcessTest) Test(org.junit.Test)

Aggregations

FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)40 Test (org.junit.Test)12 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)12 Context (org.kie.workbench.common.dmn.api.definition.model.Context)11 ArrayList (java.util.ArrayList)8 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)8 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Before (org.junit.Before)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)5 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 List (java.util.List)4 QName (javax.xml.namespace.QName)4 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)4