WfProcessMgr wfProcessMgr = wfProcess.manager();
String processInstanceId = wfProcess.key();
String processDefId = wfProcessMgr.name();
//get limit
AdminMisc admin = shark.getAdminMisc();
WMEntity actEnt = admin.getActivityDefinitionInfo(sessionHandle, processInstanceId, activityInstanceId);
WMFilter filter = new WMFilter();
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Name");
filter.setFilterString("Limit");
WMAttributeIterator actAttributeIterator = xpdl.listAttributes(sessionHandle, actEnt, filter, true);
WMAttribute[] actAttributeList = null;
if (actAttributeIterator != null) {
actAttributeList = actAttributeIterator.getArray();
}
// retrieve the user who accepted the particular activity
String username = admin.getActivityResourceUsername(sessionHandle, processInstanceId, activityInstanceId);
wfAct.setNameOfAcceptedUser(username);
double limit = -1;
if (actAttributeList != null) {
if (actAttributeList[0].getValue() != null && !actAttributeList[0].getValue().equals("")) {
try {
limit = Double.parseDouble((String) actAttributeList[0].getValue());
} catch (Exception e) {}
}
}
filter = new WMFilter();
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Name");
filter.setFilterString("Performer");
actAttributeIterator = xpdl.listAttributes(sessionHandle, actEnt, filter, true);
actAttributeList = null;
if (actAttributeIterator != null) {
actAttributeList = actAttributeIterator.getArray();
}
if (actAttributeList != null) {
String state = wfActivity.state();
if (state.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED)) {
wfAct.setStatus("Pending");
} else if (state.equals(SharkConstants.STATE_CLOSED_COMPLETED)) {
wfAct.setStatus("Completed");
} else if (state.equals(SharkConstants.STATE_CLOSED_ABORTED)) {
wfAct.setStatus("Aborted");
} else {
wfAct.setStatus("Accepted");
}
wfAct.setPerformer((String) actAttributeList[0].getValue());
}
if (includeAssignees) {
List<String> users = getAssignmentResourceIds(processDefId, processInstanceId, activityInstanceId);
Collections.sort(users);
if (users != null) {
wfAct.setAssignmentUsers(users.toArray(new String[users.size()]));
}
}
String durationUnit = "";
if (limit != -1) {
//get duration unit
filter = new WMFilter();
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Type");
filter.setFilterString("ProcessHeader");
WMEntity procEnt = admin.getProcessDefinitionInfo(sessionHandle, processInstanceId);
WMEntityIterator procEntityIterator = xpdl.listEntities(sessionHandle, procEnt, filter, true);
WMEntity[] procEntityList = null;
if (procEntityIterator != null) {
procEntityList = procEntityIterator.getArray();
}
if (procEntityList != null) {
WMEntity ent = procEntityList[0];
filter = new WMFilter();
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Name");
filter.setFilterString("DurationUnit");
WMAttributeIterator procAttributeIterator = xpdl.listAttributes(sessionHandle, ent, filter, true);
WMAttribute[] procAttributeList = null;
if (procAttributeIterator != null) {
procAttributeList = procAttributeIterator.getArray();
}
if (procAttributeList != null) {
durationUnit = (String) procAttributeList[0].getValue();
}
}
}
Calendar calendar = Calendar.getInstance();
long createdTime = admin.getActivityCreatedTime(sessionHandle, processInstanceId, activityInstanceId);
long startedTime = admin.getActivityStartedTime(sessionHandle, processInstanceId, activityInstanceId);
if (startedTime != SharkConstants.UNDEFINED_TIME) {
calendar.setTimeInMillis(startedTime);
wfAct.setStartedTime(calendar.getTime());
}
calendar.setTimeInMillis(createdTime);
wfAct.setCreatedTime(calendar.getTime());
if (limit != -1) {
if (!durationUnit.equals("")) {
if (durationUnit.equals("D")) {
wfAct.setLimitInSeconds(Math.round(limit * 24 * 60 * 60));
wfAct.setLimit(limit + " day");
} else if (durationUnit.equals("h")) {
wfAct.setLimitInSeconds(Math.round(limit * 60 * 60));
wfAct.setLimit(limit + " hour(s)");
} else if (durationUnit.equals("m")) {
wfAct.setLimitInSeconds(Math.round(limit * 60));
wfAct.setLimit(limit + " minute(s)");
} else if (durationUnit.equals("s")) {
wfAct.setLimitInSeconds(Math.round(limit));
wfAct.setLimit(limit + " second(s)");
}
wfAct.setDue(getDueDateProceedByPlugin(processInstanceId, activityInstanceId, wfAct.getLimitInSeconds(), wfAct.getCreatedTime(), wfAct.getStartedTime()));
}
}
Date currentDate = new Date();
if (wfActivity.state().equals(SharkConstants.STATE_CLOSED_COMPLETED)) {
Calendar completionCal = Calendar.getInstance();
Calendar dueCal = Calendar.getInstance();
long finishTime = admin.getActivityFinishTime(sessionHandle, processInstanceId, activityInstanceId);
completionCal.setTimeInMillis(finishTime);
wfAct.setFinishTime(completionCal.getTime());
//completion minus due if completion date is after due date, vice versa otherwise
if (wfAct.getDue() != null && wfAct.getFinishTime().after(wfAct.getDue())) {