Search in sources :

Example 31 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 32 with Diagram

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

the class AbstractVFSDiagramServiceTest method testGetDiagramByPath.

@Test
public void testGetDiagramByPath() throws IOException {
    Path path = mock(Path.class);
    when(path.toURI()).thenReturn(FILE_URI);
    String fileName = FILE_NAME + "." + RESOURCE_TYPE_SUFFIX;
    when(path.getFileName()).thenReturn(fileName);
    when(resourceType.accept(path)).thenReturn(true);
    final org.uberfire.java.nio.file.Path expectedNioPath = Paths.convert(path);
    byte[] content = DIAGRAM_MARSHALLED.getBytes();
    when(ioService.readAllBytes(expectedNioPath)).thenReturn(content);
    Graph<DefinitionSet, ?> graph = mock(Graph.class);
    DefinitionSet graphContent = mock(DefinitionSet.class);
    when(graph.getContent()).thenReturn(graphContent);
    when(graphContent.getDefinition()).thenReturn("DefinitionSet");
    when(diagramMarshaller.unmarshall(anyObject(), anyObject())).thenReturn(graph);
    DiagramFactory diagramFactory = mock(DiagramFactory.class);
    when(factoryRegistry.getDiagramFactory("DefinitionSet", getMetadataType())).thenReturn(diagramFactory);
    when(diagramFactory.build(eq(FILE_NAME), any(Metadata.class), eq(graph))).thenReturn(diagram);
    Diagram result = diagramService.getDiagramByPath(path);
    assertEquals(diagram, result);
}
Also used : Path(org.uberfire.backend.vfs.Path) DiagramFactory(org.kie.workbench.common.stunner.core.factory.diagram.DiagramFactory) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with Diagram

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

the class ClientSessionManagerImpl method destroy.

@Override
public void destroy() {
    SessionDestroyedEvent destroyedEvent = null;
    if (null != current) {
        final String uuid = current.getSessionUUID();
        final Diagram diagram = current.getCanvasHandler().getDiagram();
        final String name = null != diagram ? diagram.getName() : null;
        final String graphUuid = null != diagram ? diagram.getGraph().getUUID() : null;
        final Metadata metadata = null != diagram ? diagram.getMetadata() : null;
        destroyedEvent = new SessionDestroyedEvent(uuid, name, graphUuid, metadata);
    }
    super.destroy();
    if (null != destroyedEvent) {
        this.sessionDestroyedEvent.fire(destroyedEvent);
    }
}
Also used : Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) SessionDestroyedEvent(org.kie.workbench.common.stunner.core.client.session.event.SessionDestroyedEvent) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 34 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<>();
    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 : Collection(java.util.Collection) ModelValidator(org.kie.workbench.common.stunner.core.validation.ModelValidator) DiagramValidator(org.kie.workbench.common.stunner.core.validation.DiagramValidator) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Supplier(java.util.function.Supplier) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Consumer(java.util.function.Consumer) List(java.util.List) Graph(org.kie.workbench.common.stunner.core.graph.Graph) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) BiConsumer(java.util.function.BiConsumer) Element(org.kie.workbench.common.stunner.core.graph.Element) Optional(java.util.Optional) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) LinkedList(java.util.LinkedList) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) LinkedList(java.util.LinkedList)

Example 35 with Diagram

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

the class AbstractCanvasHandlerViewerTest method init.

@SuppressWarnings("unchecked")
public void init() throws Exception {
    this.canvasHandlerDiagram = null;
    when(canvas.getView()).thenReturn(canvasView);
    when(canvasView.asWidget()).thenReturn(canvasViewWidget);
    when(canvas.getLienzoPanel()).thenReturn(lienzoPanel);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getAbstractCanvas()).thenReturn(canvas);
    // The different viewer/editors tested reply on the canvas handler to obtain
    // the diagram instance, so applying mocked answers for CanvasHandler #open,
    // #clear and #destroy to handle the right diagram instance.
    doAnswer(invocationOnMock -> {
        final Diagram d = (Diagram) invocationOnMock.getArguments()[0];
        final ParameterizedCommand<CommandResult<?>> c = (ParameterizedCommand) invocationOnMock.getArguments()[1];
        AbstractCanvasHandlerViewerTest.this.canvasHandlerDiagram = d;
        when(canvasHandler.getDiagram()).thenReturn(canvasHandlerDiagram);
        c.execute(CanvasCommandResultBuilder.SUCCESS);
        return null;
    }).when(canvasHandler).draw(any(Diagram.class), any(ParameterizedCommand.class));
    doAnswer(invocationOnMock -> {
        AbstractCanvasHandlerViewerTest.this.canvasHandlerDiagram = null;
        when(canvasHandler.getDiagram()).thenReturn(canvasHandlerDiagram);
        return null;
    }).when(canvasHandler).clear();
    doAnswer(invocationOnMock -> {
        AbstractCanvasHandlerViewerTest.this.canvasHandlerDiagram = null;
        when(canvasHandler.getDiagram()).thenReturn(canvasHandlerDiagram);
        return null;
    }).when(canvasHandler).destroy();
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.getContent()).thenReturn(graphContent);
    when(graphContent.getBounds()).thenReturn(GRAPH_BOUNDS);
}
Also used : ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult)

Aggregations

Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)36 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)17 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)9 Collection (java.util.Collection)7 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)7 Graph (org.kie.workbench.common.stunner.core.graph.Graph)7 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)6 Node (org.kie.workbench.common.stunner.core.graph.Node)6 Before (org.junit.Before)5 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)5 Edge (org.kie.workbench.common.stunner.core.graph.Edge)5 OnStartup (org.uberfire.lifecycle.OnStartup)5 ClientSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 Command (org.uberfire.mvp.Command)4 ArrayList (java.util.ArrayList)3 Assert.assertEquals (org.junit.Assert.assertEquals)3