Search in sources :

Example 31 with Decision

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

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

the class PMMLIncludedModelHandler method destroy.

@Override
public void destroy(final String oldModelName) {
    final List<Decision> decisions = getDecisions();
    final List<BusinessKnowledgeModel> businessKnowledgeModels = getBusinessKnowledgeModels();
    final List<FunctionDefinition> functions = getPMMLFunctionDefinitions(decisions, businessKnowledgeModels);
    final Map<FunctionDefinition, Context> contexts = getPMMLContexts(functions);
    // The values in the DMN model are stored with quotes
    final String quotedOldModelName = StringUtils.createQuotedString(oldModelName);
    for (final Map.Entry<FunctionDefinition, Context> entry : contexts.entrySet()) {
        final Context context = entry.getValue();
        for (final ContextEntry contextEntry : context.getContextEntry()) {
            if (Objects.equals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, contextEntry.getVariable().getName().getValue())) {
                final Expression expression = contextEntry.getExpression();
                if (expression instanceof IsLiteralExpression) {
                    final IsLiteralExpression ile = (IsLiteralExpression) expression;
                    if (Objects.nonNull(ile.getText())) {
                        final Text text = ile.getText();
                        if (Objects.equals(quotedOldModelName, text.getValue())) {
                            clearContextValues(context);
                            entry.getKey().getFormalParameter().clear();
                        }
                    }
                }
            }
        }
    }
    // Refresh cached grids from the DMN model
    refreshCachedExpressionGrids(decisions, businessKnowledgeModels);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Map(java.util.Map)

Example 33 with Decision

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

the class DMNCommonActionsToolboxFactoryTest method testAddEditDecisionAction.

@Test
public void testAddEditDecisionAction() {
    final List<ToolboxAction<AbstractCanvasHandler>> actions = new ArrayList<>();
    final Element element = mock(Element.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final Decision decision = mock(Decision.class);
    when(element.asNode()).thenReturn(node);
    when(element.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(decision);
    tested.addEditAction(element, actions);
    assertEquals(1, actions.size());
    assertTrue(DMNEditDecisionToolboxAction.class.isInstance(actions.get(0)));
}
Also used : ToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ToolboxAction) DeleteNodeToolboxAction(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.DeleteNodeToolboxAction) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 34 with Decision

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

the class DMNDeepCloneProcess method clone.

/**
 * <p>It defines additive fields, specific to DMN domain, to be included in the target</p>
 * <p>Then, the "classic" clone operation, defined in {@link DeepCloneProcess} will be executed</p>
 * <p>Note that {@link DeepCloneProcess} is already taking care of aspects related to look&feel, such as background color, font, etc.</p>
 * <p>Every time we copy a node, in order to respect the name uniqueness logic, a new node will be created with a suffix {@code -X},
 * where {@code X} it is an incremental numeric value</p>
 *
 * @param source node to be cloned
 * @param target destination of the cloning operation
 * @return cloned instance, i.e. target element
 */
@Override
public <S, T> T clone(final S source, final T target) {
    super.clone(source, target);
    if (source instanceof DRGElement) {
        cloneDRGElementBasicInfo((DRGElement) source, (DRGElement) target);
    }
    if (source instanceof HasText) {
        cloneTextElementBasicInfo((HasText) source, (HasText) target);
    }
    if (source instanceof HasVariable) {
        final IsInformationItem sourceVariable = ((HasVariable) source).getVariable();
        final IsInformationItem targetVariable = ((HasVariable) target).getVariable();
        cloneTypeRefInfo(sourceVariable, targetVariable);
    }
    if (source instanceof Decision) {
        cloneDecision((Decision) source, (Decision) target);
    }
    if (source instanceof BusinessKnowledgeModel) {
        cloneBusinessKnowledgeModel((BusinessKnowledgeModel) source, (BusinessKnowledgeModel) target);
    }
    return target;
}
Also used : HasText(org.kie.workbench.common.dmn.api.definition.HasText) HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 35 with Decision

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

the class DMNEditDecisionToolboxAction method onMouseClick.

@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
    // Notice the toolbox factory ensure this action is only being included
    // for Decision definitions, next cast is safe.
    final Node<View<? extends Decision>, Edge> decisionNode = (Node<View<? extends Decision>, Edge>) CanvasLayoutUtils.getElement(canvasHandler, uuid).asNode();
    final Decision decision = (Decision) DefinitionUtils.getElementDefinition(decisionNode);
    final boolean isReadOnly = decision.isAllowOnlyVisualChange() || readOnlyProvider.isReadOnlyDiagram();
    editExpressionEvent.fire(new EditExpressionEvent(sessionManager.getCurrentSession(), uuid, decision, Optional.of(decision), isReadOnly));
    return this;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision)

Aggregations

Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)121 Test (org.junit.Test)79 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)39 View (org.kie.workbench.common.stunner.core.graph.content.view.View)38 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)37 Node (org.kie.workbench.common.stunner.core.graph.Node)28 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)23 Edge (org.kie.workbench.common.stunner.core.graph.Edge)23 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)22 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)21 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)20 List (java.util.List)16 TDecision (org.kie.dmn.model.v1_2.TDecision)16 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)16 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)16 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)16 ArrayList (java.util.ArrayList)15 Optional (java.util.Optional)15 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)15