Search in sources :

Example 11 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class Exporter method exportPackages.

public String exportPackages(List<WorkflowPackage> packages, boolean exportJson, boolean includeTaskTemplates, ProgressMonitor progressMonitor) throws DataAccessException, ActionCancelledException, JSONException, XmlException {
    String export = null;
    progressMonitor.progress(10);
    int schemaVersion = designerDataAccess.getDatabaseSchemaVersion();
    List<PackageVO> pkgVos = new ArrayList<>();
    for (WorkflowPackage pv : packages) pkgVos.add(pv.getPackageVO());
    export = designerDataAccess.exportPackages(pkgVos, schemaVersion, exportJson, includeTaskTemplates, progressMonitor);
    for (WorkflowPackage pv : packages) pv.setExported(true);
    return export;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList)

Example 12 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method findArchivedPackages.

/**
 * Returns all top-level archived (non-latest) packages, populated with
 * their descendants which include the appropriate process versions. Uses
 * 10% of progressMonitor.
 */
private Folder findArchivedPackages(ProgressMonitor progressMonitor, boolean visiblePkgsOnly) {
    CodeTimer timer = new CodeTimer("findAuthorizedArchivedPackages()");
    if (progressMonitor != null)
        progressMonitor.subTask("Organizing packages");
    Folder archivedPkgFolder = new Folder("Archive", this);
    archivedPkgFolder.setIcon("archive.gif");
    List<WorkflowPackage> topLevelArchivedPackageList = new ArrayList<>();
    List<WorkflowPackage> allArchivedPackages = new ArrayList<>();
    for (PackageVO packageVO : getDataAccess().getPackages(false)) {
        if (isShowDefaultPackage() || !packageVO.isDefaultPackage()) {
            WorkflowPackage potentialArchived = new WorkflowPackage(this, packageVO);
            if (!getTopLevelPackages().contains(potentialArchived)) {
                potentialArchived.setArchived(true);
                potentialArchived.setProcesses(findProcesses(potentialArchived));
                potentialArchived.setAssets(findWorkflowAssets(potentialArchived));
                potentialArchived.setActivityImpls(findActivityImplementors(potentialArchived));
                potentialArchived.setExternalEvents(findExternalEvents(potentialArchived));
                potentialArchived.setTaskTemplates(findTaskTemplates(potentialArchived));
                allArchivedPackages.add(potentialArchived);
            }
        }
    }
    // organize the package version hierarchy
    Map<String, WorkflowPackage> topLevelArchivedPackages = new HashMap<>();
    for (WorkflowPackage archivedPackage : allArchivedPackages) {
        WorkflowPackage topLevel = topLevelArchivedPackages.get(archivedPackage.getName());
        if ((!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible())) && (topLevel == null || archivedPackage.getPackageVO().getVersion() > topLevel.getPackageVO().getVersion()))
            topLevelArchivedPackages.put(archivedPackage.getName(), archivedPackage);
    }
    for (WorkflowPackage topLevelArchivedPackage : topLevelArchivedPackages.values()) {
        for (WorkflowPackage archivedPackage : allArchivedPackages) {
            if (topLevelArchivedPackage.getName().equals(archivedPackage.getName()) && (!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible()))) {
                if (topLevelArchivedPackage.equals(archivedPackage)) {
                    // clone top-level process for first child
                    WorkflowPackage firstChild = new WorkflowPackage(topLevelArchivedPackage);
                    firstChild.setArchived(true);
                    firstChild.setTopLevelVersion(topLevelArchivedPackage);
                    firstChild.setProcesses(topLevelArchivedPackage.getProcesses());
                    firstChild.setAssets(topLevelArchivedPackage.getAssets());
                    firstChild.setActivityImpls(topLevelArchivedPackage.getActivityImpls());
                    firstChild.setExternalEvents(topLevelArchivedPackage.getExternalEvents());
                    firstChild.setTaskTemplates(topLevelArchivedPackage.getTaskTemplates());
                    topLevelArchivedPackage.addDescendantPackageVersion(firstChild);
                } else {
                    archivedPackage.setTopLevelVersion(topLevelArchivedPackage);
                    topLevelArchivedPackage.addDescendantPackageVersion(archivedPackage);
                }
            }
        }
        topLevelArchivedPackageList.add(topLevelArchivedPackage);
        topLevelArchivedPackage.setArchivedFolder(archivedPkgFolder);
    }
    Collections.sort(topLevelArchivedPackageList);
    if (isShowDefaultPackage()) {
        // add unpackaged (default package)
        PackageVO defaultPackageVO = new PackageVO();
        defaultPackageVO.setPackageId(Long.valueOf(0));
        defaultPackageVO.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
        archivedDefaultPackage = new WorkflowPackage(this, defaultPackageVO);
        archivedDefaultPackage.setProcesses(findUnpackagedProcesses());
        archivedDefaultPackage.setChildFolders(findUnpackagedAssetFolders());
        archivedDefaultPackage.setArchived(true);
        topLevelArchivedPackageList.add(0, archivedDefaultPackage);
    }
    List<WorkflowElement> children = new ArrayList<>();
    children.addAll(topLevelArchivedPackageList);
    archivedPkgFolder.setChildren(children);
    if (progressMonitor != null)
        progressMonitor.progress(10);
    timer.stopAndLog();
    return archivedPkgFolder;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(com.centurylink.mdw.plugin.designer.model.Folder) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IFolder(org.eclipse.core.resources.IFolder) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Example 13 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method newPackageVersion.

