double limit = -1;
//get process limit
AdminMisc admin = shark.getAdminMisc();
WMEntity processLimitEnt = admin.getProcessDefinitionInfo(sessionHandle, processInstanceId);
filter = new WMFilter();
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Type");
filter.setFilterString("ProcessHeader");
WMEntityIterator processLimitEntityIterator = xpdl.listEntities(sessionHandle, processLimitEnt, filter, true);
WMEntity[] processLimitEntityList = null;
if (processLimitEntityIterator != null) {
processLimitEntityList = processLimitEntityIterator.getArray();
}
if (processLimitEntityList != null) {
WMEntity processLimitEntity = processLimitEntityList[0];
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Name");
filter.setFilterString("Limit");
WMAttributeIterator procAttributeIterator = xpdl.listAttributes(sessionHandle, processLimitEntity, filter, true);
WMAttribute[] procAttributeList = null;
if (procAttributeIterator != null) {
procAttributeList = procAttributeIterator.getArray();
}
if (procAttributeList[0].getValue() != null && !procAttributeList[0].getValue().equals("")) {
try {
limit = Double.parseDouble((String) procAttributeList[0].getValue());
} catch (Exception e) {}
}
}
String durationUnit = "";
if (limit != -1) {
//get duration unit
filter = new WMFilter();
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Type");
filter.setFilterString("ProcessHeader");
WMEntity processDurationEnt = admin.getProcessDefinitionInfo(sessionHandle, processInstanceId);
WMEntityIterator processDurationEntityIterator = xpdl.listEntities(sessionHandle, processDurationEnt, filter, true);
WMEntity[] processDurationEntityList = null;
if (processDurationEntityIterator != null) {
processDurationEntityList = processDurationEntityIterator.getArray();
}
if (processDurationEntityList != null) {
WMEntity entity = processDurationEntityList[0];
filter = new WMFilter();
filter.setFilterType(XPDLBrowser.SIMPLE_TYPE_XPDL);
filter.setAttributeName("Name");
filter.setFilterString("DurationUnit");
WMAttributeIterator procAttributeIterator = xpdl.listAttributes(sessionHandle, entity, filter, true);
WMAttribute[] procAttributeList = null;
if (procAttributeIterator != null) {
procAttributeList = procAttributeIterator.getArray();
}
if (procAttributeList != null) {
durationUnit = (String) procAttributeList[0].getValue();
}
}
}
Calendar startedTimeCal = Calendar.getInstance();
if (wfProcessArray != null && wfProcessArray.length > 0) {
long startedTime = admin.getProcessStartedTime(sessionHandle, processInstanceId);
startedTimeCal.setTimeInMillis(startedTime);
wfProcess.setStartedTime(startedTimeCal.getTime());
if (limit != -1) {
if (!durationUnit.equals("")) {
long limitInSecond = 0;
if (durationUnit.equals("D")) {
limitInSecond = Math.round(limit * 24 * 60 * 60);
wfProcess.setLimit(limit + " day");
} else if (durationUnit.equals("h")) {
limitInSecond = Math.round(limit * 60 * 60);
wfProcess.setLimit(limit + " hour(s)");
} else if (durationUnit.equals("m")) {
limitInSecond = Math.round(limit * 60);
wfProcess.setLimit(limit + " minute(s)");
} else if (durationUnit.equals("s")) {
limitInSecond = Math.round(limit);
wfProcess.setLimit(limit + " second(s)");
}
wfProcess.setDue(getDueDateProceedByPlugin(processInstanceId, "", limitInSecond, startedTimeCal.getTime(), startedTimeCal.getTime()));
}
}
}
Date currentDate = new Date();
if (wfProcessArray[0].state().equals(SharkConstants.STATE_CLOSED_COMPLETED)) {
Calendar completionCal = Calendar.getInstance();
Calendar dueCal = Calendar.getInstance();
long finishTime = admin.getProcessFinishTime(sessionHandle, processInstanceId);
completionCal.setTimeInMillis(finishTime);
wfProcess.setFinishTime(completionCal.getTime());
//completion minus due if completion date is after due date, vice versa otherwise
if (wfProcess.getDue() != null && wfProcess.getFinishTime().after(wfProcess.getDue())) {