package test.bpel; import java.util.ArrayList; import java.util.List; import oracle.bpel.services.workflow.WorkflowException; import oracle.bpel.services.workflow.client.IWorkflowServiceClient; import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory; import oracle.bpel.services.workflow.query.ITaskQueryService; import oracle.bpel.services.workflow.repos.Predicate; import oracle.bpel.services.workflow.repos.TableConstants; import oracle.bpel.services.workflow.task.model.SystemAttributesType; import oracle.bpel.services.workflow.task.model.Task; import oracle.bpel.services.workflow.task.model.TaskImpl; import oracle.bpel.services.workflow.verification.IWorkflowContext; import oracle.jbo.JboException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** */ /** * Class to be used to work with the BPEL API for Human Workflow. * * NOTE: Expects a wf_client_config.xml in the classpath with correct server information! * * @author pascal alma * * $Log: HumanWorkflowServices.java,v $ */ public class HumanWorkflowServices ... { private static final Log __log = LogFactory.getLog(HumanWorkflowServices.class); /** *//** * Authenticates agianst the BPEL instance. * @param name Username * @param password password of user * @param domain domain to authenticate against * @param onBehalfOfUser If * @return */ public static IWorkflowContext authenticate(String name, String password, String domain, String onBehalfOfUser) ...{ final String method = "authenticate(...)"; __log.debug(method); IWorkflowContext ctx = null; try ...{ IWorkflowServiceClient client = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT); ITaskQueryService taskQueryService = client.getTaskQueryService(); ctx = taskQueryService.authenticate(name, password, domain, onBehalfOfUser); } catch (WorkflowException wfe) ...{ __log.error("Error occured while authenticating", wfe); throw new JboException(wfe); } return ctx; } private static ITaskQueryService getTaskQueryService() ...{ IWorkflowServiceClient client = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT); ITaskQueryService taskQueryService = client.getTaskQueryService(); return taskQueryService; } /** *//** * Queries the BPEL enigine and gets a list of assigned tasks for the * user in the WorkflowContext * @param ctx * @return */ public static List<Task> getTaskList(IWorkflowContext ctx) ...{ final String method = "getTaskList(...)"; __log.debug(method); List<TaskImpl> resultSet = null; try ...{ //Set up list of columns to query List queryColumns = new ArrayList(); 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()); Predicate filter = null; //getFilter(ctx); // Do not query addtional info // No keywords // No custom predicate // No special ordering // Do not page the query result resultSet = getTaskQueryService().queryTasks(ctx, queryColumns, null, ITaskQueryService.ASSIGNMENT_FILTER_ALL , null, filter, null, 0, 0); //MY_AND_GROUP __log.info("resultSet = " + resultSet.size()); } catch (WorkflowException wfe) ...{ __log.error("Error occured while getting tasklist", wfe); throw new JboException(wfe); } // Get the detailed tasks and put them in the list. List<Task> tasks = new ArrayList<Task>(); for (TaskImpl taskImpl: resultSet) ...{ tasks.add(getTaskDetail(ctx, taskImpl)); } __log.info("#tasks = " + tasks.size()); return tasks; } /** *//** * Gets the taskDetails for a given TaskImpl (is kind of summary in TaskList) * @param ctx * @param taskImpl * @return */ private static Task getTaskDetail(IWorkflowContext ctx, TaskImpl taskImpl) ...{ final String method = "getTaskDetail(...)"; __log.debug(method); SystemAttributesType strAttrType = taskImpl.getSystemAttributes(); Task task = null; try ...{ task = getTaskQueryService().getTaskDetailsById(ctx, strAttrType.getTaskId()); __log.debug("Tasknumber = " + task.getSystemAttributes().getTaskNumber()); } catch (WorkflowException wfe) ...{ __log.error("Error occurred while getting task detail", wfe); throw new JboException(wfe); } return task; } /** *//** * Creates the filter used when getting tasks from BPEL workflow * * @return */ private static Predicate getFilter(IWorkflowContext ctx) ...{ final String method = "getFilter(...)"; __log.debug(method); Predicate mainFilter = null; try ...{ Predicate subFilter1 = new Predicate(TableConstants.WFTASK_STATE_COLUMN, Predicate.OP_EQ, "ASSIGNED"); Predicate acquireSubFilter1 = new Predicate(TableConstants.WFTASK_ACQUIREDBY_COLUMN, Predicate.OP_EQ, (Object)null); Predicate acquireSubFilter2 = new Predicate(TableConstants.WFTASK_ACQUIREDBY_COLUMN, Predicate.OP_EQ, ctx.getUser()); Predicate acquireFilter = new Predicate(acquireSubFilter1, Predicate.OR, acquireSubFilter2); mainFilter = new Predicate(subFilter1, Predicate.AND, acquireFilter); } catch (WorkflowException wfe) ...{ __log.error("Error occurred while getting task detail", wfe); throw new JboException(wfe); } __log.debug( "Filter takslist: " + mainFilter!=null ? mainFilter.getString(): "<<leeg>>"); return mainFilter; } public static void main(String[] args) ...{ __log.debug("main(String[] args)"); IWorkflowContext ctx = authenticate("oc4jadmin","ias_admin1","jazn.com", null); __log.debug("ctx = " + ctx); List tasks = getTaskList(ctx); } }