Search in sources :

Example 1 with MDWProcessDefinition

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

use of com.centurylink.mdw.bpm.MDWProcessDefinition 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 3 with MDWProcessDefinition

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

MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)3 MDWProcess (com.centurylink.mdw.bpm.MDWProcess)2 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)2 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)2 XmlOptions (org.apache.xmlbeans.XmlOptions)2 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)1 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)1 ImporterExporterJson (com.centurylink.mdw.dataaccess.file.ImporterExporterJson)1 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)1 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)1 Discoverer (com.centurylink.mdw.plugin.designer.Discoverer)1 File (com.centurylink.mdw.plugin.designer.model.File)1 Folder (com.centurylink.mdw.plugin.designer.model.Folder)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1