Created
October 16, 2011 18:36
Query WorkFlow Tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Task> queryTasks(IWorkflowContext context, | |
int noOfRecords, | |
String orderBy, | |
String searchString) throws WorkflowException { | |
List<String> queryColumns = new ArrayList<String>(); | |
queryColumns.add(TableConstants.WFTASK_TITLE_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_PRIORITY_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_STATE_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_SUBSTATE_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_ACQUIREDBY_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_TASKID_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_TASKNUMBER_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_PROCESSNAME_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_PROCESSID_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_INSTANCEID_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_PROCESSVERSION_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_IDENTIFICATIONKEY_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_ASSIGNEEGROUPS_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_ASSIGNEEUSERS_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_EXPIRATIONDATE_COLUMN.getName()); | |
// specific "text string" columns | |
queryColumns.add(TableConstants.WFTASK_TEXTATTRIBUTE1_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_TEXTATTRIBUTE2_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_TEXTATTRIBUTE3_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_TEXTATTRIBUTE4_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_URLATTRIBUTE1_COLUMN.getName()); | |
queryColumns.add(TableConstants.WFTASK_URLATTRIBUTE2_COLUMN.getName()); | |
// Correct state | |
List<String> correctStates = new ArrayList<String>(); | |
correctStates.add(IWorkflowConstants.TASK_STATE_ALERTED); | |
correctStates.add(IWorkflowConstants.TASK_STATE_ASSIGNED); | |
correctStates.add(IWorkflowConstants.TASK_STATE_INFO_REQUESTED); | |
correctStates.add(IWorkflowConstants.TASK_STATE_OUTCOME_UPDATED); | |
// only these states | |
Predicate predicateBasic = | |
new Predicate(TableConstants.WFTASK_STATE_COLUMN, | |
Predicate.OP_IN, | |
correctStates); | |
// not stale tasks | |
predicateBasic.addClause(Predicate.AND, | |
TableConstants.WFTASK_STATE_COLUMN, | |
Predicate.OP_NEQ, | |
IWorkflowConstants.TASK_STATE_STALE); | |
Predicate predicateSearch = null; | |
if ( searchString != null && !"".equals(searchString) ) { | |
predicateSearch = new Predicate(TableConstants.WFTASK_TEXTATTRIBUTE1_COLUMN, | |
Predicate.OP_CONTAINS, | |
searchString); | |
predicateSearch.addClause(Predicate.OR, | |
TableConstants.WFTASK_TEXTATTRIBUTE2_COLUMN, | |
Predicate.OP_CONTAINS, | |
searchString); | |
predicateSearch.addClause(Predicate.OR, | |
TableConstants.WFTASK_TEXTATTRIBUTE3_COLUMN, | |
Predicate.OP_CONTAINS, | |
searchString); | |
if ( isParsableToInt(searchString) ){ | |
predicateSearch.addClause(Predicate.OR, | |
TableConstants.WFTASK_TASKNUMBER_COLUMN, | |
Predicate.OP_EQ, | |
searchString); | |
} | |
} | |
Predicate predicate = null; | |
if ( predicateSearch == null ) { | |
predicate = predicateBasic; | |
} else { | |
predicate = new Predicate (predicateBasic,Predicate.AND,predicateSearch); | |
} | |
// Ordering | |
Ordering taskOrdering = null; | |
logger.info("set the default Priority / EscalationDate Ordering"); | |
if ( "PRIO".equalsIgnoreCase(orderBy) ) { | |
taskOrdering = new Ordering(TableConstants.WFTASK_PRIORITY_COLUMN, true,false); | |
taskOrdering.addClause(TableConstants.WFTASK_TASKNUMBER_COLUMN, true,false); | |
} else if ("ID".equalsIgnoreCase(orderBy) ) { | |
taskOrdering = new Ordering(TableConstants.WFTASK_TASKNUMBER_COLUMN, false,true); | |
} else if ("ESC_DESC".equalsIgnoreCase(orderBy) ) { | |
taskOrdering = new Ordering(TableConstants.WFTASK_EXPIRATIONDATE_COLUMN, false, false); | |
} else if ("ESC_ASC".equalsIgnoreCase(orderBy) ) { | |
taskOrdering = new Ordering(TableConstants.WFTASK_EXPIRATIONDATE_COLUMN, true, false); | |
} else if ("CRE_DESC".equalsIgnoreCase(orderBy) ) { | |
taskOrdering = new Ordering(TableConstants.WFTASK_CREATEDDATE_COLUMN, false, false); | |
} else if ("CRE_ASC".equalsIgnoreCase(orderBy) ) { | |
taskOrdering = new Ordering(TableConstants.WFTASK_CREATEDDATE_COLUMN, true, false); | |
} | |
List<ITaskQueryService.OptionalInfo> optionalInfo = new ArrayList<ITaskQueryService.OptionalInfo>(); | |
optionalInfo.add(ITaskQueryService.OptionalInfo.CUSTOM_ACTIONS); | |
optionalInfo.add(ITaskQueryService.OptionalInfo.COMMENTS); | |
optionalInfo.add(ITaskQueryService.OptionalInfo.PAYLOAD); | |
optionalInfo.add(ITaskQueryService.OptionalInfo.DISPLAY_INFO); | |
List<Task> tasks = | |
getTaskQueryService().queryTasks(context, | |
queryColumns, | |
optionalInfo, | |
ITaskQueryService.AssignmentFilter.MY_AND_GROUP, | |
null, | |
predicate, | |
taskOrdering, | |
0, | |
noOfRecords); | |
logger.debug("[EINDE] queryTasks()"); | |
getTaskQueryService().destroyWorkflowContext(context); | |
return tasks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment