Search in sources :

Example 6 with DesignerProxy

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

the class ProcessExplorerDropTarget method handleDropWorkflowAsset.

private boolean handleDropWorkflowAsset(String assetInfo, WorkflowPackage targetPackage, int operation) {
    if (!targetPackage.getProject().checkRequiredVersion(5, 0)) {
        String msg = "Packaging of Definition Documents (such as scripts and pages) is only supported for MDWFramework 5.0 and later.";
        MessageDialog.openError(getViewer().getControl().getShell(), "Package Def Doc", msg);
        return false;
    }
    Long assetId = getWorkflowAssetId(assetInfo);
    WorkflowProject workflowProject = targetPackage.getProject();
    WorkflowPackage sourcePackage = workflowProject.getPackage(getPackageName(assetInfo));
    DesignerProxy designerProxy = workflowProject.getDesignerProxy();
    if (operation == DND.DROP_COPY) {
        WorkflowAsset existing = workflowProject.getAsset(assetId);
        CopyDialog copyDialog = new CopyDialog(getViewer().getControl().getShell(), existing, existing.getName(), String.valueOf(existing.getVersion()), targetPackage);
        if (copyDialog.open() == Dialog.OK) {
            String newName = copyDialog.getNewName();
            if (!existing.isLoaded())
                existing.load();
            WorkflowAsset newCopy;
            try {
                // try and use reflection to make it the correct type
                Constructor<? extends WorkflowAsset> ctor = existing.getClass().getConstructor(existing.getClass());
                newCopy = ctor.newInstance(existing);
            } catch (Exception ex) {
                PluginMessages.log(ex);
                newCopy = new WorkflowAsset(existing);
            }
            newCopy.setName(newName);
            newCopy.setVersion(1);
            newCopy.setPackage(targetPackage);
            try {
                designerProxy.createNewWorkflowAsset(newCopy, true);
            } catch (Exception ex) {
                PluginMessages.uiError(ex, "Copy " + existing.getTitle(), existing.getProject());
            }
            newCopy.addElementChangeListener(workflowProject);
            newCopy.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newCopy);
            WorkflowAssetFactory.registerAsset(newCopy);
            ((TreeViewer) getViewer()).refresh(targetPackage, true);
            return true;
        }
        return false;
    } else if (operation == DND.DROP_MOVE) {
        // don't allow multiple versions of the same asset in a package
        if (!targetPackage.isDefaultPackage()) {
            WorkflowAsset asset = workflowProject.getAsset(assetId);
            if (targetPackage.getAsset(asset.getName()) != null) {
                MessageDialog.openError(MdwPlugin.getShell(), "Asset Exists", "Asset '" + asset.getName() + "' already exists in package '" + targetPackage.getName() + "'.");
                return false;
            }
        }
        if (targetPackage.isDefaultPackage()) {
            designerProxy.removeWorkflowAssetFromPackage(assetId, sourcePackage);
        } else {
            assetId = designerProxy.moveWorkflowAssetToPackage(assetId, targetPackage);
        }
        ((TreeViewer) getViewer()).refresh(targetPackage.getProject(), true);
        WorkflowAssetFactory.registerAsset(workflowProject.getAsset(assetId));
        return true;
    } else {
        return false;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) CopyDialog(com.centurylink.mdw.plugin.designer.dialogs.CopyDialog) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) SWTException(org.eclipse.swt.SWTException)

Example 7 with DesignerProxy

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

the class VariableInstancesSection method openDialog.

