Search in sources :

Example 6 with TaskTemplate

use of com.centurylink.mdw.plugin.designer.model.TaskTemplate in project mdw-designer by CenturyLinkCloud.

the class AssetLocator method getTaskTemplateVersion.

private TaskTemplate getTaskTemplateVersion(String versionSpec, List<TaskTemplate> taskTemplates) {
    AssetVersionSpec spec = AssetVersionSpec.parse(versionSpec);
    boolean isDefaultSmart = isDefaultSmartFormat(spec.getVersion());
    TaskTemplate match = null;
    for (TaskTemplate taskTemplate : taskTemplates) {
        if (taskTemplate.getName().matches(spec.getName())) {
            if (taskTemplate.getVersionString().equals(spec.getVersion())) {
                match = taskTemplate;
                break;
            } else if ((AssetVersionSpec.VERSION_LATEST.equals(spec.getVersion()) || (isDefaultSmart && taskTemplate.meetsVersionSpec(spec.getVersion()))) && (match == null || taskTemplate.getVersion() > match.getVersion())) {
                match = taskTemplate;
            }
        }
    }
    return match;
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) AssetVersionSpec(com.centurylink.mdw.model.value.attribute.AssetVersionSpec)

Example 7 with TaskTemplate

use of com.centurylink.mdw.plugin.designer.model.TaskTemplate in project mdw-designer by CenturyLinkCloud.

the class WorkflowElementActionHandler method delete.

