Friday, September 16, 2011

Propagate authenticated user from BPM to ADF using BPM API and ADF Task Flow parameters

In my previous post, I have demonstrated how you can propagate the authenticated user from BPM to your custom ADF Application using Contextual Events.

In this post, I will demonstrate how you can achieve the exact same result, this time using BPM API and ADF Task Flow parameters.

So, let’s first start with creating the custom ADF application. This will be a very simple application, where I will create a taskflow with a parameter and a fragment page to just display the taskflow parameter that will eventually hold the authenticated username that will get propagated from BPM.
I just created an ADF Application, named “DemoADF” and selected “Fusion Web Application (ADF)” from the Application Templates.
Next create an ADF TaskFlow and name it, DemoTF. Make Sure that the “Create with Page Fragments” checkbox is selected.
If not opened, open the DemoHT ADF Human Task that you have just created and using the overview view option, create a parameter, naming it “UserNameFromBPM”, setting the class to “java.lang.String” and the value to “#{pageFlowScope.UserNameFromBPM}”.
Create a new view component and name it “Demo”.
Double click to create the page fragment and drag an output label ADF component, setting the value attribute to “Authenticated User: #{pageFlowScope.UserNameFromBPM}”
Now, we need to package this ADF Application that we have just created into an ADF Jar Library. To do this, right-click the ViewController project, select new from the context menu and in the “New Gallery” window, select “Deployment Profiles“ from the Categories and “ADF Library JAR File” from the items and click OK.
In the “Create Deployment Profile” window, give your deployment profile a meaningfull name (for example, DemoADF, and click OK.
In the “Edit ADF Library JAR Deployment Profile Properties”, just click OK. The same with the “Project Properties” window, just click OK.
To deploy your ADF Application in the ADF JAR Library, you need to right-click the ViewController project and select Deploy > DemoADF
In the “Deploy DemoADF” window, click next and in the Summary screen, make sure to note down the location of the generated jar file (in my case, it’s C:\JDeveloper\mywork\myBlog\DemoADF\ViewController\deploy) and click Finish.
So, we are done with the custom ADF Application, now it’s time to create our SOA Application. So create a new application, name it DemoSOA and from the templates select “SOA Application”.
In the project name screen, you can give your project the same name as your application, that is DemoSOA.
In the “Configure SOA settings” screen, select “Composite with BPEL Process” from the Composite Template section and click Finish.
In the “Create BPEL Process” window, accept all defaults and click OK.
Create a Human Task by dragging the Human Task component form the Component Pallet onto the components swim lane. On the “Create Human Task” window, accept all defaults and click OK. Your composite application should resemble as the image below.
Edit the newly create Human Task and assign the “weblogic” user as the participant of this Human Task.
Edit the BPEL component and drag and drop a human component between the receive (receiveInput) and invoke(callbackClient) activity.
Edit the Human Task component that you have just dropped onto the BPEL Designer and in the “Task Definition” drop down, select “Humantask1” (it’s the human task that you have created in the composite application) and click OK.
Now it’s time to generate the human task form for the human task component. To do this, go to the composite.xml file, and double-click the human task component. From the human task editor, select Create Form > Auto-Generate Task Form.
In the “Create Project” window, give your project a name, such as DemoHT, and click OK.
JDeveloper will automatically create for you the ADF Human Task Form in the project that you have specified in the previous step. Once finished, it should display you with the auto-generated form.
So, now I want to include the Demo.jsff page fragment that I have create from the custom ADF Application in my human task form. How to do this? First, we need to create a File System Connection to the location of the generated ADF JAR Library. You can do this using the Resource Palette. In the “Create File System Connection” window, give your connection a name (for example, DemoADF) and the path to the generated ADF JAR Library. Click “Test Connection” to test your connection and then OK.
From the Resource Palette, expand the IDE Connection, File System and your file system connection name (in my case it’s DemoADF) and you should see the generated ADF JAR Library (DemoADF.jar).
To include and use the contents of this jar file in the human task project, make sure that you have selected from the application navigator the DemoHT project, and from the Resource Paletter, right-click the DemoADF.jar file and select from the context menu “Add to Project”.
In the “Confirm Add ADF Library” window, just click the Add Library button.
Oracle provides us with an API to get the authenticated BPM user from a human task (that is from the BPM context), using the IWorkflowServiceClient, ITaskQueryService queryService and IWorkflowContext wfContext interfaces.
So to use this API, we must create a java class with a simple method that will use this API and return the authenticated user as a string.
In the newly created java class, add the following method:

String userId = "";
try {
IWorkflowServiceClient wfSvcClient;
ITaskQueryService queryService;
IWorkflowContext wfContext;

String contextStr = ADFWorklistBeanUtil.getWorklistContextId();
wfSvcClient = WorkflowService.getWorkflowServiceClient();
queryService = wfSvcClient.getTaskQueryService();
wfContext = queryService.getWorkflowContext(contextStr);
userId = wfContext.getUser();

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

return userId;

When prompted, please import the following packages:

import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.datacontrol.WorkflowService;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.verification.IWorkflowContext;
import oracle.bpel.services.workflow.worklist.adf.ADFWorklistBeanUtil;
Using this newly created java class, create a data control by right-clicking the java class and selecting from the context menu “Create Data Control”.
Open the human task form (taskDetails1.jspx) and go the page bindings by using the “Bindings” tab. From the “Bindings and Executables” tab, click the green plus sign in the bindings section to create a new control binding.
In the “Insert Item” window, ensure that “Generic Bindings” is selected in the drop down menu and select “attributteValues” from the items and click “OK”.
In the “Create Attribute Binding” window, click the green plus sign to add a new data source.
In the “Add Data Source” window, expand SecurityUtils, Constructors, demoht.utils.SecurityUtils and select “SecurityUtils” and click “OK”.
Back in the “Create Attribute Binding” window, select “authenticatedUser” and click “OK”.
Switch back to design view and from the Component Palette, make sure that you have selected DemoADF.jar from the drop down menu.
Expand the Regions section and drag and drop the DemoTF region from into the panelGroupLayout component that is included into the Contents showDetailHeader component as an ADF Region (you might find it easier to user the structure window).
In the “Edit Task Flow Binding” window, set the value of “UserNameFromBPM” input parameter to the inputValue (if you followed my exact steps, then this would be “#{bindings.authenticatedUser.inputValue}”) of the attributeValue that we have created just above that represents the return value of the java method created earlier and click “OK”.
So now, we are ready to deploy and test if the authenticated user from the BPM workspace is propagated to the custom ADF application that was included in the Human Task form as an ADF region.

First, we need to deploy the DemoSOA project by right-clicking the project and selecting Deploy > DemoSOA
and then we need to deploy the human task form. Please note that you should deploy the project that contains the human task form (DemoHT) using the Application menu, Deploy > DemoHT and NOT by right-clicking the project and selecting deploy.
Once you have successfully deployed both, DemoSOA and DemoHT projects, please go to the Oracle Enterprise Manage (http://localhost:7001/em), locate the newly deployed SOA Composite Application (DemoSOA) and create a new instance by clicking on the test button.
Specify a value in the input field and click the “Test Web Service” button.
This will create a new instance of the DemoSOA composite application. If you remember, this composite consists of a BPEL and a Human Task Component. So it will initiate a bpel process and when it reaches the human task component, it will wait for a human intervention by the weblogic user.

So let’s login to the BPM workspace application (http://localhost:8001/bpm/workspace) to see all pending tasks.
Click on the DemoSOA task and wait for the human task form to load on the bottom half of the screen. The human task form should load and you should see the authenticated user, in this case weblogic, to get propagated from the BPM workspace to the custom ADF Application that we have developed earlier and included in the human task form as an ADF region.
Download: Propagate authenticated user from BPM to ADF using BPM API and ADF Task Flow parameters

No comments:

Post a Comment