Search in sources :

Example 1 with Decision

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

the class DMNMarshallerStandalone method stunnerToDDExt.

@SuppressWarnings("unchecked")
private static DMNShape stunnerToDDExt(final Definitions definitions, final View<? extends DMNElement> v) {
    final DMNShape result = new org.kie.dmn.model.v1_2.dmndi.DMNShape();
    result.setId("dmnshape-" + v.getDefinition().getId().getValue());
    result.setDmnElementRef(getDmnElementRef(definitions, v));
    final Bounds bounds = new org.kie.dmn.model.v1_2.dmndi.Bounds();
    result.setBounds(bounds);
    bounds.setX(xOfBound(upperLeftBound(v)));
    bounds.setY(yOfBound(upperLeftBound(v)));
    result.setStyle(new org.kie.dmn.model.v1_2.dmndi.DMNStyle());
    result.setDMNLabel(new org.kie.dmn.model.v1_2.dmndi.DMNLabel());
    if (v.getDefinition() instanceof Decision) {
        final Decision d = (Decision) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getStylingSet(), result);
        applyFontStyle(d.getStylingSet(), result);
    } else if (v.getDefinition() instanceof InputData) {
        final InputData d = (InputData) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getStylingSet(), result);
        applyFontStyle(d.getStylingSet(), result);
    } else if (v.getDefinition() instanceof BusinessKnowledgeModel) {
        final BusinessKnowledgeModel d = (BusinessKnowledgeModel) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getStylingSet(), result);
        applyFontStyle(d.getStylingSet(), result);
    } else if (v.getDefinition() instanceof KnowledgeSource) {
        final KnowledgeSource d = (KnowledgeSource) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getStylingSet(), result);
        applyFontStyle(d.getStylingSet(), result);
    } else if (v.getDefinition() instanceof TextAnnotation) {
        final TextAnnotation d = (TextAnnotation) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getStylingSet(), result);
        applyFontStyle(d.getStylingSet(), result);
    } else if (v.getDefinition() instanceof DecisionService) {
        final DecisionService d = (DecisionService) v.getDefinition();
        applyBounds(d.getDimensionsSet(), bounds);
        applyBackgroundStyles(d.getStylingSet(), result);
        applyFontStyle(d.getStylingSet(), result);
        final DMNDecisionServiceDividerLine dl = new org.kie.dmn.model.v1_2.dmndi.DMNDecisionServiceDividerLine();
        final org.kie.dmn.model.api.dmndi.Point leftPoint = new org.kie.dmn.model.v1_2.dmndi.Point();
        leftPoint.setX(v.getBounds().getUpperLeft().getX());
        final double dlY = v.getBounds().getUpperLeft().getY() + d.getDividerLineY().getValue();
        leftPoint.setY(dlY);
        dl.getWaypoint().add(leftPoint);
        final org.kie.dmn.model.api.dmndi.Point rightPoint = new org.kie.dmn.model.v1_2.dmndi.Point();
        rightPoint.setX(v.getBounds().getLowerRight().getX());
        rightPoint.setY(dlY);
        dl.getWaypoint().add(rightPoint);
        result.setDMNDecisionServiceDividerLine(dl);
    }
    return result;
}
Also used : Bounds(org.kie.dmn.model.api.dmndi.Bounds) DMNDecisionServiceDividerLine(org.kie.dmn.model.api.dmndi.DMNDecisionServiceDividerLine) Point(org.kie.dmn.model.api.dmndi.Point) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) DMNShape(org.kie.dmn.model.api.dmndi.DMNShape) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)

Example 2 with Decision

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

the class DecisionConverter method nodeFromDMN.

