Search in sources :

Example 1 with ActionCancelledException

use of com.centurylink.mdw.common.utilities.timer.ActionCancelledException 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 ActionCancelledException

use of com.centurylink.mdw.common.utilities.timer.ActionCancelledException in project mdw-designer by CenturyLinkCloud.

the class Importer method importPackage.

public void importPackage(String xml, boolean overwrite) throws DataAccessException, RemoteException, ActionCancelledException, XmlException {
    int preexistingVersion = -1;
    System.out.println("Parsing XML...");
    importedPackageVO = parsePackageXml(xml);
    PackageVO existing = null;
    try {
        existing = dataAccess.getPackage(importedPackageVO.getPackageName());
    } catch (DataAccessException ex) {
        if (!ex.getMessage().startsWith("Package does not exist:"))
            throw ex;
    }
    if (existing != null) {
        if (existing.getVersion() == importedPackageVO.getVersion()) {
            String msg = "Target already contains Package '" + importedPackageVO.getPackageName() + "' v" + importedPackageVO.getVersionString();
            if (!overwrite)
                throw new ActionCancelledException(msg + " and overwrite argument NOT specified.");
            else
                System.out.println(msg + " -- will overwrite existing package.");
            // overwrite existing
            importedPackageVO.setPackageId(existing.getId());
            if (!isLocal())
                importedPackageVO.setVersion(0);
            preexistingVersion = existing.getVersion();
        } else if (existing.getVersion() > importedPackageVO.getVersion()) {
            String msg = "Target already contains Package '" + importedPackageVO.getPackageName() + "' v" + existing.getVersionString() + ", whose version is greater than that of the imported package.  Cannot continue.";
            throw new ActionCancelledException(msg);
        }
    }
    System.out.println("Checking elements...");
    final List<RuleSetVO> conflicts = new ArrayList<>();
    final List<RuleSetVO> conflictsWithDifferences = new ArrayList<>();
    List<ProcessVO> existingProcessVOs = new ArrayList<>();
    List<ProcessVO> processVOsToBeImported = new ArrayList<>();
    ProcessExporter exporter = null;
    System.out.println("Comparing processes...");
    for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
        ProcessVO existingProcess = null;
        try {
            existingProcess = dataAccess.getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
        } catch (DataAccessException ex) {
            // trap process does not exist
            if (!ex.getMessage().startsWith("Process does not exist;"))
                throw ex;
        }
        if (existingProcess != null) {
            conflicts.add(existingProcess);
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion52) {
                // content comparison
                if (exporter == null) {
                    boolean isOldNamespaces = dataAccess.getDatabaseSchemaVersion() < DataAccess.schemaVersion55;
                    exporter = DataAccess.getProcessExporter(dataAccess.getDatabaseSchemaVersion(), isOldNamespaces ? DesignerCompatibility.getInstance() : null);
                }
                String existingProcessXml = dataAccess.getRuleSet(existingProcess.getId()).getRuleSet();
                String importedProcessXml = exporter.exportProcess(importedProcessVO, dataAccess.getDatabaseSchemaVersion(), null);
                if (dataAccess.getSupportedSchemaVersion() < DataAccess.schemaVersion55) {
                    // may need to replace old namespace prefix in existing
                    // to avoid false positives in 5.2
                    String oldNamespaceDecl = "xmlns:xs=\"http://mdw.qwest.com/XMLSchema\"";
                    int oldNsIdx = existingProcessXml.indexOf(oldNamespaceDecl);
                    if (oldNsIdx > 0) {
                        String newNamespaceDecl = "xmlns:bpm=\"http://mdw.qwest.com/XMLSchema\"";
                        existingProcessXml = existingProcessXml.substring(0, oldNsIdx) + newNamespaceDecl + importedProcessXml.substring(oldNsIdx + oldNamespaceDecl.length() + 2);
                        existingProcessXml = existingProcessXml.replaceAll("<xs:", "<bpm:");
                        existingProcessXml = existingProcessXml.replaceAll("</xs:", "</bpm:");
                    }
                }
                // avoid false positives
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_ACTIVITIES\".*/>", "");
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_PROCESSES\".*/>", "");
                existingProcessXml = existingProcessXml.replaceFirst(" packageVersion=\"0.0\"", "");
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"processid\".*/>", "");
                if (!existingProcessXml.equals(importedProcessXml))
                    conflictsWithDifferences.add(existingProcess);
            }
            if (isLocal())
                processVOsToBeImported.add(importedProcessVO);
            else
                existingProcessVOs.add(existingProcess);
        } else {
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion52)
                // not optional
                importedProcessVO.setInRuleSet(true);
            processVOsToBeImported.add(importedProcessVO);
        }
        for (ProcessVO subProcVO : importedProcessVO.getSubProcesses()) {
            ProcessVO existingSubProc = null;
            try {
                existingSubProc = dataAccess.getProcessDefinition(subProcVO.getProcessName(), subProcVO.getVersion());
            } catch (DataAccessException ex) {
                // trap process does not exist
                if (!ex.getMessage().startsWith("Process does not exist;"))
                    throw ex;
            }
            if (existingSubProc != null) {
                conflicts.add(existingSubProc);
                existingProcessVOs.add(existingSubProc);
                if (!isLocal())
                    existingProcessVOs.add(existingSubProc);
            }
        }
    }
    List<RuleSetVO> existingRuleSets = new ArrayList<>();
    List<RuleSetVO> ruleSetsToBeImported = new ArrayList<>();
    List<RuleSetVO> emptyRuleSets = new ArrayList<>();
    if (importedPackageVO.getRuleSets() != null) {
        System.out.println("Comparing assets...");
        for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
            RuleSetVO existingAsset = null;
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55) {
                // supports same-named assets in different packages
                if (existing != null) {
                    RuleSetVO latestAsset = dataAccess.getRuleSet(existing.getPackageId(), importedRuleSet.getName());
                    if (latestAsset != null && latestAsset.getVersion() >= importedRuleSet.getVersion())
                        existingAsset = latestAsset;
                }
            } else {
                existingAsset = dataAccess.getRuleSet(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
            }
            if (existingAsset != null) {
                conflicts.add(existingAsset);
                if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion52) {
                    // content comparison
                    existingAsset = dataAccess.getRuleSet(existingAsset.getId());
                    String existingAssetStr = existingAsset.getRuleSet().trim();
                    String importedAssetStr = importedRuleSet.getRuleSet().trim();
                    if (!existingAsset.isBinary()) {
                        existingAssetStr = existingAssetStr.replaceAll("\r", "");
                        importedAssetStr = importedAssetStr.replaceAll("\r", "");
                    }
                    if (!existingAssetStr.equals(importedAssetStr))
                        conflictsWithDifferences.add(existingAsset);
                }
                if (isLocal())
                    ruleSetsToBeImported.add(importedRuleSet);
                else
                    existingRuleSets.add(existingAsset);
            } else if (importedRuleSet.getRuleSet().trim().isEmpty()) {
                emptyRuleSets.add(importedRuleSet);
            } else {
                ruleSetsToBeImported.add(importedRuleSet);
            }
        }
    }
    if (existing != null && importedPackageVO.getTaskTemplates() != null && existing.getTaskTemplates() != null) {
        for (TaskVO importedTask : importedPackageVO.getTaskTemplates()) {
            for (TaskVO taskTemplate : existing.getTaskTemplates()) {
                if (taskTemplate.getName().equals(importedTask.getName()) && taskTemplate.getVersion() == importedTask.getVersion()) {
                    conflicts.add(taskTemplate);
                    String existingTemplStr = taskTemplate.toTemplate().xmlText();
                    String importedTemplStr = importedTask.toTemplate().xmlText();
                    if (!existingTemplStr.equals(importedTemplStr))
                        conflictsWithDifferences.add(taskTemplate);
                }
            }
        }
    }
    if (!conflicts.isEmpty()) {
        Collections.sort(conflicts, new Comparator<RuleSetVO>() {

            public int compare(RuleSetVO rs1, RuleSetVO rs2) {
                return rs1.getLabel().compareToIgnoreCase(rs2.getLabel());
            }
        });
        String msg;
        if (isLocal())
            msg = "The following versions exist locally in '" + importedPackageVO.getPackageName() + "' and will be overwritten:";
        else
            msg = "The following versions from package '" + importedPackageVO.getPackageName() + "' will not be imported:\n(The same or later versions already exist in the target environment";
        if (dataAccess.getDatabaseSchemaVersion() >= DataAccess.schemaVersion52)
            msg += " -- * indicates content differs";
        msg += ").";
        System.out.println(msg);
        for (RuleSetVO rs : conflicts) {
            String flag = conflictsWithDifferences.contains(rs) ? " *" : "";
            System.out.println("   " + rs.getLabel() + flag);
        }
    }
    if (!emptyRuleSets.isEmpty()) {
        System.out.println("The following assets from package '" + importedPackageVO.getPackageName() + "' will not be imported because they're empty:");
        for (RuleSetVO rs : emptyRuleSets) System.out.println("   " + rs.getLabel());
    }
    importedPackageVO.setProcesses(processVOsToBeImported);
    importedPackageVO.setRuleSets(ruleSetsToBeImported);
    // designer fix for backward compatibility
    ProcessWorker worker = new ProcessWorker();
    if (importedPackageVO.getProcesses() != null) {
        NodeMetaInfo nodeMetaInfo = new NodeMetaInfo();
        nodeMetaInfo.init(dataAccess.getActivityImplementors(), dataAccess.getDatabaseSchemaVersion());
        NodeMetaInfo syncedNodeMetaInfo = syncNodeMetaInfo(nodeMetaInfo, importedPackageVO);
        for (ProcessVO p : importedPackageVO.getProcesses()) {
            worker.convert_to_designer(p);
            worker.convert_from_designer(p, syncedNodeMetaInfo);
        }
    }
    System.out.println("Saving package...");
    if (isLocal())
        dataAccess.savePackageNoAudit(importedPackageVO, ProcessPersister.PersistType.IMPORT);
    else
        dataAccess.savePackage(importedPackageVO, ProcessPersister.PersistType.IMPORT);
    if (preexistingVersion > 0)
        // reset version
        importedPackageVO.setVersion(preexistingVersion);
    if (importedPackageVO.getProcesses() != null) {
        System.out.println("Reloading processes...");
        for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
            ProcessVO reloaded = dataAccess.getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
            importedProcessVO.setProcessId(reloaded.getProcessId());
        }
        if (dataAccess.getSupportedSchemaVersion() < DataAccess.schemaVersion52) {
            for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) updateSubProcessIdAttributes(importedProcessVO);
        }
    }
    if (!existingProcessVOs.isEmpty()) {
        // add back existing processes
        importedPackageVO.getProcesses().addAll(existingProcessVOs);
        dataAccess.savePackage(importedPackageVO);
    }
    if (importedPackageVO.getRuleSets() != null) {
        System.out.println("Reloading workflow assets");
        for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
            RuleSetVO reloaded;
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55) {
                reloaded = dataAccess.getRuleSet(importedPackageVO.getId(), importedRuleSet.getName());
                if (// need to verify whether the above is
                reloaded == null)
                    // even needed
                    reloaded = dataAccess.getRuleSet(importedRuleSet.getId());
            } else {
                reloaded = dataAccess.getRuleSet(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
            }
            importedRuleSet.setId(reloaded.getId());
        }
    }
    if (!existingRuleSets.isEmpty()) {
        importedPackageVO.getRuleSets().addAll(existingRuleSets);
        System.out.println("Saving Package...");
        if (isLocal())
            dataAccess.savePackageNoAudit(importedPackageVO);
        else
            dataAccess.savePackage(importedPackageVO);
    }
    if (preexistingVersion > 0 && existingProcessVOs.isEmpty() && existingRuleSets.isEmpty()) {
        System.out.println("Saving Package...");
        if (isLocal())
            // force
            dataAccess.savePackageNoAudit(importedPackageVO);
        else
            // associate
            // processes
            // force associate
            dataAccess.savePackage(importedPackageVO);
    // processes
    }
}
Also used : NodeMetaInfo(com.centurylink.mdw.designer.utils.NodeMetaInfo) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 3 with ActionCancelledException

