Search in sources :

Example 11 with ProcessWorker

use of com.centurylink.mdw.designer.utils.ProcessWorker in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method renameProcess.

public void renameProcess(final WorkflowProcess processVersion, final String newName) {
    if (dataAccess.processNameExists(processVersion.getPackage().getPackageVO(), newName)) {
        Shell shell = MdwPlugin.getActiveWorkbenchWindow().getShell();
        MessageDialog.openError(shell, RENAME_ERROR, "Process name already exists: '" + newName + "'");
        return;
    }
    String version = "v" + processVersion.getVersionString();
    String progressMsg = "Renaming to '" + newName + "' " + version;
    String errorMsg = "Rename Process";
    designerRunner = new DesignerRunner(progressMsg, errorMsg, project) {

        public void perform() throws ValidationException, DataAccessException, RemoteException, XmlException {
            try {
                if (dataAccess.getDesignerDataAccess().hasProcessInstances(processVersion.getId()))
                    throw new DataAccessException("Process " + processVersion.getLabel() + " has instances and cannot be renamed.\nPlease save as a new version.");
            } catch (DataAccessOfflineException ex) {
                final StringBuilder confirm = new StringBuilder();
                MdwPlugin.getDisplay().syncExec(new Runnable() {

                    public void run() {
                        String msg = "Cannot connect to server to check for instances.  Are you sure you want to rename?";
                        confirm.append(MessageDialog.openConfirm(MdwPlugin.getShell(), "Rename Process", msg));
                    }
                });
                if (!Boolean.valueOf(confirm.toString()))
                    return;
            }
            dataAccess.removeProcess(processVersion.getProcessVO());
            if (processVersion.isInRuleSet() && !project.isFilePersist()) {
                ProcessVO procVO = dataAccess.getDesignerDataAccess().getProcessDefinition(processVersion.getName(), processVersion.getVersion());
                procVO = dataAccess.getDesignerDataAccess().getProcess(procVO.getProcessId(), procVO);
                procVO.setName(newName);
                procVO.setVersion(1);
                new ProcessWorker().convert_to_designer(procVO);
                dataAccess.getDesignerDataAccess().updateProcess(procVO, 0, false);
                processVersion.setProcessVO(procVO);
            } else {
                processVersion.setName(newName);
                processVersion.getProcessVO().setVersion(1);
                processVersion.getProcessVO().setId(dataAccess.getDesignerDataAccess().renameProcess(processVersion.getId(), newName, 1));
            }
            dataAccess.getDesignerDataModel().addProcess(processVersion.getProcessVO());
        }
    };
    designerRunner.run();
}
Also used : DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) Shell(org.eclipse.swt.widgets.Shell) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) XmlException(org.apache.xmlbeans.XmlException) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) RemoteException(java.rmi.RemoteException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 12 with ProcessWorker

use of com.centurylink.mdw.designer.utils.ProcessWorker in project mdw-designer by CenturyLinkCloud.

the class Importer method importProcess.

public WorkflowProcess importProcess(final WorkflowPackage targetPackage, final WorkflowProcess targetProcess, final String xml) throws DataAccessException, RemoteException, XmlException, ValidationException {
    CodeTimer timer = new CodeTimer("importProcess()");
    ProcessVO importedProcessVO = null;
    int schemaVersion = dataAccess.getSchemaVersion();
    ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
    importedProcessVO = importer.importProcess(xml);
    if (targetProcess != null && !importedProcessVO.getName().equals(targetProcess.getName()))
        throw new ValidationException("Process in XML (" + importedProcessVO.getName() + ") is not " + targetProcess.getName());
    for (WorkflowProcess existing : targetPackage.getProject().getAllProcesses()) {
        if (existing.getName().equals(importedProcessVO.getName())) {
            if (existing.getVersion() == importedProcessVO.getVersion())
                throw new ValidationException(existing.getLabel() + " already exists in " + targetPackage.getProject().getLabel() + ".");
            if (existing.getVersion() > importedProcessVO.getVersion())
                throw new ValidationException(existing.getLabel() + " already exists in " + targetPackage.getProject().getLabel() + " with a version greater than the imported process (v" + importedProcessVO.getVersionString() + ").");
        }
    }
    // designer fix for backward compatibility
    ProcessWorker worker = new ProcessWorker();
    worker.convert_to_designer(importedProcessVO);
    worker.convert_from_designer(importedProcessVO, syncNodeMetaInfo(dataAccess.getDesignerDataModel().getNodeMetaInfo(), importedProcessVO));
    if (!importedProcessVO.isInRuleSet()) {
        // fix pseudo variables
        for (VariableVO varVO : importedProcessVO.getVariables()) varVO.setVariableId(null);
    }
    importedProcessVO.setPackageName(targetPackage.getName());
    WorkflowProcess alreadyInPackage = null;
    if (targetPackage.getProject().getProcess(importedProcessVO.getName()) == null)
        dataAccess.getDesignerDataAccess().createProcess(importedProcessVO);
    else {
        alreadyInPackage = targetPackage.getProcess(importedProcessVO.getName());
        dataAccess.getDesignerDataAccess().updateProcess(importedProcessVO, importedProcessVO.getVersion(), false);
    }
    ProcessVO reloaded = dataAccess.getDesignerDataAccess().getProcessDefinition(importedProcessVO.getProcessName(), importedProcessVO.getVersion());
    importedProcessVO.setProcessId(reloaded.getProcessId());
    if (targetPackage.getProject().getDataAccess().getSupportedSchemaVersion() < DataAccess.schemaVersion52)
        updateSubProcessIdAttributes(importedProcessVO);
    WorkflowProcess importedProcess = new WorkflowProcess(targetPackage.getProject(), importedProcessVO);
    dataAccess.getProcesses(false).add(importedProcess.getProcessVO());
    if (alreadyInPackage != null)
        targetPackage.removeProcess(alreadyInPackage);
    targetPackage.addProcess(importedProcess);
    importedProcess.setPackage(targetPackage);
    dataAccess.auditLog(Action.Import, importedProcess);
    timer.stopAndLog();
    return importedProcess;
}
Also used : ValidationException(com.centurylink.mdw.designer.utils.ValidationException) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess)