public void newPackageVersion(WorkflowPackage newPkg, WorkflowPackage prevPkg) {
    if (isFilePersist()) {
        // refresh prevPkg since it's fast
        try {
            PackageVO pkg = getDesignerDataAccess().loadPackage(prevPkg.getId(), false);
            if (// when incrementing by saving non-process
            pkg == null)
                // pkgs
                return;
            prevPkg.setPackageVO(pkg);
            prevPkg.setProcesses(findProcesses(prevPkg));
            prevPkg.setExternalEvents(findExternalEvents(prevPkg));
            prevPkg.setActivityImpls(findActivityImplementors(prevPkg));
            prevPkg.setAssets(findWorkflowAssets(prevPkg));
            prevPkg.setTaskTemplates(findTaskTemplates(prevPkg));
            // may have been called in response to vcs save new process
            // version
            prevPkg.syncProcesses();
        } catch (Exception ex) {
            PluginMessages.log(ex);
        }
    }
    // contents
    for (WorkflowElement we : getArchivedUserVisiblePackagesFolder().getChildren()) {
        WorkflowPackage pv = (WorkflowPackage) we;
        if (pv.getName().equals(prevPkg.getName())) {
            List<WorkflowPackage> descendants = pv.getDescendantPackageVersions();
            if (descendants == null) {
                descendants = new ArrayList<>();
                pv.setDescendantPackageVersions(descendants);
            }
            descendants.add(prevPkg);
            prevPkg.setTopLevelVersion(pv);
        }
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) MalformedURLException(java.net.MalformedURLException) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Example 14 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO 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 15 with PackageVO

use of com.centurylink.mdw.model.value.process.PackageVO in project mdw-designer by CenturyLinkCloud.

the class ImportPackageWizard method unzipToLocal.

void unzipToLocal(WorkflowProject wfp, java.io.File zipFile, java.io.File tempDir, java.io.File assetDir, List<WorkflowPackage> importedPackages, ProgressMonitor progressMonitor) throws IOException, DataAccessException, CoreException, JSONException {
    VersionControl vcs = new VersionControlGit();
    vcs.connect(null, null, null, wfp.getAssetDir());
    progressMonitor.subTask("Archive existing assets...");
    VcsArchiver archiver = new VcsArchiver(assetDir, tempDir, vcs, progressMonitor);
    archiver.backup();
    PluginMessages.log("Unzipping " + zipFile + " into: " + assetDir);
    ZipHelper.unzip(zipFile, assetDir, null, null, true);
    archiver.archive();
    ZipHelper.unzip(zipFile, tempDir, null, null, true);
    wfp.getSourceProject().refreshLocal(2, null);
    java.io.File explodedDir = new java.io.File(tempDir + "/com");
    if (explodedDir.isDirectory()) {
        List<java.io.File> fileList = FileHelper.getFilesRecursive(explodedDir, "package.json", new ArrayList<java.io.File>());
        for (java.io.File file : fileList) {
            WorkflowPackage workflowPackage = new WorkflowPackage();
            workflowPackage.setProject(wfp);
            workflowPackage.setPackageVO(new PackageVO(new JSONObject(FileHelper.getFileContents(file.getPath()))));
            importedPackages.add(workflowPackage);
        }
        FileHelper.deleteRecursive(explodedDir);
    }
}
Also used : VcsArchiver(com.centurylink.mdw.dataaccess.file.VcsArchiver) VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) JSONObject(org.json.JSONObject) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) File(com.centurylink.mdw.plugin.designer.model.File)

Aggregations

PackageVO (com.centurylink.mdw.model.value.process.PackageVO)27 ArrayList (java.util.ArrayList)18 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)11 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)8 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)7 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)6 IOException (java.io.IOException)6 JSONObject (org.json.JSONObject)6 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)5 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)5 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)5 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)5 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)5 JSONException (org.json.JSONException)5 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)4 CodeTimer (com.centurylink.mdw.plugin.CodeTimer)4 HashMap (java.util.HashMap)4 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)3 ImporterExporterJson (com.centurylink.mdw.dataaccess.file.ImporterExporterJson)3 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)3