Search in sources :

Example 1 with ImporterExporterJson

use of com.centurylink.mdw.dataaccess.file.ImporterExporterJson 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 2 with ImporterExporterJson

use of com.centurylink.mdw.dataaccess.file.ImporterExporterJson in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method exportPackages.

public String exportPackages(List<PackageVO> packages, int schemaVersion, boolean exportJson, boolean includeTaskTemplates, ProgressMonitor monitor) throws DataAccessException, ActionCancelledException, JSONException, XmlException {
    if (monitor != null)
        monitor.subTask("Loading package(s)...");
    List<PackageVO> loadedPackages = new ArrayList<>();
    for (PackageVO pkg : packages) {
        if (monitor != null)
            monitor.subTask("Loading " + pkg.getLabel() + "...");
        PackageVO packageVO = loadPackage(pkg.getId(), true);
        if (monitor != null)
            monitor.progress(30 / packages.size());
        if (monitor != null) {
            if (monitor.isCanceled())
                throw new ActionCancelledException();
            else
                monitor.subTask("Sorting processes and implementors");
        }
        if (packageVO.getRuleSets() != null) {
            Map<String, CustomAttributeVO> customAttrs = new HashMap<>();
            for (RuleSetVO ruleSet : packageVO.getRuleSets()) {
                if (ruleSet.getLanguage() != null && !customAttrs.containsKey(ruleSet.getLanguage())) {
                    CustomAttributeVO custAttrVO = getCustomAttribute("RULE_SET", ruleSet.getLanguage());
                    if (custAttrVO != null)
                        customAttrs.put(ruleSet.getLanguage(), custAttrVO);
                }
            }
            List<CustomAttributeVO> customAttributes = new ArrayList<>();
            for (CustomAttributeVO customAttr : customAttrs.values()) customAttributes.add(customAttr);
            packageVO.setCustomAttributes(customAttributes);
        }
        loadedPackages.add(packageVO);
    }
    if (monitor != null && monitor.isCanceled())
        throw new ActionCancelledException();
    if (monitor != null)
        monitor.progress(5);
    if (monitor != null)
        monitor.subTask(EXPORTXML);
    String export;
    if (exportJson) {
        ImporterExporterJson exporter = new ImporterExporterJson();
        export = exporter.exportPackages(loadedPackages);
    } else {
        ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
        export = exporter.exportPackages(loadedPackages, includeTaskTemplates);
    }
    if (monitor != null)
        monitor.progress(25);
    for (PackageVO packageVO : loadedPackages) {
        packageVO.setExported(true);
        persister.persistPackage(packageVO, PersistType.UPDATE);
    }
    if (monitor != null)
        monitor.progress(15);
    return export;
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) HashMap(java.util.HashMap) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) CustomAttributeVO(com.centurylink.mdw.model.value.attribute.CustomAttributeVO) ArrayList(java.util.ArrayList) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter) ImporterExporterJson(com.centurylink.mdw.dataaccess.file.ImporterExporterJson) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 3 with ImporterExporterJson

use of com.centurylink.mdw.dataaccess.file.ImporterExporterJson in project mdw-designer by CenturyLinkCloud.

the class Exporter method exportPackage.

public String exportPackage(String packageName, boolean includeTaskTemplates, boolean isJson) throws DataAccessException, RemoteException, ActionCancelledException, XmlException, JSONException {
    int schemaVersion = dataAccess.getDatabaseSchemaVersion();
    PackageVO packageVo = dataAccess.getPackage(packageName);
    if (isJson) {
        List<PackageVO> packages = new ArrayList<>();
        packages.add(dataAccess.loadPackage(packageVo.getId(), true));
        ImporterExporterJson jsonExporter = new ImporterExporterJson();
        return jsonExporter.exportPackages(packages);
    } else {
        String xml = dataAccess.exportPackage(packageVo.getId(), schemaVersion, includeTaskTemplates, null);
        if (!isLocal()) {
            packageVo.setExported(true);
            dataAccess.savePackage(packageVo);
        }
        return xml;
    }
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) ImporterExporterJson(com.centurylink.mdw.dataaccess.file.ImporterExporterJson)

Aggregations

ImporterExporterJson (com.centurylink.mdw.dataaccess.file.ImporterExporterJson)3 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)3 ArrayList (java.util.ArrayList)3 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)1 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)1 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)1 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)1 CustomAttributeVO (com.centurylink.mdw.model.value.attribute.CustomAttributeVO)1 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)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 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 JSONObject (org.json.JSONObject)1