Search in sources :

Example 1 with File

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

the class ProcessExplorerActionGroup method createRunFromStartPageAction.

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

        @Override
        public void run() {
            if (!runFromPageApplies(getSelection()))
                return;
            view.setFocus();
            Object element = getSelection().getFirstElement();
            if (element instanceof AutomatedTestSuite || element instanceof AutomatedTestCase)
                actionHandler.test(getSelection());
            else if (element instanceof File && ((File) element).getParent() instanceof AutomatedTestCase && TestCase.LEGACY_TEST_CASE_FILENAMES.values().contains(((File) element).getName()))
                actionHandler.test(getSelection());
            else
                actionHandler.runFromPage((WorkflowElement) element);
        }
    };
    ImageDescriptor imageDesc = MdwPlugin.getImageDescriptor(ICON_RUN_GIF);
    action.setImageDescriptor(imageDesc);
    action.setId(MdwMenuManager.MDW_MENU_PREFIX + "run.start.page");
    action.setText("Run Start Page...");
    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) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) IFile(org.eclipse.core.resources.IFile) TestFile(com.centurylink.mdw.designer.testing.TestFile) File(com.centurylink.mdw.plugin.designer.model.File) JarFile(com.centurylink.mdw.plugin.designer.model.JarFile) AutomatedTestSuite(com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite)

Example 2 with File

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

the class Discoverer method crawlForPackageFiles.

/**
 * Crawls to find any package XML or JSON files.
 */
