WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
ReportManager reportManager = (ReportManager) AppUtil.getApplicationContext().getBean("reportManager");
if (wfActivity != null) {
ReportWorkflowActivityInstance aInstance = reportManager.getReportWorkflowActivityInstance(activityInstanceId);
List<String> userList = new ArrayList<String>();
if (aInstance == null) {
aInstance = new ReportWorkflowActivityInstance();
aInstance.setInstanceId(activityInstanceId);
//set process Instance
String processInstanceId = wfActivity.getProcessId();
ReportWorkflowProcessInstance processInstance = reportManager.getReportWorkflowProcessInstance(processInstanceId);
if (processInstance == null) {
processInstance = updateProcessData(wfProcess, wfTrackProcess, appId, appVersion);
}
aInstance.setReportWorkflowProcessInstance(processInstance);
//set activity
ReportWorkflowActivity reportActivtiy = reportManager.getReportWorkflowActivity(processInstance.getReportWorkflowProcess(), wfActivity.getActivityDefId(), wfActivity.getName());
aInstance.setReportWorkflowActivity(reportActivtiy);
//get assignment users
try {
Thread.sleep(2000);
int maxAttempt = 5;
int numOfAttempt = 0;
while ((userList == null || userList.isEmpty()) && numOfAttempt < maxAttempt) {
LogUtil.debug(getClass().getName(), "Attempting to get resource ids....");
userList = workflowManager.getAssignmentResourceIds(wfActivity.getProcessDefId(), wfActivity.getProcessId(), activityInstanceId);
Thread.sleep(2000);
numOfAttempt++;
}
LogUtil.debug(getClass().getName(), "Resource ids=" + userList);
} catch (Exception e) {
LogUtil.error(getClass().getName(), e, "Error executing report plugin");
}
} else {
userList = workflowManager.getAssignmentResourceIds(wfActivity.getProcessDefId(), wfActivity.getProcessId(), activityInstanceId);
}
String assignmentUsers = "";
if (userList != null) {
for (String username : userList) {
assignmentUsers += username + ",";
}
}
if (assignmentUsers.endsWith(",")) {
assignmentUsers = assignmentUsers.substring(0, assignmentUsers.length() - 1);
}
aInstance.setAssignmentUsers(assignmentUsers);
aInstance.setPerformer(wfTrackActivity.getPerformer());
aInstance.setNameOfAcceptedUser(wfTrackActivity.getNameOfAcceptedUser());
aInstance.setState(wfActivity.getState());
aInstance.setStatus(wfTrackActivity.getStatus());
aInstance.setDue(wfTrackActivity.getDue());
aInstance.setCreatedTime(wfTrackActivity.getCreatedTime());
aInstance.setStartedTime(wfTrackActivity.getStartedTime());
aInstance.setFinishTime(wfTrackActivity.getFinishTime());
aInstance.setDelay(wfTrackActivity.getDelayInSeconds());
aInstance.setTimeConsumingFromCreatedTime(wfTrackActivity.getTimeConsumingFromDateCreatedInSeconds());
aInstance.setTimeConsumingFromStartedTime(wfTrackActivity.getTimeConsumingFromDateStartedInSeconds());
reportManager.saveReportWorkflowActivityInstance(aInstance);
return null;
}