Search in sources :

Example 11 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class IconFactory method loadIcon.

private byte[] loadIcon(String file) throws RemoteException, IOException, DataAccessException {
    RuleSetVO ruleset = dao == null ? null : dao.getRuleSet(file, null, 0);
    byte[] bytes;
    if (ruleset != null) {
        if (ruleset.isRaw()) {
            bytes = ruleset.getRawContent();
        } else {
            String content = ruleset.getRuleSet();
            int k = content.indexOf('\n');
            bytes = RuleSetVO.decode(content.substring(k + 1));
        }
    } else {
        String resource = "/images/" + file;
        InputStream is = Icon.class.getResourceAsStream(resource);
        if (is == null)
            is = Icon.class.getResourceAsStream(file);
        if (is != null) {
            bytes = FileHelper.readFromResourceStream(is);
        } else
            bytes = null;
    }
    return bytes;
}
Also used : InputStream(java.io.InputStream) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 12 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class AutomatedTestView method updateTreeAndProgressBar.

private synchronized void updateTreeAndProgressBar(boolean done) {
    int completedCases = 0;
    int erroredCases = 0;
    int failedCases = 0;
    int casePercents = 0;
    boolean loadTest = testSuite.isLoadTest();
    for (AutomatedTestCase testCase : testSuite.getTestCases()) {
        String oldStatus = testCaseStatuses.get(testCase);
        boolean statusChanged = done || oldStatus == null || !oldStatus.equals(testCase.getStatus());
        if (statusChanged) {
            testSuite.getProject().fireTestCaseStatusChange(testCase, testCase.getStatus());
            testCaseStatuses.put(testCase, testCase.getStatus());
        }
        int casePercent = 0;
        if (testCase.isFinished()) {
            if (statusChanged && !done && testSuite.isCreateReplaceResults() && // only applies for VCS assets
            testCase.isSuccess()) {
                if (testCase.isLegacy()) {
                    // trigger
                    testCase.setTestCase(testCase.getTestCase());
                    // results
                    if (testCase.getLegacyExpectedResults() != null) {
                        for (LegacyExpectedResults legacyResults : testCase.getLegacyExpectedResults()) {
                            legacyResults.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
                            testSuite.getProject().fireElementChangeEvent(ChangeType.ELEMENT_CREATE, legacyResults);
                        }
                    }
                } else {
                    try {
                        // create asset from newly-created results and
                        // refresh process explorer (only for VCS assets)
                        String resAssetName = testCase.getTestCase().getCaseName() + RuleSetVO.getFileExtension(RuleSetVO.YAML);
                        if (testCase.isPostman() && testCase.getItemName() != null)
                            resAssetName = testCase.getItemName().replace('/', '_') + RuleSetVO.getFileExtension(RuleSetVO.YAML);
                        File resFile = new File(testSuite.getProject().getProjectDir() + "/" + testCase.getPackage().getVcsAssetPath() + "/" + resAssetName);
                        if (// may not exist if test case
                        resFile.exists()) // does not launch any
                        // processes
                        {
                            byte[] bytes = PluginUtil.readFile(resFile);
                            WorkflowAsset existing = testSuite.getProject().getAsset(testCase.getPackage().getName() + "/" + resAssetName);
                            if (existing == null) {
                                // create (waiting a second or two for the
                                // results file to have been created)
                                RuleSetVO newRuleSet = new RuleSetVO();
                                newRuleSet.setName(resAssetName);
                                newRuleSet.setLanguage(RuleSetVO.YAML);
                                newRuleSet.setRaw(true);
                                newRuleSet.setRawFile(resFile);
                                newRuleSet.setRawContent(bytes);
                                WorkflowAsset newAsset = WorkflowAssetFactory.createAsset(newRuleSet, testCase.getPackage());
                                newAsset.setPackage(testCase.getPackage());
                                newAsset.setId(new Long(-1));
                                newAsset.setCreateUser(testSuite.getProject().getUser().getUsername());
                                newAsset.setLockingUser(testSuite.getProject().getUser().getUsername());
                                designerProxy.saveWorkflowAsset(newAsset, true);
                                testSuite.getProject().getDataAccess().getDesignerDataModel().addRuleSet(newAsset.getRuleSetVO());
                                newAsset.getPackage().addAsset(newAsset);
                                designerProxy.savePackage(newAsset.getPackage());
                                newAsset.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newAsset);
                            } else {
                                // increment version
                                existing.getRuleSetVO().setRawContent(bytes);
                                existing.setVersion(existing.getNextMinorVersion());
                                existing.setRevisionComment("Auto-created");
                                testSuite.getProject().getDesignerProxy().saveWorkflowAsset(existing, true);
                                existing.fireElementChangeEvent(ChangeType.VERSION_CHANGE, existing.getVersion());
                            }
                        }
                    } catch (Exception ex) {
                        PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
                    }
                }
            }
            updateExpectedResults(testCase);
            if (loadTest) {
                completedCases = testCase.getTestCase().getNumberPrepared();
                casePercents = testCase.getTestCase().getNumberPrepared() * 100;
            } else {
                completedCases++;
                casePercent = 100;
            }
        } else {
            casePercent = testCase.getTotalSteps() == 0 ? 0 : (testCase.getStepsCompleted() * 100) / testCase.getTotalSteps();
        }
        if (!loadTest)
            casePercents += casePercent;
        if (testCase.isErrored()) {
            if (loadTest)
                erroredCases = testCase.getTestCase().getNumberPrepared();
            else
                erroredCases++;
        } else if (testCase.isFailed()) {
            if (loadTest)
                failedCases = testCase.getTestCase().getNumberPrepared();
            else
                failedCases++;
        }
        if (statusChanged)
            try {
                testSuite.writeTestCaseResults(testCase);
            } catch (Exception ex) {
                PluginMessages.uiError(ex, "Create/Replace Test Results", testSuite.getProject());
            }
    }
    if (done) {
        testSuite.setRunning(false);
        updateCounterPanel(testSuite.getTestCases().size(), erroredCases, failedCases, true);
        updateProgressBar(100, testSuite.hasErrors() || testSuite.hasFailures(), testSuite.isStopped());
    } else {
        int count = testSuite.getTestCases().size();
        if (loadTest)
            count = testSuite.getRunCount();
        int totalPercents = count * 100;
        if (counterData.completed < completedCases) {
            updateCounterPanel(completedCases, erroredCases, failedCases, false);
            float percentComplete = totalPercents == 0 ? 0 : (casePercents * 100) / totalPercents;
            updateProgressBar(Math.round(percentComplete * 90 / 100) + 10, erroredCases + failedCases > 0, testSuite.isStopped());
        }
    }
    refreshOutputFromSelection();
}
Also used : LegacyExpectedResults(com.centurylink.mdw.plugin.designer.model.LegacyExpectedResults) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) AutomatedTestCase(com.centurylink.mdw.plugin.designer.model.AutomatedTestCase) File(java.io.File) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Example 13 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO 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 14 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO 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 15 with RuleSetVO