use of com.centurylink.mdw.common.utilities.timer.ActionCancelledException in project mdw-designer by CenturyLinkCloud.

the class Importer method importPackage.

public WorkflowPackage importPackage(final WorkflowProject project, final String content, final ProgressMonitor progressMonitor) throws DataAccessException, RemoteException, ActionCancelledException, JSONException, XmlException {
    CodeTimer timer = new CodeTimer("importPackage()");
    int preexistingVersion = -1;
    importedPackageVO = null;
    progressMonitor.start("Importing Package into: '" + project.getLabel() + "'");
    progressMonitor.progress(5);
    progressMonitor.subTask(PARSING_XML);
    boolean isJson = content.trim().startsWith("{");
    importedPackageVO = parsePackageContent(content);
    progressMonitor.subTask("Importing " + importedPackageVO.getLabel());
    progressMonitor.progress(10);
    final WorkflowPackage existing = project.getPackage(importedPackageVO.getPackageName());
    if (existing != null) {
        if (existing.getVersion() == importedPackageVO.getVersion()) {
            final String msg = project.getName() + " already contains Package '" + importedPackageVO.getPackageName() + "' v" + importedPackageVO.getVersionString();
            if (shell != null) {
                shell.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        if (!MessageDialog.openConfirm(shell, "Import Package", msg + ".\nImport this package?"))
                            importedPackageVO = null;
                    }
                });
            } else {
                PluginMessages.log(msg);
            }
            if (importedPackageVO != null) {
                // overwrite existing
                importedPackageVO.setPackageId(existing.getId());
                if (!isLocal())
                    importedPackageVO.setVersion(0);
                preexistingVersion = existing.getVersion();
            }
        } else if (existing.getVersion() > importedPackageVO.getVersion()) {
            final String msg = project.getName() + " already contains Package '" + importedPackageVO.getPackageName() + "' v" + existing.getVersionString() + ", whose version is greater than that of the imported package.  Cannot continue.";
            if (shell != null) {
                shell.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        MessageDialog.openError(shell, "Import Package", msg);
                        importedPackageVO = null;
                    }
                });
            } else {
                PluginMessages.log(msg);
            }
        }
        if (importedPackageVO == null)
            return null;
    }
    if (shell != null && progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.progress(10);
    progressMonitor.subTask("Checking elements");
    final List<WorkflowElement> conflicts = new ArrayList<>();
    final List<WorkflowElement> conflictsWithDifferences = new ArrayList<>();
    final List<ProcessVO> existingProcessVOs = new ArrayList<>();
    List<ProcessVO> processVOsToBeImported = new ArrayList<>();
    ProcessExporter exporter = null;
    for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
        WorkflowProcess existingProcess = project.getProcess(importedProcessVO.getProcessName(), importedProcessVO.getVersionString());
        if (existingProcess != null) {
            conflicts.add(existingProcess);
            if (project.getDataAccess().getSupportedSchemaVersion() >= DataAccess.schemaVersion52 && MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport()) {
                progressMonitor.subTask("Comparing processes (can be disabled in prefs)");
                // content comparison
                if (exporter == null)
                    exporter = DataAccess.getProcessExporter(project.getDataAccess().getSchemaVersion(), project.isOldNamespaces() ? DesignerCompatibility.getInstance() : null);
                String existingProcessXml = project.getDataAccess().loadRuleSet(existingProcess.getId()).getRuleSet();
                String importedProcessXml = isJson ? importedProcessVO.getJson().toString(2) : exporter.exportProcess(importedProcessVO, project.getDataAccess().getSchemaVersion(), null);
                if (project.getDataAccess().getSupportedSchemaVersion() < DataAccess.schemaVersion55) {
                    // may need to replace old namespace prefix in existing
                    // to avoid false positives in 5.2
                    String oldNamespaceDecl = "xmlns:xs=\"http://mdw.qwest.com/XMLSchema\"";
                    int oldNsIdx = existingProcessXml.indexOf(oldNamespaceDecl);
                    if (oldNsIdx > 0) {
                        String newNamespaceDecl = "xmlns:bpm=\"http://mdw.qwest.com/XMLSchema\"";
                        existingProcessXml = existingProcessXml.substring(0, oldNsIdx) + newNamespaceDecl + importedProcessXml.substring(oldNsIdx + oldNamespaceDecl.length() + 2);
                        existingProcessXml = existingProcessXml.replaceAll("<xs:", "<bpm:");
                        existingProcessXml = existingProcessXml.replaceAll("</xs:", "</bpm:");
                    }
                }
                // avoid false positives
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_ACTIVITIES\".*/>", "");
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"REFERENCED_PROCESSES\".*/>", "");
                existingProcessXml = existingProcessXml.replaceFirst(" packageVersion=\"0.0\"", "");
                existingProcessXml = existingProcessXml.replaceAll("\\s*<bpm:Attribute Name=\"processid\".*/>", "");
                if (!existingProcessXml.equals(importedProcessXml))
                    conflictsWithDifferences.add(existingProcess);
            }
            if (isLocal())
                processVOsToBeImported.add(importedProcessVO);
            else
                existingProcessVOs.add(existingProcess.getProcessVO());
        } else {
            if (project.getDataAccess().getSupportedSchemaVersion() >= DataAccess.schemaVersion52)
                // not optional
                importedProcessVO.setInRuleSet(true);
            processVOsToBeImported.add(importedProcessVO);
        }
        for (ProcessVO subProcVO : importedProcessVO.getSubProcesses()) {
            WorkflowProcess existingSubProc = project.getProcess(subProcVO.getProcessName(), subProcVO.getVersionString());
            if (existingSubProc != null) {
                conflicts.add(existingSubProc);
                existingProcessVOs.add(existingSubProc.getProcessVO());
                if (!isLocal())
                    existingProcessVOs.add(existingSubProc.getProcessVO());
            }
        }
    }
    if (shell != null && progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.progress(10);
    final List<RuleSetVO> existingRuleSets = new ArrayList<>();
    List<RuleSetVO> ruleSetsToBeImported = new ArrayList<>();
    final List<RuleSetVO> emptyRuleSets = new ArrayList<>();
    if (importedPackageVO.getRuleSets() != null) {
        for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
            WorkflowAsset existingAsset = null;
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55)
                existingAsset = project.getAsset(importedPackageVO.getName(), importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
            else
                existingAsset = project.getAsset(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
            if (existingAsset != null) {
                conflicts.add(existingAsset);
                if (project.getDataAccess().getSupportedSchemaVersion() >= DataAccess.schemaVersion52 && MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport() && !existingAsset.isBinary()) {
                    progressMonitor.subTask("Comparing assets (can be disabled in prefs)");
                    // content comparison
                    existingAsset = project.getDesignerProxy().loadWorkflowAsset(existingAsset);
                    String existingAssetStr = existingAsset.getRuleSetVO().getRuleSet().trim();
                    String importedAssetStr = importedRuleSet.getRuleSet().trim();
                    if (!existingAsset.isBinary()) {
                        existingAssetStr = existingAssetStr.replaceAll("\r", "");
                        importedAssetStr = importedAssetStr.replaceAll("\r", "");
                    }
                    if (!existingAssetStr.equals(importedAssetStr))
                        conflictsWithDifferences.add(existingAsset);
                }
                if (isLocal())
                    ruleSetsToBeImported.add(importedRuleSet);
                else
                    existingRuleSets.add(existingAsset.getRuleSetVO());
            } else if (importedRuleSet.getRuleSet().trim().isEmpty()) {
                emptyRuleSets.add(importedRuleSet);
            } else {
                ruleSetsToBeImported.add(importedRuleSet);
            }
        }
    }
    if (MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport() && existing != null && importedPackageVO.getTaskTemplates() != null && existing.getTaskTemplates() != null) {
        for (TaskVO importedTask : importedPackageVO.getTaskTemplates()) {
            for (TaskTemplate taskTemplate : existing.getTaskTemplates()) {
                if (taskTemplate.getName().equals(importedTask.getName()) && taskTemplate.getVersion() == importedTask.getVersion()) {
                    conflicts.add(taskTemplate);
                    String existingTemplStr = taskTemplate.getTaskVO().toTemplate().xmlText();
                    String importedTemplStr = importedTask.toTemplate().xmlText();
                    if (!existingTemplStr.equals(importedTemplStr))
                        conflictsWithDifferences.add(taskTemplate);
                }
            }
        }
    }
    if (progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.progress(10);
    if (!conflicts.isEmpty()) {
        Collections.sort(conflicts, new Comparator<WorkflowElement>() {

            public int compare(WorkflowElement we1, WorkflowElement we2) {
                return we1.getLabel().compareToIgnoreCase(we2.getLabel());
            }
        });
        final String msg;
        if (isLocal())
            msg = "The following versions exist locally in '" + importedPackageVO.getPackageName() + "'.\nThese files in project '" + project.getName() + "' will be overwritten.\n";
        else
            msg = "The following versions from package '" + importedPackageVO.getPackageName() + "' will not be imported.\nThe same versions already exist in the '" + project.getName() + "' project.\n";
        if (shell != null) {
            shell.getDisplay().syncExec(new Runnable() {

                public void run() {
                    String msg2 = msg;
                    if (project.checkRequiredVersion(5, 2) && MdwPlugin.getSettings().isCompareConflictingAssetsDuringImport())
                        msg2 += "(Asterisk * indicates content differs.)\n";
                    int res = PluginMessages.uiList(shell, msg2, "Package Import", conflicts, conflictsWithDifferences);
                    if (res == Dialog.CANCEL)
                        importedPackageVO = null;
                }
            });
        } else {
            StringBuilder msg2 = new StringBuilder(msg);
            msg2.append(" (");
            if (project.checkRequiredVersion(5, 2))
                msg2.append(" -- * indicates content differs");
            msg2.append(").\n");
            for (WorkflowElement we : conflicts) {
                String flag = conflictsWithDifferences.contains(we) ? " *" : "";
                msg2.append("   ").append(we.getLabel()).append(flag).append("\n");
            }
            PluginMessages.log(msg2.toString());
        }
        if (importedPackageVO == null)
            return null;
    }
    if (!emptyRuleSets.isEmpty()) {
        final String msg = "The following assets from package '" + importedPackageVO.getPackageName() + "' will not be imported because they're empty.\n";
        if (shell != null) {
            shell.getDisplay().syncExec(new Runnable() {

                public void run() {
                    int res = PluginMessages.uiList(shell, msg, "Package Import", emptyRuleSets);
                    if (res == Dialog.CANCEL)
                        importedPackageVO = null;
                }
            });
        } else {
            StringBuilder msg2 = new StringBuilder(msg);
            for (RuleSetVO rs : emptyRuleSets) msg2.append("   ").append(rs.getLabel()).append("\n");
            PluginMessages.log(msg2.toString());
        }
        if (importedPackageVO == null)
            return null;
    }
    importedPackageVO.setProcesses(processVOsToBeImported);
    importedPackageVO.setRuleSets(ruleSetsToBeImported);
    // designer fix for backward compatibility
    ProcessWorker worker = new ProcessWorker();
    if (importedPackageVO.getProcesses() != null) {
        NodeMetaInfo syncedNodeMetaInfo = syncNodeMetaInfo(dataAccess.getDesignerDataModel().getNodeMetaInfo(), importedPackageVO);
        for (ProcessVO p : importedPackageVO.getProcesses()) {
            worker.convert_to_designer(p);
            worker.convert_from_designer(p, syncedNodeMetaInfo);
        }
    }
    if (shell != null && progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.progress(10);
    progressMonitor.subTask("Saving package");
    ProcessPersister.PersistType persistType = ProcessPersister.PersistType.IMPORT;
    if (isJson && !project.checkRequiredVersion(6, 1, 1))
        persistType = ProcessPersister.PersistType.IMPORT_JSON;
    Long packageId = dataAccess.getDesignerDataAccess().savePackage(importedPackageVO, persistType);
    if (preexistingVersion > 0)
        // reset version
        importedPackageVO.setVersion(preexistingVersion);
    // for overwrite
    progressMonitor.progress(10);
    progressMonitor.subTask("Reloading processes");
    if (importedPackageVO.getProcesses() != null) {
        for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) {
            ProcessVO reloaded = dataAccess.getDesignerDataAccess().getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
            importedProcessVO.setProcessId(reloaded.getProcessId());
        }
        if (project.getDataAccess().getSupportedSchemaVersion() < DataAccess.schemaVersion52) {
            for (ProcessVO importedProcessVO : importedPackageVO.getProcesses()) updateSubProcessIdAttributes(importedProcessVO);
        }
    }
    if (!existingProcessVOs.isEmpty()) {
        // add back existing processes
        importedPackageVO.getProcesses().addAll(existingProcessVOs);
        dataAccess.getDesignerDataAccess().savePackage(importedPackageVO);
    }
    progressMonitor.progress(10);
    progressMonitor.subTask("Reloading workflow assets");
    if (importedPackageVO.getRuleSets() != null) {
        for (RuleSetVO importedRuleSet : importedPackageVO.getRuleSets()) {
            RuleSetVO reloaded;
            if (dataAccess.getSupportedSchemaVersion() >= DataAccess.schemaVersion55) {
                reloaded = dataAccess.getDesignerDataAccess().getRuleSet(importedPackageVO.getId(), importedRuleSet.getName());
                if (// TODO: verify whether the above is
                reloaded == null)
                    // even needed
                    reloaded = dataAccess.getDesignerDataAccess().getRuleSet(importedRuleSet.getId());
            } else {
                reloaded = dataAccess.getDesignerDataAccess().getRuleSet(importedRuleSet.getName(), importedRuleSet.getLanguage(), importedRuleSet.getVersion());
            }
            importedRuleSet.setId(reloaded.getId());
        }
    }
    if (!existingRuleSets.isEmpty()) {
        importedPackageVO.getRuleSets().addAll(existingRuleSets);
        progressMonitor.subTask("Saving Package");
        dataAccess.getDesignerDataAccess().savePackage(importedPackageVO);
    }
    if (preexistingVersion > 0 && existingProcessVOs.isEmpty() && existingRuleSets.isEmpty()) {
        progressMonitor.subTask("Saving Package");
        // force
        dataAccess.getDesignerDataAccess().savePackage(importedPackageVO);
    // associate
    // processes
    }
    progressMonitor.progress(10);
    progressMonitor.subTask("Loading package");
    PackageVO newPackageVO = dataAccess.getDesignerDataAccess().loadPackage(packageId, false);
    WorkflowPackage importedPackage = new WorkflowPackage(project, newPackageVO);
    List<WorkflowProcess> processVersions = new ArrayList<>();
    for (ProcessVO processVO : newPackageVO.getProcesses()) {
        WorkflowProcess processVersion = new WorkflowProcess(project, processVO);
        processVersion.setPackage(importedPackage);
        processVersions.add(processVersion);
    }
    Collections.sort(processVersions);
    importedPackage.setProcesses(processVersions);
    List<ExternalEvent> externalEvents = new ArrayList<>();
    for (ExternalEventVO externalEventVO : newPackageVO.getExternalEvents()) {
        ExternalEvent externalEvent = new ExternalEvent(externalEventVO, importedPackage);
        externalEvents.add(externalEvent);
    }
    Collections.sort(externalEvents);
    importedPackage.setExternalEvents(externalEvents);
    List<TaskTemplate> taskTemplates = new ArrayList<>();
    if (newPackageVO.getTaskTemplates() != null) {
        for (TaskVO taskVO : newPackageVO.getTaskTemplates()) {
            TaskTemplate taskTemplate = new TaskTemplate(taskVO, importedPackage);
            taskTemplates.add(taskTemplate);
        }
        Collections.sort(taskTemplates);
        importedPackage.setTaskTemplates(taskTemplates);
    }
    List<ActivityImpl> activityImpls = new ArrayList<>();
    if (newPackageVO.getImplementors() != null) {
        for (ActivityImplementorVO activityImplVO : newPackageVO.getImplementors()) {
            if (importedPackageVO.getImplementors() != null) {
                // attrs not included in reload -- take from original XML
                ActivityImplementorVO xmlImplVO = null;
                for (ActivityImplementorVO implVO : importedPackageVO.getImplementors()) {
                    if (activityImplVO.getImplementorClassName().equals(implVO.getImplementorClassName()))
                        xmlImplVO = implVO;
                }
                if (xmlImplVO != null) {
                    activityImplVO.setBaseClassName(xmlImplVO.getBaseClassName());
                    activityImplVO.setIconName(xmlImplVO.getIconName());
                    activityImplVO.setShowInToolbox(xmlImplVO.isShowInToolbox());
                    activityImplVO.setLabel(xmlImplVO.getLabel());
                    activityImplVO.setAttributeDescription(xmlImplVO.getAttributeDescription());
                }
            }
            ActivityImpl activityImpl = new ActivityImpl(activityImplVO, importedPackage);
            activityImpls.add(activityImpl);
        }
        Collections.sort(activityImpls);
        importedPackage.setActivityImpls(activityImpls);
    }
    if (newPackageVO.getRuleSets() != null) {
        List<WorkflowAsset> assets = new ArrayList<>();
        for (RuleSetVO ruleSet : newPackageVO.getRuleSets()) {
            WorkflowAsset asset = WorkflowAssetFactory.createAsset(ruleSet, importedPackage);
            assets.add(asset);
        }
        Collections.sort(assets);
        importedPackage.setAssets(assets);
    }
    if (existing != null) {
        // deregister old assets
        if (existing.getAssets() != null) {
            for (WorkflowAsset oldAsset : existing.getAssets()) WorkflowAssetFactory.deRegisterAsset(oldAsset);
        }
        project.removePackage(existing);
    }
    // register new assets
    if (importedPackage.getAssets() != null) {
        for (WorkflowAsset newAsset : importedPackage.getAssets()) WorkflowAssetFactory.registerAsset(newAsset);
    }
    project.addPackage(importedPackage);
    progressMonitor.progress(10);
    dataAccess.auditLog(Action.Import, importedPackage);
    dataAccess.getPackages(true);
    dataAccess.getProcesses(true);
    dataAccess.getRuleSets(true);
    dataAccess.getActivityImplementors(true);
    project.findActivityImplementors(importedPackage);
    progressMonitor.progress(5);
    timer.stopAndLog();
    return importedPackage;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) ProcessPersister(com.centurylink.mdw.dataaccess.ProcessPersister) ExternalEvent(com.centurylink.mdw.plugin.designer.model.ExternalEvent) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) NodeMetaInfo(com.centurylink.mdw.designer.utils.NodeMetaInfo) ExternalEventVO(com.centurylink.mdw.model.value.event.ExternalEventVO) ActivityImplementorVO(com.centurylink.mdw.model.value.activity.ActivityImplementorVO) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Example 4 with ActionCancelledException

