This discussion is archived
0 Replies Latest reply: Nov 9, 2009 12:12 PM by 722597 RSS

Worklist FYI task is not visible after updating protectednumberattribute2

722597 Newbie
Currently Being Moderated
Hi,

I need you guys help please. The case is that or bpel process is creating a FYI task for user notification where a custom worklist screen is created to retreive FYI tasks for the users.
If any of the FYI task is later updated with the API, the task becomes invisible in the worklist application and also cannot be retreived with the worklist API.

Below is the code for retreiving and updating the task. Its an struts action and the init method is executed the first time to display all tasks.
Later the delete method is invoked and again the init method to see the remaining tasks.


import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.bpel.services.workflow.IWorkflowConstants;
import oracle.bpel.services.workflow.StaleObjectException;
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.Ordering;
import oracle.bpel.services.workflow.repos.Predicate;
import oracle.bpel.services.workflow.repos.TableConstants;
import oracle.bpel.services.workflow.task.ITaskService;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

@SuppressWarnings( { "unchecked", "deprecation" })
public class Crud extends BaseAction {

     private Log log = LogFactory.getLog(getClass());

     private String getRemoteUser(HttpServletRequest request) {
          boolean isDevMode = Boolean.valueOf(System.getProperty("DEV_MODE"));
          String remoteUser = null;

          if (isDevMode) {
               if ((remoteUser = request.getParameter("remote_user")) != null)
                    request.getSession().setAttribute("remote_user", remoteUser);
               else
                    remoteUser = request.getSession().getAttribute("remote_user").toString();
          }

          if (remoteUser == null)
               remoteUser = request.getHeader("REMOTE-USER");

          return remoteUser;
     }