use of com.centurylink.mdw.model.value.attribute.RuleSetVO in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method saveProcessWithProgress.

public void saveProcessWithProgress(final WorkflowProcess process, final FlowchartPage flowchartPage, final PersistType persistType, final int version, final boolean validate, final boolean keepLocked) {
    String progressMsg = SAVING + process.getName() + "'";
    String errorMsg = "Save Process";
    designerRunner = new DesignerRunner(progressMsg, errorMsg, project) {

        public void perform() throws ValidationException, DataAccessException, RemoteException {
            WorkflowProcess oldProcess = null;
            if (persistType == PersistType.NEW_VERSION) {
                RuleSetVO existing = null;
                if (process.isInRuleSet())
                    existing = dataAccess.getDesignerDataAccess().getRuleSet(process.getName(), RuleSetVO.PROCESS, version);
                if (existing != null)
                    throw new DataAccessException("\n" + process.getLabel() + ALREADY_EXISTS);
                process.getProcessVO().setProcessId(-1L);
                // preserve the old version for the process tree
                ProcessVO oldProcessVoStub = new ProcessVO();
                oldProcessVoStub.setProcessId(process.getId());
                oldProcessVoStub.setProcessName(process.getName());
                oldProcessVoStub.setVersion(process.getProcessVO().getVersion());
                oldProcess = new WorkflowProcess(process.getProject(), oldProcessVoStub);
                oldProcess.setPackage(process.getPackage());
                oldProcess.setTopLevelVersion(process.getTopLevelVersion());
                if (// temp attribute to avoid API
                project.isFilePersist())
                    // change
                    process.setAttribute("previousProcessVersion", oldProcess.getVersionString());
            }
            saveProcess(process, flowchartPage, persistType, version, validate, keepLocked);
            if (process.getTopLevelVersion() != null)
                process.getTopLevelVersion().setProcessVO(process.getProcessVO());
            if (persistType == PersistType.NEW_VERSION && process.isInRuleSet()) {
                RuleSetVO procRs = dataAccess.getRuleSet(process.getId());
                if (procRs == null)
                    dataAccess.getAllRuleSets(false).add(process.getProcessVO());
            }
        }
    };
    designerRunner.run();
}
Also used : ValidationException(com.centurylink.mdw.designer.utils.ValidationException) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) RemoteException(java.rmi.RemoteException) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Aggregations

RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)32 ArrayList (java.util.ArrayList)13 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)10 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)7 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)7 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)6 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)6 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)5 ExternalEventVO (com.centurylink.mdw.model.value.event.ExternalEventVO)5 File (java.io.File)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 ProcessExporter (com.centurylink.mdw.dataaccess.ProcessExporter)4 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)4 CustomAttributeVO (com.centurylink.mdw.model.value.attribute.CustomAttributeVO)4 RemoteException (java.rmi.RemoteException)4 ProcessWorker (com.centurylink.mdw.designer.utils.ProcessWorker)3 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)3 MbengException (com.qwest.mbeng.MbengException)3 PackageDir (com.centurylink.mdw.dataaccess.file.PackageDir)2