Search in sources :

Example 71 with WorkflowPackage

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

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

the class WorkflowProject method getSuppressedActivityImplementors.

public List<String> getSuppressedActivityImplementors() throws IOException {
    if (suppressedActivityImplementors == null) {
        suppressedActivityImplementors = new ArrayList<>();
        String compressed = getPersistentProperty(MDW_SUPPRESSED_ACTIVITY_IMPLEMENTORS);
        String suppressedImplsProp = compressed == null ? null : StringHelper.uncompress(compressed);
        if (suppressedImplsProp == null) {
            if (checkRequiredVersion(5, 5)) {
                // suppress the old baseline package impls by default
                WorkflowPackage baseline52 = getPackage("MDW Baseline");
                if (baseline52 != null) {
                    for (ActivityImpl impl : baseline52.getActivityImpls()) suppressedActivityImplementors.add(impl.getImplClassName());
                }
            }
        } else {
            for (String impl : suppressedImplsProp.split(",")) suppressedActivityImplementors.add(impl);
        }
    }
    return suppressedActivityImplementors;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl)

Example 73 with WorkflowPackage

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

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

the class Importer method importAttributes.

public void importAttributes(final WorkflowElement element, final String xml, final ProgressMonitor progressMonitor, String attrPrefix) throws DataAccessException, XmlException {
    progressMonitor.subTask(PARSING_XML);
    int schemaVersion = dataAccess.getSchemaVersion();
    ProcessImporter importer = DataAccess.getProcessImporter(schemaVersion);
    progressMonitor.progress(40);
    progressMonitor.subTask("Saving attributes");
    ProcessDefinitionDocument procdef = ProcessDefinitionDocument.Factory.parse(xml, Compatibility.namespaceOptions());
    if (element instanceof WorkflowPackage && !((WorkflowPackage) element).getName().equals(procdef.getProcessDefinition().getPackageName()))
        throw new DataAccessException("Expected package: " + ((WorkflowPackage) element).getName() + " in attributes XML but found: " + procdef.getProcessDefinition().getPackageName());
    for (MDWProcess process : procdef.getProcessDefinition().getProcessList()) {
        ProcessDefinitionDocument oneProcDef = ProcessDefinitionDocument.Factory.newInstance();
        MDWProcessDefinition oneProc = oneProcDef.addNewProcessDefinition();
        oneProc.getProcessList().add(process);
        ProcessVO importedProc = importer.importProcess(oneProcDef.xmlText());
        if (element instanceof WorkflowProcess && !((WorkflowProcess) element).getName().equals(importedProc.getProcessName()))
            throw new DataAccessException("Expected process: " + ((WorkflowProcess) element).getName() + " in attributes XML but found: " + importedProc.getName());
        ProcessVO proc = dataAccess.getLatestProcess(importedProc.getName());
        if (proc == null)
            throw new DataAccessException("Process not found: " + importedProc.getName());
        Map<String, String> existAttrs = dataAccess.getDesignerDataAccess().getAttributes(OwnerType.PROCESS, proc.getId());
        Map<String, String> importedAttrs = importedProc.getOverrideAttributes();
        Map<String, String> setAttrs = new HashMap<>();
        if (existAttrs != null) {
            // retain existing attrs not related to this prefix
            for (Map.Entry<String, String> attrs : existAttrs.entrySet()) {
                if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
                    setAttrs.put(attrs.getKey(), attrs.getValue());
            }
        }
        if (importedAttrs != null) {
            for (Map.Entry<String, String> attrs : importedAttrs.entrySet()) {
                if (!WorkAttributeConstant.isAttrNameFor(attrs.getKey(), attrPrefix))
                    throw new DataAccessException("Expected attribute prefix: " + attrPrefix + " in attributes XML but found attribute: " + attrs.getKey());
                else
                    setAttrs.put(attrs.getKey(), attrs.getValue());
            }
        }
        dataAccess.getDesignerDataAccess().setOverrideAttributes(attrPrefix, OwnerType.PROCESS, proc.getId(), setAttrs);
    }
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) HashMap(java.util.HashMap) MDWProcessDefinition(com.centurylink.mdw.bpm.MDWProcessDefinition) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter) ProcessDefinitionDocument(com.centurylink.mdw.bpm.ProcessDefinitionDocument) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) MDWProcess(com.centurylink.mdw.bpm.MDWProcess)

Example 75 with WorkflowPackage

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

the class TableEditor method createTableViewer.

