Search in sources :

Example 36 with WorkflowAsset

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

the class WorkflowProject method getAllWorkflowAssets.

/**
 * Returns all assets regardless of user access, packaging and archive
 * status.
 */
public List<WorkflowAsset> getAllWorkflowAssets() {
    List<WorkflowAsset> allAssets = new ArrayList<>();
    allAssets.addAll(getTopLevelWorkflowAssets());
    if (isShowDefaultPackage())
        allAssets.addAll(getUnpackagedWorkflowAssets());
    Map<String, WorkflowAsset> latestPackaged = new HashMap<>();
    for (WorkflowAsset asset : allAssets) {
        String key = (asset.isInDefaultPackage() ? "" : asset.getPackage().getName() + "/") + asset.getName() + asset.getVersionLabel();
        latestPackaged.put(key, asset);
    }
    // get archived def docs if they don't match any non-archived version
    for (WorkflowElement child : getArchivedPackageFolder().getChildren()) {
        WorkflowPackage topLevelArchivedPackage = (WorkflowPackage) child;
        if (topLevelArchivedPackage.getDescendantPackageVersions() != null) {
            for (WorkflowPackage archivedPackage : topLevelArchivedPackage.getDescendantPackageVersions()) {
                for (WorkflowAsset archivedAsset : archivedPackage.getAssets()) {
                    String key = (archivedAsset.isInDefaultPackage() ? "" : archivedAsset.getPackage().getName() + "/") + archivedAsset.getName() + archivedAsset.getVersionLabel();
                    WorkflowAsset curPkgMax = latestPackaged.get(key);
                    if (curPkgMax == null || archivedAsset.getPackage().getVersion() > curPkgMax.getPackage().getVersion())
                        latestPackaged.put(key, archivedAsset);
                }
            }
        }
    }
    // reset list to include those added above
    allAssets = new ArrayList<>(latestPackaged.values());
    // account for assets not visible to user (cached separately)
    if (assetsNotForCurrentUser == null) {
        assetsNotForCurrentUser = new ArrayList<>();
        for (RuleSetVO rs : getDataAccess().getAllRuleSets(false)) {
            WorkflowAsset asset = WorkflowAssetFactory.createAsset(rs, findPackage(rs));
            if (asset != null && !allAssets.contains(asset))
                assetsNotForCurrentUser.add(asset);
        }
    }
    allAssets.addAll(assetsNotForCurrentUser);
    return allAssets;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) HashMap(java.util.HashMap) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) ArrayList(java.util.ArrayList) WorkflowElement(com.centurylink.mdw.plugin.designer.model.WorkflowElement) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 37 with WorkflowAsset

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

the class WorkflowProject method findUnpackagedAssetFolders.

/**
 * Returns the folders for unpackaged archived workflow assets. Side-effect:
 * If an unpackaged version is later than any package, add to default
 * package.
 */
