use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.
the class RuntimeDataAccessRest method deleteProcessInstances.
public int deleteProcessInstances(List<Long> processInstanceIds) throws DataAccessException {
try {
List<ProcessInstanceVO> instances = new ArrayList<ProcessInstanceVO>();
for (Long id : processInstanceIds) instances.add(new ProcessInstanceVO(id));
ProcessList processList = new ProcessList(ProcessList.PROCESS_INSTANCES, instances);
if (getServer().getSchemaVersion() >= 6000) {
try {
getServer().delete("Processes", processList.getJson().toString(2));
} catch (IOException ex) {
throw new DataAccessOfflineException("Unable to connect to " + getServer().getServiceUrl(), ex);
}
} else {
ActionRequestMessage actionRequest = new ActionRequestMessage();
actionRequest.setAction("DeleteProcessInstances");
actionRequest.addParameter("appName", "MDW Designer");
JSONObject msgJson = actionRequest.getJson();
msgJson.put(processList.getJsonName(), processList.getJson());
invokeActionService(msgJson.toString(2));
}
return processList.getCount();
} catch (XmlException ex) {
throw new DataAccessException(ex.getMessage(), ex);
} catch (JSONException ex) {
throw new DataAccessException(ex.getMessage(), ex);
}
}
use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.
the class RuntimeDataAccessRest method getProcessInstanceBase.
public ProcessInstanceVO getProcessInstanceBase(Long processInstanceId) throws DataAccessException {
try {
String pathWithArgs = "Processes/" + processInstanceId + "?shallow=true";
if (!getServer().isSchemaVersion61())
pathWithArgs = "ProcessInstance?format=json&shallow=true&instanceId=" + processInstanceId;
String response = invokeResourceService(pathWithArgs);
return new ProcessInstanceVO(new JSONObject(response));
} catch (IOException ex) {
throw new DataAccessOfflineException(ex.getMessage(), ex);
} catch (Exception ex) {
throw new DataAccessException(ex.getMessage(), ex);
}
}
use of com.centurylink.mdw.model.value.process.ProcessInstanceVO 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();
}
use of com.centurylink.mdw.model.value.process.ProcessInstanceVO 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;
}
use of com.centurylink.mdw.model.value.process.ProcessInstanceVO in project mdw-designer by CenturyLinkCloud.
the class LogWatcher method openInstance.
private synchronized void openInstance(final ProcessInstanceVO processInstanceInfo) {
final WorkflowProcess newProcess = new WorkflowProcess(process);
if (!processInstanceInfo.getProcessId().equals(process.getId())) {
// must be a subprocess
ProcessVO subprocVO = new ProcessVO();
subprocVO.setProcessId(processInstanceInfo.getProcessId());
subprocVO.setProcessName(processInstanceInfo.getProcessName());
newProcess.setProcessVO(subprocVO);
}
final boolean isEmbedded = isEmbeddedProcess(processInstanceInfo);
final ProcessInstanceVO pageInfo = isEmbedded ? processInstances.get(processInstanceInfo.getOwnerId()) : processInstanceInfo;
newProcess.setProcessInstance(pageInfo);
display.syncExec(new Runnable() {
public void run() {
ProcessInstancePage procInstPage = null;
try {
IWorkbenchPage page = MdwPlugin.getActivePage();
ProcessEditor editor = null;
if (processInstancePages.get(pageInfo.getId()) == null) {
newProcess.setDesignerDataAccess(dataAccess);
editor = (ProcessEditor) page.openEditor(newProcess, "mdw.editors.process");
procInstPage = editor.getProcessCanvasWrapper().getProcessInstancePage();
if (procInstPage != null) {
processInstancePages.put(pageInfo.getId(), procInstPage);
}
} else if (isEmbedded && processInstancePages.get(processInstanceInfo.getId()) == null) {
newProcess.getProject().getDesignerProxy().loadProcessInstance(newProcess, processInstancePages.get(pageInfo.getId()));
processInstancePages.put(processInstanceInfo.getId(), processInstancePages.get(pageInfo.getId()));
} else {
editor = (ProcessEditor) page.findEditor(newProcess);
if (editor != null)
page.activate(editor);
}
} catch (Exception ex) {
PluginMessages.log(ex);
processInstancePages.remove(processInstanceInfo.getId());
}
}
});
}
Aggregations