Search in sources :

Example 6 with ActionCancelledException

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

the class ImportAssetWizard method performImportExport.

void performImportExport(ProgressMonitor progressMonitor) throws IOException, XmlException, DataAccessException, ValidationException, ActionCancelledException {
    DesignerProxy designerProxy = getProject().getDesignerProxy();
    progressMonitor.progress(10);
    progressMonitor.subTask("Reading file");
    byte[] bytes = readFile(getPage().getFilePath());
    progressMonitor.progress(20);
    if (progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.subTask("Performing Import");
    File assetFile = new File(getPage().getFilePath());
    WorkflowAsset existingAsset = getAsset();
    if (// package selected, not asset
    existingAsset == null)
        existingAsset = getPackage().getAsset(assetFile.getName());
    boolean binary;
    RuleSetVO newRuleSet = new RuleSetVO();
    if (existingAsset == null) {
        newRuleSet.setName(assetFile.getName());
        newRuleSet.setLanguage(RuleSetVO.getFormat(assetFile.getName()));
        binary = newRuleSet.isBinary();
    } else {
        newRuleSet.setName(existingAsset.getName());
        newRuleSet.setLanguage(existingAsset.getLanguage());
        binary = existingAsset.isBinary();
        // custom
        newRuleSet.setAttributes(existingAsset.getAttributes());
    // attributes
    }
    newRuleSet.setRaw(getProject().isFilePersist());
    if (getProject().isFilePersist())
        newRuleSet.setRawFile(new File(getProject().getAssetDir() + "/" + getPackage().getName() + "/" + newRuleSet.getName()));
    if (binary) {
        if (newRuleSet.isRaw())
            newRuleSet.setRawContent(bytes);
        else
            newRuleSet.setRuleSet(RuleSetVO.encode(bytes));
    } else
        newRuleSet.setRuleSet(new String(bytes));
    WorkflowAsset newAsset = WorkflowAssetFactory.createAsset(newRuleSet, getPackage());
    // check db in case created in another session
    RuleSetVO existing = getProject().getDesignerDataAccess().getRuleSet(getPackage().getId(), newRuleSet.getName());
    progressMonitor.progress(10);
    newAsset.setVersion(existing == null ? 1 : existing.getVersion() + 1);
    newAsset.setComment(getPage().getComments());
    newAsset.setPackage(getPackage());
    newAsset.setId(Long.valueOf(-1));
    newAsset.setCreateUser(getProject().getUser().getUsername());
    newAsset.setLockingUser(getProject().getUser().getUsername());
    designerProxy.saveWorkflowAsset(newAsset, getPage().isLocked());
    getProject().getDataAccess().getDesignerDataModel().addRuleSet(newAsset.getRuleSetVO());
    // update the tree
    if (existingAsset != null) {
        getPackage().removeAsset(existingAsset);
        newAsset.getRuleSetVO().setPrevVersion(existingAsset.getRuleSetVO());
        getProject().getUnpackagedWorkflowAssets().add(existingAsset);
        existingAsset.setPackage(getProject().getDefaultPackage());
    }
    newAsset.getPackage().addAsset(newAsset);
    designerProxy.savePackage(newAsset.getPackage());
    setElement(newAsset);
    progressMonitor.progress(30);
    if (existingAsset != null)
        WorkflowAssetFactory.deRegisterAsset(existingAsset);
}
Also used : DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) File(java.io.File) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 7 with ActionCancelledException

use of com.centurylink.mdw.common.utilities.timer.ActionCancelledException 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 8 with ActionCancelledException

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

the class ImportTaskTemplatesWizard method performImportExport.

void performImportExport(ProgressMonitor progressMonitor) throws IOException, XmlException, DataAccessException, ValidationException, ActionCancelledException {
    Importer importer = new Importer(getProject().getDataAccess(), getShell());
    progressMonitor.progress(10);
    progressMonitor.subTask("Reading XML file");
    byte[] bytes = readFile(getPage().getFilePath());
    if (progressMonitor.isCanceled())
        throw new ActionCancelledException();
    progressMonitor.subTask("Performing Import");
    WorkflowPackage pkg = getPackage();
    if (pkg == null)
        throw new ValidationException("No package found.");
    importer.importTaskTemplates(pkg, new String(bytes), progressMonitor);
    progressMonitor.progress(30);
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) Importer(com.centurylink.mdw.plugin.designer.Importer)

