}
}
}
private WorkflowInstance toWorkflowInstance(Document doc) {
WorkflowInstance inst = new WorkflowInstance();
// first read all the instance info
inst.setId(doc.get("workflow_inst_id"));
inst.setStatus(doc.get("workflow_inst_status"));
inst.setCurrentTaskId(doc.get("workflow_inst_current_task_id"));
inst.setCurrentTaskStartDateTimeIsoStr(doc
.get("workflow_inst_currenttask_startdatetime"));
inst.setCurrentTaskEndDateTimeIsoStr(doc
.get("workflow_inst_currenttask_enddatetime"));
inst.setStartDateTimeIsoStr(doc.get("workflow_inst_startdatetime"));
inst.setEndDateTimeIsoStr(doc.get("workflow_inst_enddatetime"));
// read the workflow instance metadata
Metadata sharedContext = new Metadata();
String[] instMetFields = doc.getValues("workflow_inst_met_flds");
if (instMetFields != null && instMetFields.length > 0) {
for (int i = 0; i < instMetFields.length; i++) {
String fldName = instMetFields[i];
String[] vals = doc.getValues(fldName);
if (vals != null && vals.length > 0) {
for (int j = 0; j < vals.length; j++) {
sharedContext.addMetadata(fldName, vals[j]);
}
}
}
}
inst.setSharedContext(sharedContext);
// now read all of the workflow info
Workflow workflow = new Workflow();
workflow.setId(doc.get("workflow_id"));
workflow.setName(doc.get("workflow_name"));
workflow.setTasks(toTasks(doc));
inst.setWorkflow(workflow);
return inst;
}