public void delete(WorkflowElement[] elements) {
    boolean globalConf = false;
    boolean includeInstances = false;
    if (elements.length > 1) {
        boolean globalConfAllowed = true;
        List<WorkflowElement> lockedElems = new ArrayList<WorkflowElement>();
        for (WorkflowElement element : elements) {
            if ((element instanceof WorkflowProject) || (element instanceof WorkflowPackage)) {
                globalConfAllowed = false;
                break;
            } else if (element instanceof WorkflowProcess) {
                WorkflowProcess pv = (WorkflowProcess) element;
                if (pv.getLockingUser() != null && !pv.isLockedToUser())
                    lockedElems.add(pv);
            } else if (element instanceof WorkflowAsset) {
                WorkflowAsset dd = (WorkflowAsset) element;
                if (dd.getLockingUser() != null && !dd.isLockedToUser())
                    lockedElems.add(dd);
            }
        }
        if (!lockedElems.isEmpty()) {
            PluginMessages.uiList(getShell(), "Error: The following elements are locked to other users.\nPlease exclude them from your selection or have them unlocked before proceeding.", "Delete Elements", lockedElems);
            return;
        }
        if (globalConfAllowed) {
            WorkflowElementDeleteDialog multipleDeleteDialog = new WorkflowElementDeleteDialog(getShell(), Arrays.asList(elements));
            int res = multipleDeleteDialog.open();
            if (res == Dialog.CANCEL)
                return;
            else if (res == Dialog.OK) {
                globalConf = true;
                includeInstances = multipleDeleteDialog.isIncludeInstances();
            }
        }
    }
    for (WorkflowElement element : elements) {
        if (element instanceof WorkflowProject) {
            WorkflowProject workflowProject = (WorkflowProject) element;
            if (!workflowProject.isRemote()) {
                MessageDialog.openWarning(getShell(), "Delete Project", "Please delete the underlying Java Project in Package Explorer view.");
                return;
            }
            boolean confirmed = MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete workflow project: " + workflowProject.getName() + "?");
            if (confirmed) {
                WorkflowProjectManager.getInstance().deleteProject(workflowProject);
                workflowProject.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
            } else {
                return;
            }
        } else if (element instanceof AutomatedTestCase && ((AutomatedTestCase) element).isLegacy()) {
            // still allow deletion of legacy test stuff
            final AutomatedTestCase testCase = (AutomatedTestCase) element;
            if (globalConf || MessageDialog.openConfirm(getShell(), "Delete Legacy Test Case", "Delete " + testCase.getLabel() + "?")) {
                BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                    public void run() {
                        File tcDir = testCase.getTestCaseDirectory();
                        try {
                            PluginUtil.deleteDirectory(tcDir);
                            testCase.getTestSuite().getTestCases().remove(testCase);
                            try {
                                IFolder folder = testCase.getProject().getOldTestCasesFolder();
                                if (folder.exists())
                                    folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                            } catch (CoreException ex) {
                                PluginMessages.uiError(ex, "Delete Legacy Test Case", testCase.getProject());
                            }
                            testCase.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                            testCase.removeElementChangeListener(testCase.getProject());
                        } catch (IOException ex) {
                            PluginMessages.uiError(ex, "Delete Test Case", testCase.getProject());
                        }
                    }
                });
            }
        } else if (element instanceof LegacyExpectedResults) {
            final LegacyExpectedResults expectedResult = (LegacyExpectedResults) element;
            if (globalConf || MessageDialog.openConfirm(getShell(), "Delete Legacy Expected Result", "Delete " + expectedResult.getLabel() + "?")) {
                BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                    public void run() {
                        File file = expectedResult.getExpectedResultFile();
                        if (file.delete()) {
                            expectedResult.getTestCase().getLegacyExpectedResults().remove(expectedResult);
                            try {
                                IFolder folder = expectedResult.getProject().getOldTestCasesFolder();
                                if (folder.exists())
                                    folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                            } catch (CoreException ex) {
                                PluginMessages.uiError(ex, "Delete Legacy Expected Result", expectedResult.getProject());
                            }
                            expectedResult.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                            expectedResult.removeElementChangeListener(expectedResult.getProject());
                        } else {
                            PluginMessages.uiError("Cannot delete expected result " + expectedResult.getName(), "Delete Result", expectedResult.getProject());
                        }
                    }
                });
            }
        } else if (element instanceof com.centurylink.mdw.plugin.designer.model.File) {
            final com.centurylink.mdw.plugin.designer.model.File file = (com.centurylink.mdw.plugin.designer.model.File) element;
            if (globalConf || MessageDialog.openConfirm(getShell(), "Delete File", "Delete " + file.getLabel() + "?")) {
                BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                    public void run() {
                        IFile workspaceFile = file.getWorkspaceFile();
                        try {
                            workspaceFile.delete(true, null);
                            WorkflowElement parent = file.getParent();
                            if (parent instanceof AutomatedTestCase) {
                                AutomatedTestCase testCase = (AutomatedTestCase) parent;
                                testCase.getFiles().remove(file);
                            }
                            file.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                            file.removeElementChangeListener(file.getProject());
                            refresh(file.getProject().getLegacyTestSuite());
                        } catch (Exception ex) {
                            PluginMessages.uiError("Cannot delete file " + file.getName(), "Delete File", file.getProject());
                        }
                    }
                });
            }
        } else {
            WorkflowProject workflowProject = element.getProject();
            DesignerProxy designerProxy = workflowProject.getDesignerProxy();
            if (element instanceof WorkflowPackage) {
                WorkflowPackage packageToDelete = (WorkflowPackage) element;
                PackageDeleteDialog packageDeleteDialog = new PackageDeleteDialog(getShell(), packageToDelete);
                if (packageDeleteDialog.open() == Dialog.OK) {
                    designerProxy.deletePackage(packageToDelete);
                } else {
                    return;
                }
            } else if (element instanceof WorkflowProcess) {
                WorkflowProcess processVersion = (WorkflowProcess) element;
                if (!processVersion.getProject().isFilePersist() && processVersion.getLockingUser() != null && !processVersion.isLockedToUser()) {
                    MessageDialog.openError(getShell(), "Cannot Delete", "Process '" + processVersion.getLabel() + "' is locked to user '" + processVersion.getLockingUser() + "'.\nPlease have it unlocked before deleting.");
                    return;
                }
                ProcessDeleteDialog deleteDialog = new ProcessDeleteDialog(getShell(), processVersion);
                if (globalConf || deleteDialog.open() == Dialog.OK) {
                    closeOpenEditor(processVersion, false);
                    includeInstances = includeInstances || deleteDialog.isIncludeInstances();
                    designerProxy.deleteProcess(processVersion, includeInstances);
                } else {
                    return;
                }
            } else if (element instanceof TaskTemplate) {
                TaskTemplate taskTemplate = (TaskTemplate) element;
                if (globalConf || MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete " + taskTemplate.getTitle() + " '" + taskTemplate.getLabel() + "'?")) {
                    designerProxy.deleteTaskTemplate(taskTemplate);
                } else {
                    return;
                }
            } else if (element instanceof WorkflowAsset) {
                WorkflowAsset asset = (WorkflowAsset) element;
                if (!asset.getProject().isFilePersist() && asset.getLockingUser() != null && !asset.isLockedToUser()) {
                    MessageDialog.openError(getShell(), "Cannot Delete", asset.getTitle() + " '" + asset.getLabel() + "' is locked to user '" + asset.getLockingUser() + "'.\nPlease have it unlocked before deleting");
                    return;
                }
                if (globalConf || MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete " + asset.getTitle() + " '" + asset.getLabel() + "'?")) {
                    if (asset.getFileEditor() != null) {
                        IEditorInput editorInput = asset.getFileEditor().getEditorInput();
                        if (editorInput != null)
                            closeOpenEditor(editorInput, false);
                    }
                    WorkflowAssetFactory.deRegisterAsset(asset);
                    designerProxy.deleteWorkflowAsset(asset);
                } else {
                    return;
                }
            } else if (element instanceof ActivityImpl) {
                ActivityImpl activityImpl = (ActivityImpl) element;
                ActivityImplDeleteDialog deleteDialog = new ActivityImplDeleteDialog(getShell(), activityImpl);
                if (globalConf || deleteDialog.open() == Dialog.OK) {
                    designerProxy.deleteActivityImpl(activityImpl, deleteDialog.isIncludeActivities());
                } else {
                    return;
                }
            } else if (element instanceof ExternalEvent) {
                ExternalEvent externalEvent = (ExternalEvent) element;
                if (globalConf || MessageDialog.openConfirm(getShell(), "Confirm Delete", "Delete Event Handler: " + externalEvent.getLabel() + "?")) {
                    designerProxy.deleteExternalEvent(externalEvent);
                } else {
                    return;
                }
            } else if (element instanceof TaskTemplate) {
                MessageDialog.openWarning(getShell(), "TODO", "Delete task template not yet implemented");
            }
            if (RunnerStatus.SUCCESS.equals(designerProxy.getRunnerStatus())) {
                // notify listeners
                element.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                element.removeElementChangeListener(workflowProject);
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) WorkflowElementDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.WorkflowElementDeleteDialog) ProcessDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.ProcessDeleteDialog) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) PackageDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.PackageDeleteDialog) ExternalEvent(com.centurylink.mdw.plugin.designer.model.ExternalEvent) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl) LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) ActivityImplDeleteDialog(com.centurylink.mdw.plugin.designer.dialogs.ActivityImplDeleteDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(com.centurylink.mdw.plugin.designer.model.JarFile) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with TaskTemplate

use of com.centurylink.mdw.plugin.designer.model.TaskTemplate in project mdw-designer by CenturyLinkCloud.

the class WorkflowProject method findTaskTemplates.

/**
 * Returns the task templates belonging to a package version.
 */
private List<TaskTemplate> findTaskTemplates(WorkflowPackage aPackage) {
    if (aPackage.isDefaultPackage()) {
        List<TaskTemplate> unpackagedTaskTemplates = new ArrayList<>();
        for (TaskVO taskVO : getDataAccess().getTaskTemplates(false)) {
            if (!isPackaged(taskVO)) {
                TaskTemplate taskTemplate = new TaskTemplate(taskVO, aPackage);
                taskTemplate.addElementChangeListener(this);
                unpackagedTaskTemplates.add(taskTemplate);
            }
        }
        Collections.sort(unpackagedTaskTemplates);
        return unpackagedTaskTemplates;
    } else {
        List<TaskTemplate> packagedTaskTemplates = new ArrayList<>();
        for (TaskVO taskVO : getDataAccess().getTaskTemplates(false)) {
            if (aPackage.getPackageVO().containsTaskTemplate(taskVO.getTaskId())) {
                TaskTemplate taskTemplate = new TaskTemplate(taskVO, aPackage);
                if (!packagedTaskTemplates.contains(taskTemplate)) {
                    taskTemplate.addElementChangeListener(this);
                    packagedTaskTemplates.add(taskTemplate);
                }
            }
        }
        Collections.sort(packagedTaskTemplates);
        return packagedTaskTemplates;
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) ArrayList(java.util.ArrayList) TaskVO(com.centurylink.mdw.model.value.task.TaskVO)

Example 9 with TaskTemplate

use of com.centurylink.mdw.plugin.designer.model.TaskTemplate in project mdw-designer by CenturyLinkCloud.

the class Importer method importTaskTemplates.

public void importTaskTemplates(final WorkflowPackage pkg, final String xml, final ProgressMonitor progressMonitor) throws XmlException, DataAccessException {
    progressMonitor.subTask(PARSING_XML);
    PackageDocument pkgDoc = PackageDocument.Factory.parse(xml);
    MDWPackage packageDef = pkgDoc.getPackage();
    if (!pkg.getName().equals(packageDef.getName()))
        throw new DataAccessException("Expected package: " + pkg.getName() + " in tasks XML but found: " + packageDef.getName());
    com.centurylink.mdw.task.TaskTemplatesDocument.TaskTemplates templates = packageDef.getTaskTemplates();
    PackageVO packageVO = new PackageVO();
    if (packageDef.getName() != null)
        packageVO.setPackageName(packageDef.getName());
    else
        packageVO.setPackageName("package");
    packageVO.setVersion(PackageVO.parseVersion(packageDef.getVersion()));
    List<TaskVO> packageTaskTemplates = new ArrayList<>();
    for (com.centurylink.mdw.task.TaskTemplate template : templates.getTaskList()) {
        TaskVO taskTemplateVO = new TaskVO(template);
        taskTemplateVO.setPackageName(packageVO.getPackageName());
        String v = template.getVersion();
        if (v != null && !v.equals("0"))
            taskTemplateVO.setVersion(RuleSetVO.parseVersion(v));
        String assetName = template.getAssetName();
        if (assetName != null && !assetName.isEmpty())
            taskTemplateVO.setName(assetName);
        packageTaskTemplates.add(taskTemplateVO);
    }
    packageVO.setTaskTemplates(packageTaskTemplates);
    if (!packageTaskTemplates.isEmpty())
        dataAccess.getDesignerDataAccess().savePackage(packageVO, ProcessPersister.PersistType.IMPORT);
    for (TaskVO taskVo : packageVO.getTaskTemplates()) {
        TaskTemplate existing = null;
        for (TaskTemplate taskTemplate : pkg.getTaskTemplates()) {
            if (taskTemplate.getLogicalId().equals(taskVo.getLogicalId())) {
                existing = taskTemplate;
                break;
            }
        }
        if (existing == null) {
            TaskTemplate newTemplate = new TaskTemplate(taskVo, pkg.getPackage());
            pkg.addTaskTemplate(newTemplate);
        } else {
            existing.setTaskVO(taskVo);
        }
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) MDWPackage(com.centurylink.mdw.bpm.MDWPackage) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) TaskVO(com.centurylink.mdw.model.value.task.TaskVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 10 with TaskTemplate

use of com.centurylink.mdw.plugin.designer.model.TaskTemplate in project mdw-designer by CenturyLinkCloud.

the class NewTaskTemplateWizard method performFinish.

@Override
public boolean performFinish() {
    TaskTemplate taskTemplate = (TaskTemplate) getWorkflowAsset();
    try {
        TaskTemplateDocument doc;
        if (isImportFile()) {
            // load from selected file
            doc = TaskTemplateDocument.Factory.parse(new File(getImportFilePath()));
            com.centurylink.mdw.task.TaskTemplate template = doc.getTaskTemplate();
            // selection)
            if (template.getLogicalId() == null)
                throw new XmlException("Task template missing logicalId");
            else if (template.getCategory() == null)
                throw new XmlException("Task template missing category");
            else if (template.getName() == null || template.getName().isEmpty())
                throw new XmlException("Task template missing name");
        } else {
            doc = TaskTemplateDocument.Factory.newInstance();
            com.centurylink.mdw.task.TaskTemplate template = doc.addNewTaskTemplate();
            String taskName = taskTemplate.getName().substring(0, taskTemplate.getName().length() - 5);
            template.setLogicalId(taskName.replace(' ', '_'));
            template.setCategory("GEN");
            template.setName(taskName);
            if ("AUTOFORM".equals(taskTemplate.getLanguage())) {
                Attribute form = template.addNewAttribute();
                form.setName("FormName");
                form.setStringValue("Autoform");
            }
        }
        XmlOptions xmlOptions = new XmlOptions().setSaveAggressiveNamespaces();
        xmlOptions.setSavePrettyPrint().setSavePrettyPrintIndent(2);
        taskTemplate.setContent(doc.xmlText(xmlOptions));
        String templateName = taskTemplate.getName();
        taskTemplate.setTaskVO(new TaskVO(doc.getTaskTemplate()));
        taskTemplate.setName(templateName);
        taskTemplate.getTaskVO().setPackageName(taskTemplate.getPackage().getName());
        DesignerProxy designerProxy = taskTemplate.getProject().getDesignerProxy();
        designerProxy.createNewTaskTemplate(taskTemplate);
        if (designerProxy.getRunnerStatus().equals(RunnerStatus.SUCCESS)) {
            taskTemplate.openFile(new NullProgressMonitor());
            taskTemplate.addElementChangeListener(taskTemplate.getProject());
            taskTemplate.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, taskTemplate);
            taskTemplate.setVersion(1);
            taskTemplate.fireElementChangeEvent(ChangeType.VERSION_CHANGE, taskTemplate);
            DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), taskTemplate);
            return true;
        } else {
            return false;
        }
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Create " + taskTemplate.getTitle(), taskTemplate.getProject());
        return false;
    }
}
Also used : TaskTemplate(com.centurylink.mdw.plugin.designer.model.TaskTemplate) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) Attribute(com.centurylink.mdw.task.Attribute) XmlOptions(org.apache.xmlbeans.XmlOptions) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) XmlException(org.apache.xmlbeans.XmlException) XmlException(org.apache.xmlbeans.XmlException) File(java.io.File) TaskVO(com.centurylink.mdw.model.value.task.TaskVO)

Aggregations

TaskTemplate (com.centurylink.mdw.plugin.designer.model.TaskTemplate)10 ArrayList (java.util.ArrayList)5 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)4 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)4 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)3 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)3 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)2 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)2 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)2 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)2 ActivityImpl (com.centurylink.mdw.plugin.designer.model.ActivityImpl)2 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)2 File (java.io.File)2 IOException (java.io.IOException)2 XmlException (org.apache.xmlbeans.XmlException)2 PartInitException (org.eclipse.ui.PartInitException)2 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)1 MDWPackage (com.centurylink.mdw.bpm.MDWPackage)1