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