Search in sources :

Example 1 with DMNModelInstrumentedBase

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsBKM.

@Test
public void testModelEnrichmentWhenParentIsBKM() {
    final FunctionDefinition functionDefinition = mock(FunctionDefinition.class);
    final DMNModelInstrumentedBase dmnModelInstrumentedBase = mock(DMNModelInstrumentedBase.class);
    final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
    businessKnowledgeModel.setVariable(new InformationItemPrimary(new Id(), new Name(), OUTPUT_DATA_QNAME));
    businessKnowledgeModel.setEncapsulatedLogic(functionDefinition);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(functionDefinition);
    when(functionDefinition.asDMNModelInstrumentedBase()).thenReturn(dmnModelInstrumentedBase);
    when(dmnModelInstrumentedBase.getParent()).thenReturn(businessKnowledgeModel);
    definition.enrich(Optional.empty(), functionDefinition, 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 : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) 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 2 with DMNModelInstrumentedBase

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

the class DecisionTableEditorDefinitionEnricher method getOutputClauseTypeRef.

private Optional<QName> getOutputClauseTypeRef(final HasVariable hasVariable) {
    final IsInformationItem variable = hasVariable.getVariable();
    if (Objects.nonNull(variable)) {
        return Optional.ofNullable(variable.getTypeRef());
    }
    final DMNModelInstrumentedBase base = hasVariable.asDMNModelInstrumentedBase().getParent();
    final DMNModelInstrumentedBase parent = base.getParent();
    if (parent instanceof HasTypeRef) {
        return Optional.ofNullable(((HasTypeRef) parent).getTypeRef());
    }
    if (parent instanceof HasVariable) {
        return getOutputClauseTypeRef((HasVariable) parent);
    }
    return Optional.empty();
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)

Example 3 with DMNModelInstrumentedBase

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

the class HasTypeRefHelperTest method testGetFlatHasTypeRefsFromExpressions.

@Test
public void testGetFlatHasTypeRefsFromExpressions() {
    final Expression expression1 = mock(Expression.class);
    final Expression expression2 = mock(Expression.class);
    final DMNModelInstrumentedBase parent = mock(DMNModelInstrumentedBase.class);
    final HasExpression hasExpression1 = HasExpression.wrap(parent, expression1);
    final HasExpression hasExpression2 = HasExpression.wrap(parent, expression2);
    final List<HasExpression> hasExpressions = asList(hasExpression1, hasExpression2);
    final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef3 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef4 = mock(HasTypeRef.class);
    final List<HasTypeRef> typeRefList1 = asList(hasTypeRef1, hasTypeRef2);
    final List<HasTypeRef> typeRefList2 = asList(hasTypeRef3, hasTypeRef4);
    when(expression1.getHasTypeRefs()).thenReturn(typeRefList1);
    when(expression2.getHasTypeRefs()).thenReturn(typeRefList2);
    final List<HasTypeRef> actual = HasTypeRefHelper.getFlatHasTypeRefsFromExpressions(hasExpressions);
    final List<HasTypeRef> expected = asList(hasTypeRef1, hasTypeRef2, hasTypeRef3, hasTypeRef4);
    assertEquals(expected, actual);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Test(org.junit.Test)

Example 4 with DMNModelInstrumentedBase

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

the class TypeRefUtils method getTypeRefOfExpression.

public static <E extends Expression> HasTypeRef getTypeRefOfExpression(final E expression, final HasExpression hasExpression) {
    HasTypeRef hasTypeRef = expression;
    final DMNModelInstrumentedBase base = hasExpression.asDMNModelInstrumentedBase();
    if (base instanceof HasVariable) {
        final HasVariable hasVariable = (HasVariable) base;
        hasTypeRef = hasVariable.getVariable();
    }
    return hasTypeRef;
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)

Example 5 with DMNModelInstrumentedBase

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

the class RelationGridTest method testAsDMNModelInstrumentedBase.

@Test
public void testAsDMNModelInstrumentedBase() {
    setupGrid(0);
    final DMNModelInstrumentedBase actual = extractHeaderMetaData().asDMNModelInstrumentedBase();
    assertThat(actual).isInstanceOf(InformationItem.class);
}
Also used : DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Test(org.junit.Test)

Aggregations

DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)11 Test (org.junit.Test)3 HasTypeRef (org.kie.workbench.common.dmn.api.definition.HasTypeRef)3 HasVariable (org.kie.workbench.common.dmn.api.definition.HasVariable)3 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)3 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)3 Node (org.kie.workbench.common.stunner.core.graph.Node)3 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)3 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)3 HasName (org.kie.workbench.common.dmn.api.definition.HasName)2 IsInformationItem (org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)2 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2 Point2D (com.ait.lienzo.client.core.types.Point2D)1 List (java.util.List)1 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)1 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)1 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)1