Search in sources :

Example 61 with ProcessVO

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

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

use of com.centurylink.mdw.model.value.process.ProcessVO 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)

Example 64 with ProcessVO

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

the class Importer method updateSubProcessIdAttributes.

/**
 * Update processid attribute for calling processes within this package.
 * TODO: Get rid of this method, which is only needed for ancient (pre-4.5)
 * runtimes.
 */
private void updateSubProcessIdAttributes(ProcessVO processVO) throws DataAccessException, XmlException {
    // save calling processes to update subprocess activity attributes
    boolean toUpdate = false;
    if (processVO.getActivities() != null) {
        for (ActivityVO actVO : processVO.getActivities()) {
            String procNameAttr = actVO.getAttribute(PROCESS_NAME);
            String procVerAttr = actVO.getAttribute(PROCESS_VERSION);
            if (procNameAttr != null && procVerAttr != null) {
                toUpdate = true;
            }
        }
        if (processVO.getSubProcesses() != null) {
            for (ProcessVO embedded : processVO.getSubProcesses()) {
                for (ActivityVO actVO : embedded.getActivities()) {
                    String procNameAttr = actVO.getAttribute(PROCESS_NAME);
                    String procVerAttr = actVO.getAttribute(PROCESS_VERSION);
                    if (procNameAttr != null && procVerAttr != null) {
                        toUpdate = true;
                    }
                }
            }
        }
    }
    if (toUpdate) {
        ProcessVO procVO = dataAccess.getDesignerDataAccess().getProcess(processVO.getProcessId(), processVO);
        for (ActivityVO actVO : procVO.getActivities()) {
            String procNameAttr = actVO.getAttribute(PROCESS_NAME);
            String procVerAttr = actVO.getAttribute(PROCESS_VERSION);
            if (procNameAttr != null && procVerAttr != null) {
                for (ProcessVO checkVO : importedPackageVO.getProcesses()) {
                    if (checkVO.getProcessName().equals(procNameAttr) && String.valueOf(checkVO.getVersion()).equals(procVerAttr))
                        actVO.setAttribute("processid", checkVO.getProcessId().toString());
                }
            }
        }
        if (procVO.getSubProcesses() != null) {
            for (ProcessVO embedded : procVO.getSubProcesses()) {
                for (ActivityVO actVO : embedded.getActivities()) {
                    String procNameAttr = actVO.getAttribute(PROCESS_NAME);
                    String procVerAttr = actVO.getAttribute(PROCESS_VERSION);
                    if (procNameAttr != null && procVerAttr != null) {
                        for (ProcessVO checkVO : importedPackageVO.getProcesses()) {
                            if (checkVO.getProcessName().equals(procNameAttr) && String.valueOf(checkVO.getVersion()).equals(procVerAttr))
                                actVO.setAttribute("processid", checkVO.getProcessId().toString());
                        }
                    }
                }
            }
        }
        dataAccess.getDesignerDataAccess().updateProcess(procVO, 0, false);
    }
}
Also used : ActivityVO(com.centurylink.mdw.model.value.activity.ActivityVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO)

Example 65 with ProcessVO

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

the class WorkflowPackage method syncProcesses.

public void syncProcesses() {
    List<WorkflowProcess> processVersions = new ArrayList<>();
    for (ProcessVO processVO : packageVO.getProcesses()) {
        WorkflowProcess processVersion = new WorkflowProcess(getProject(), processVO);
        processVersion.setPackage(this);
        processVersions.add(processVersion);
    }
    this.setProcesses(processVersions);
}
Also used : ArrayList(java.util.ArrayList) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO)

Aggregations

ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)92 ArrayList (java.util.ArrayList)29 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)28 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)25 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)17 IOException (java.io.IOException)17 HashMap (java.util.HashMap)15 RemoteException (java.rmi.RemoteException)14 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)12 ActivityVO (com.centurylink.mdw.model.value.activity.ActivityVO)11 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)11 JSONException (org.json.JSONException)11 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)10 XmlException (org.apache.xmlbeans.XmlException)10 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)9 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)9 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)8 ExternalEventVO (com.centurylink.mdw.model.value.event.ExternalEventVO)8 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)7 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)5