private void openDialog(VariableInstanceInfo variableInstanceInfo) {
    Integer processStatus = process.getProcessInstance().getStatusCode();
    VariableTypeVO varType = getType(variableInstanceInfo);
    boolean readOnly = WorkStatus.STATUS_COMPLETED.equals(processStatus) || WorkStatus.STATUS_CANCELLED.equals(processStatus);
    if (varType.isJavaObjectType()) {
        try {
            // update based on object instance or from server
            varType = getDesignerProxy().getVariableInfo(variableInstanceInfo);
            if (!varType.isUpdateable())
                readOnly = true;
        } catch (Exception ex) {
            PluginMessages.log(ex);
        }
    }
    try {
        String varValue = getDesignerProxy().getVariableValue(getShell(), variableInstanceInfo, true);
        VariableValueDialog variableValueDialog = new VariableValueDialog(getShell(), variableInstanceInfo, varType, varValue, readOnly);
        if (variableValueDialog.open() == Dialog.OK) {
            DesignerProxy designerProxy = process.getProject().getDesignerProxy();
            designerProxy.updateVariableValue(process, variableInstanceInfo, variableValueDialog.getVariableValue().getValue());
            List<VariableInstanceInfo> variables = process.getProcessInstance().getVariables();
            List<VariableInstanceInfo> uninitializedVariables = getTheUninitializedVariables();
            variables.addAll(uninitializedVariables);
            tableEditor.setValue(variables);
        }
    } catch (Exception ex) {
        PluginMessages.uiMessage(ex, "Retrieve Variable", process.getProject(), PluginMessages.VALIDATION_MESSAGE);
        return;
    }
}
Also used : VariableTypeVO(com.centurylink.mdw.model.value.variable.VariableTypeVO) VariableValueDialog(com.centurylink.mdw.plugin.designer.dialogs.VariableValueDialog) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) VariableInstanceInfo(com.centurylink.mdw.model.value.variable.VariableInstanceInfo)

Example 8 with DesignerProxy

use of com.centurylink.mdw.plugin.designer.DesignerProxy 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 9 with DesignerProxy

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

the class ProcessExplorerDropTarget method handleDropActivityImpl.

private boolean handleDropActivityImpl(String activityImplInfo, WorkflowPackage targetPackage, int operation) {
    Long activityImplId = getActivityImplId(activityImplInfo);
    WorkflowProject workflowProject = targetPackage.getProject();
    WorkflowPackage sourcePackage = workflowProject.getPackage(getPackageName(activityImplInfo));
    DesignerProxy designerProxy = workflowProject.getDesignerProxy();
    if (operation == DND.DROP_COPY) {
        if (!targetPackage.isDefaultPackage()) {
            designerProxy.addActivityImplToPackage(activityImplId, targetPackage);
            ((TreeViewer) getViewer()).refresh(targetPackage, true);
            return true;
        }
        return false;
    } else if (operation == DND.DROP_MOVE) {
        if (targetPackage.isDefaultPackage()) {
            designerProxy.removeActivityImplFromPackage(activityImplId, sourcePackage);
        } else {
            designerProxy.addActivityImplToPackage(activityImplId, targetPackage);
            if (RunnerStatus.SUCCESS.equals(designerProxy.getRunnerStatus()))
                designerProxy.removeActivityImplFromPackage(activityImplId, sourcePackage);
        }
        ((TreeViewer) getViewer()).refresh(targetPackage.getProject(), true);
        return true;
    } else {
        return false;
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject)

Example 10 with DesignerProxy

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

the class ProcessInstanceContentProvider method getElements.

public Object[] getElements(Object inputElement) {
    WorkflowProcess processVersion = (WorkflowProcess) inputElement;
    if (instanceInfo == null) {
        DesignerProxy designerProxy = processVersion.getProject().getDesignerProxy();
        ProcessList instanceList = designerProxy.getProcessInstanceList(processVersion, filter.getProcessCriteria(), filter.getVariableCriteria(processVersion), pageIndex, filter.getPageSize(), sort.getOrderBy());
        instanceCount = instanceList.getTotal();
        instanceInfo = instanceList.getItems();
    }
    return instanceInfo.toArray(new ProcessInstanceVO[0]);
}
Also used : ProcessList(com.centurylink.mdw.model.value.process.ProcessList) DesignerProxy(com.centurylink.mdw.plugin.designer.DesignerProxy) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess)

Aggregations

DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)19 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)8 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)8 CoreException (org.eclipse.core.runtime.CoreException)6 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)5 File (java.io.File)5 IOException (java.io.IOException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)4 ArrayList (java.util.ArrayList)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)3 CopyDialog (com.centurylink.mdw.plugin.designer.dialogs.CopyDialog)3 ConnectException (java.net.ConnectException)3 IFile (org.eclipse.core.resources.IFile)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 VariableTypeVO (com.centurylink.mdw.model.value.variable.VariableTypeVO)2 Importer (com.centurylink.mdw.plugin.designer.Importer)2 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)2