private List<Folder> findUnpackagedAssetFolders() {
    CodeTimer timer = new CodeTimer("findUnpackagedAssetFolders()");
    Map<String, Folder> upAssetFolders = new HashMap<>();
    Map<String, List<RuleSetVO>> nonLatestUnpackaged = new HashMap<>();
    for (RuleSetVO ruleSetVO : getDataAccess().getRuleSets(false)) {
        if (!isPackaged(ruleSetVO)) {
            // if version is later than that in any non-archived package,
            // it belongs in the top-level default package
            boolean laterThanPackaged = true;
            for (WorkflowPackage pkg : getTopLevelPackages()) {
                WorkflowAsset packaged = pkg.getAsset(ruleSetVO.getName());
                if (packaged != null && packaged.getVersion() >= ruleSetVO.getVersion()) {
                    laterThanPackaged = false;
                    break;
                }
            }
            boolean latestUnpackaged = true;
            if (laterThanPackaged) {
                WorkflowAsset defPkgAsset = getDefaultPackage().getAsset(ruleSetVO.getName());
                if (defPkgAsset != null) {
                    if (defPkgAsset.getVersion() > ruleSetVO.getVersion()) {
                        latestUnpackaged = false;
                    } else if (defPkgAsset.getVersion() < ruleSetVO.getVersion()) {
                        defPkgAsset.removeElementChangeListener(this);
                        getDefaultPackage().removeAsset(defPkgAsset);
                        WorkflowAssetFactory.deRegisterAsset(defPkgAsset);
                        List<RuleSetVO> list = nonLatestUnpackaged.get(ruleSetVO.getName());
                        if (list == null) {
                            list = new ArrayList<>();
                            nonLatestUnpackaged.put(ruleSetVO.getName(), list);
                        }
                        list.add(defPkgAsset.getRuleSetVO());
                    }
                }
            }
            if (laterThanPackaged && latestUnpackaged) {
                WorkflowAsset asset = WorkflowAssetFactory.createAsset(ruleSetVO, getDefaultPackage());
                if (asset != null) {
                    asset.addElementChangeListener(this);
                    getDefaultPackage().addAsset(asset);
                    WorkflowAssetFactory.registerAsset(asset);
                }
            } else {
                List<RuleSetVO> list = nonLatestUnpackaged.get(ruleSetVO.getName());
                if (list == null) {
                    list = new ArrayList<>();
                    nonLatestUnpackaged.put(ruleSetVO.getName(), list);
                }
                list.add(ruleSetVO);
            }
        }
    }
    for (String rsName : nonLatestUnpackaged.keySet()) {
        List<RuleSetVO> list = nonLatestUnpackaged.get(rsName);
        Collections.sort(list, new Comparator<RuleSetVO>() {

            public int compare(RuleSetVO rs1, RuleSetVO rs2) {
                return rs2.getVersion() - rs1.getVersion();
            }
        });
        for (RuleSetVO rs : list) {
            WorkflowAsset asset = WorkflowAssetFactory.createAsset(rs, archivedDefaultPackage);
            if (asset != null) {
                Folder folder = upAssetFolders.get(asset.getName());
                if (folder == null) {
                    folder = WorkflowAssetFactory.createAssetFolder(asset);
                    upAssetFolders.put(asset.getName(), folder);
                } else {
                    folder.getChildren().add(asset);
                }
            }
        }
    }
    List<Folder> folders = new ArrayList<>();
    folders.addAll(upAssetFolders.values());
    Collections.sort(folders);
    timer.stopAndLog();
    return folders;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(com.centurylink.mdw.plugin.designer.model.Folder) IVirtualFolder(org.eclipse.wst.common.componentcore.resources.IVirtualFolder) IFolder(org.eclipse.core.resources.IFolder) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) ArrayList(java.util.ArrayList) List(java.util.List) CodeTimer(com.centurylink.mdw.plugin.CodeTimer)

Example 38 with WorkflowAsset

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

the class WorkflowProject method findTopLevelPackages.

/**
 * Finds the list of top level packages (including the default if
 * supported), populated with the appropriate processes, etc.
 */
private void findTopLevelPackages(ProgressMonitor progressMonitor) {
    CodeTimer timer = new CodeTimer("findTopLevelPackages()");
    topLevelPackages = new ArrayList<>();
    topLevelUserVisiblePackages = new ArrayList<>();
    activityImpls.clear();
    for (PackageVO packageVO : getTopLevelPackageVOs(progressMonitor)) {
        WorkflowPackage topLevelPackage = new WorkflowPackage(this, packageVO);
        topLevelPackage.setProcesses(findProcesses(topLevelPackage));
        topLevelPackage.setExternalEvents(findExternalEvents(topLevelPackage));
        topLevelPackage.setActivityImpls(findActivityImplementors(topLevelPackage));
        topLevelPackage.setAssets(findWorkflowAssets(topLevelPackage));
        topLevelPackage.setTaskTemplates(findTaskTemplates(topLevelPackage));
        topLevelPackages.add(topLevelPackage);
        if (topLevelPackage.isVisible())
            topLevelUserVisiblePackages.add(topLevelPackage);
        // register as a listener so that i can pass on element change
        // events
        topLevelPackage.addElementChangeListener(this);
        for (WorkflowProcess process : topLevelPackage.getProcesses()) process.addElementChangeListener(this);
    }
    Collections.sort(topLevelPackages);
    Collections.sort(topLevelUserVisiblePackages);
    File resultsFile = getFunctionTestResultsFile();
    if (resultsFile.exists()) {
        // update test case statuses
        List<TestCase> testCases = new ArrayList<>();
        for (WorkflowPackage pkg : topLevelPackages) {
            for (WorkflowAsset asset : pkg.getAssets()) {
                if (asset instanceof AutomatedTestCase)
                    testCases.add(((AutomatedTestCase) asset).getTestCase());
            }
        }
        if (!testCases.isEmpty()) {
            try {
                TestResultsParser parser = new TestResultsParser(resultsFile, testCases);
                if (resultsFile.getName().endsWith(".xml"))
                    parser.parseXml();
                else
                    parser.parseJson(getAssetDir());
            } catch (Exception ex) {
                PluginMessages.uiError(ex, "Parse Test Results", this);
            }
        }
    }
    timer.stopAndLog();
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) PackageVO(com.centurylink.mdw.model.value.process.PackageVO) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) MalformedURLException(java.net.MalformedURLException) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestCase(com.centurylink.mdw.designer.testing.TestCase) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) TestResultsParser(com.centurylink.mdw.designer.testing.TestResultsParser) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 39 with WorkflowAsset

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

