Search in sources :

Example 1 with PackageDocument

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

the class DesignerDataAccess method exportTaskTemplates.

public String exportTaskTemplates(Long packageId, ProgressMonitor monitor) throws DataAccessException, ActionCancelledException {
    monitor.subTask("Loading package");
    PackageVO packageVO = loadPackage(packageId, true);
    monitor.progress(30);
    if (monitor.isCanceled())
        throw new ActionCancelledException();
    if (monitor != null)
        monitor.progress(5);
    if (monitor != null)
        monitor.subTask(EXPORTXML);
    PackageDocument pkgDoc = PackageDocument.Factory.newInstance();
    MDWPackage pkg = pkgDoc.addNewPackage();
    pkg.setName(packageVO.getName());
    pkg.setVersion(PackageVO.formatVersion(packageVO.getVersion()));
    TaskTemplatesDocument.TaskTemplates templates = pkg.addNewTaskTemplates();
    if (packageVO.getTaskTemplates() != null) {
        for (TaskVO taskVO : packageVO.getTaskTemplates()) {
            if (taskVO.getVersion() > 0) {
                TaskTemplate templateDef = templates.addNewTask();
                templateDef.setLogicalId(taskVO.getLogicalId());
                templateDef.setVersion(RuleSetVO.formatVersion(taskVO.getVersion()));
                templateDef.setAssetName(taskVO.getName());
                templateDef.setName(taskVO.getTaskName());
                if (taskVO.getTaskCategory() != null)
                    templateDef.setCategory(taskVO.getTaskCategory());
                if (taskVO.getComment() != null)
                    templateDef.setDescription(taskVO.getComment());
                if (taskVO.getAttributes() != null) {
                    for (AttributeVO attrVO : taskVO.getAttributes()) {
                        if (!"TaskDescription".equals(attrVO.getAttributeName())) {
                            Attribute attr = templateDef.addNewAttribute();
                            attr.setName(attrVO.getAttributeName());
                            attr.setStringValue(attrVO.getAttributeValue());
                        }
                    }
                }
            }
        }
    }
    String xml = pkgDoc.xmlText(new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2));
    if (monitor != null && monitor.isCanceled())
        throw new ActionCancelledException();
    if (monitor != null)
        monitor.progress(40);
    return xml;
}
Also used : PackageDocument(com.centurylink.mdw.bpm.PackageDocument) TaskTemplate(com.centurylink.mdw.task.TaskTemplate) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) CustomAttributeVO(com.centurylink.mdw.model.value.attribute.CustomAttributeVO) TaskTemplatesDocument(com.centurylink.mdw.task.TaskTemplatesDocument) Attribute(com.centurylink.mdw.task.Attribute) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) XmlOptions(org.apache.xmlbeans.XmlOptions) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) MDWPackage(com.centurylink.mdw.bpm.MDWPackage)

Example 2 with PackageDocument

use of com.centurylink.mdw.bpm.PackageDocument 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 PackageDocument

use of com.centurylink.mdw.bpm.PackageDocument 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 PackageDocument

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

the class ImportPackagePage method populateTopFolder.

public Folder populateTopFolder(String discoveryUrl, String groupId, boolean latestVersionsOnly, IProgressMonitor progressMonitor) throws Exception {
    Folder folder = null;
    getImportPackageWizard().getImportPackageSelectPage().clear();
    if (discoveryUrl != null || groupId != null) {
        if (discoveryUrl != null) {
            if (getProject().checkRequiredVersion(6, 0, 13))
                folder = new Discoverer(new URL(discoveryUrl), getProject().getHttpHelper(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
            else
                folder = new Discoverer(new URL(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
        }
        if (groupId != null)
            folder = new Discoverer(groupId).getAssetTopFolder(latestVersionsOnly, progressMonitor);
        if (getProject().isRemote() && getProject().isGitVcs()) {
            List<Folder> emptyFolders = removeGitVersionedPackages(folder);
            List<Folder> emptyParents = new ArrayList<>();
            for (Folder emptyFolder : emptyFolders) {
                if (emptyFolder.getParent() instanceof Folder) {
                    Folder parent = emptyFolder.getParent();
                    parent.getChildren().remove(emptyFolder);
                    // go one more level up
                    if (parent.getChildren().isEmpty() && !emptyParents.contains(parent))
                        emptyParents.add(parent);
                }
            }
            for (Folder emptyParent : emptyParents) {
                if (emptyParent.getParent() instanceof Folder)
                    (emptyParent.getParent()).getChildren().remove(emptyParent);
            }
        }
    } else {
        String filepath = filePathText.getText().trim();
        String contents = FileHelper.getFileContents(filepath);
        folder = new Folder(filepath);
        boolean hasOldImpls = false;
        if (contents.trim().startsWith("{")) {
            ImporterExporterJson importer = new ImporterExporterJson();
            List<PackageVO> packages = importer.importPackages(contents);
            for (PackageVO pkg : packages) {
                if (getProject().isRemote() && getProject().isGitVcs()) {
                    for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                        if (existingVcs.getName().equals(pkg.getName()))
                            getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkg.getName());
                    }
                }
                File aFile = new File(folder, pkg.getName() + " v" + pkg.getVersionString());
                ImporterExporterJson jsonExporter = new ImporterExporterJson();
                List<PackageVO> pkgs = new ArrayList<>();
                pkgs.add(pkg);
                JSONObject pkgJson = new JSONObject(jsonExporter.exportPackages(pkgs));
                pkgJson.put("name", pkg.getName());
                aFile.setContent(pkgJson.toString(2));
                folder.addChild(aFile);
            }
            preselected = folder;
        } else {
            try {
                // try and parse as multiple packages
                PackageDocument pkgDoc = PackageDocument.Factory.parse(contents);
                QName docElement = new QName("http://mdw.centurylink.com/bpm", "processDefinition");
                for (MDWProcessDefinition pkgDef : pkgDoc.getPackage().getProcessDefinitionList()) {
                    if (getProject().isRemote() && getProject().isGitVcs()) {
                        for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                            if (existingVcs.getName().equals(pkgDef.getPackageName()))
                                getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkgDef.getPackageName());
                        }
                    }
                    if (!hasOldImpls && getProject().isFilePersist() && !getProject().isRemote())
                        hasOldImpls = checkForOldImplementors(pkgDef);
                    File aFile = new File(folder, pkgDef.getPackageName() + " v" + pkgDef.getPackageVersion());
                    aFile.setContent(pkgDef.xmlText(new XmlOptions().setSaveOuter().setSaveSyntheticDocumentElement(docElement)));
                    folder.addChild(aFile);
                }
                preselected = folder;
            } catch (XmlException ex) {
                // unparseable -- assume single package
                if (getProject().isRemote() && getProject().isGitVcs()) {
                    MDWProcessDefinition procDef = ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition();
                    for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                        if (existingVcs.getName().equals(procDef.getPackageName()))
                            getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + procDef.getPackageName());
                    }
                }
                if (getProject().isFilePersist() && !getProject().isRemote())
                    hasOldImpls = checkForOldImplementors(ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition());
                File file = new File(folder, filepath);
                file.setContent(contents);
                folder.addChild(file);
                preselected = file;
            }
        }
        getImportPackageWizard().setHasOldImplementors(hasOldImpls);
    }
    return folder;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) Discoverer(com.centurylink.mdw.plugin.designer.Discoverer) Folder(com.centurylink.mdw.plugin.designer.model.Folder) URL(java.net.URL) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) JSONObject(org.json.JSONObject) XmlException(org.apache.xmlbeans.XmlException) File(com.centurylink.mdw.plugin.designer.model.File) ImporterExporterJson(com.centurylink.mdw.dataaccess.file.ImporterExporterJson)

