Search in sources :

Example 1 with DefinitionSetService

use of org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService in project kie-wb-common by kiegroup.

the class AbstractVFSDiagramService method getDiagramByPath.

@SuppressWarnings("unchecked")
public D getDiagramByPath(final org.uberfire.backend.vfs.Path file) {
    if (accepts(file)) {
        DefinitionSetService services = getServiceByPath(file);
        if (null != services) {
            final String defSetId = getDefinitionSetId(services);
            final String name = parseFileName(file, services);
            // Check if any metadata definition exist.
            M metadata = obtainMetadata(services, file, defSetId, name);
            if (null == metadata) {
                metadata = (M) buildMetadataInstance(file, defSetId, name);
            }
            metadata.setPath(file);
            // Parse and load the diagram raw data.
            final InputStream is = loadPath(file);
            try {
                Graph<DefinitionSet, ?> graph = services.getDiagramMarshaller().unmarshall(metadata, is);
                DiagramFactory<M, ?> factory = factoryManager.registry().getDiagramFactory(graph.getContent().getDefinition(), getMetadataType());
                return (D) factory.build(name, metadata, graph);
            } catch (java.io.IOException e) {
                LOG.error("Cannot unmarshall diagram for diagram's path [" + file + "]", e);
                return null;
            }
        }
    }
    throw new UnsupportedOperationException("Diagram format not supported [" + file + "]");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) DefinitionSetService(org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService)

Example 2 with DefinitionSetService

use of org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService in project kie-wb-common by kiegroup.

the class DiagramServiceImpl method getNewFileName.

private String getNewFileName(final Diagram diagram) {
    final String defSetId = diagram.getMetadata().getDefinitionSetId();
    final DefinitionSetService defSetService = getServiceById(defSetId);
    return UUID.uuid(8) + "." + defSetService.getResourceType().getSuffix();
}
Also used : DefinitionSetService(org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService)

Example 3 with DefinitionSetService

use of org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService in project kie-wb-common by kiegroup.

the class AbstractVFSDiagramService method create.

public Path create(final Path path, final String name, final String defSetId, final Metadata metadata) {
    final DefinitionSetService services = getServiceById(defSetId);
    if (null == services) {
        throw new IllegalStateException("No backend Definition Set services for [" + defSetId + "]");
    }
    final String fName = buildFileName(name, services.getResourceType());
    final org.uberfire.java.nio.file.Path kiePath = Paths.convert(path).resolve(fName);
    try {
        if (getIoService().exists(kiePath)) {
            throw new FileAlreadyExistsException(kiePath.toString());
        }
        final D diagram = factoryManager.newDiagram(name, defSetId, metadata);
        final String[] raw = serialize(diagram);
        getIoService().write(kiePath, raw[0]);
        return Paths.convert(kiePath);
    } catch (final Exception e) {
        LOG.error("Cannot create diagram in path [" + kiePath + "]", e);
    }
    return null;
}
Also used : FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) DefinitionSetService(org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService) IOException(org.uberfire.java.nio.IOException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException)

Example 4 with DefinitionSetService

use of org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService 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)

Aggregations

DefinitionSetService (org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)1 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)1 Graph (org.kie.workbench.common.stunner.core.graph.Graph)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1 IOException (org.uberfire.java.nio.IOException)1 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)1