Example 13 with ProcessWorker

use of com.centurylink.mdw.designer.utils.ProcessWorker in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method exportPackage.

public String exportPackage(Long packageId, int schemaVersion, boolean includeTaskTemplates, ProgressMonitor monitor) throws DataAccessException, ActionCancelledException, XmlException {
    if (monitor != null)
        monitor.subTask("Loading package...");
    PackageVO packageVO = loadPackage(packageId, true);
    if (monitor != null)
        monitor.progress(30);
    if (monitor != null) {
        if (monitor.isCanceled())
            throw new ActionCancelledException();
        else
            monitor.subTask("Sorting processes and implementors");
    }
    // adding same logic as in PopupHandler export to get same result
    for (ProcessVO processVO : packageVO.getProcesses()) new ProcessWorker().convert_to_designer(processVO);
    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);
    }
    if (monitor != null && monitor.isCanceled())
        throw new ActionCancelledException();
    if (monitor != null)
        monitor.progress(5);
    if (monitor != null)
        monitor.subTask(EXPORTXML);
    ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
    String xml = exporter.exportPackage(packageVO, includeTaskTemplates);
    if (monitor != null)
        monitor.progress(25);
    packageVO.setExported(true);
    persister.persistPackage(packageVO, PersistType.UPDATE);
    if (monitor != null)
        monitor.progress(15);
    return xml;
}
Also used : PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) HashMap(java.util.HashMap) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) CustomAttributeVO(com.centurylink.mdw.model.value.attribute.CustomAttributeVO) ArrayList(java.util.ArrayList) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Aggregations

ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)13 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)12 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)5 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)4 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)4 NodeMetaInfo (com.centurylink.mdw.designer.utils.NodeMetaInfo)4 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)3 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)3 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)3 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)3 RemoteException (java.rmi.RemoteException)3 ArrayList (java.util.ArrayList)3 Graph (com.centurylink.mdw.designer.display.Graph)2 SubGraph (com.centurylink.mdw.designer.display.SubGraph)2 ExternalEventVO (com.centurylink.mdw.model.value.event.ExternalEventVO)2 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)2 CodeTimer (com.centurylink.mdw.plugin.CodeTimer)2 Dimension (java.awt.Dimension)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2