Search in sources :

Example 16 with InputData

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

the class DecisionComponentFilterTest method testQueryFilteredByTerm.

@Test
public void testQueryFilteredByTerm() {
    final DecisionComponentsItem item1 = item("Can Drive?", new Decision());
    final DecisionComponentsItem item2 = item("Is Allowed?", new Decision());
    final DecisionComponentsItem item3 = item("Age", new InputData());
    final DecisionComponentsItem item4 = item("Name", new InputData());
    final Stream<DecisionComponentsItem> stream = Stream.of(item1, item2, item3, item4);
    filter.setTerm("name");
    final Stream<DecisionComponentsItem> query = filter.query(stream);
    final List<DecisionComponentsItem> actualResult = query.collect(Collectors.toList());
    final List<DecisionComponentsItem> expectedResult = singletonList(item4);
    assertEquals(expectedResult, actualResult);
}
Also used : InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 17 with InputData

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

the class DMNDeepCloneProcessTest method testCloneWhenSourceIsInputData.

@Test
public void testCloneWhenSourceIsInputData() {
    final InputData source = buildInputData();
    setLinks(source, FIRST_URL, SECOND_URL);
    final InputData cloned = dmnDeepCloneProcess.clone(source, new InputData());
    assertThat(cloned).isNotNull();
    assertThat(cloned.getId().getValue()).isNotEqualTo(SOURCE_ID);
    assertThat(cloned.getName().getValue()).isEqualTo(INPUT_DATA_NAME + FIRST_INDEX_IN_SUFFIX);
    assertThat(cloned.getVariable().getTypeRef()).isEqualTo(BuiltInType.STRING.asQName());
    assertThat(cloned.getLinksHolder().getValue().getLinks()).hasSize(2).extracting(DMNExternalLink::getUrl).contains(FIRST_URL, SECOND_URL);
}
Also used : InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) AbstractCloneProcessTest(org.kie.workbench.common.stunner.core.definition.clone.AbstractCloneProcessTest) Test(org.junit.Test)

Example 18 with InputData

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

the class TextAnnotationTextPropertyProviderImplTest method checkSupportsTextAnnotationElements.

@Test
@SuppressWarnings("unchecked")
public void checkSupportsTextAnnotationElements() {
    assertTrue(provider.supports(element));
    final Element other = mock(Element.class);
    final Definition otherContent = mock(Definition.class);
    final InputData otherDefinition = mock(InputData.class);
    when(other.getContent()).thenReturn(otherContent);
    when(otherContent.getDefinition()).thenReturn(otherDefinition);
    assertFalse(provider.supports(other));
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Test(org.junit.Test)

Example 19 with InputData

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

the class DecisionTableEditorDefinitionEnricher method enrichInputClauses.

@SuppressWarnings("unchecked")
void enrichInputClauses(final String uuid, final DecisionTable dtable) {
    final Graph<?, Node> graph = sessionManager.getCurrentSession().getCanvasHandler().getDiagram().getGraph();
    final Node<?, Edge> node = graph.getNode(uuid);
    if (Objects.isNull(node)) {
        return;
    }
    // Get all Decision nodes feeding into this DecisionTable
    final List<Decision> decisionSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof Decision).map(definition -> (Decision) definition).collect(Collectors.toList());
    // Get all InputData nodes feeding into this DecisionTable
    final List<InputData> inputDataSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof InputData).map(definition -> (InputData) definition).collect(Collectors.toList());
    if (decisionSet.isEmpty() && inputDataSet.isEmpty()) {
        return;
    }
    // Extract individual components of InputData TypeRefs
    final Definitions definitions = dmnGraphUtils.getModelDefinitions();
    final List<ClauseRequirement> inputClauseRequirements = new ArrayList<>();
    decisionSet.forEach(decision -> addInputClauseRequirement(decision.getVariable().getTypeRef(), definitions, inputClauseRequirements, decision.getName().getValue()));
    inputDataSet.forEach(inputData -> addInputClauseRequirement(inputData.getVariable().getTypeRef(), definitions, inputClauseRequirements, inputData.getName().getValue()));
    // Add InputClause columns for each InputData TypeRef component, sorted alphabetically
    dtable.getInput().clear();
    dtable.getRule().stream().forEach(decisionRule -> decisionRule.getInputEntry().clear());
    inputClauseRequirements.stream().sorted(Comparator.comparing(inputClauseRequirement -> inputClauseRequirement.text)).forEach(inputClauseRequirement -> {
        final InputClause inputClause = new InputClause();
        final InputClauseLiteralExpression literalExpression = new InputClauseLiteralExpression();
        literalExpression.getText().setValue(inputClauseRequirement.text);
        literalExpression.setTypeRef(inputClauseRequirement.typeRef);
        inputClause.setInputExpression(literalExpression);
        dtable.getInput().add(inputClause);
        dtable.getRule().stream().forEach(decisionRule -> {
            final UnaryTests decisionRuleUnaryTest = new UnaryTests();
            decisionRuleUnaryTest.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
            decisionRule.getInputEntry().add(decisionRuleUnaryTest);
            decisionRuleUnaryTest.setParent(decisionRule);
        });
        inputClause.setParent(dtable);
        literalExpression.setParent(inputClause);
    });
}
Also used : DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DecisionTableOrientation(org.kie.workbench.common.dmn.api.definition.model.DecisionTableOrientation) ANY(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType.ANY) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) ItemDefinitionUtils(org.kie.workbench.common.dmn.client.editors.types.common.ItemDefinitionUtils) TypeRefUtils(org.kie.workbench.common.dmn.client.editors.expressions.util.TypeRefUtils) HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) Predicate(java.util.function.Predicate) NULL_NS_URI(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) HitPolicy(org.kie.workbench.common.dmn.api.definition.model.HitPolicy) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Node(org.kie.workbench.common.stunner.core.graph.Node) BuiltInTypeUtils.isBuiltInType(org.kie.workbench.common.dmn.api.editors.types.BuiltInTypeUtils.isBuiltInType) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) ExpressionEditorModelEnricher(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorModelEnricher) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) Comparator(java.util.Comparator) Collections(java.util.Collections) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 20 with InputData

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

the class DMNIncludedModelHandlerTest method testDestroy.

@Test
public void testDestroy() {
    final Decision drgElement1 = makeDecision("model1.tUUID", "string", true);
    final Decision drgElement2 = makeDecision("model1.imported person", "model1.tPerson", true);
    final InputData drgElement3 = makeInputData("local person", "model1.tPerson", false);
    final InputData drgElement4 = makeInputData("regular DRG Element", "boolean", false);
    final List<DRGElement> drgElements = asList(drgElement1, drgElement2, drgElement3, drgElement4);
    doNothing().when(handler).deleteDRGElement(any());
    when(dmnGraphUtils.getModelDRGElements()).thenReturn(drgElements);
    handler.destroy("model1");
    verify(handler).deleteDRGElement(drgElement1);
    verify(handler).deleteDRGElement(drgElement2);
}
Also used : InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Aggregations

InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)67 Test (org.junit.Test)42 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)37 View (org.kie.workbench.common.stunner.core.graph.content.view.View)26 Node (org.kie.workbench.common.stunner.core.graph.Node)22 Edge (org.kie.workbench.common.stunner.core.graph.Edge)21 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)17 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)17 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)15 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)13 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)13 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)12 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)11 Optional (java.util.Optional)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)8 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)8 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7