Search in sources :

Example 16 with ActivityVO

use of com.centurylink.mdw.model.value.activity.ActivityVO in project mdw-designer by CenturyLinkCloud.

the class Importer method updateSubProcessIdAttributes.

/**
 * Update processid attribute for calling processes within this package. Get
 * rid of this method, which is only needed for ancient (pre-4.5) runtimes.
 */
private void updateSubProcessIdAttributes(ProcessVO processVO) throws DataAccessException, RemoteException, XmlException {
    boolean toUpdate = false;
    if (processVO.getActivities() != null) {
        for (ActivityVO actVO : processVO.getActivities()) {
            String procNameAttr = actVO.getAttribute(PROCESSNAME);
            String procVerAttr = actVO.getAttribute(PROCESSVERSION);
            if (procNameAttr != null && procVerAttr != null) {
                toUpdate = true;
            }
        }
        if (processVO.getSubProcesses() != null) {
            for (ProcessVO embedded : processVO.getSubProcesses()) {
                for (ActivityVO actVO : embedded.getActivities()) {
                    String procNameAttr = actVO.getAttribute(PROCESSNAME);
                    String procVerAttr = actVO.getAttribute(PROCESSVERSION);
                    if (procNameAttr != null && procVerAttr != null) {
                        toUpdate = true;
                    }
                }
            }
        }
    }
    if (toUpdate) {
        ProcessVO procVO = dataAccess.getProcess(processVO.getProcessId(), processVO);
        for (ActivityVO actVO : procVO.getActivities()) {
            String procNameAttr = actVO.getAttribute(PROCESSNAME);
            String procVerAttr = actVO.getAttribute(PROCESSVERSION);
            if (procNameAttr != null && procVerAttr != null) {
                for (ProcessVO checkVO : importedPackageVO.getProcesses()) {
                    if (checkVO.getProcessName().equals(procNameAttr) && String.valueOf(checkVO.getVersion()).equals(procVerAttr))
                        actVO.setAttribute("processid", checkVO.getProcessId().toString());
                }
            }
        }
        if (procVO.getSubProcesses() != null) {
            for (ProcessVO embedded : procVO.getSubProcesses()) {
                for (ActivityVO actVO : embedded.getActivities()) {
                    String procNameAttr = actVO.getAttribute(PROCESSNAME);
                    String procVerAttr = actVO.getAttribute(PROCESSVERSION);
                    if (procNameAttr != null && procVerAttr != null) {
                        for (ProcessVO checkVO : importedPackageVO.getProcesses()) {
                            if (checkVO.getProcessName().equals(procNameAttr) && String.valueOf(checkVO.getVersion()).equals(procVerAttr))
                                actVO.setAttribute("processid", checkVO.getProcessId().toString());
                        }
                    }
                }
            }
        }
        dataAccess.updateProcess(procVO, 0, false);
    }
}
Also used : ActivityVO(com.centurylink.mdw.model.value.activity.ActivityVO) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO)

Example 17 with ActivityVO

use of com.centurylink.mdw.model.value.activity.ActivityVO in project mdw-designer by CenturyLinkCloud.

the class TestCaseRun method loadResults.