Example 5 with PackageDocument

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

the class Importer method importTaskTemplates.

public void importTaskTemplates(final WorkflowPackage pkg, final String xml, final ProgressMonitor progressMonitor) throws XmlException, DataAccessException {
    progressMonitor.subTask(PARSING_XML);
    PackageDocument pkgDoc = PackageDocument.Factory.parse(xml);
    MDWPackage packageDef = pkgDoc.getPackage();
    if (!pkg.getName().equals(packageDef.getName()))
        throw new DataAccessException("Expected package: " + pkg.getName() + " in tasks XML but found: " + packageDef.getName());
    com.centurylink.mdw.task.TaskTemplatesDocument.TaskTemplates templates = packageDef.getTaskTemplates();
    PackageVO packageVO = new PackageVO();
    if (packageDef.getName() != null)
        packageVO.setPackageName(packageDef.getName());
    else
        packageVO.setPackageName("package");
    packageVO.setVersion(PackageVO.parseVersion(packageDef.getVersion()));
    List<TaskVO> packageTaskTemplates = new ArrayList<>();
    for (com.centurylink.mdw.task.TaskTemplate template : templates.getTaskList()) {
        TaskVO taskTemplateVO = new TaskVO(template);
        taskTemplateVO.setPackageName(packageVO.getPackageName());
        String v = template.getVersion();
        if (v != null && !v.equals("0"))
            taskTemplateVO.setVersion(RuleSetVO.parseVersion(v));
        String assetName = template.getAssetName();
        if (assetName != null && !assetName.isEmpty())
            taskTemplateVO.setName(assetName);
        packageTaskTemplates.add(taskTemplateVO);
    }
    packageVO.setTaskTemplates(packageTaskTemplates);
    if (!packageTaskTemplates.isEmpty())
        dataAccess.getDesignerDataAccess().savePackage(packageVO, ProcessPersister.PersistType.IMPORT);
    for (TaskVO taskVo : packageVO.getTaskTemplates()) {
        TaskTemplate existing = null;
        for (TaskTemplate taskTemplate : pkg.getTaskTemplates()) {
            if (taskTemplate.getLogicalId().equals(taskVo.getLogicalId())) {
                existing = taskTemplate;
                break;
            }
        }
        if (existing == null) {
            TaskTemplate newTemplate = new TaskTemplate(taskVo, pkg.getPackage());
            pkg.addTaskTemplate(newTemplate);
        } else {
            existing.setTaskVO(taskVo);
        }
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) MDWPackage(com.centurylink.mdw.bpm.MDWPackage) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Aggregations

PackageDocument (com.centurylink.mdw.bpm.PackageDocument)5 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)5 ArrayList (java.util.ArrayList)4 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)3 XmlOptions (org.apache.xmlbeans.XmlOptions)3 JSONObject (org.json.JSONObject)3 MDWPackage (com.centurylink.mdw.bpm.MDWPackage)2 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)2 Property (com.centurylink.mdw.bpm.PropertyDocument.Property)2 PropertyGroup (com.centurylink.mdw.bpm.PropertyGroupDocument.PropertyGroup)2 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 XmlException (org.apache.xmlbeans.XmlException)2 Yaml (org.yaml.snakeyaml.Yaml)2 ApplicationProperties (com.centurylink.mdw.bpm.ApplicationPropertiesDocument.ApplicationProperties)1 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)1 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)1