Search in sources :

Example 96 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class AbstractVFSDiagramService method serialize.

@SuppressWarnings("unchecked")
protected String[] serialize(final D diagram) throws java.io.IOException {
    final String defSetId = diagram.getMetadata().getDefinitionSetId();
    final DefinitionSetService services = getServiceById(defSetId);
    // Serialize using the concrete marshalling service.
    DiagramMarshaller<Graph, Metadata, Diagram<Graph, Metadata>> marshaller = services.getDiagramMarshaller();
    final String rawData = marshaller.marshall((Diagram<Graph, Metadata>) diagram);
    final Metadata metadata = diagram.getMetadata();
    final String metadataRaw = marshaller.getMetadataMarshaller().marshall(metadata);
    return new String[] { rawData, metadataRaw };
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) DefinitionSetService(org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 97 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class AbstractDiagramValidator method validate.

@Override
@SuppressWarnings("unchecked")
public void validate(final Diagram diagram, final Consumer<Collection<DiagramElementViolation<RuleViolation>>> resultConsumer) {
    final Graph graph = diagram.getGraph();
    final List<DiagramElementViolation<RuleViolation>> violations = new LinkedList<>();
    final Collection<DiagramElementViolation<RuleViolation>> diagramElementViolations = validateDomain(diagram);
    violations.addAll(diagramElementViolations);
    graphValidator.validate(graph, Optional.empty(), Optional.of((g, v) -> consumeBeanAndViolations(() -> violations).accept(g, v)), Optional.of((n, v) -> consumeBeanAndViolations(() -> violations).accept(n, v)), Optional.of((e, v) -> consumeBeanAndViolations(() -> violations).accept(e, v)), // to use the resulting ones here.
    vs -> resultConsumer.accept(violations));
}
Also used : ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) DiagramValidator(org.kie.workbench.common.stunner.core.validation.DiagramValidator) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) DomainViolation(org.kie.workbench.common.stunner.core.validation.DomainViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) BiConsumer(java.util.function.BiConsumer) Element(org.kie.workbench.common.stunner.core.graph.Element) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) StreamSupport(java.util.stream.StreamSupport) LinkedList(java.util.LinkedList) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DomainValidator(org.kie.workbench.common.stunner.core.validation.DomainValidator) Collection(java.util.Collection) ModelValidator(org.kie.workbench.common.stunner.core.validation.ModelValidator) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Optional(java.util.Optional) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) Collections(java.util.Collections) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) LinkedList(java.util.LinkedList)

Example 98 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class AssociationsTest method marshallAssociations.

@Test
public void marshallAssociations() throws Exception {
    Diagram<Graph, Metadata> d = unmarshall(marshaller, BPMN_FILE_PATH);
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(d.getGraph());
    Definitions definitions = definitionsConverter.toDefinitions();
    Process p = (Process) definitions.getRootElements().get(0);
    org.eclipse.bpmn2.UserTask flowElement = (org.eclipse.bpmn2.UserTask) p.getFlowElements().stream().filter(e -> e.getId().equals(TASK_ID)).findFirst().get();
    List<DataInputAssociation> associations = flowElement.getDataInputAssociations();
    assertEquals("myprocvar", findVar(associations, "From"));
    assertEquals("<![CDATA[HELLO]]>", findAssignment(associations, "Body"));
}
Also used : StartEvent(org.eclipse.bpmn2.StartEvent) FormalExpression(org.eclipse.bpmn2.FormalExpression) FlatVariableScope(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.FlatVariableScope) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) View(org.kie.workbench.common.stunner.core.graph.content.view.View) HashSet(java.util.HashSet) DataInput(org.eclipse.bpmn2.DataInput) Property(org.eclipse.bpmn2.Property) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Definitions(org.eclipse.bpmn2.Definitions) Ids(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Ids) AssignmentsInfo(org.kie.workbench.common.stunner.bpmn.definition.property.dataio.AssignmentsInfo) Process(org.eclipse.bpmn2.Process) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) Factories.bpmn2(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2) Test(org.junit.Test) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Assignment(org.eclipse.bpmn2.Assignment) CatchEventPropertyWriter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.properties.CatchEventPropertyWriter) BPMNDiagramMarshallerBaseTest(org.kie.workbench.common.stunner.bpmn.backend.service.diagram.marshalling.BPMNDiagramMarshallerBaseTest) Node(org.kie.workbench.common.stunner.core.graph.Node) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Definitions(org.eclipse.bpmn2.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) Process(org.eclipse.bpmn2.Process) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Factories.bpmn2(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.bpmn2) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) Test(org.junit.Test) BPMNDiagramMarshallerBaseTest(org.kie.workbench.common.stunner.bpmn.backend.service.diagram.marshalling.BPMNDiagramMarshallerBaseTest)

Example 99 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DRDContextMenuServiceTest method testRemoveFromCurrentDRD.

