Search in sources :

Example 1 with ProcessDefinitionDocument

use of com.centurylink.mdw.bpm.ProcessDefinitionDocument in project mdw-designer by CenturyLinkCloud.

the class GraphFragment method toString.

@Override
public String toString() {
    ProcessDefinitionDocument defnDoc = ProcessDefinitionDocument.Factory.newInstance();
    MDWProcessDefinition procDefn = defnDoc.addNewProcessDefinition();
    MDWProcess process = procDefn.addNewProcess();
    process.setId(sourceProcessId.toString());
    for (Node node : nodes) {
        exportActivity(node.nodet, process.addNewActivity());
    }
    for (Link link : links) {
        exportTransition(link.conn, process.addNewTransition());
    }
    for (SubGraph subgraph : subgraphs) {
        MDWProcess subproc = process.addNewSubProcess();
        subproc.setId(subgraph.getId().toString());
        subproc.setName(subgraph.getName());
        for (Node node : subgraph.nodes) {
            exportActivity(node.nodet, subproc.addNewActivity());
        }
        for (Link link : subgraph.links) {
            exportTransition(link.conn, subproc.addNewTransition());
        }
    }
    return defnDoc.xmlText(new XmlOptions().setSavePrettyPrint());
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) ProcessDefinitionDocument(com.centurylink.mdw.bpm.ProcessDefinitionDocument) MDWProcess(com.centurylink.mdw.bpm.MDWProcess)

Example 2 with ProcessDefinitionDocument

use of com.centurylink.mdw.bpm.ProcessDefinitionDocument in project mdw-designer by CenturyLinkCloud.

the class PackageConfigurationSection method updatePackageMetaContent.

private void updatePackageMetaContent() throws XmlException, JSONException, IOException {
    if (!workflowPackage.getProject().isOldNamespaces()) {
        if (workflowPackage.getMetaContent() != null && workflowPackage.getMetaContent().trim().startsWith("{")) {
            PackageVO metaPkg = new PackageVO(new JSONObject(workflowPackage.getMetaContent()));
            List<AttributeVO> attributes = null;
            if (propertyGroups != null) {
                attributes = new ArrayList<>();
                for (PropertyGroup propGroup : propertyGroups) {
                    String group = propGroup.getName();
                    for (Property prop : propGroup.getPropertyList()) {
                        AttributeVO attribute = new AttributeVO(prop.getName(), prop.getStringValue());
                        if (group != null)
                            attribute.setAttributeGroup(group);
                        attributes.add(attribute);
                    }
                }
            }
            metaPkg.setAttributes(attributes);
            workflowPackage.setMetaContent(metaPkg.getJson(false).toString(2));
        } else if (workflowPackage.getSchemaVersion() >= DataAccess.schemaVersion61) {
            List<AttributeVO> attributes = null;
            Yaml yaml = new Yaml();
            Map<String, Object> map = (Map<String, Object>) yaml.load(workflowPackage.getMetaContent());
            PackageVO metaPkg = new PackageVO(map);
            if (propertyGroups != null) {
                attributes = new ArrayList<>();
                for (PropertyGroup propGroup : propertyGroups) {
                    String group = propGroup.getName();
                    for (Property prop : propGroup.getPropertyList()) {
                        AttributeVO attribute = new AttributeVO(prop.getName(), prop.getStringValue());
                        if (group != null)
                            attribute.setAttributeGroup(group);
                        attributes.add(attribute);
                    }
                }
            }
            metaPkg.setAttributes(attributes);
            workflowPackage.setMetaContent(metaPkg.getJson(false).toString(2));
        } else {
            PackageDocument pkgDefDoc = null;
            if (workflowPackage.getMetaContent() == null || workflowPackage.getMetaContent().isEmpty()) {
                pkgDefDoc = PackageDocument.Factory.newInstance();
            } else {
                if (workflowPackage.getMetaContent().startsWith("<bpm:package") || workflowPackage.getMetaContent().startsWith("<package")) {
                    pkgDefDoc = PackageDocument.Factory.parse(workflowPackage.getMetaContent());
                } else {
                    pkgDefDoc = PackageDocument.Factory.newInstance();
                }
            }
            if (pkgDefDoc.getPackage() == null)
                pkgDefDoc.addNewPackage();
            if (pkgDefDoc.getPackage().getApplicationProperties() == null)
                pkgDefDoc.getPackage().addNewApplicationProperties();
            pkgDefDoc.getPackage().getApplicationProperties().setPropertyGroupArray(propertyGroups.toArray(new PropertyGroup[0]));
            String procDefStr = pkgDefDoc.xmlText(new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2));
            workflowPackage.setMetaContent(procDefStr);
        }
    } else {
        ProcessDefinitionDocument procDefDoc;
        if (workflowPackage.getMetaContent() == null || workflowPackage.getMetaContent().isEmpty())
            procDefDoc = ProcessDefinitionDocument.Factory.newInstance();
        else
            procDefDoc = ProcessDefinitionDocument.Factory.parse(workflowPackage.getMetaContent(), Compatibility.namespaceOptions());
        if (procDefDoc.getProcessDefinition() == null)
            procDefDoc.addNewProcessDefinition();
        if (procDefDoc.getProcessDefinition().getApplicationProperties() == null)
            procDefDoc.getProcessDefinition().addNewApplicationProperties();
        procDefDoc.getProcessDefinition().getApplicationProperties().setPropertyGroupArray(propertyGroups.toArray(new PropertyGroup[0]));
        String procDefStr = DesignerCompatibility.getInstance().getOldProcessDefinition(procDefDoc);
        workflowPackage.setMetaContent(procDefStr);
    }
}
Also used : PropertyGroup(com.centurylink.mdw.bpm.PropertyGroupDocument.PropertyGroup) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) JSONObject(org.json.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) ProcessDefinitionDocument(com.centurylink.mdw.bpm.ProcessDefinitionDocument) Property(com.centurylink.mdw.bpm.PropertyDocument.Property) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ProcessDefinitionDocument