use of com.centurylink.mdw.common.utilities.timer.ActionCancelledException in project mdw-designer by CenturyLinkCloud.

the class Exporter method exportPackage.

public String exportPackage(WorkflowPackage packageVersion, boolean includeTaskTemplates, boolean inferReferencedImplementors, ProgressMonitor progressMonitor) throws DataAccessException, ActionCancelledException, XmlException {
    String xml = null;
    // auto-infer the implementors and save the package before exporting
    List<ActivityImplementorVO> implementors = packageVersion.getPackageVO().getImplementors();
    if (implementors == null)
        implementors = new ArrayList<>();
    if (inferReferencedImplementors) {
        progressMonitor.subTask("Finding referenced activity implementors");
        List<ActivityImplementorVO> inferredImplementors = designerDataAccess.getReferencedImplementors(packageVersion.getPackageVO());
        for (ActivityImplementorVO inferred : inferredImplementors) {
            if (!implementors.contains(inferred))
                implementors.add(inferred);
        }
    }
    if (progressMonitor.isCanceled())
        throw new ActionCancelledException();
    packageVersion.getPackageVO().setImplementors(implementors);
    progressMonitor.progress(10);
    progressMonitor.subTask("Saving package");
    designerDataAccess.savePackage(packageVersion.getPackageVO(), ProcessPersister.PersistType.UPDATE);
    if (progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.progress(10);
    int schemaVersion = designerDataAccess.getDatabaseSchemaVersion();
    xml = designerDataAccess.exportPackage(packageVersion.getId(), schemaVersion, includeTaskTemplates, progressMonitor);
    packageVersion.setExported(true);
    return xml;
}
Also used : ActivityImplementorVO(com.centurylink.mdw.model.value.activity.ActivityImplementorVO) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) ArrayList(java.util.ArrayList)