the class AssetSearchQuery method run.

public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
    if (getScopedProjects().isEmpty() && getSelectedPackage() != null)
        getScopedProjects().add(getSelectedPackage().getProject());
    if (getScopedProjects().isEmpty()) {
        String msg = "No MDW projects in search scope.";
        showError(msg, "MDW Search", null);
        return new Status(IStatus.WARNING, MdwPlugin.getPluginId(), 0, msg, null);
    }
    for (WorkflowProject project : getScopedProjects()) {
        if (getSearchType().equals(SearchType.ENTITY_BY_NAME) || (getSearchType().equals(SearchType.ENTITY_BY_ID) && getPattern().equals("*"))) {
            if (getResourceType().equalsIgnoreCase("External Event Handler")) {
                for (ExternalEvent eventHandler : project.getAllExternalEvents()) {
                    String name = isCaseSensitive() ? eventHandler.getName() : eventHandler.getName().toLowerCase();
                    if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (eventHandler.getPackage() != null && eventHandler.getPackage().equals(getSelectedPackage()))))
                        getSearchResults().addMatchingElement(eventHandler);
                }
            } else {
                for (WorkflowAsset asset : project.getAllWorkflowAssets()) {
                    if (asset.getLanguage().equalsIgnoreCase(getResourceType())) {
                        String name = isCaseSensitive() ? asset.getName() : asset.getName().toLowerCase();
                        if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (asset.getPackage() != null && asset.getPackage().equals(getSelectedPackage()))))
                            getSearchResults().addMatchingElement(asset);
                    }
                }
            }
        } else if (getSearchType().equals(SearchType.CONTAINING_TEXT)) {
            if (getResourceType().equalsIgnoreCase("External Event Handler")) {
                for (ExternalEvent eventHandler : project.getAllExternalEvents()) {
                    String name = isCaseSensitive() ? eventHandler.getName() : eventHandler.getName().toLowerCase();
                    if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (eventHandler.getPackage() != null && eventHandler.getPackage().equals(getSelectedPackage())))) {
                        // resource name pattern is matched, check for
                        // contained text
                        String searchText = isCaseSensitive() ? getContainedText() : getContainedText().toLowerCase();
                        searchText = searchText.replaceAll("\\*", "");
                        if (eventHandler.getName().indexOf(searchText) >= 0)
                            getSearchResults().addMatchingElement(eventHandler);
                    }
                }
            } else {
                for (WorkflowAsset asset : project.getAllWorkflowAssets()) {
                    if (asset.getLanguage().equalsIgnoreCase(getResourceType())) {
                        String name = isCaseSensitive() ? asset.getName() : asset.getName().toLowerCase();
                        if ((getPattern().equals("*") || name.indexOf(getPattern()) >= 0) && (getSelectedPackage() == null || (asset.getPackage() != null && asset.getPackage().equals(getSelectedPackage())))) {
                            // resource name pattern is matched, check for
                            // contained text
                            asset = asset.getProject().getDesignerProxy().loadWorkflowAsset(asset);
                            if (!asset.isBinary()) {
                                String content = isCaseSensitive() ? asset.getContent() : asset.getContent().toLowerCase();
                                String searchText = isCaseSensitive() ? getContainedText() : getContainedText().toLowerCase();
                                searchText = searchText.replaceAll("\\*", "");
                                if (content.indexOf(searchText) >= 0)
                                    getSearchResults().addMatchingElement(asset);
                            }
                        }
                    }
                }
            }
        } else if (getSearchType().equals(SearchType.ENTITY_BY_ID)) {
            WorkflowAsset asset = project.getAsset(new Long(getPattern()));
            if (asset != null && asset.getLanguage().equalsIgnoreCase(getResourceType()))
                getSearchResults().addMatchingElement(asset);
        } else {
            showError("Unsupported search type: " + getSearchType(), "MDW Search", null);
        }
    }
    if (getSearchResults().getMatchingElements().size() == 0)
        return new Status(IStatus.WARNING, MdwPlugin.getPluginId(), 0, "No matching elements found", null);
    else
        return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) ExternalEvent(com.centurylink.mdw.plugin.designer.model.ExternalEvent) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject)