@Test
public void testRemoveFromCurrentDRD() {
    final String nodeUUID = "UUID";
    final Node node = mock(Node.class);
    final Diagram diagram = mock(Diagram.class);
    final DMNDiagramElement dmnDiagram = mock(DMNDiagramElement.class);
    when(node.getUUID()).thenReturn(nodeUUID);
    when(dmnDiagramsSession.getCurrentDiagram()).thenReturn(Optional.of(diagram));
    when(dmnDiagramsSession.getCurrentDMNDiagramElement()).thenReturn(Optional.of(dmnDiagram));
    when(diagram.getGraph()).thenReturn(graph);
    drdContextMenuService.removeFromCurrentDRD(singleton(node));
    verify(graph, times(1)).removeNode(nodeUUID);
    verify(selectedEvent, times(1)).fire(Mockito.<DMNDiagramSelected>any());
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Test(org.junit.Test)

Example 100 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DecisionNavigatorItemsProviderTest method testGetItems.

@Test
public void testGetItems() {
    final Diagram stunnerDiagram1 = mock(Diagram.class);
    final Diagram stunnerDiagram2 = mock(Diagram.class);
    final DMNDiagramElement dmnDiagramElement1 = mock(DMNDiagramElement.class);
    final DMNDiagramElement dmnDiagramElement2 = mock(DMNDiagramElement.class);
    final DMNDiagramTuple dmnDiagramTuple1 = new DMNDiagramTuple(stunnerDiagram1, dmnDiagramElement1);
    final DMNDiagramTuple dmnDiagramTuple2 = new DMNDiagramTuple(stunnerDiagram2, dmnDiagramElement2);
    final DecisionNavigatorItem decisionNavigatorItem1 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem2 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem3 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem4 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem5 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem6 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem7 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem8 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem9 = mock(DecisionNavigatorItem.class);
    final DecisionNavigatorItem decisionNavigatorItem10 = mock(DecisionNavigatorItem.class);
    final List<DMNDiagramTuple> diagramTuples = asList(dmnDiagramTuple1, dmnDiagramTuple2);
    final Node node1 = mockNode(new Decision());
    final Node node2 = mockNode(new InputData());
    final Node node3 = mockNode(new TextAnnotation());
    final Node node4 = mockNode(new BusinessKnowledgeModel());
    final Node node5 = mockNode(new KnowledgeSource());
    final Node node6 = mockNode(new TextAnnotation());
    final Stream<Node> stunnerNodes1 = Stream.of(node1, node2, node3);
    final Stream<Node> stunnerNodes2 = Stream.of(node4, node5, node6);
    when(dmnDiagramElement1.getName()).thenReturn(new Name("DRD"));
    when(dmnDiagramElement2.getName()).thenReturn(new Name("DRG"));
    when(dmnDiagramsSession.getDMNDiagrams()).thenReturn(diagramTuples);
    when(itemFactory.makeRoot(dmnDiagramTuple1)).thenReturn(decisionNavigatorItem1);
    when(itemFactory.makeRoot(dmnDiagramTuple2)).thenReturn(decisionNavigatorItem2);
    when(itemFactory.makeItem(node1)).thenReturn(decisionNavigatorItem5);
    when(itemFactory.makeItem(node2)).thenReturn(decisionNavigatorItem6);
    when(itemFactory.makeItem(node3)).thenReturn(decisionNavigatorItem7);
    when(itemFactory.makeItem(node4)).thenReturn(decisionNavigatorItem8);
    when(itemFactory.makeItem(node5)).thenReturn(decisionNavigatorItem9);
    when(itemFactory.makeItem(node6)).thenReturn(decisionNavigatorItem10);
    when(itemFactory.makeSeparator(DRG)).thenReturn(decisionNavigatorItem3);
    when(itemFactory.makeSeparator(DRDs)).thenReturn(decisionNavigatorItem4);
    when(dmnDiagramUtils.getNodeStream(stunnerDiagram1)).thenReturn(stunnerNodes1);
    when(dmnDiagramUtils.getNodeStream(stunnerDiagram2)).thenReturn(stunnerNodes2);
    final List<DecisionNavigatorItem> actualItems = itemsProvider.getItems();
    final List<DecisionNavigatorItem> expectedItems = asList(decisionNavigatorItem3, decisionNavigatorItem2, decisionNavigatorItem4, decisionNavigatorItem1);
    assertEquals(expectedItems, actualItems);
    verify(decisionNavigatorItem1).addChild(decisionNavigatorItem5);
    verify(decisionNavigatorItem1).addChild(decisionNavigatorItem6);
    verify(decisionNavigatorItem1).addChild(decisionNavigatorItem7);
    verify(decisionNavigatorItem2).addChild(decisionNavigatorItem8);
    verify(decisionNavigatorItem2).addChild(decisionNavigatorItem9);
    verify(decisionNavigatorItem2).addChild(decisionNavigatorItem10);
}
Also used : DMNDiagramTuple(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple) Node(org.kie.workbench.common.stunner.core.graph.Node) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Test(org.junit.Test)

Aggregations

Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)128 Test (org.junit.Test)64 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)48 Node (org.kie.workbench.common.stunner.core.graph.Node)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)31 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)24 View (org.kie.workbench.common.stunner.core.graph.content.view.View)23 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)22 ArrayList (java.util.ArrayList)20 List (java.util.List)20 Edge (org.kie.workbench.common.stunner.core.graph.Edge)20 Inject (javax.inject.Inject)15 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)15 Before (org.junit.Before)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 Map (java.util.Map)13 Optional (java.util.Optional)13 Collectors (java.util.stream.Collectors)13 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)13 Collection (java.util.Collection)12