Search in sources :

Example 1 with ApplicationProperties

use of com.centurylink.mdw.bpm.ApplicationPropertiesDocument.ApplicationProperties 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)

Aggregations

ApplicationProperties (com.centurylink.mdw.bpm.ApplicationPropertiesDocument.ApplicationProperties)1 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)1 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)1 Property (com.centurylink.mdw.bpm.PropertyDocument.Property)1 PropertyGroup (com.centurylink.mdw.bpm.PropertyGroupDocument.PropertyGroup)1 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)1 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 XmlException (org.apache.xmlbeans.XmlException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Yaml (org.yaml.snakeyaml.Yaml)1