Search in sources :

Example 1 with ExtensionAttributeValue

use of org.eclipse.bpmn2.ExtensionAttributeValue in project kie-wb-common by kiegroup.

the class Bpmn2JsonMarshaller method marshallDefinitions.

protected void marshallDefinitions(Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException {
    try {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", def.getId());
        /**
         * "properties":{"name":"",
         * "documentation":"",
         * "auditing":"",
         * "monitoring":"",
         * "executable":"true",
         * "package":"com.sample",
         * "vardefs":"a,b,c,d",
         * "lanes" : "a,b,c",
         * "id":"",
         * "version":"",
         * "author":"",
         * "language":"",
         * "namespaces":"",
         * "targetnamespace":"",
         * "expressionlanguage":"",
         * "typelanguage":"",
         * "creationdate":"",
         * "modificationdate":""
         * }
         */
        Map<String, Object> props = new LinkedHashMap<String, Object>();
        props.put(NAMESPACES, "");
        // props.put("targetnamespace", def.getTargetNamespace());
        props.put(TARGETNAMESPACE, "http://www.omg.org/bpmn20");
        props.put(TYPELANGUAGE, def.getTypeLanguage());
        props.put(NAME, StringEscapeUtils.unescapeXml(def.getName()));
        props.put(ID, def.getId());
        props.put(EXPRESSIONLANGUAGE, def.getExpressionLanguage());
        // backwards compat for BZ 1048191
        putDocumentationProperty(def, props);
        for (RootElement rootElement : def.getRootElements()) {
            if (rootElement instanceof Process) {
                // have to wait for process node to finish properties and stencil marshalling
                props.put(EXECUTABLE, ((Process) rootElement).isIsExecutable() + "");
                props.put(ID, rootElement.getId());
                if (rootElement.getDocumentation() != null && rootElement.getDocumentation().size() > 0) {
                    props.put(DOCUMENTATION, rootElement.getDocumentation().get(0).getText());
                }
                Process pr = (Process) rootElement;
                if (pr.getName() != null && pr.getName().length() > 0) {
                    props.put(PROCESSN, StringEscapeUtils.unescapeXml(((Process) rootElement).getName()));
                }
                List<Property> processProperties = ((Process) rootElement).getProperties();
                if (processProperties != null && processProperties.size() > 0) {
                    String propVal = "";
                    for (int i = 0; i < processProperties.size(); i++) {
                        Property p = processProperties.get(i);
                        String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI");
                        propVal += p.getId();
                        // check the structureRef value
                        if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) {
                            propVal += ":" + p.getItemSubjectRef().getStructureRef();
                        }
                        if (pKPI != null && pKPI.length() > 0) {
                            propVal += ":" + pKPI;
                        }
                        if (i != processProperties.size() - 1) {
                            propVal += ",";
                        }
                    }
                    props.put("vardefs", propVal);
                }
                // packageName and version and adHoc are jbpm-specific extension attribute
                Iterator<FeatureMap.Entry> iter = ((Process) rootElement).getAnyAttribute().iterator();
                while (iter.hasNext()) {
                    FeatureMap.Entry entry = iter.next();
                    if (entry.getEStructuralFeature().getName().equals("packageName")) {
                        props.put(PACKAGE, entry.getValue());
                    }
                    if (entry.getEStructuralFeature().getName().equals("version")) {
                        props.put(VERSION, entry.getValue());
                    }
                    if (entry.getEStructuralFeature().getName().equals("adHoc")) {
                        props.put(ADHOCPROCESS, entry.getValue());
                    }
                }
                // process imports, custom description and globals extension elements
                String allImports = "";
                if ((rootElement).getExtensionValues() != null && (rootElement).getExtensionValues().size() > 0) {
                    String importsStr = "";
                    String globalsStr = "";
                    for (ExtensionAttributeValue extattrval : rootElement.getExtensionValues()) {
                        FeatureMap extensionElements = extattrval.getValue();
                        @SuppressWarnings("unchecked") List<ImportType> importExtensions = (List<ImportType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, true);
                        @SuppressWarnings("unchecked") List<GlobalType> globalExtensions = (List<GlobalType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, true);
                        List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true);
                        for (ImportType importType : importExtensions) {
                            importsStr += importType.getName();
                            importsStr += "|default,";
                        }
                        for (GlobalType globalType : globalExtensions) {
                            globalsStr += (globalType.getIdentifier() + ":" + globalType.getType());
                            globalsStr += ",";
                        }
                        for (MetaDataType metaType : metadataExtensions) {
                            props.put("customdescription", metaType.getMetaValue());
                        }
                    }
                    allImports += importsStr;
                    if (globalsStr.length() > 0) {
                        if (globalsStr.endsWith(",")) {
                            globalsStr = globalsStr.substring(0, globalsStr.length() - 1);
                        }
                        props.put(GLOBALS, globalsStr);
                    }
                }
                // definitions imports (wsdl)
                List<org.eclipse.bpmn2.Import> wsdlImports = def.getImports();
                if (wsdlImports != null) {
                    for (org.eclipse.bpmn2.Import imp : wsdlImports) {
                        allImports += imp.getLocation() + "|" + imp.getNamespace() + "|wsdl,";
                    }
                }
                if (allImports.endsWith(",")) {
                    allImports = allImports.substring(0, allImports.length() - 1);
                }
                props.put(IMPORTS, allImports);
                // simulation
                if (_simulationScenario != null && _simulationScenario.getScenarioParameters() != null) {
                    props.put(CURRENCY, _simulationScenario.getScenarioParameters().getBaseCurrencyUnit() == null ? "" : _simulationScenario.getScenarioParameters().getBaseCurrencyUnit());
                    props.put(TIMEUNIT, _simulationScenario.getScenarioParameters().getBaseTimeUnit().getName());
                }
                marshallProperties(props, generator);
                marshallStencil("BPMNDiagram", generator);
                linkSequenceFlows(((Process) rootElement).getFlowElements());
                marshallProcess((Process) rootElement, def, generator, preProcessingData);
            } else if (rootElement instanceof Interface) {
            // TODO
            } else if (rootElement instanceof ItemDefinition) {
            // TODO
            } else if (rootElement instanceof Resource) {
            // TODO
            } else if (rootElement instanceof Error) {
            // TODO
            } else if (rootElement instanceof Message) {
            // TODO
            } else if (rootElement instanceof Signal) {
            // TODO
            } else if (rootElement instanceof Escalation) {
            // TODO
            } else if (rootElement instanceof Collaboration) {
            } else {
                _logger.warn("Unknown root element " + rootElement + ". This element will not be parsed.");
            }
        }
        generator.writeObjectFieldStart("stencilset");
        generator.writeObjectField("url", this.profile.getStencilSetURL());
        generator.writeObjectField("namespace", this.profile.getStencilSetNamespaceURL());
        generator.writeEndObject();
        generator.writeArrayFieldStart("ssextensions");
        generator.writeObject(this.profile.getStencilSetExtensionURL());
        generator.writeEndArray();
        generator.writeEndObject();
    } finally {
        _diagramElements.clear();
    }
}
Also used : Message(org.eclipse.bpmn2.Message) Escalation(org.eclipse.bpmn2.Escalation) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) Signal(org.eclipse.bpmn2.Signal) MetaDataType(org.jboss.drools.MetaDataType) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) Property(org.eclipse.bpmn2.Property) ImportType(org.jboss.drools.ImportType) Resource(org.eclipse.bpmn2.Resource) Error(org.eclipse.bpmn2.Error) Point(org.eclipse.dd.dc.Point) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) RootElement(org.eclipse.bpmn2.RootElement) Collaboration(org.eclipse.bpmn2.Collaboration) DataObject(org.eclipse.bpmn2.DataObject) Interface(org.eclipse.bpmn2.Interface) GlobalType(org.jboss.drools.GlobalType)