Example 40 with WorkflowAsset

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

the class JavaSourceHyperlink method linkActivated.

@SuppressWarnings("restriction")
public void linkActivated() {
    String linkText = getLinkText();
    if (// dynamic java
    linkText.startsWith("string:///")) {
        try {
            WorkflowProject workflowProj = WorkflowProjectManager.getInstance().getWorkflowProject(project);
            // package
            String path = linkText.substring(10);
            int slashIdx = path.indexOf('/');
            String pkg = slashIdx > 0 ? path.substring(0, slashIdx) : null;
            // asset
            int javaIdx = path.indexOf(".java");
            String assetName = path.substring(slashIdx > 0 ? slashIdx + 1 : 0, javaIdx);
            // lineNum
            String lineNum = "";
            int i = javaIdx + 6;
            while (i < path.length() && Character.isDigit(path.charAt(i))) lineNum += path.charAt(i++);
            WorkflowAsset asset = workflowProj.getAsset(pkg, assetName);
            if (asset == null) {
                cantFindSourceWarning();
            } else {
                asset.openFile(new NullProgressMonitor());
                if (lineNum.length() > 0) {
                    ITextEditor editor = (ITextEditor) asset.getFileEditor();
                    if (editor != null) {
                        IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                        IRegion lineInfo = document.getLineInformation(Integer.parseInt(lineNum) - 1);
                        if (lineInfo != null)
                            editor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength());
                    }
                }
            }
        } catch (Exception ex) {
            cantFindSourceWarning();
            PluginMessages.log(ex);
        }
        return;
    }
    int lineNumber = getLineNumber();
    // documents start at 0
    if (lineNumber > 0)
        lineNumber--;
    try {
        Object sourceElement = getJavaElement(getTypeName());
        if (sourceElement != null) {
            IDebugModelPresentation presentation = org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin.getDefault().getModelPresentation();
            IEditorInput editorInput = presentation.getEditorInput(sourceElement);
            if (editorInput != null) {
                String editorId = presentation.getEditorId(editorInput, sourceElement);
                if (editorId != null) {
                    IEditorPart editorPart = org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin.getActivePage().openEditor(editorInput, editorId);
                    if (editorPart instanceof ITextEditor && lineNumber >= 0) {
                        ITextEditor textEditor = (ITextEditor) editorPart;
                        IDocumentProvider provider = textEditor.getDocumentProvider();
                        provider.connect(editorInput);
                        IDocument document = provider.getDocument(editorInput);
                        try {
                            IRegion line = document.getLineInformation(lineNumber);
                            textEditor.selectAndReveal(line.getOffset(), line.getLength());
                        } catch (BadLocationException e) {
                        }
                        provider.disconnect(editorInput);
                    }
                    return;
                }
            }
        }
    } catch (CoreException ex) {
        cantFindSourceWarning();
        PluginMessages.log(ex);
        return;
    }
    // did not find source
    cantFindSourceWarning();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IEditorPart(org.eclipse.ui.IEditorPart) IRegion(org.eclipse.jface.text.IRegion) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)46 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)17 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)15 ArrayList (java.util.ArrayList)13 ExternalEvent (com.centurylink.mdw.plugin.designer.model.ExternalEvent)8 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)8 IFile (org.eclipse.core.resources.IFile)8 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)7 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)6 File (java.io.File)6 IOException (java.io.IOException)6 CoreException (org.eclipse.core.runtime.CoreException)6 IEditorPart (org.eclipse.ui.IEditorPart)5 DesignerProxy (com.centurylink.mdw.plugin.designer.DesignerProxy)4 ActivityImpl (com.centurylink.mdw.plugin.designer.model.ActivityImpl)4 AutomatedTestCase (com.centurylink.mdw.plugin.designer.model.AutomatedTestCase)4 List (java.util.List)4 IFolder (org.eclipse.core.resources.IFolder)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 CodeTimer (com.centurylink.mdw.plugin.CodeTimer)3