Example 5 with ActionCancelledException

use of com.centurylink.mdw.common.utilities.timer.ActionCancelledException in project mdw-designer by CenturyLinkCloud.

the class ImportAttributesWizard method performImportExport.

void performImportExport(ProgressMonitor progressMonitor) throws IOException, XmlException, DataAccessException, ValidationException, ActionCancelledException {
    progressMonitor.progress(10);
    progressMonitor.subTask("Reading XML file");
    byte[] bytes = readFile(getPage().getFilePath());
    progressMonitor.progress(20);
    if (progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.subTask("Performing Import");
    Importer importer = new Importer(getProject().getDataAccess(), getShell());
    importer.importAttributes(getProcess() == null ? getPackage() : getProcess(), new String(bytes), progressMonitor, prefix);
    getProject().getDesignerProxy().getCacheRefresh().doRefresh(true);
    progressMonitor.progress(30);
}
Also used : ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) Importer(com.centurylink.mdw.plugin.designer.Importer)

Aggregations

ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)13 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)6 ArrayList (java.util.ArrayList)6 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)5 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)5 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)4 Importer (com.centurylink.mdw.plugin.designer.Importer)4 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)3 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)3 CustomAttributeVO (com.centurylink.mdw.model.value.attribute.CustomAttributeVO)3 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)3 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)3 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)3 IOException (java.io.IOException)3 ProgressMonitor (com.centurylink.mdw.common.utilities.timer.ProgressMonitor)2 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)2 NodeMetaInfo (com.centurylink.mdw.designer.utils.NodeMetaInfo)2 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)2 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)2 SwtProgressMonitor (com.centurylink.mdw.plugin.designer.SwtProgressMonitor)2