private TableViewer createTableViewer(Table table) {
    TableViewer lTableViewer = new TableViewer(table);
    lTableViewer.setUseHashlookup(true);
    lTableViewer.setColumnProperties(columnProps);
    if (!isReadOnly()) {
        CellEditor[] cellEditors = new CellEditor[columnSpecs.size()];
        for (int i = 0; i < columnSpecs.size(); i++) {
            ColumnSpec colSpec = columnSpecs.get(i);
            CellEditor cellEditor = null;
            if (!colSpec.hidden) {
                if (colSpec.type.equals(TYPE_TEXT)) {
                    if (colSpec.style != 0)
                        cellEditor = new TextCellEditor(table, colSpec.style);
                    else
                        cellEditor = new TextCellEditor(table);
                } else if (colSpec.type.equals(TYPE_CHECKBOX)) {
                    cellEditor = new CheckboxCellEditor(table);
                } else if (colSpec.type.equals(TYPE_COMBO)) {
                    int style = SWT.None;
                    if (colSpec.readOnly)
                        style = style | SWT.READ_ONLY;
                    cellEditor = new ComboBoxCellEditor(table, colSpec.options, style);
                    if (!colSpec.readOnly)
                        cellEditor.addListener(new EditableComboCellEditorListener((ComboBoxCellEditor) cellEditor, i));
                } else if (colSpec.type.equals(WorkflowAssetEditor.TYPE_ASSET)) {
                    int style = SWT.None;
                    if (colSpec.readOnly)
                        style = style | SWT.READ_ONLY;
                    cellEditor = new TreeComboCellEditor(table, style) {

                        @Override
                        protected void doSetValue(Object value) {
                            Object val = getValue();
                            if (val instanceof CTreeComboItem) {
                                CTreeComboItem selItem = (CTreeComboItem) getValue();
                                if (selItem != null) {
                                    super.doSetValue(selItem.getText());
                                    return;
                                }
                            }
                            if (value instanceof String) {
                                String strVal = (String) value;
                                if (strVal.indexOf('/') > -1) {
                                    super.doSetValue(strVal.substring(strVal.indexOf('/') + 1));
                                    return;
                                }
                            }
                            super.doSetValue(value);
                        }
                    };
                    ((TreeComboCellEditor) cellEditor).setSelectionModifier(new SelectionModifier() {

                        public String modify(CTreeComboItem selection) {
                            if (selection.getParentItem() != null) {
                                WorkflowPackage pkg = getProject().getPackage(selection.getParentItem().getText());
                                if (pkg == null || pkg.isDefaultPackage())
                                    return selection.getText();
                                else
                                    return pkg.getName() + "/" + selection.getText();
                            } else {
                                // ignore packages
                                return null;
                            }
                        }
                    });
                    // populate the treecombo
                    if (colSpec.source.equals(PROCESS)) {
                        List<WorkflowPackage> packages = getProject().getTopLevelUserVisiblePackages();
                        for (WorkflowPackage pkg : packages) {
                            CTreeComboItem packageItem = ((TreeComboCellEditor) cellEditor).addItem(pkg.getName());
                            packageItem.setText(pkg.getName());
                            packageItem.setImage(pkg.getIconImage());
                            for (WorkflowProcess process : pkg.getProcesses()) {
                                CTreeComboItem processItem = new CTreeComboItem(packageItem, SWT.NONE);
                                processItem.setText(process.getLabel());
                                processItem.setImage(process.getIconImage());
                            }
                        }
                    } else {
                        List<WorkflowAsset> assets = getProject().getAssetList(Arrays.asList(colSpec.assetTypes));
                        Map<String, CTreeComboItem> packageItems = new HashMap<>();
                        for (WorkflowAsset asset : assets) {
                            String pkgName = asset.getPackage().getName();
                            CTreeComboItem packageItem = packageItems.get(pkgName);
                            if (packageItem == null) {
                                packageItem = ((TreeComboCellEditor) cellEditor).addItem(pkgName);
                                packageItem.setImage(asset.getPackage().getIconImage());
                                packageItems.put(pkgName, packageItem);
                            }
                            CTreeComboItem assetItem = new CTreeComboItem(packageItem, SWT.NONE);
                            assetItem.setText(asset.getLabel());
                            assetItem.setImage(asset.getIconImage());
                        }
                    }
                }
                if (colSpec.listener != null && cellEditor != null)
                    cellEditor.addListener(colSpec.listener);
                cellEditors[i] = cellEditor;
            }
        }
        lTableViewer.setCellEditors(cellEditors);
        lTableViewer.setCellModifier(cellModifier);
    }
    return lTableViewer;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) TreeComboCellEditor(com.centurylink.jface.viewers.TreeComboCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) CTreeComboItem(com.centurylink.swt.widgets.CTreeComboItem) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SelectionModifier(com.centurylink.jface.viewers.TreeComboCellEditor.SelectionModifier) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) TreeComboCellEditor(com.centurylink.jface.viewers.TreeComboCellEditor) List(java.util.List) ArrayList(java.util.ArrayList) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap)

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