Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Friday, 15 January 2016

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);
    }
}

Saturday, 1 December 2012

Consuming "No WSDL" services

Oracle Service Bus offers to have "Any XML" or "Any SOAP" proxy services. These services do not have associated WSDLs so it means that you can not use standard features, such Web Services Data Control or Web Services Proxy. Instead one option is to use java class to consume such services. E.g.


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import javax.faces.component.html.HtmlCommandButton;
import javax.faces.event.ActionEvent;


    public void runPrepareTransaction(ActionEvent actionEvent) {
        try {
            String data = inputText.getValue().toString();
            URL url =
                new URL("http://blabla.com/Proxy/PrepareTransaction");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter oSW =
                new OutputStreamWriter(conn.getOutputStream());
            oSW.write(data);
            oSW.flush();
            BufferedReader bR =
                new BufferedReader(new InputStreamReader(conn.getInputStream()));
            int i = 0;
            String line;
            while ((line = bR.readLine()) != null) {
                System.out.println("Line is : " + i + " : " +
                                   line);
                i++;
            }
            oSW.close();
            bR.close();
        } catch (Exception e) {
        }
    }