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