Example 2 with ExtensionAttributeValue

use of org.eclipse.bpmn2.ExtensionAttributeValue 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 3 with ExtensionAttributeValue

use of org.eclipse.bpmn2.ExtensionAttributeValue in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyProcessProperties.

protected void applyProcessProperties(Process process, Map<String, String> properties) {
    if (properties.get("processn") != null) {
        process.setName(StringEscapeUtils.escapeXml(properties.get("processn")));
    } else {
        process.setName("");
    }
    if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) {
        Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing();
        audit.getDocumentation().add(createDocumentation(properties.get("auditing")));
        process.setAuditing(audit);
    }
    process.setProcessType(ProcessType.getByName(properties.get("processtype")));
    process.setIsClosed(Boolean.parseBoolean(properties.get("isclosed")));
    process.setIsExecutable(Boolean.parseBoolean(properties.get("executable")));
    // get the drools-specific extension packageName attribute to Process if defined
    if (properties.get("package") != null && properties.get("package").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "packageName", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("package"));
        process.getAnyAttribute().add(extensionEntry);
    }
    // add version attrbute to process
    if (properties.get("version") != null && properties.get("version").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "version", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("version"));
        process.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) {
        Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring();
        monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring")));
        process.setMonitoring(monitoring);
    }
    // import extension elements
    if (properties.get("imports") != null && properties.get("imports").length() > 0) {
        String[] allImports = properties.get("imports").split(",\\s*");
        for (String importStr : allImports) {
            String[] importParts = importStr.split("\\|\\s*");
            // sample 'com.sample.Myclass|default,location|namespace|wsdl
            if (importParts.length == 2 || importParts.length == 3) {
                if (importParts[1] != null && importParts[1].equals("default")) {
                    ImportType importType = DroolsFactory.eINSTANCE.createImportType();
                    importType.setName(importParts[0]);
                    if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                        ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                        process.getExtensionValues().add(extensionElement);
                    }
                    FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType);
                    process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
                } else {
                    Import imp = Bpmn2Factory.eINSTANCE.createImport();
                    imp.setImportType("http://schemas.xmlsoap.org/wsdl/");
                    imp.setLocation(importParts[0]);
                    imp.setNamespace(importParts[1]);
                    _wsdlImports.add(imp);
                }
            } else {
                // just default (support legacy)
                ImportType importType = DroolsFactory.eINSTANCE.createImportType();
                importType.setName(importStr);
                if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    process.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType);
                process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            }
        }
    }
    // globals extension elements
    if (properties.get("globals") != null && properties.get("globals").length() > 0) {
        String[] allGlobals = properties.get("globals").split(",\\s*");
        for (String globalStr : allGlobals) {
            // identifier:type
            String[] globalParts = globalStr.split(":\\s*");
            if (globalParts.length == 2) {
                GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType();
                globalType.setIdentifier(globalParts[0]);
                globalType.setType(globalParts[1]);
                if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    process.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType);
                process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            } else if (globalParts.length == 1) {
                GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType();
                globalType.setIdentifier(globalParts[0]);
                globalType.setType("Object");
                if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    process.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType);
                process.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            }
        }
    }
    // simulation properties
    if (properties.get("timeunit") != null && properties.get("timeunit").length() > 0) {
        _simulationScenarioParameters.setBaseTimeUnit(TimeUnit.getByName(properties.get("timeunit")));
    }
    if (properties.get("currency") != null && properties.get("currency").length() > 0) {
        _simulationScenarioParameters.setBaseCurrencyUnit(properties.get("currency"));
    }
}
Also used : ImportType(org.jboss.drools.ImportType) Import(org.eclipse.bpmn2.Import) Internal(org.eclipse.emf.ecore.EStructuralFeature.Internal) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) Auditing(org.eclipse.bpmn2.Auditing) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) Monitoring(org.eclipse.bpmn2.Monitoring) GlobalType(org.jboss.drools.GlobalType)

