Search in sources :

Example 1 with ProgressMonitor

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

the class ImportExportWizard method performFinish.

@Override
public boolean performFinish() {
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
            try {
                progressMonitor.start((page.isExport ? "Exporting from " : "Importing into ") + "'" + getProject().getLabel() + "'");
                progressMonitor.progress(5);
                performImportExport(progressMonitor);
                progressMonitor.done();
            } catch (ActionCancelledException ex) {
                throw new OperationCanceledException();
            } catch (Exception ex) {
                PluginMessages.log(ex);
                throw new InvocationTargetException(ex);
            }
        }
    };
    try {
        getContainer().run(true, true, op);
        postRunUpdates();
        return true;
    } catch (InvocationTargetException ex) {
        if (ex.getCause() instanceof DataAccessOfflineException)
            MessageDialog.openError(getShell(), "Export Attributes", "Server appears to be offline: " + ex.getMessage());
        else
            PluginMessages.uiError(getShell(), ex, page.getTitle(), getProject());
        return false;
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, page.getTitle(), getProject());
        return false;
    }
}
Also used : ProgressMonitor(com.centurylink.mdw.common.utilities.timer.ProgressMonitor) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JSONException(org.json.JSONException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with ProgressMonitor

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

the class ToolboxWrapper method refresh.

/**
 * Reloads from the database.
 */
public void refresh() {
    try {
        IRunnableWithProgress loader = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
                progressMonitor.start("Loading Activity Implementors for " + getProject().getLabel());
                progressMonitor.progress(25);
                getProject().reloadActivityImplementors();
                progressMonitor.done();
            }
        };
        ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(Display.getCurrent().getActiveShell());
        progMonDlg.run(true, false, loader);
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Refresh Implementors", getProject());
    }
    update();
    clearDirty();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitor(com.centurylink.mdw.common.utilities.timer.ProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 3 with ProgressMonitor

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

the class ProcessExplorerContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof WorkflowProject) {
        final WorkflowProject workflowProject = (WorkflowProject) parentElement;
        if (!workflowProject.isLoaded()) {
            try {
                IRunnableWithProgress loader = new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
                        progressMonitor.start("Loading " + workflowProject.getLabel());
                        progressMonitor.progress(5);
                        try {
                            workflowProject.initialize(progressMonitor);
                            if (workflowProject.getDataAccess() != null) {
                                workflowProject.getTopLevelUserVisiblePackages(progressMonitor);
                                workflowProject.getArchivedUserVisiblePackagesFolder(progressMonitor);
                                progressMonitor.done();
                            }
                        } catch (Exception ex) {
                            throw new InvocationTargetException(ex);
                        }
                    }
                };
                ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(MdwPlugin.getShell());
                progMonDlg.run(true, false, loader);
            } catch (InvocationTargetException itx) {
                if (itx.getCause() instanceof DataUnavailableException) {
                    PluginMessages.log(itx);
                    MessageDialog.openWarning(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
                } else if (itx.getCause() instanceof DataAccessOfflineException) {
                    PluginMessages.log(itx);
                    MessageDialog.openError(MdwPlugin.getShell(), LOAD_WF_PROJECT, itx.getCause().getMessage());
                    return new WorkflowPackage[0];
                } else {
                    PluginMessages.uiError(itx, LOAD_WF_PROJECT, workflowProject);
                    return new WorkflowPackage[0];
                }
            } catch (Exception ex) {
                PluginMessages.uiError(ex, LOAD_WF_PROJECT, workflowProject);
                return new WorkflowPackage[0];
            }
        }
        if (workflowProject.getDataAccess() == null)
            return new WorkflowPackage[0];
        List<WorkflowPackage> topLevelPackages = workflowProject.getTopLevelUserVisiblePackages();
        Folder archivedPackageFolder = workflowProject.getArchivedUserVisiblePackagesFolder();
        int size = topLevelPackages.size();
        boolean showArchived = isShowArchivedItems(workflowProject);
        if (showArchived)
            size++;
        AutomatedTestSuite testSuite = workflowProject.getLegacyTestSuite();
        if (testSuite != null && !testSuite.isEmpty())
            size++;
        Object[] objects = new Object[size];
        for (int i = 0; i < topLevelPackages.size(); i++) objects[i] = topLevelPackages.get(i);
        int cur = topLevelPackages.size();
        if (showArchived) {
            objects[cur] = archivedPackageFolder;
            cur++;
        }
        if (testSuite != null && !testSuite.isEmpty())
            objects[cur] = testSuite;
        return objects;
    } else if (parentElement instanceof WorkflowPackage) {
        WorkflowPackage packageVersion = (WorkflowPackage) parentElement;
        if (packageVersion.isArchived() && packageVersion.hasDescendantPackageVersions()) {
            return packageVersion.getDescendantPackageVersions().toArray(new WorkflowPackage[0]);
        } else {
            List<WorkflowElement> elements = new ArrayList<>();
            IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_PROCESSES_IN_PEX))
                elements.addAll(packageVersion.getProcesses());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_WORKFLOW_ASSETS_IN_PEX))
                elements.addAll(packageVersion.getAssets());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_EVENT_HANDLERS_IN_PEX))
                elements.addAll(packageVersion.getExternalEvents());
            if (prefsStore.getBoolean(PreferenceConstants.PREFS_SHOW_ACTIVITY_IMPLEMENTORS_IN_PEX))
                elements.addAll(packageVersion.getActivityImpls());
            if (!prefsStore.getBoolean(PreferenceConstants.PREFS_FILTER_TASK_TEMPLATES_IN_PEX))
                elements.addAll(packageVersion.getTaskTemplates());
            elements.addAll(packageVersion.getChildFolders());
            if (isSortPackageContentsAtoZ()) {
                Collections.sort(elements, new Comparator<WorkflowElement>() {

                    public int compare(WorkflowElement e1, WorkflowElement e2) {
                        return e1.getLabel().compareToIgnoreCase(e2.getLabel());
                    }
                });
            }
            return elements.toArray(new Object[0]);
        }
    } else if (parentElement instanceof WorkflowProcess) {
        WorkflowProcess processVersion = (WorkflowProcess) parentElement;
        if (processVersion.hasDescendantProcessVersions()) {
            return processVersion.getDescendantProcessVersions().toArray(new WorkflowProcess[0]);
        } else {
            return emptyARRAY;
        }
    } else if (parentElement instanceof Folder) {
        Folder folder = (Folder) parentElement;
        return folder.getChildren().toArray(new WorkflowElement[0]);
    } else if (parentElement instanceof AutomatedTestSuite) {
        AutomatedTestSuite testSuite = (AutomatedTestSuite) parentElement;
        return testSuite.getTestCases().toArray(new AutomatedTestCase[0]);
    } else if (parentElement instanceof AutomatedTestCase) {
        AutomatedTestCase testCase = (AutomatedTestCase) parentElement;
        if (!testCase.isLegacy())
            return emptyARRAY;
        List<LegacyExpectedResults> expectedResults = testCase.getLegacyExpectedResults();
        List<File> files = testCase.getFiles();
        Object[] objects = new Object[expectedResults.size() + files.size()];
        for (int i = 0; i < expectedResults.size(); i++) objects[i] = expectedResults.get(i);
        for (int i = expectedResults.size(); i < objects.length; i++) objects[i] = files.get(i - expectedResults.size());
        return objects;
    } else {
        return emptyARRAY;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) Folder(com.centurylink.mdw.plugin.designer.model.Folder) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) List(java.util.List) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) MdwProgressMonitorDialog(com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataUnavailableException(com.centurylink.mdw.designer.DataUnavailableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProgressMonitor(com.centurylink.mdw.common.utilities.timer.ProgressMonitor) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DataUnavailableException(com.centurylink.mdw.designer.DataUnavailableException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement)

Example 4 with ProgressMonitor

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

the class ImportPackageWizard method performFinish.

@Override
public boolean performFinish() {
    final List<WorkflowPackage> importedPackages = new ArrayList<>();
    final List<java.io.File> includes = new ArrayList<>();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                WorkflowProject wfp = topFolder.getProject();
                DesignerProxy designerProxy = wfp.getDesignerProxy();
                java.io.File assetDir = wfp.getAssetDir();
                java.io.File zipFile = null;
                java.io.File tempDir = wfp.getTempDir();
                monitor.beginTask("Import Packages", 100 * importPackageSelectPage.getSelectedPackages().size());
                monitor.subTask("Importing selected packages...");
                monitor.worked(10);
                StringBuilder sb = new StringBuilder();
                ProgressMonitor progressMonitor = new SwtProgressMonitor(new SubProgressMonitor(monitor, 100));
                for (File pkgFile : importPackageSelectPage.getSelectedPackages()) {
                    if (pkgFile.getContent() == null) {
                        // discovered
                        if (pkgFile.getUrl() != null) {
                            // assets
                            HttpHelper httpHelper = new HttpHelper(pkgFile.getUrl());
                            httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
                            httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
                            pkgFile.setContent(httpHelper.get());
                        } else if (mavenDiscovery)
                            importFromMaven(pkgFile.getName(), wfp, includes, monitor);
                        else {
                            getPackageNames(pkgFile.getName(), sb);
                        }
                    }
                    String pkgFileContent = pkgFile.getContent();
                    if (pkgFileContent != null) {
                        Importer importer = new Importer(designerProxy.getPluginDataAccess(), wfp.isFilePersist() && wfp.isRemote() ? null : getShell());
                        WorkflowPackage importedPackage = importer.importPackage(wfp, pkgFileContent, progressMonitor);
                        if (// canceled
                        importedPackage == null) {
                            progressMonitor.done();
                            break;
                        } else {
                            if (upgradeAssets) {
                                progressMonitor.subTask("Upgrading activity implementors and other assets...");
                                designerProxy.upgradeAssets(importedPackage);
                            }
                            if (// file system eclipse
                            wfp.isFilePersist())
                                // sync
                                wfp.getSourceProject().refreshLocal(2, null);
                            // TODO refresh Archive in case existing package
                            // was
                            // moved there
                            importedPackages.add(importedPackage);
                            includes.add(new java.io.File(assetDir + "/" + importedPackage.getName().replace('.', '/')));
                        }
                        progressMonitor.done();
                    }
                }
                if (sb.length() > 0) {
                    String url = wfp.getServiceUrl() + "/Services/Assets";
                    Map<String, String> hdrs = new HashMap<>();
                    hdrs.put("Content-Type", "application/json");
                    hdrs.put("request-query-string", "discoveryUrl=" + discoveryUrl + "&discoveryType=distributed");
                    DesignerHttpHelper httpHelper = new DesignerHttpHelper(new URL(url), wfp.getUser().getJwtToken());
                    httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
                    httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
                    httpHelper.setHeaders(hdrs);
                    httpHelper.put("{packages: [" + sb.toString() + "]}");
                }
                if (zipFormat) {
                    zipFile = importFile;
                    if (!wfp.isRemote())
                        unzipToLocal(wfp, zipFile, tempDir, assetDir, importedPackages, progressMonitor);
                }
                if (!includes.isEmpty()) {
                    if (!tempDir.exists() && !tempDir.mkdirs()) {
                        throw new IOException("Unable to create temp directory: " + tempDir);
                    }
                    zipFile = new java.io.File(tempDir + "/packages" + StringHelper.filenameDateToString(new Date()) + ".zip");
                    ZipHelper.zipWith(assetDir, zipFile, includes);
                }
                if (zipFile != null && wfp.isRemote() && wfp.isFilePersist()) {
                    uploadToRemoteServer(wfp, zipFile);
                    if (!zipFile.delete())
                        PluginMessages.log("Unable to delete the file " + zipFile.getPath());
                    progressMonitor.done();
                }
                wfp.getDesignerProxy().getCacheRefresh().doRefresh(true);
            } catch (ActionCancelledException ex) {
                throw new OperationCanceledException();
            } catch (Exception ex) {
                PluginMessages.log(ex);
                throw new InvocationTargetException(ex);
            }
        }
    };
    try {
        boolean confirmed = true;
        if (topFolder.getProject().checkRequiredVersion(6, 0, 13) && topFolder.getProject().isRemote())
            confirmed = MessageDialog.openConfirm(getShell(), "Confirm Import", "This import will impact the remote environment. Are you sure you want to import?");
        if (confirmed) {
            getContainer().run(true, true, op);
            if (!importedPackages.isEmpty())
                DesignerPerspective.promptForShowPerspective(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), importedPackages.get(0));
            IWorkbenchPage page = MdwPlugin.getActivePage();
            ProcessExplorerView processExplorer = (ProcessExplorerView) page.findView(ProcessExplorerView.VIEW_ID);
            if (processExplorer != null) {
                processExplorer.handleRefresh();
                processExplorer.expand(topFolder);
            }
        }
        return true;
    } catch (InterruptedException ex) {
        MessageDialog.openInformation(getShell(), "Import Package", "Import Cancelled");
        return true;
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Import Package", importPackagePage.getProject());
        return false;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) DesignerHttpHelper(com.centurylink.mdw.designer.utils.DesignerHttpHelper) URL(java.net.URL) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Importer(com.centurylink.mdw.plugin.designer.Importer) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) ProcessExplorerView(com.centurylink.mdw.plugin.designer.views.ProcessExplorerView) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) Date(java.util.Date) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitor(com.centurylink.mdw.common.utilities.timer.ProgressMonitor) SwtProgressMonitor(com.centurylink.mdw.plugin.designer.SwtProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(com.centurylink.mdw.plugin.designer.model.File) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DesignerHttpHelper(com.centurylink.mdw.designer.utils.DesignerHttpHelper)

Aggregations

ProgressMonitor (com.centurylink.mdw.common.utilities.timer.ProgressMonitor)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 SwtProgressMonitor (com.centurylink.mdw.plugin.designer.SwtProgressMonitor)3 IOException (java.io.IOException)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)2 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)2 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)2 MdwProgressMonitorDialog (com.centurylink.mdw.plugin.designer.dialogs.MdwProgressMonitorDialog)2 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)2 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)2 ArrayList (java.util.ArrayList)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 JSONException (org.json.JSONException)2 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)1 DataUnavailableException (com.centurylink.mdw.designer.DataUnavailableException)1 DesignerHttpHelper (com.centurylink.mdw.designer.utils.DesignerHttpHelper)1 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)1