Search in sources :

Example 31 with WorkflowElement

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

the class AutomatedTestContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof AutomatedTestSuite) {
        AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
        List<WorkflowPackage> packages = new ArrayList<WorkflowPackage>();
        List<WorkflowElement> legacyTests = new ArrayList<WorkflowElement>();
        for (AutomatedTestCase testCase : testSuite.getTestCases()) {
            if (testCase.isLegacy()) {
                legacyTests.add(testCase);
            } else {
                WorkflowPackage pkg = testCase.getPackage();
                if (!packages.contains(pkg))
                    packages.add(pkg);
            }
        }
        Folder folder = null;
        if (!legacyTests.isEmpty()) {
            folder = new Folder("Legacy Tests");
            folder.setChildren(legacyTests);
            for (WorkflowElement legacyTest : legacyTests) legacyTest.setArchivedFolder(folder);
        }
        Object[] children = new Object[packages.size() + (folder == null ? 0 : 1)];
        for (int i = 0; i < packages.size(); i++) children[i] = packages.get(i);
        if (folder != null)
            children[children.length - 1] = folder;
        return children;
    } else if (parentElement instanceof WorkflowPackage) {
        WorkflowPackage pkg = (WorkflowPackage) parentElement;
        @SuppressWarnings("unchecked") AutomatedTestSuite suite = ((List<AutomatedTestSuite>) treeViewer.getInput()).get(0);
        List<AutomatedTestCase> selectedCases = new ArrayList<AutomatedTestCase>();
        List<String> testCasesStringList;
        try {
            testCasesStringList = pkg.getTestCaseStringList();
            for (AutomatedTestCase testCase : suite.getTestCases()) {
                String path = testCase.getPath();
                if (testCase.isPostman())
                    path = testCase.getItemPath();
                if (testCasesStringList.contains(path))
                    selectedCases.add(testCase);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return selectedCases.toArray();
    } else if (parentElement instanceof Folder) {
        return ((Folder) parentElement).getChildren().toArray();
    } else if (parentElement instanceof AutomatedTestCase) {
        AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
        if (testCase.isLegacy()) {
            return testCase.getLegacyExpectedResults().toArray(new LegacyExpectedResults[0]);
        } else {
            AutomatedTestResults results = testCase.getExpectedResults();
            return results == null ? EMPTY_ARRAY : new Object[] { results };
        }
    } else {
        return EMPTY_ARRAY;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Folder(com.centurylink.mdw.plugin.designer.model.Folder) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite) AutomatedTestResults(com.centurylink.mdw.plugin.designer.model.AutomatedTestResults) LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) ArrayList(java.util.ArrayList) List(java.util.List) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Example 32 with WorkflowElement

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

the class ProcessExplorerDropTarget method drop.

public boolean drop(String data, Object target, int operation) {
    String elementInfo = data;
    String[] elements = elementInfo.split("#");
    if (target instanceof WorkflowElement && ((WorkflowElement) target).getPackage() != null) {
        WorkflowPackage targetPackage = ((WorkflowElement) target).getPackage();
        if (checkForDuplicates(targetPackage, elements))
            return false;
        for (String element : elements) {
            if (element.startsWith("Process~")) {
                if (!handleDropProcess(element.substring(8), targetPackage, operation))
                    return false;
            } else if (element.startsWith("ExternalEvent~")) {
                if (!handleDropExternalEvent(element.substring(14), targetPackage, operation))
                    return false;
            } else if (element.startsWith("ActivityImpl~")) {
                if (!handleDropActivityImpl(element.substring(14), targetPackage, operation))
                    return false;
            } else if (element.startsWith("WorkflowAsset~")) {
                if (!handleDropWorkflowAsset(element.substring(14), targetPackage, operation))
                    return false;
            } else {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Example 33 with WorkflowElement

use of com.centurylink.mdw.plugin.designer.model.WorkflowElement 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 34 with WorkflowElement

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

the class CodeGenWizard method init.

public void init(IWorkbench workbench, IStructuredSelection selection, Code codeElement) {
    this.workbench = workbench;
    this.selection = selection;
    this.codeElement = codeElement;
    setDefaultPageImageDescriptor(MdwPlugin.getImageDescriptor("icons/mdw_wiz.png"));
    setNeedsProgressMonitor(true);
    if (selection != null) {
        if (selection.getFirstElement() instanceof WorkflowPackage) {
            WorkflowPackage workflowPackage = (WorkflowPackage) selection.getFirstElement();
            getCodeElement().setProject(workflowPackage.getProject());
            getCodeElement().setPackage(workflowPackage);
        } else if (selection.getFirstElement() instanceof WorkflowElement) {
            WorkflowElement workflowElement = ((WorkflowElement) selection.getFirstElement());
            getCodeElement().setProject(workflowElement.getProject());
            getCodeElement().setPackage(workflowElement.getPackage());
        } else if (selection.getFirstElement() instanceof IResource) {
            IResource resource = (IResource) selection.getFirstElement();
            if (resource.getProject() != null) {
                WorkflowProject workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(resource.getProject());
                if (workflowProject != null)
                    getCodeElement().setProject(workflowProject);
            }
        }
    }
    if (getCodeElement().getProject() == null) {
        // choose any available workflow project
        List<WorkflowProject> workflowProjects = WorkflowProjectManager.getInstance().getWorkflowProjects();
        if (workflowProjects == null || workflowProjects.size() == 0)
            MessageDialog.openError(getShell(), "Error", "No MDW projects found");
        else
            getCodeElement().setProject(workflowProjects.get(0));
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) IResource(org.eclipse.core.resources.IResource)

Example 35 with WorkflowElement

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

the class ProcessExplorerActionGroup method createRunTestsAction.

private IAction createRunTestsAction() {
    IAction action = new Action() {

        @Override
        public void run() {
            if (!runTestsApplies(getSelection()))
                return;
            try {
                WorkflowElement element = (WorkflowElement) getSelection().getFirstElement();
                WorkflowProject project = element.getProject();
                restServer = ((RestfulServer) project.getDesignerDataAccess().getCurrentServer());
                restServer.getAppSummary();
                refreshRolePermissions(project);
                if (!isAuthorized(element)) {
                    MessageDialog.openError(getViewSite().getShell(), RUN_ACTION, "You are not authorized to run " + element.getName());
                    return;
                }
                view.setFocus();
                actionHandler.test(getSelection());
            } catch (ConnectException ex) {
                PluginMessages.log(ex);
                MessageDialog.openError(MdwPlugin.getShell(), RUN_ACTION, "Server appears to be offline: " + restServer.getServerUrl());
            } catch (Exception ex) {
                PluginMessages.log(ex);
                MessageDialog.openError(MdwPlugin.getShell(), RUN_ACTION, ex.getMessage());
            }
        }
    };
    ImageDescriptor imageDesc = MdwPlugin.getImageDescriptor("icons/testrun.gif");
    action.setImageDescriptor(imageDesc);
    action.setId(MdwMenuManager.MDW_MENU_PREFIX + "run.tests");
    action.setText("Run Tests...");
    return action;
}
Also used : WebLaunchAction(com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction) IAction(org.eclipse.jface.action.IAction) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) PartInitException(org.eclipse.ui.PartInitException) ConnectException(java.net.ConnectException) NamingException(javax.naming.NamingException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException)

Aggregations

WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)65 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)25 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)25 IAction (org.eclipse.jface.action.IAction)22 Action (org.eclipse.jface.action.Action)21 IWorkbenchAction (org.eclipse.ui.actions.ActionFactory.IWorkbenchAction)21 WebLaunchAction (com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction)19 ArrayList (java.util.ArrayList)17 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)14 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)11 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 IFile (org.eclipse.core.resources.IFile)8 AutomatedTestSuite (com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite)7 Folder (com.centurylink.mdw.plugin.designer.model.Folder)7 LegacyExpectedResults (com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults)7 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)7 PartInitException (org.eclipse.ui.PartInitException)7 AutomatedTestResults (com.centurylink.mdw.plugin.designer.model.AutomatedTestResults)5 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)5