}
}
}
private WorkflowInstance toWorkflowInstance(Document doc) {
WorkflowInstance inst = new WorkflowInstance();
// first read all the instance info
inst.setId(doc.get("workflow_inst_id"));
inst.setTimesBlocked(Integer.parseInt(doc.get("workflow_inst_timesblocked") !=
null ? doc.get("workflow_inst_timesblocked"):"0"));
// try and construct a state
WorkflowState state = new WorkflowState();
state.setName(doc.get("workflow_inst_status"));
if(doc.get("workflow_inst_state_category") != null){
WorkflowLifecycleStage category = new WorkflowLifecycleStage();
category.setName(doc.get("workflow_inst_state_category"));
state.setCategory(category);
}
if(doc.get("workflow_inst_state_desc") != null){
state.setDescription(doc.get("workflow_inst_state_desc"));
}
if(doc.get("workflow_inst_state_message") != null){
state.setMessage(doc.get("workflow_inst_state_message"));
}
inst.setState(state);
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"));
inst.setPriority(Priority.getPriority(doc.get("workflow_inst_priority") != null ?
Double.valueOf(doc.get("workflow_inst_priority")):Priority.getDefault().getValue()));
// 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));
workflow.setConditions(toConditions("workflow_condition_"+workflow.getId(), doc));
inst.setWorkflow(workflow);
return inst;
}