private void crawlForPackageFiles(Folder parent) throws DiscoveryException, IOException, InterruptedException {
    if (progressMonitor.isCanceled())
        throw new InterruptedException();
    String parentUrl = getFullUrl(parent);
    if (httpHelper == null)
        httpHelper = new HttpHelper(new URL(parentUrl));
    httpHelper.setConnectTimeout(MdwPlugin.getSettings().getHttpConnectTimeout());
    httpHelper.setReadTimeout(MdwPlugin.getSettings().getHttpReadTimeout());
    if (// topLevel
    !parent.hasParent())
        httpHelper.setFollowHtmlHeadMetaRefresh(true);
    String content = httpHelper.get();
    if (content.startsWith("{")) {
        parseJsonPacakges(parent, content);
    } else {
        if (content.startsWith("<!"))
            content = content.substring(content.indexOf('\n') + 1);
        if (content.contains("&nbsp;"))
            content = content.replaceAll("&nbsp;", "").replace("<HR size=\"1\" noshade=\"noshade\">", "");
        if (!parent.hasParent() && httpHelper.getRedirect() != null)
            parent.setName(httpHelper.getRedirect().toString());
        try {
            List<String> links = parseDirectoryResponse(content);
            if (!parent.hasParent())
                topLevelFolders = links.size();
            if (latestVersionsOnly) {
                List<String> latestLinks = new ArrayList<>();
                String latestDir = null;
                for (String link : links) {
                    if (// snapshots excluded from
                    !link.startsWith("6") && !link.endsWith("-SNAPSHOT/")) // "latest only"
                    {
                        if (link.matches("[0-9.]*/")) {
                            if ((latestDir == null || latestDir.compareTo(link) < 0))
                                latestDir = link;
                        } else {
                            latestLinks.add(link);
                        }
                    }
                }
                if (latestDir != null)
                    latestLinks.add(latestDir);
                links = latestLinks;
            }
            for (String link : links) {
                if (!link.startsWith("6") && link.endsWith("/") && (MdwPlugin.getSettings().isIncludePreviewBuilds() || !link.endsWith("-SNAPSHOT/"))) {
                    // directory
                    if (!parent.hasParent())
                        progressMonitor.subTask("Scanning " + link);
                    Folder child = new Folder(link.substring(0, link.length() - 1));
                    if (link.matches("[0-9.]*/"))
                        parent.addChild(0, child);
                    else
                        parent.addChild(child);
                    httpHelper = null;
                    crawlForPackageFiles(child);
                    if (// topLevel
                    !parent.hasParent())
                        progressMonitor.worked(80 / topLevelFolders);
                } else if (link.endsWith(".xml") || link.endsWith(".json")) {
                    // XML or JSON file
                    File child = new File(parent, link);
                    parent.addChild(0, child);
                    child.setUrl(new URL(getFullUrl(child)));
                }
            }
        } catch (InterruptedException iex) {
            throw iex;
        } catch (Exception ex) {
            throw new DiscoveryException("Error crawling: " + parentUrl, ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Folder(com.centurylink.mdw.plugin.designer.model.Folder) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) File(com.centurylink.mdw.plugin.designer.model.File) URL(java.net.URL) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 3 with File

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

the class ImportPackagePage method populateTopFolder.

public Folder populateTopFolder(String discoveryUrl, String groupId, boolean latestVersionsOnly, IProgressMonitor progressMonitor) throws Exception {
    Folder folder = null;
    getImportPackageWizard().getImportPackageSelectPage().clear();
    if (discoveryUrl != null || groupId != null) {
        if (discoveryUrl != null) {
            if (getProject().checkRequiredVersion(6, 0, 13))
                folder = new Discoverer(new URL(discoveryUrl), getProject().getHttpHelper(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
            else
                folder = new Discoverer(new URL(discoveryUrl)).getAssetTopFolder(latestVersionsOnly, progressMonitor);
        }
        if (groupId != null)
            folder = new Discoverer(groupId).getAssetTopFolder(latestVersionsOnly, progressMonitor);
        if (getProject().isRemote() && getProject().isGitVcs()) {
            List<Folder> emptyFolders = removeGitVersionedPackages(folder);
            List<Folder> emptyParents = new ArrayList<>();
            for (Folder emptyFolder : emptyFolders) {
                if (emptyFolder.getParent() instanceof Folder) {
                    Folder parent = emptyFolder.getParent();
                    parent.getChildren().remove(emptyFolder);
                    // go one more level up
                    if (parent.getChildren().isEmpty() && !emptyParents.contains(parent))
                        emptyParents.add(parent);
                }
            }
            for (Folder emptyParent : emptyParents) {
                if (emptyParent.getParent() instanceof Folder)
                    (emptyParent.getParent()).getChildren().remove(emptyParent);
            }
        }
    } else {
        String filepath = filePathText.getText().trim();
        String contents = FileHelper.getFileContents(filepath);
        folder = new Folder(filepath);
        boolean hasOldImpls = false;
        if (contents.trim().startsWith("{")) {
            ImporterExporterJson importer = new ImporterExporterJson();
            List<PackageVO> packages = importer.importPackages(contents);
            for (PackageVO pkg : packages) {
                if (getProject().isRemote() && getProject().isGitVcs()) {
                    for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                        if (existingVcs.getName().equals(pkg.getName()))
                            getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkg.getName());
                    }
                }
                File aFile = new File(folder, pkg.getName() + " v" + pkg.getVersionString());
                ImporterExporterJson jsonExporter = new ImporterExporterJson();
                List<PackageVO> pkgs = new ArrayList<>();
                pkgs.add(pkg);
                JSONObject pkgJson = new JSONObject(jsonExporter.exportPackages(pkgs));
                pkgJson.put("name", pkg.getName());
                aFile.setContent(pkgJson.toString(2));
                folder.addChild(aFile);
            }
            preselected = folder;
        } else {
            try {
                // try and parse as multiple packages
                PackageDocument pkgDoc = PackageDocument.Factory.parse(contents);
                QName docElement = new QName("http://mdw.centurylink.com/bpm", "processDefinition");
                for (MDWProcessDefinition pkgDef : pkgDoc.getPackage().getProcessDefinitionList()) {
                    if (getProject().isRemote() && getProject().isGitVcs()) {
                        for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                            if (existingVcs.getName().equals(pkgDef.getPackageName()))
                                getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + pkgDef.getPackageName());
                        }
                    }
                    if (!hasOldImpls && getProject().isFilePersist() && !getProject().isRemote())
                        hasOldImpls = checkForOldImplementors(pkgDef);
                    File aFile = new File(folder, pkgDef.getPackageName() + " v" + pkgDef.getPackageVersion());
                    aFile.setContent(pkgDef.xmlText(new XmlOptions().setSaveOuter().setSaveSyntheticDocumentElement(docElement)));
                    folder.addChild(aFile);
                }
                preselected = folder;
            } catch (XmlException ex) {
                // unparseable -- assume single package
                if (getProject().isRemote() && getProject().isGitVcs()) {
                    MDWProcessDefinition procDef = ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition();
                    for (WorkflowPackage existingVcs : getProject().getTopLevelPackages()) {
                        if (existingVcs.getName().equals(procDef.getPackageName()))
                            getImportPackageWizard().getImportPackageSelectPage().setError(PKG_EXISTS + procDef.getPackageName());
                    }
                }
                if (getProject().isFilePersist() && !getProject().isRemote())
                    hasOldImpls = checkForOldImplementors(ProcessDefinitionDocument.Factory.parse(contents, Compatibility.namespaceOptions()).getProcessDefinition());
                File file = new File(folder, filepath);
                file.setContent(contents);
                folder.addChild(file);
                preselected = file;
            }
        }
        getImportPackageWizard().setHasOldImplementors(hasOldImpls);
    }
    return folder;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) ArrayList(java.util.ArrayList) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) Discoverer(com.centurylink.mdw.plugin.designer.Discoverer) Folder(com.centurylink.mdw.plugin.designer.model.Folder) URL(java.net.URL) PackageDocument(com.centurylink.mdw.bpm.PackageDocument) JSONObject(org.json.JSONObject) XmlException(org.apache.xmlbeans.XmlException) File(com.centurylink.mdw.plugin.designer.model.File) ImporterExporterJson(com.centurylink.mdw.dataaccess.file.ImporterExporterJson)

Example 4 with File

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

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

File (com.centurylink.mdw.plugin.designer.model.File)11 Folder (com.centurylink.mdw.plugin.designer.model.Folder)6 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)4 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)4 ArrayList (java.util.ArrayList)4 TestFile (com.centurylink.mdw.designer.testing.TestFile)3 JarFile (com.centurylink.mdw.plugin.designer.model.JarFile)3 IOException (java.io.IOException)3 URL (java.net.URL)3 IFile (org.eclipse.core.resources.IFile)3 JSONObject (org.json.JSONObject)3 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)2 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)2 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)2 WebLaunchAction (com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction)2 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)2 AutomatedTestSuite (com.centurylink.mdw.plugin.designer.model.AutomatedTestSuite)2 LegacyExpectedResults (com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults)2 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)2 HashMap (java.util.HashMap)2