Example 9 with ActionCancelledException

use of com.centurylink.mdw.common.utilities.timer.ActionCancelledException 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)

Example 10 with ActionCancelledException

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

the class DesignerDataAccess method exportAttributes.

public String exportAttributes(String prefix, Long artifactId, int schemaVersion, ProgressMonitor monitor, String exportArtifactType) throws DataAccessException, ActionCancelledException, XmlException {
    monitor.subTask("Loading attributes...");
    PackageVO packageVO = null;
    ProcessVO processVO = null;
    if (exportArtifactType.equals(OwnerType.PACKAGE)) {
        packageVO = loadPackage(artifactId, true);
        if (isVcsPersist()) {
            try {
                for (ProcessVO process : packageVO.getProcesses()) {
                    Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, process.getId());
                    process.applyOverrideAttributes(overrideAttrs);
                }
            } catch (IOException ex) {
                throw new DataAccessOfflineException("Server does not appear to be running.", ex);
            }
        } else {
            for (ProcessVO process : packageVO.getProcesses()) {
                if (process.isInRuleSet()) {
                    Map<String, String> overrideAttrs = getAttributes(OwnerType.PROCESS, process.getId());
                    process.applyOverrideAttributes(overrideAttrs);
                }
            }
        }
    } else {
        processVO = getProcess(artifactId, null);
        if (isVcsPersist()) {
            try {
                // need to make sure attributes are retrieved
                Map<String, String> overrideAttrs = workflowAccessRest.getAttributes(OwnerType.PROCESS, processVO.getId());
                processVO.applyOverrideAttributes(overrideAttrs);
            } catch (IOException ex) {
                throw new DataAccessOfflineException("Server does not appear to be running.", ex);
            }
        }
    }
    monitor.progress(30);
    if (monitor.isCanceled())
        throw new ActionCancelledException();
    if (packageVO != null) {
        // -- subprocesses must come after their containing parent processes
        Collections.sort(packageVO.getProcesses(), new Comparator<ProcessVO>() {

            public int compare(ProcessVO pVO1, ProcessVO pVO2) {
                boolean pVO1HasSubProcs = pVO1.getSubProcesses() != null && !pVO1.getSubProcesses().isEmpty();
                boolean pVO2HasSubProcs = pVO2.getSubProcesses() != null && !pVO2.getSubProcesses().isEmpty();
                if (pVO1HasSubProcs == pVO2HasSubProcs) {
                    // sort by label
                    return pVO1.getLabel().compareToIgnoreCase(pVO2.getLabel());
                } else if (pVO1HasSubProcs)
                    return -1;
                else
                    return 1;
            }
        });
    }
    if (monitor.isCanceled())
        throw new ActionCancelledException();
    monitor.progress(5);
    monitor.subTask(EXPORTXML);
    ProcessExporter exporter = DataAccess.getProcessExporter(schemaVersion, oldNamespaces ? DesignerCompatibility.getInstance() : null);
    String xml;
    if (packageVO != null)
        xml = exporter.exportOverrideAttributes(prefix, packageVO);
    else
        xml = exporter.exportOverrideAttributes(prefix, processVO, schemaVersion);
    monitor.progress(40);
    return xml;
}
Also used : DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) IOException(java.io.IOException) ProcessExporter(com.centurylink.mdw.dataaccess.ProcessExporter)

Aggregations

ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)13 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)6 ArrayList (java.util.ArrayList)6 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)5 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)5 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)4 Importer (com.centurylink.mdw.plugin.designer.Importer)4 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)3 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)3 CustomAttributeVO (com.centurylink.mdw.model.value.attribute.CustomAttributeVO)3 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)3 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)3 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)3 IOException (java.io.IOException)3 ProgressMonitor (com.centurylink.mdw.common.utilities.timer.ProgressMonitor)2 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)2 NodeMetaInfo (com.centurylink.mdw.designer.utils.NodeMetaInfo)2 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)2 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)2 SwtProgressMonitor (com.centurylink.mdw.plugin.designer.SwtProgressMonitor)2