Example 4 with ExtensionAttributeValue

use of org.eclipse.bpmn2.ExtensionAttributeValue in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyOnEntryActions.

protected void applyOnEntryActions(BaseElement element, Map<String, String> properties) {
    if (properties.get("onentryactions") != null && properties.get("onentryactions").length() > 0) {
        ScriptTypeListValue onEntryActions = new ScriptTypeListTypeSerializer().parse(properties.get("onentryactions"));
        if (!onEntryActions.isEmpty()) {
            ScriptTypeValue onEntryAction = onEntryActions.getValues().get(0);
            if (onEntryAction.getScript() != null && !onEntryAction.getScript().isEmpty()) {
                OnEntryScriptType onEntryScript = DroolsFactory.eINSTANCE.createOnEntryScriptType();
                onEntryScript.setScript(wrapInCDATABlock(onEntryAction.getScript()));
                String scriptLanguage = Utils.getScriptLanguageFormat(onEntryAction.getLanguage());
                if (scriptLanguage == null) {
                    // default to java
                    scriptLanguage = "http://www.java.com/java";
                }
                onEntryScript.setScriptFormat(scriptLanguage);
                if (element.getExtensionValues() == null || element.getExtensionValues().size() < 1) {
                    ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
                    element.getExtensionValues().add(extensionElement);
                }
                FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT, onEntryScript);
                element.getExtensionValues().get(0).getValue().add(extensionElementEntry);
            }
        }
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) OnEntryScriptType(org.jboss.drools.OnEntryScriptType) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue) ScriptTypeListTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer) ScriptTypeListValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue) ScriptTypeValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)