use of com.centurylink.mdw.bpm.ProcessDefinitionDocument in project mdw-designer by CenturyLinkCloud.

the class PackageConfigurationSection method getPropertyGroups.

private List<PropertyGroup> getPropertyGroups() {
    if (// empty
    workflowPackage.getMetaContent() == null && !workflowPackage.isDefaultPackage()) // string
    // signifies
    // already
    // loaded
    {
        try {
            PackageVO packageVO = workflowPackage.getProject().getDesignerProxy().getDesignerDataAccess().loadPackage(workflowPackage.getId(), false);
            workflowPackage.setMetaContent(packageVO.getMetaContent() == null ? "" : packageVO.getMetaContent());
        } catch (Exception ex) {
            PluginMessages.uiError(getShell(), ex, "Package Config", workflowPackage.getProject());
        }
    }
    if (workflowPackage.getMetaContent() == null || workflowPackage.getMetaContent().trim().length() == 0) {
        return new ArrayList<>();
    } else {
        ApplicationProperties appProps = null;
        try {
            if (workflowPackage.getMetaContent().trim().startsWith("{")) {
                List<PropertyGroup> propGroups = new ArrayList<>();
                PackageVO metaPkg = new PackageVO(new JSONObject(workflowPackage.getMetaContent()));
                if (metaPkg.getAttributes() != null) {
                    Map<String, List<AttributeVO>> groupedAttrs = metaPkg.getAttributesByGroup();
                    for (Map.Entry<String, List<AttributeVO>> group : groupedAttrs.entrySet()) {
                        PropertyGroup propGroup = PropertyGroup.Factory.newInstance();
                        if (group.getKey() != null)
                            propGroup.setName(group.getKey());
                        for (AttributeVO groupAttr : group.getValue()) {
                            Property prop = propGroup.addNewProperty();
                            prop.setName(groupAttr.getAttributeName());
                            prop.setStringValue(groupAttr.getAttributeValue());
                        }
                        propGroups.add(propGroup);
                    }
                }
                return propGroups;
            } else if (workflowPackage.getSchemaVersion() >= DataAccess.schemaVersion61) {
                List<PropertyGroup> propGroups = new ArrayList<>();
                Yaml yaml = new Yaml();
                Map<String, Object> map = (Map<String, Object>) yaml.load(workflowPackage.getMetaContent());
                PackageVO metaPkg = new PackageVO(map);
                if (metaPkg.getAttributes() != null) {
                    Map<String, List<AttributeVO>> groupedAttrs = metaPkg.getAttributesByGroup();
                    for (Map.Entry<String, List<AttributeVO>> group : groupedAttrs.entrySet()) {
                        PropertyGroup propGroup = PropertyGroup.Factory.newInstance();
                        if (group.getKey() != null)
                            propGroup.setName(group.getKey());
                        for (AttributeVO groupAttr : group.getValue()) {
                            Property prop = propGroup.addNewProperty();
                            prop.setName(groupAttr.getAttributeName());
                            prop.setStringValue(groupAttr.getAttributeValue());
                        }
                        propGroups.add(propGroup);
                    }
                }
                return propGroups;
            } else if (workflowPackage.getMetaContent().startsWith("<bpm:package") || workflowPackage.getMetaContent().startsWith("<package")) {
                PackageDocument pkgDoc = PackageDocument.Factory.parse(workflowPackage.getMetaContent());
                appProps = pkgDoc.getPackage().getApplicationProperties();
            } else {
                ProcessDefinitionDocument procDefDoc = ProcessDefinitionDocument.Factory.parse(workflowPackage.getMetaContent(), Compatibility.namespaceOptions());
                appProps = procDefDoc.getProcessDefinition().getApplicationProperties();
            }
        } catch (Exception ex) {
            PluginMessages.uiError(getShell(), ex, "Package Config", workflowPackage.getProject());
        }
        if (appProps != null && appProps.getPropertyGroupList() != null)
            return appProps.getPropertyGroupList();
        // not found or can't parse
        return new ArrayList<>();
    }
}
Also used : PropertyGroup(com.centurylink.mdw.bpm.PropertyGroupDocument.PropertyGroup) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) Yaml(org.yaml.snakeyaml.Yaml) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) JSONObject(org.json.JSONObject) ApplicationProperties(com.centurylink.mdw.bpm.ApplicationPropertiesDocument.ApplicationProperties) List(java.util.List) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) ProcessDefinitionDocument(com.centurylink.mdw.bpm.ProcessDefinitionDocument) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Property(com.centurylink.mdw.bpm.PropertyDocument.Property)

