Search in sources :

Example 1 with YamlBuilder

use of com.centurylink.mdw.designer.utils.YamlBuilder in project mdw-designer by CenturyLinkCloud.

the class TestCaseRun method translateToYaml.

private String translateToYaml(Map<String, List<ProcessInstanceVO>> processInstances, Map<String, String> activityNames, boolean orderById, String newLineChars) throws IOException, DataAccessException {
    YamlBuilder yaml = new YamlBuilder(newLineChars);
    for (String procName : processInstances.keySet()) {
        List<ProcessInstanceVO> procInsts = processInstances.get(procName);
        for (int i = 0; i < procInsts.size(); i++) {
            ProcessInstanceVO procInst = procInsts.get(i);
            yaml.append("process: # ").append(procInst.getId()).newLine();
            yaml.append("  name: ").append(procName).newLine();
            yaml.append("  instance: ").append((i + 1)).newLine();
            LinkedList<ActivityInstanceVO> orderedList = new LinkedList<>();
            for (ActivityInstanceVO act : procInst.getActivities()) {
                if (dao.getDatabaseSchemaVersion() < 6000)
                    orderedList.add(0, act);
                else
                    orderedList.add(act);
            }
            if (orderById) {
                Collections.sort(orderedList, new Comparator<ActivityInstanceVO>() {

                    public int compare(ActivityInstanceVO ai1, ActivityInstanceVO ai2) {
                        return (int) (ai1.getDefinitionId() - ai2.getDefinitionId());
                    }
                });
            }
            for (ActivityInstanceVO act : orderedList) {
                yaml.append("  activity: # ").append(act.getDefinitionId()).append(" \"").append(act.getStartDate()).append("\"").newLine();
                String actNameKey = procInst.getProcessId() + "-" + act.getDefinitionId();
                yaml.append("    name: ").appendMulti("      ", activityNames.get(actNameKey)).newLine();
                yaml.append("    status: ").append(WorkStatuses.getWorkStatuses().get(act.getStatusCode())).newLine();
                if (act.getStatusMessage() != null) {
                    String[] msgLines = act.getStatusMessage().split("\\r\\n|\\n|\\r");
                    String result = msgLines[0];
                    if (msgLines.length > 1)
                        result += "...";
                    yaml.append("    result: ").append(result).newLine();
                }
            }
            for (VariableInstanceInfo var : procInst.getVariables()) {
                yaml.append("  variable: # ").append(var.getInstanceId()).newLine();
                yaml.append("    name: ").append(var.getName()).newLine();
                yaml.append("    value: ");
                try {
                    String val = var.getStringValue();
                    if (VariableHelper.isDocumentVariable(var.getType(), val)) {
                        DocumentReference docref = new DocumentReference(val);
                        val = dao.getDocumentContent(docref, var.getType());
                        // pre-populate document values
                        procInst.getVariable().put(var.getName(), val);
                    }
                    yaml.appendMulti("      ", val).newLine();
                } catch (Throwable t) {
                    log.println("Failed to translate variable instance: " + var.getInstanceId() + " to string with the following exception");
                    t.printStackTrace(log);
                    yaml.append(" \"").append(var.getStringValue()).append("\"").newLine();
                }
            }
        }
    }
    return yaml.toString();
}
Also used : YamlBuilder(com.centurylink.mdw.designer.utils.YamlBuilder) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) LinkedList(java.util.LinkedList) VariableInstanceInfo(com.centurylink.mdw.model.value.variable.VariableInstanceInfo) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference)

Aggregations

YamlBuilder (com.centurylink.mdw.designer.utils.YamlBuilder)1 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)1 DocumentReference (com.centurylink.mdw.model.value.variable.DocumentReference)1 VariableInstanceInfo (com.centurylink.mdw.model.value.variable.VariableInstanceInfo)1 ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)1 LinkedList (java.util.LinkedList)1