     public void init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
               HttpServletResponse response) throws WorkflowException {

          log.debug("init");

          IWorkflowServiceClient wfSvcClient = WorkflowServiceClientFactory
                    .getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT);

          String remoteUser = getRemoteUser(request);

          log.debug("remote user: " + remoteUser);

          IWorkflowContext wfCtx = WorkflowUtils.getWorkflowContextOnBehalf(AppProperties
                    .getProperty("weblogic.username"), AppProperties.getProperty("weblogic.password"),
                    AppProperties.getProperty("identityContext"), remoteUser);

          log.debug(wfCtx.getClass());

          ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();

          // category is CRUD
          Predicate crudPredicate = new Predicate(TableConstants.WFTASK_CATEGORY_COLUMN,
                    Predicate.OP_EQ, "CRUD");


          // should not be a stale task
          crudPredicate.addClause(Predicate.AND,TableConstants.WFTASK_STATE_COLUMN, Predicate.OP_NEQ,
                    IWorkflowConstants.TASK_STATE_STALE);

          log.debug(crudPredicate);

          List queryColumns = new ArrayList();
          queryColumns.add("TASKID");
          queryColumns.add("TASKNUMBER");
          queryColumns.add("TITLE");
          queryColumns.add("PRIORITY");
          queryColumns.add("STATE");

          queryColumns.add("PROTECTEDNUMBERATTRIBUTE1"); // trxTypeId
          queryColumns.add("PROTECTEDNUMBERATTRIBUTE2"); // trxStatus
          queryColumns.add("PROTECTEDTEXTATTRIBUTE1"); // trxNo

          // List optionalInfo = new ArrayList();
          // optionalInfo.add("PAYLOAD");

          Ordering ordering = new Ordering(TableConstants.WFTASK_TITLE_COLUMN, true, true);
          ordering.addClause(TableConstants.WFTASK_PRIORITY_COLUMN, true, true);

          List<Task> tasksList = querySvc.queryTasks(wfCtx, queryColumns, null,
                    ITaskQueryService.ASSIGNMENT_FILTER_MY, null, crudPredicate, ordering, 0, 0);
          request.setAttribute("CRUD_TASKS", tasksList);
          logTaskAttributes(tasksList);
     }


     public void delete(ActionMapping mapping, ActionForm form, HttpServletRequest request,
               HttpServletResponse response) throws WorkflowException, StaleObjectException {
          log.debug("delete");

          DynaActionForm deleteForm = (DynaActionForm) form;

          IWorkflowServiceClient wfSvcClient = WorkflowServiceClientFactory
                    .getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT);
          ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();

          String remoteUser = getRemoteUser(request);

          log.debug("remote user: " + remoteUser);

          IWorkflowContext wfCtx = WorkflowUtils.getWorkflowContextOnBehalf(AppProperties
                    .getProperty("weblogic.username"), AppProperties.getProperty("weblogic.password"),
                    AppProperties.getProperty("identityContext"), remoteUser);

          log.debug(wfCtx.getClass());

          // category is CRUD
          Predicate crudPredicate = new Predicate(TableConstants.WFTASK_CATEGORY_COLUMN,
                    Predicate.OP_EQ, "CRUD");

          // assigned to the remote user
          crudPredicate.addClause(Predicate.AND, TableConstants.ASSIGNEE_ASSIGNEE_COLUMN,
                    Predicate.OP_EQ, remoteUser);

          // task is assigned
          crudPredicate.addClause(Predicate.AND, TableConstants.WFTASK_STATE_COLUMN, Predicate.OP_EQ,
                    IWorkflowConstants.TASK_STATE_ASSIGNED);

          // trxNo
          crudPredicate.addClause(Predicate.AND,
                    TableConstants.WFTASK_PROTECTEDTEXTATTRIBUTE1_COLUMN, Predicate.OP_EQ, deleteForm
                              .getString("trxNo"));

          // is a draft
          crudPredicate.addClause(Predicate.AND,
                    TableConstants.WFTASK_PROTECTEDNUMBERATTRIBUTE2_COLUMN, Predicate.OP_EQ, Double
                              .valueOf(Constants.TrxTypeId.DRAFT.getTrxTypeId()));

          log.debug(crudPredicate);

          List queryColumns = new ArrayList();
          queryColumns.add("TASKID");
          queryColumns.add("PROTECTEDNUMBERATTRIBUTE1"); // trxTypeId
          queryColumns.add("PROTECTEDNUMBERATTRIBUTE2"); // trxStatus
          queryColumns.add("PROTECTEDTEXTATTRIBUTE1"); // trxNo

          Ordering ordering = new Ordering(TableConstants.WFTASK_TITLE_COLUMN, true, true);
          ordering.addClause(TableConstants.WFTASK_PRIORITY_COLUMN, true, true);

          Task draftTask = null;

          List<Task> tasksList = querySvc.queryTasks(wfCtx, queryColumns, null,
                    ITaskQueryService.ASSIGNMENT_FILTER_MY, null, crudPredicate, ordering, 0, 0);

          logTaskAttributes(tasksList);

          if (tasksList!=null && tasksList.size() > 0)
               draftTask = tasksList.get(0);

          if (draftTask == null)
               return;
          try {

               // settting the task status to Constants.TrxTypeId.DELETED
               log.debug("update from: "
                         + draftTask.getSystemMessageAttributes().getProtectedNumberAttribute2());
               draftTask.getSystemMessageAttributes().setProtectedNumberAttribute2(
                         Double.valueOf(Constants.TrxTypeId.DELETED.getTrxTypeId()));
               wfSvcClient.getTaskService().updateTask(wfCtx, draftTask);
               log.debug("updated to: "
                         + draftTask.getSystemMessageAttributes().getProtectedNumberAttribute2());
               c.commit();
          } catch (Exception e) {
               log.error(e, e);
          }      
     }


     private void logTaskAttributes(List<Task> tasksList) {
          // log.debug("task:" + task + " payload: "
          // + (task.getPayload() == null ? "null" :
          // task.getPayload().getContent()));
          log.debug("***********");
          for (Task task : tasksList) {
          log.debug("\ttask owner:" + task.getOwnerUser());
          log.debug("task state:" + task.getSystemAttributes().getState());
          // log.debug("task assigned date:" +
          // task.getSystemAttributes().getAssignedDate());
          log.debug("task status :"
                    + task.getSystemMessageAttributes().getProtectedNumberAttribute2());
          log.debug("task id :" + task.getSystemAttributes().getTaskId());
          }
          log.debug("***********");
     }
}


Please help,

Regards
Mehdi

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points