use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshall.
/**
* NOTE:
* This method has been added for Stunner support. Stunner bpmn parser provides a custom JsonGenerator that
* is used instead of the one used in jbpm-designer-backend.
*/
public void marshall(JsonGenerator generator, Definitions def, String preProcessingData) throws IOException {
if (def.getRelationships() != null && def.getRelationships().size() > 0) {
// current support for single relationship
Relationship relationship = def.getRelationships().get(0);
for (ExtensionAttributeValue extattrval : relationship.getExtensionValues()) {
FeatureMap extensionElements = extattrval.getValue();
@SuppressWarnings("unchecked") List<BPSimDataType> bpsimExtensions = (List<BPSimDataType>) extensionElements.get(BpsimPackage.Literals.DOCUMENT_ROOT__BP_SIM_DATA, true);
if (bpsimExtensions != null && bpsimExtensions.size() > 0) {
BPSimDataType processAnalysis = bpsimExtensions.get(0);
if (processAnalysis.getScenario() != null && processAnalysis.getScenario().size() > 0) {
_simulationScenario = processAnalysis.getScenario().get(0);
}
}
}
}
if (preProcessingData == null || preProcessingData.length() < 1) {
preProcessingData = "ReadOnlyService";
}
// this is a temp way to determine if
// coordinate system changes are necessary
String bpmn2Exporter = def.getExporter();
String bpmn2ExporterVersion = def.getExporterVersion();
boolean haveExporter = bpmn2Exporter != null && bpmn2ExporterVersion != null;
if (_simulationScenario != null && !haveExporter) {
coordianteManipulation = false;
}
marshallDefinitions(def, generator, preProcessingData);
// generator.close(); FIXME: can we remove this from here?
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallAssociation.
protected void marshallAssociation(Association association, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>();
Iterator<FeatureMap.Entry> iter = association.getAnyAttribute().iterator();
boolean foundBrColor = false;
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("type")) {
properties.put(TYPE, entry.getValue());
}
if (entry.getEStructuralFeature().getName().equals("bordercolor")) {
properties.put(BORDERCOLOR, entry.getValue());
foundBrColor = true;
}
}
if (!foundBrColor) {
properties.put("bordercolor", defaultSequenceflowColor);
}
putDocumentationProperty(association, properties);
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
if (association.getAssociationDirection().equals(AssociationDirection.ONE)) {
generator.writeObjectField("id", "Association_Unidirectional");
} else if (association.getAssociationDirection().equals(AssociationDirection.BOTH)) {
generator.writeObjectField("id", "Association_Bidirectional");
} else {
generator.writeObjectField("id", "Association_Undirected");
}
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
generator.writeStartObject();
generator.writeObjectField("resourceId", association.getTargetRef().getId());
generator.writeEndObject();
generator.writeEndArray();
Bounds sourceBounds = ((BPMNShape) findDiagramElement(plane, association.getSourceRef())).getBounds();
Bounds targetBounds = null;
float tbx = 0;
float tby = 0;
if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNShape) {
targetBounds = ((BPMNShape) findDiagramElement(plane, association.getTargetRef())).getBounds();
} else if (findDiagramElement(plane, association.getTargetRef()) instanceof BPMNEdge) {
// connect it to first waypoint on edge
List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association.getTargetRef())).getWaypoint();
if (waypoints != null && waypoints.size() > 0) {
tbx = waypoints.get(0).getX();
tby = waypoints.get(0).getY();
}
}
generator.writeArrayFieldStart("dockers");
generator.writeStartObject();
generator.writeObjectField("x", sourceBounds.getWidth() / 2);
generator.writeObjectField("y", sourceBounds.getHeight() / 2);
generator.writeEndObject();
List<Point> waypoints = ((BPMNEdge) findDiagramElement(plane, association)).getWaypoint();
for (int i = 1; i < waypoints.size() - 1; i++) {
Point waypoint = waypoints.get(i);
generator.writeStartObject();
generator.writeObjectField("x", waypoint.getX());
generator.writeObjectField("y", waypoint.getY());
generator.writeEndObject();
}
if (targetBounds != null) {
generator.writeStartObject();
// text annotations have to be treated specia
if (association.getTargetRef() instanceof TextAnnotation) {
generator.writeObjectField("x", 1);
generator.writeObjectField("y", targetBounds.getHeight() / 2);
} else {
generator.writeObjectField("x", targetBounds.getWidth() / 2);
generator.writeObjectField("y", targetBounds.getHeight() / 2);
}
generator.writeEndObject();
generator.writeEndArray();
} else {
generator.writeStartObject();
generator.writeObjectField("x", tbx);
generator.writeObjectField("y", tby);
generator.writeEndObject();
generator.writeEndArray();
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class BPMFinderServiceImpl method parse.
protected Optional<Definitions> parse(FileUtils.ScanResult process) {
org.uberfire.java.nio.file.Path formPath = process.getFile();
try {
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new DroolsResourceFactoryImpl());
resourceSet.getPackageRegistry().put(DroolsPackage.eNS_URI, DroolsPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl());
resourceSet.getPackageRegistry().put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.setEncoding("UTF-8");
Map<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.load(ioService.newInputStream(formPath), options);
DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);
return Optional.of(root.getDefinitions());
} catch (Exception ex) {
logger.warn("Error reading process '" + process.getFile().getFileName(), ex);
}
return Optional.empty();
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class BPMFinderServiceImpl method scannProcessesForType.
protected void scannProcessesForType(final Path path, final String extension, final GenerationConfig generationConfig) {
List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<>();
nioPaths.add(Paths.convert(path));
Collection<FileUtils.ScanResult> processes = fileUtils.scan(ioService, nioPaths, extension, true);
processes.stream().map(scanResult -> parse(scanResult)).filter(definitions -> definitions != null && generationConfig.getPredicate().test(definitions)).forEach(definitions -> {
BusinessProcessFormModel processFormModel = bpmnFormModelGenerator.generateProcessFormModel(definitions.get(), path);
List<TaskFormModel> taskModels = bpmnFormModelGenerator.generateTaskFormModels(definitions.get(), path);
generationConfig.getConsumer().accept(new JBPMProcessModel(processFormModel, taskModels));
});
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class BPMNFormModelGeneratorImpl method generateTaskFormModel.
@Override
public TaskFormModel generateTaskFormModel(Definitions source, String taskId, Path path) {
Process process = getProcess(source);
if (process != null) {
ProcessTaskFormsGenerationResult generationResult = readUserTaskFormVariables(process);
Optional<TaskFormVariables> resultTaskFormVariables = Optional.ofNullable(generationResult.getTaskFormVariablesByTaskId(taskId));
if (resultTaskFormVariables.isPresent()) {
TaskFormVariables formVariables = resultTaskFormVariables.get();
if (!formVariables.isValid()) {
throw new IllegalStateException(generateErrorMessage(formVariables));
}
final ClassLoader projectClassLoader = projectClassLoaderHelper.getModuleClassLoader(moduleService.resolveModule(path));
return formVariables.toFormModel(variable -> createModelProperty(variable, projectClassLoader));
}
}
return null;
}
Aggregations