Search in sources :

Example 1 with MetaDataType

use of org.jboss.drools.MetaDataType 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 MetaDataType

use of org.jboss.drools.MetaDataType 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)

Example 3 with MetaDataType

use of org.jboss.drools.MetaDataType in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest method getProcessExtensionValue.

private String getProcessExtensionValue(Process process, String propertyName) {
    List<ExtensionAttributeValue> extensionValues = process.getExtensionValues();
    for (ExtensionAttributeValue extensionValue : extensionValues) {
        FeatureMap featureMap = extensionValue.getValue();
        for (int i = 0; i < featureMap.size(); i++) {
            EStructuralFeatureImpl.SimpleFeatureMapEntry featureMapEntry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) featureMap.get(i);
            MetaDataType featureMapValue = (MetaDataType) featureMapEntry.getValue();
            if (propertyName.equals(featureMapValue.getName())) {
                return featureMapValue.getMetaValue();
            }
        }
    }
    return "";
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) MetaDataType(org.jboss.drools.MetaDataType) EStructuralFeatureImpl(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue)

Example 4 with MetaDataType

use of org.jboss.drools.MetaDataType in project kie-wb-common by kiegroup.

the class BPMNDiagramMarshallerTest method getProcessExtensionValue.

private String getProcessExtensionValue(Process process, String propertyName) {
    List<ExtensionAttributeValue> extensionValues = process.getExtensionValues();
    for (ExtensionAttributeValue extensionValue : extensionValues) {
        FeatureMap featureMap = extensionValue.getValue();
        for (int i = 0; i < featureMap.size(); i++) {
            EStructuralFeatureImpl.SimpleFeatureMapEntry featureMapEntry = (EStructuralFeatureImpl.SimpleFeatureMapEntry) featureMap.get(i);
            MetaDataType featureMapValue = (MetaDataType) featureMapEntry.getValue();
            if (propertyName.equals(featureMapValue.getName())) {
                return featureMapValue.getMetaValue();
            }
        }
    }
    return "";
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) MetaDataType(org.jboss.drools.MetaDataType) EStructuralFeatureImpl(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue)

Example 5 with MetaDataType

use of org.jboss.drools.MetaDataType in project jbpm by kiegroup.

the class BPMN2EmfExtTest method testMetadataElement.

@SuppressWarnings("unchecked")
public void testMetadataElement() throws Exception {
    // write
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
    MetaDataType metadataType = DroolsFactory.eINSTANCE.createMetaDataType();
    metadataType.setName("testvalue");
    metadataType.setMetaValue("testentry");
    documentRoot.setMetaData(metadataType);
    inResource.getContents().add(documentRoot);
    StringWriter stringWriter = new StringWriter();
    inResource.save(stringWriter, null);
    assertNotNull(stringWriter.getBuffer().toString());
    if (stringWriter.getBuffer().toString().length() < 1) {
        fail("generated xml is empty");
    }
    // read
    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");
    InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
    outResource.load(is, options);
    DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
    assertNotNull(outRoot.getMetaData());
    MetaDataType outMetadataType = outRoot.getMetaData();
    assertEquals(outMetadataType.getName(), "testvalue");
    assertEquals(outMetadataType.getMetaValue(), "testentry");
}
Also used : StringWriter(java.io.StringWriter) MetaDataType(org.jboss.drools.MetaDataType) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.jboss.drools.DocumentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

MetaDataType (org.jboss.drools.MetaDataType)8 ExtensionAttributeValue (org.eclipse.bpmn2.ExtensionAttributeValue)7 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)7 List (java.util.List)3 ArrayList (java.util.ArrayList)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 EStructuralFeatureImpl (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)1 Collaboration (org.eclipse.bpmn2.Collaboration)1 DataObject (org.eclipse.bpmn2.DataObject)1 Error (org.eclipse.bpmn2.Error)1 Escalation (org.eclipse.bpmn2.Escalation)1 FlowElement (org.eclipse.bpmn2.FlowElement)1 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)1