Search in sources :

Example 26 with Definitions

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?
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Relationship(org.eclipse.bpmn2.Relationship) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) BPSimDataType(bpsim.BPSimDataType)

Example 27 with Definitions

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();
    }
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Point(org.eclipse.dd.dc.Point) LinkedHashMap(java.util.LinkedHashMap) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Entry(java.util.Map.Entry) DataObject(org.eclipse.bpmn2.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge)

Example 28 with Definitions

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();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) HashMap(java.util.HashMap) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) DroolsResourceFactoryImpl(org.jboss.drools.util.DroolsResourceFactoryImpl) Bpmn2ResourceFactoryImpl(org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl)

Example 29 with Definitions

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));
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) URI(org.eclipse.emf.common.util.URI) BPMFinderService(org.kie.workbench.common.forms.jbpm.service.shared.BPMFinderService) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) Service(org.jboss.errai.bus.server.annotations.Service) Named(javax.inject.Named) Path(org.uberfire.backend.vfs.Path) Definitions(org.eclipse.bpmn2.Definitions) DroolsResourceFactoryImpl(org.jboss.drools.util.DroolsResourceFactoryImpl) FileUtils(org.kie.workbench.common.services.datamodeller.util.FileUtils) Process(org.eclipse.bpmn2.Process) Logger(org.slf4j.Logger) DroolsPackage(org.jboss.drools.DroolsPackage) DocumentRoot(org.eclipse.bpmn2.DocumentRoot) Predicate(java.util.function.Predicate) Collection(java.util.Collection) JBPMProcessModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMProcessModel) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel) Consumer(java.util.function.Consumer) List(java.util.List) Dependent(javax.enterprise.context.Dependent) PostConstruct(javax.annotation.PostConstruct) Bpmn2ResourceFactoryImpl(org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) IOService(org.uberfire.io.IOService) Optional(java.util.Optional) BPMNFormModelGenerator(org.kie.workbench.common.forms.jbpm.server.service.BPMNFormModelGenerator) Bpmn2Package(org.eclipse.bpmn2.Bpmn2Package) JBPMProcessModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMProcessModel) ArrayList(java.util.ArrayList) BusinessProcessFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel) TaskFormModel(org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)

Example 30 with Definitions

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;
}
Also used : Process(org.eclipse.bpmn2.Process)

Aggregations

Process (org.eclipse.bpmn2.Process)40 RootElement (org.eclipse.bpmn2.RootElement)35 ArrayList (java.util.ArrayList)27 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)26 SubProcess (org.eclipse.bpmn2.SubProcess)26 Definitions (org.eclipse.bpmn2.Definitions)25 Definitions (org.kie.dmn.model.v1_1.Definitions)22 List (java.util.List)21 Test (org.junit.Test)20 FlowElement (org.eclipse.bpmn2.FlowElement)18 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)16 ItemDefinition (org.eclipse.bpmn2.ItemDefinition)15 Entry (java.util.Map.Entry)14 CompensateEventDefinition (org.eclipse.bpmn2.CompensateEventDefinition)13 ErrorEventDefinition (org.eclipse.bpmn2.ErrorEventDefinition)13 EscalationEventDefinition (org.eclipse.bpmn2.EscalationEventDefinition)13 EventDefinition (org.eclipse.bpmn2.EventDefinition)13 MessageEventDefinition (org.eclipse.bpmn2.MessageEventDefinition)13 SignalEventDefinition (org.eclipse.bpmn2.SignalEventDefinition)13 ConditionalEventDefinition (org.eclipse.bpmn2.ConditionalEventDefinition)12