Wednesday 20 January 2016

How to set maximum file upload size in BPM Human Task

To change the maximum upload size of a file, you need to make changes to web.xml file.
Here are the changes which need to be introduced.

.

Friday 15 January 2016

How to set current user in BPM tasks

To obtain current user in BPM tasks (especially when page fragments are being used) you can follow below approach.

1. First create the following java class, the current user's login is stored in HttpSession (this survives AM activation/passivation events).

package home.common.ext;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import javax.servlet.http.HttpSession;

import oracle.bpel.services.workflow.WorkflowException;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.verification.IWorkflowContext;
import oracle.bpel.services.workflow.worklist.adf.ADFWorklistBeanUtil;

import oracle.jbo.client.Configuration;


public class ContextUtils {
    public ContextUtils() {
        super();
    }

    public void initializeUserContextData(String applicationId) {
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext ectx = context.getExternalContext();
        HttpSession userSession = (HttpSession)ectx.getSession(true);
        try {
            String ctx =
                (String)context.getApplication().evaluateExpressionGet(context,
                                                                       "#{pageFlowScope.bpmWorklistContext}",
                                                                       String.class);
            IWorkflowServiceClient workflowSvcClient =
                ADFWorklistBeanUtil.getWorkflowServiceClient();
            ITaskQueryService wfQueryService =
                workflowSvcClient.getTaskQueryService();
            IWorkflowContext wfContext;
            String userName = "";
            try {
                wfContext = wfQueryService.getWorkflowContext(ctx);
                userName = wfContext.getUser();
            } catch (WorkflowException e) {
                e.printStackTrace();
            }
            if (userName != null) {
                userSession.setAttribute("currentUserLogin", userName);
                System.out.println("Current user's login from workspace is: " +
                                   userName);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

2. Create data control from this class (Just right click on this class and choose "Create Data Control" from the context menu);

3. Add this method as a default activity into the Task UI project.

4. The value is also available in Model project, so you can populate your WHO columns with current user login.



How to update programmatically a BPM task acquired by field

To update a BPM task programmatically one can leverage BPM APIs. Here is a short example to update an acquired by field.
Find tasknumber, for this you need to issue a select query against WFTASK table.

E.g, let's find latest task for a given instance Id:

select taskNumber, acquiredBy from wftask
where compositeInstanceId=(instance Id)
order by taskNumber desc;

The java code itself. To have this working to you have to complete the prerequisite steps.
I forgot to mention, that this is tested with BPM 11.1.1.7.8.

package home.generic;

import java.util.HashMap;
import java.util.Map;

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.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.task.ITaskService;
import oracle.bpel.services.workflow.task.model.SystemAttributesType;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;


public class UpdateTaskAssignees {
    public static void main(String[] args) throws WorkflowException,
                                                  StaleObjectException {
        String userid = "username";
        String password = "password";
        String serverUrl =
            "t3://localhost:8001"; // host:port of the soa server
        Map connProperties =
            new HashMap();
        connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
                           WorkflowServiceClientFactory.REMOTE_CLIENT);
        connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
                           serverUrl);
        connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
                           "weblogic.jndi.WLInitialContextFactory");
        IWorkflowServiceClient wfSvcClient =
            WorkflowServiceClientFactory.getWorkflowServiceClient(connProperties,
                                                                  null, null);
        IWorkflowContext ctx =
            wfSvcClient.getTaskQueryService().authenticate(userid,
                                                           password.toCharArray(),
                                                           "jazn.com");
        ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
        ITaskService taskSvc = wfSvcClient.getTaskService();
        // Get task by its tasknumber
        Task currentTask = querySvc.getTaskDetailsByNumber(ctx, 239120);
        SystemAttributesType types = currentTask.getSystemAttributes();
        System.out.println("Currently task is acquired by: " +
                           types.getAcquiredBy());
        types.setAcquiredBy("new_login");
        currentTask.setSystemAttributes(types);
        taskSvc.updateTask(ctx, currentTask);
    }
}