Search in sources :

Example 1 with InputClauseLiteralExpression

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

the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseNameWithExistingInputClauses.

@Test
public void testGetNewInputClauseNameWithExistingInputClauses() {
    final InputClause inputClause1 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause1);
    inputClause1.getInputExpression().getText().setValue("input");
    final InputClause inputClause2 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause2);
    inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
    assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
}
Also used : InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 2 with InputClauseLiteralExpression

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

the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseName.

@Test
public void testGetNewInputClauseName() {
    final InputClause inputClause1 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause1);
    inputClause1.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
    assertThat(inputClause1.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
    final InputClause inputClause2 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause2);
    inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
    assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "2");
}
Also used : InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 3 with InputClauseLiteralExpression

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

the class InputClauseLiteralExpressionPropertyConverter method wbFromDMN.

public static InputClauseLiteralExpression wbFromDMN(final JSITLiteralExpression dmn) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final Text text = new Text(dmn.getText());
    final ImportedValues importedValues = ImportedValuesConverter.wbFromDMN(dmn.getImportedValues());
    final InputClauseLiteralExpression result = new InputClauseLiteralExpression(id, description, typeRef, text, importedValues);
    if (Objects.nonNull(importedValues)) {
        importedValues.setParent(result);
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ImportedValues(org.kie.workbench.common.dmn.api.definition.model.ImportedValues) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 4 with InputClauseLiteralExpression

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

the class AddInputClauseCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            dtable.getComponentWidths().add(uiColumnIndex, null);
            final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            dtable.getInput().add(clauseIndex, inputClause);
            final InputClauseLiteralExpression le = new InputClauseLiteralExpression();
            inputClause.setInputExpression(le);
            le.getText().setValue(name);
            dtable.getRule().forEach(rule -> {
                final UnaryTests ut = new UnaryTests();
                ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
                rule.getInputEntry().add(clauseIndex, ut);
                ut.setParent(rule);
            });
            inputClause.setParent(dtable);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            dtable.getComponentWidths().remove(uiColumnIndex);
            final int clauseIndex = dtable.getInput().indexOf(inputClause);
            dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex));
            dtable.getInput().remove(inputClause);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 5 with InputClauseLiteralExpression

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

Aggregations

InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)10 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)7 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 Test (org.junit.Test)3 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)3 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)3 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)2 ImportedValues (org.kie.workbench.common.dmn.api.definition.model.ImportedValues)2 InputClauseUnaryTests (org.kie.workbench.common.dmn.api.definition.model.InputClauseUnaryTests)2 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)2 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1