Search in sources :

Example 46 with WorkflowPackage

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

the class ImportPackageWizard method unzipToLocal.

void unzipToLocal(WorkflowProject wfp, java.io.File zipFile, java.io.File tempDir, java.io.File assetDir, List<WorkflowPackage> importedPackages, ProgressMonitor progressMonitor) throws IOException, DataAccessException, CoreException, JSONException {
    VersionControl vcs = new VersionControlGit();
    vcs.connect(null, null, null, wfp.getAssetDir());
    progressMonitor.subTask("Archive existing assets...");
    VcsArchiver archiver = new VcsArchiver(assetDir, tempDir, vcs, progressMonitor);
    archiver.backup();
    PluginMessages.log("Unzipping " + zipFile + " into: " + assetDir);
    ZipHelper.unzip(zipFile, assetDir, null, null, true);
    archiver.archive();
    ZipHelper.unzip(zipFile, tempDir, null, null, true);
    wfp.getSourceProject().refreshLocal(2, null);
    java.io.File explodedDir = new java.io.File(tempDir + "/com");
    if (explodedDir.isDirectory()) {
        List<java.io.File> fileList = FileHelper.getFilesRecursive(explodedDir, "package.json", new ArrayList<java.io.File>());
        for (java.io.File file : fileList) {
            WorkflowPackage workflowPackage = new WorkflowPackage();
            workflowPackage.setProject(wfp);
            workflowPackage.setPackageVO(new PackageVO(new JSONObject(FileHelper.getFileContents(file.getPath()))));
            importedPackages.add(workflowPackage);
        }
        FileHelper.deleteRecursive(explodedDir);
    }
}
Also used : VcsArchiver(com.centurylink.mdw.dataaccess.file.VcsArchiver) VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) JSONObject(org.json.JSONObject) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) File(com.centurylink.mdw.plugin.designer.model.File)

Example 47 with WorkflowPackage

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

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

the class AutoTestPropertyTester method test.

// TODO: support multiple selections
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    ResourceWrapper resourceWrapper = new ResourceWrapper((IAdaptable) receiver);
    try {
        WorkflowProject workflowProject = resourceWrapper.getOwningWorkflowProject();
        if ("canLaunchAutoTest".equals(property)) {
            // currently only for
            // debug
            IFile file = resourceWrapper.getFile();
            if (file != null && ("test".equals(file.getFileExtension()) || "postman".equals(file.getFileExtension())) && file.exists() && !file.isDerived() && workflowProject != null) {
                WorkflowPackage pkg = workflowProject.getPackage((IFolder) file.getParent());
                if (pkg != null)
                    return pkg.getAsset(file) != null;
            }
        } else if ("canLaunchAutomatedTests".equals(property)) {
            IFolder folder = resourceWrapper.getFolder();
            if (folder != null) {
                workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(folder.getProject());
                if (workflowProject != null && workflowProject.isInitialized()) {
                    WorkflowPackage pkg = workflowProject.getPackage(folder);
                    if (pkg != null)
                        return !pkg.getTestCases().isEmpty();
                }
            } else {
                IProject project = resourceWrapper.getProject();
                if (project != null) {
                    WorkflowProject proj = WorkflowProjectManager.getInstance().getWorkflowProject(project);
                    if (proj != null && proj.isInitialized()) {
                        return !proj.getTestCases().isEmpty();
                    }
                }
            }
        } else if ("canLaunchCucumberTest".equals(property)) {
            if (resourceWrapper.getOwningJavaProject() != null) {
                IFile file = resourceWrapper.getFile();
                if (file != null && "feature".equals(file.getFileExtension()) && file.exists() && !file.isDerived()) {
                    // exclude mdw automated gherkin tests
                    if (workflowProject != null && workflowProject.isInitialized()) {
                        ResourceWrapper parentWrapper = new ResourceWrapper((IAdaptable) file.getParent());
                        IFolder folder = parentWrapper.getFolder();
                        if (folder != null && workflowProject.getPackage(folder) != null)
                            return false;
                    }
                    return true;
                }
            }
        } else if ("canLaunchCucumberTests".equals(property) && resourceWrapper.getOwningJavaProject() != null) {
            IFolder folder = resourceWrapper.getFolder();
            if (folder != null) {
                if (workflowProject != null && workflowProject.isInitialized() && workflowProject.getPackage(folder) != null)
                    return false;
                List<CucumberTest> tests = new ArrayList<>();
                CucumberTest.findTests(folder, tests);
                return !tests.isEmpty();
            } else {
                return false;
            }
        }
    } catch (CoreException ex) {
        PluginMessages.log(ex);
    }
    return false;
}
Also used : ResourceWrapper(com.centurylink.mdw.plugin.ResourceWrapper) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) ArrayList(java.util.ArrayList) List(java.util.List) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 49 with WorkflowPackage

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

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

the class AssetLocator method assetFromAttr.

public WorkflowElement assetFromAttr(String attrValue) {
    if (attrValue == null || attrValue.isEmpty() || attrValue.startsWith("$") || attrValue.startsWith("#")) {
        return null;
    }
    if (isProcess()) {
        int slashIdx = attrValue.indexOf('/');
        if (slashIdx <= 0) {
            // prefer process in same package
            WorkflowProcess proc = getElement().getPackage() == null ? null : getProcessVersion(attrValue, getElement().getPackage().getProcesses());
            if (proc != null)
                return proc;
            else
                return getProcessVersion(attrValue, getProject().getAllProcessVersions());
        } else {
            String pkgName = attrValue.substring(0, slashIdx);
            WorkflowPackage pkg = getProject().getPackage(pkgName);
            if (pkg == null)
                return null;
            else
                return getProcessVersion(attrValue.substring(slashIdx + 1), pkg.getProcesses());
        }
    } else if (isTaskTemplate()) {
        // no need to handle unqualified attrs
        int slashIdx = attrValue.indexOf('/');
        String pkgName = slashIdx <= 0 ? null : attrValue.substring(0, slashIdx);
        WorkflowPackage pkg = pkgName == null ? null : getProject().getPackage(pkgName);
        if (pkg == null)
            return null;
        else
            return getTaskTemplateVersion(attrValue.substring(slashIdx + 1), pkg.getTaskTemplates());
    } else {
        int slashIdx = attrValue.indexOf('/');
        if (slashIdx <= 0) {
            // prefer asset in same package
            WorkflowAsset pkgDoc = getElement().getPackage() == null ? null : getWorkflowAssetVersion(attrValue, getElement().getPackage().getAssets());
            if (pkgDoc != null)
                return pkgDoc;
            else
                return getWorkflowAssetVersion(attrValue, getProject().getAllWorkflowAssets());
        } else {
            String pkgName = attrValue.substring(0, slashIdx);
            WorkflowPackage pkg = getProject().getPackage(pkgName);
            if (pkg == null)
                return null;
            else
                return getWorkflowAssetVersion(attrValue.substring(slashIdx + 1), pkg.getAssets());
        }
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess)

Aggregations

WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)85 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)31 ArrayList (java.util.ArrayList)27 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)25 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)21 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)17 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)11 GridData (org.eclipse.swt.layout.GridData)11 CoreException (org.eclipse.core.runtime.CoreException)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)8 List (java.util.List)8 Label (org.eclipse.swt.widgets.Label)8 JSONException (org.json.JSONException)8 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)7 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)7 Folder (com.centurylink.mdw.plugin.designer.model.Folder)7 IOException (java.io.IOException)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)7