Example 4 with ProcessDefinitionDocument

use of com.centurylink.mdw.bpm.ProcessDefinitionDocument in project mdw-designer by CenturyLinkCloud.

the class Importer method importAttributes.

public void importAttributes(final WorkflowElement element, final String xml, final ProgressMonitor progressMonitor, String attrPrefix) throws DataAccessException, XmlException {
    progressMonitor.subTask(PARSING_XML);
    int schemaVersion = dataAccess.getSchemaVersion();
    ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
    progressMonitor.progress(40);
    progressMonitor.subTask("Saving attributes");
    ProcessDefinitionDocument procdef = ProcessDefinitionDocument.Factory.parse(xml, Compatibility.namespaceOptions());
    if (element instanceof WorkflowPackage && !((WorkflowPackage) element).getName().equals(procdef.getProcessDefinition().getPackageName()))
        throw new DataAccessException("Expected package: " + ((WorkflowPackage) element).getName() + " in attributes XML but found: " + procdef.getProcessDefinition().getPackageName());
    for (MDWProcess process : procdef.getProcessDefinition().getProcessList()) {
        ProcessDefinitionDocument oneProcDef = ProcessDefinitionDocument.Factory.newInstance();
        MDWProcessDefinition oneProc = oneProcDef.addNewProcessDefinition();
        oneProc.getProcessList().add(process);
        ProcessVO importedProc = importer.importProcess(oneProcDef.xmlText());
        if (element instanceof WorkflowProcess && !((WorkflowProcess) element).getName().equals(importedProc.getProcessName()))
            throw new DataAccessException("Expected process: " + ((WorkflowProcess) element).getName() + " in attributes XML but found: " + importedProc.getName());
        ProcessVO proc = dataAccess.getLatestProcess(importedProc.getName());
        if (proc == null)
            throw new DataAccessException("Process not found: " + importedProc.getName());
        Map<String, String> existAttrs = dataAccess.getDesignerDataAccess().getAttributes(OwnerType.PROCESS, proc.getId());
        Map<String, String> importedAttrs = importedProc.getOverrideAttributes();
        Map<String, String> setAttrs = new HashMap<>();
        if (existAttrs != null) {
            // retain existing attrs not related to this prefix
            for (Map.Entry<String, String> attrs : existAttrs.entrySet()) {
                if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
                    setAttrs.put(attrs.getKey(), attrs.getValue());
            }
        }
        if (importedAttrs != null) {
            for (Map.Entry<String, String> attrs : importedAttrs.entrySet()) {
                if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
                    throw new DataAccessException("Expected attribute prefix: " + attrPrefix + " in attributes XML but found attribute: " + attrs.getKey());
                else
                    setAttrs.put(attrs.getKey(), attrs.getValue());
            }
        }
        dataAccess.getDesignerDataAccess().setOverrideAttributes(attrPrefix, OwnerType.PROCESS, proc.getId(), setAttrs);
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) HashMap(java.util.HashMap) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) ProcessDefinitionDocument(com.centurylink.mdw.bpm.ProcessDefinitionDocument) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) MDWProcess(com.centurylink.mdw.bpm.MDWProcess)

Aggregations

ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)4 Map (java.util.Map)3 MDWProcess (com.centurylink.mdw.bpm.MDWProcess)2 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)2 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)2 Property (com.centurylink.mdw.bpm.PropertyDocument.Property)2 PropertyGroup (com.centurylink.mdw.bpm.PropertyGroupDocument.PropertyGroup)2 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)2 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 XmlOptions (org.apache.xmlbeans.XmlOptions)2 JSONObject (org.json.JSONObject)2 Yaml (org.yaml.snakeyaml.Yaml)2 ApplicationProperties (com.centurylink.mdw.bpm.ApplicationPropertiesDocument.ApplicationProperties)1 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)1 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1