protected List<ProcessInstanceVO> loadResults(List<ProcessVO> processes, TestCaseAsset expectedResults, boolean orderById) throws DataAccessException, IOException {
    List<ProcessInstanceVO> mainProcessInsts = new ArrayList<>();
    Map<String, List<ProcessInstanceVO>> fullProcessInsts = new TreeMap<>();
    Map<String, String> fullActivityNameMap = new HashMap<>();
    for (ProcessVO proc : processes) {
        Map<String, String> criteria = new HashMap<>();
        criteria.put("masterRequestId", masterRequestId);
        criteria.put("processId", proc.getId().toString());
        List<ProcessInstanceVO> procInstList = dao.getProcessInstanceList(criteria, 1, 100, proc, null).getItems();
        int n = procInstList.size();
        Map<Long, String> activityNameMap = new HashMap<>();
        for (ActivityVO act : proc.getActivities()) {
            activityNameMap.put(act.getActivityId(), act.getActivityName());
            fullActivityNameMap.put(proc.getId() + "-" + act.getActivityId(), act.getActivityName());
        }
        if (proc.getSubProcesses() != null) {
            for (ProcessVO subproc : proc.getSubProcesses()) {
                for (ActivityVO act : subproc.getActivities()) {
                    activityNameMap.put(act.getActivityId(), act.getActivityName());
                    fullActivityNameMap.put(proc.getId() + "-" + act.getActivityId(), act.getActivityName());
                }
            }
        }
        for (ProcessInstanceVO procInst : procInstList) {
            procInst = dao.getProcessInstanceAll(procInst.getId(), proc);
            mainProcessInsts.add(procInst);
            if (getTestCase().isLegacy()) {
                translateToLegacyTestFile(proc.getProcessName(), procInst, n, activityNameMap);
            } else {
                List<ProcessInstanceVO> procInsts = fullProcessInsts.get(proc.getName());
                if (procInsts == null)
                    procInsts = new ArrayList<>();
                procInsts.add(procInst);
                fullProcessInsts.put(proc.getName(), procInsts);
            }
            if (proc.getSubProcesses() != null) {
                criteria.clear();
                if (proc.isInRuleSet()) {
                    criteria.put("owner", OwnerType.MAIN_PROCESS_INSTANCE);
                    criteria.put("ownerId", procInst.getId().toString());
                    criteria.put("processId", proc.getProcessId().toString());
                    List<ProcessInstanceVO> embeddedProcInstList = dao.getProcessInstanceList(criteria, 0, QueryRequest.ALL_ROWS, proc, null).getItems();
                    int m = embeddedProcInstList.size();
                    for (ProcessInstanceVO embeddedProcInst : embeddedProcInstList) {
                        ProcessInstanceVO fullChildInfo = dao.getProcessInstanceAll(embeddedProcInst.getId(), proc);
                        String childProcName = "unknown_subproc_name";
                        for (ProcessVO subproc : proc.getSubProcesses()) {
                            if (subproc.getProcessId().toString().equals(embeddedProcInst.getComment())) {
                                childProcName = subproc.getProcessName();
                                if (!childProcName.startsWith(proc.getProcessName()))
                                    childProcName = proc.getProcessName() + " " + childProcName;
                                break;
                            }
                        }
                        if (getTestCase().isLegacy()) {
                            translateToLegacyTestFile(childProcName, fullChildInfo, m, activityNameMap);
                        } else {
                            List<ProcessInstanceVO> procInsts = fullProcessInsts.get(childProcName);
                            if (procInsts == null)
                                procInsts = new ArrayList<>();
                            procInsts.add(fullChildInfo);
                            fullProcessInsts.put(childProcName, procInsts);
                        }
                        m--;
                    }
                } else {
                    StringBuilder sb = new StringBuilder();
                    sb.append("(");
                    for (ProcessVO subproc : proc.getSubProcesses()) {
                        if (sb.length() > 1)
                            sb.append(",");
                        sb.append(subproc.getProcessId());
                    }
                    sb.append(")");
                    criteria.put("owner", OwnerType.PROCESS_INSTANCE);
                    criteria.put("ownerId", procInst.getId().toString());
                    criteria.put("processIdList", sb.toString());
                    List<ProcessInstanceVO> embeddedProcInstList = dao.getProcessInstanceList(criteria, 0, QueryRequest.ALL_ROWS, proc, null).getItems();
                    int m = embeddedProcInstList.size();
                    for (ProcessInstanceVO embeddedProcInst : embeddedProcInstList) {
                        ProcessInstanceVO fullChildInfo = dao.getProcessInstanceAll(embeddedProcInst.getId(), proc);
                        String childProcName = "unknown_subproc_name";
                        for (ProcessVO subproc : proc.getSubProcesses()) {
                            if (subproc.getProcessId().equals(embeddedProcInst.getProcessId())) {
                                childProcName = subproc.getProcessName();
                                if (!childProcName.startsWith(proc.getProcessName()))
                                    childProcName = proc.getProcessName() + " " + childProcName;
                                break;
                            }
                        }
                        if (getTestCase().isLegacy()) {
                            translateToLegacyTestFile(childProcName, fullChildInfo, m, activityNameMap);
                        }
                        m--;
                    }
                }
            }
            n--;
        }
    }
    if (!getTestCase().isLegacy()) {
        String newLine = "\n";
        if (!createReplace) {
            // try to determine newline chars from expectedResultsFile
            if (expectedResults.exists() && expectedResults.text().indexOf("\r\n") >= 0)
                newLine = "\r\n";
        }
        String yaml = translateToYaml(fullProcessInsts, fullActivityNameMap, orderById, newLine);
        if (createReplace) {
            log.println("creating expected results: " + expectedResults);
            FileHelper.writeToFile(expectedResults.toString(), yaml, false);
        }
        String fileName = testcase.getResultDirectory() + "/" + expectedResults.getName();
        if (verbose)
            log.println("creating actual results file: " + fileName);
        FileHelper.writeToFile(fileName, yaml, false);
    }
    // set friendly statuses
    if (mainProcessInsts != null) {
        for (ProcessInstanceVO pi : mainProcessInsts) pi.setStatus(WorkStatuses.getWorkStatuses().get(pi.getStatusCode()));
    }
    return mainProcessInsts;
}
Also used : HashMap(java.util.HashMap) ActivityVO(com.centurylink.mdw.model.value.activity.ActivityVO) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Aggregations

ActivityVO (com.centurylink.mdw.model.value.activity.ActivityVO)17 ProcessVO (com.centurylink.mdw.model.value.process.ProcessVO)11 ArrayList (java.util.ArrayList)8 WorkTransitionVO (com.centurylink.mdw.model.value.work.WorkTransitionVO)6 MbengNode (com.qwest.mbeng.MbengNode)6 HashMap (java.util.HashMap)5 ActivityImplementorVO (com.centurylink.mdw.model.value.activity.ActivityImplementorVO)4 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)4 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)3 HashSet (java.util.HashSet)2 TextNoteVO (com.centurylink.mdw.model.value.activity.TextNoteVO)1 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)1 ExternalEventVO (com.centurylink.mdw.model.value.event.ExternalEventVO)1 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)1 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)1 DomDocument (com.qwest.mbeng.DomDocument)1 FormatDom (com.qwest.mbeng.FormatDom)1 MbengException (com.qwest.mbeng.MbengException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1