Example 5 with ExtensionAttributeValue

use of org.eclipse.bpmn2.ExtensionAttributeValue in project kie-wb-common by kiegroup.

the class Utils method setMetaDataExtensionValue.

public static void setMetaDataExtensionValue(BaseElement element, String metaDataName, String metaDataValue) {
    if (element != null) {
        MetaDataType eleMetadata = DroolsFactory.eINSTANCE.createMetaDataType();
        eleMetadata.setName(metaDataName);
        eleMetadata.setMetaValue(metaDataValue);
        if (element.getExtensionValues() == null || element.getExtensionValues().isEmpty()) {
            ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
            element.getExtensionValues().add(extensionElement);
        }
        FeatureMap.Entry eleExtensionElementEntry = new EStructuralFeatureImpl.SimpleFeatureMapEntry((EStructuralFeature.Internal) DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, eleMetadata);
        element.getExtensionValues().get(0).getValue().add(eleExtensionElementEntry);
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) MetaDataType(org.jboss.drools.MetaDataType) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue)

Aggregations

ExtensionAttributeValue (org.eclipse.bpmn2.ExtensionAttributeValue)16 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)15 MetaDataType (org.jboss.drools.MetaDataType)7 List (java.util.List)6 ArrayList (java.util.ArrayList)5 EList (org.eclipse.emf.common.util.EList)4 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)4 ScriptTypeListValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue)4 ScriptTypeValue (org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeValue)4 BPSimDataType (bpsim.BPSimDataType)3 Relationship (org.eclipse.bpmn2.Relationship)3 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)3 Scenario (bpsim.Scenario)2 Entry (java.util.Map.Entry)2 EStructuralFeatureImpl (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl)2 GlobalType (org.jboss.drools.GlobalType)2 ImportType (org.jboss.drools.ImportType)2 OnEntryScriptType (org.jboss.drools.OnEntryScriptType)2 OnExitScriptType (org.jboss.drools.OnExitScriptType)2 ScriptTypeListTypeSerializer (org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer)2