@Override
public Node<View<Decision>, ?> nodeFromDMN(final org.kie.dmn.model.api.Decision dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    @SuppressWarnings("unchecked") final Node<View<Decision>, ?> node = (Node<View<Decision>, ?>) factoryManager.newElement(dmn.getId(), getDefinitionId(Decision.class)).asNode();
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Name name = new Name(dmn.getName());
    final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
    final Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    final Decision decision = new Decision(id, description, name, new Question(), new AllowedAnswers(), informationItem, expression, new StylingSet(), new GeneralRectangleDimensionsSet());
    decision.setQuestion(QuestionPropertyConverter.wbFromDMN(dmn.getQuestion()));
    decision.setAllowedAnswers(AllowedAnswersPropertyConverter.wbFromDMN(dmn.getAllowedAnswers()));
    node.getContent().setDefinition(decision);
    if (informationItem != null) {
        informationItem.setParent(decision);
    }
    if (expression != null) {
        expression.setParent(decision);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decision);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) GeneralRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.GeneralRectangleDimensionsSet) AllowedAnswers(org.kie.workbench.common.dmn.api.property.dmn.AllowedAnswers) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) Question(org.kie.workbench.common.dmn.api.property.dmn.Question) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId)

Example 3 with Decision

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

the class DMNDiagramUtilsTest method testGetDefinitionsWithConnectedNodes.

@Test
public void testGetDefinitionsWithConnectedNodes() {
    final Decision definition1 = new Decision();
    final DMNDiagram definition2 = new DMNDiagram();
    final Node<View, Edge> node1 = newNode(definition1);
    final Node<View, Edge> node2 = newNode(definition2);
    final Edge<View, Node> edge = new EdgeImpl<>(UUID.uuid());
    node1.getInEdges().add(edge);
    node2.getOutEdges().add(edge);
    edge.setSourceNode(node2);
    edge.setTargetNode(node1);
    graph.addNode(node1);
    graph.addNode(node2);
    final Definitions definitions = utils.getDefinitions(diagram);
    assertNotNull(definitions);
    assertEquals(definition2.getDefinitions(), definitions);
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) 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) Test(org.junit.Test)

Example 4 with Decision

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

the class ExpressionEditorTest method testOnCanvasElementUpdatedDifferentNode.

@Test
@SuppressWarnings("unchecked")
public void testOnCanvasElementUpdatedDifferentNode() {
    final CanvasElementUpdatedEvent event = new CanvasElementUpdatedEvent(canvasHandler, node);
    final Decision differentNodeDefinition = mock(Decision.class);
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(differentNodeDefinition);
    setupExpression(decision, decision, toolbarStateHandler, false);
    testedEditor.handleCanvasElementUpdated(event);
    verify(view, never()).setExpressionNameText(any(Optional.class));
}
Also used : Optional(java.util.Optional) CanvasElementUpdatedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasElementUpdatedEvent) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 5 with Decision

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

the class ContextGridTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(parent.getGridWidget()).thenReturn(parentGridWidget);
    when(parentGridWidget.getModel()).thenReturn(parentGridData);
    when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getGridPanel()).thenReturn(gridPanel);
    when(session.getGridLayer()).thenReturn(gridLayer);
    when(session.getCellEditorControls()).thenReturn(cellEditorControls);
    tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
    tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
    definition = new ContextEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, headerEditor, readOnlyProvider);
    final Decision decision = new Decision();
    decision.setName(new Name(NAME));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    when(undefinedExpressionEditor.getParentInformation()).thenReturn(parent);
    when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
    when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    when(gridLayer.getDomElementContainer()).thenReturn(gridLayerDomElementContainer);
    when(gridLayerDomElementContainer.iterator()).thenReturn(mock(Iterator.class));
    when(gridLayer.getVisibleBounds()).thenReturn(new BaseBounds(0, 0, 100, 200));
    when(gridLayer.getViewport()).thenReturn(viewport);
    when(viewport.getTransform()).thenReturn(transform);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    when(canvasHandler.getGraphIndex()).thenReturn(index);
    when(index.get(Mockito.<String>any())).thenReturn(element);
    when(element.getContent()).thenReturn(mock(Definition.class));
    when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
    when(canvasCommandFactory.updatePropertyValue(any(Element.class), Mockito.<String>any(), any())).thenReturn(mock(UpdateElementPropertyCommand.class));
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Optional(java.util.Optional) Element(org.kie.workbench.common.stunner.core.graph.Element) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) UndefinedExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionEditorDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BaseBounds(org.uberfire.ext.wires.core.grids.client.model.impl.BaseBounds) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Iterator(java.util.Iterator) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Before(org.junit.Before)

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