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;
}
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;
}
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);
}
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));
}
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());
}
Aggregations