Wednesday, February 24, 2010

Assign Activity

BPEL process manager provides a lot of activity.The first activity in the list is assign activity.It is very simple to use and you can use it for many purposes .I just have created a simple example to illustrate the functionality and use case of assign activity to show how strong is this activity.

Lets consider a situation when a employee joins a company.He needs to provide his informations like first name,last name,date of birth,place and other details.

Finally based on these details he is assigned some competency,package and department.We will just see how we can do the same using an assign activity.I believe you have some basic knowledge of xml because we will be using it extensively for creating the process.

I am using jdeveloper IDE for creating the business process.I will guide you through step by step process so that you can design your own business process.



open your jdeveloper and create a new project

just right click on the Application and say create a new application

Give some name to the application.



SAy ok and you will be prompted to enter the project name like this

say cancel to that



Now select the application created in the jdeveloper and right click on New project.IN the other tab select BPEL Process Project.



Say ok and following screen will come up.



Let this window be untouched we will make the process name as BPELProcess1 and we will make it as an asynchronous process only.I will be covering the difference between a synchronous and asynchronous bpel process in my next post.Say next and let the windows be untouched and say finish.




NOw go to the bpel process created and navigate to the xsd file the bpel process is using.




as you can notice

we have the two element

<element name="BPELProcess1ProcessRequest">
<complexType>
<sequence>
<element name="input" type="string"/>
</sequence>
</complexType>
</element>
<element name="BPELProcess1ProcessResponse">
<complexType>
<sequence>
<element name="result" type="string"/>
</sequence>
</complexType>
</element>

One is BPELProcess1ProcessRequest and other is BPELProcess1ProcessResponse.They are the input and output varible for our bpel process.We will make some changes in these activities according to our requirement.


Since we are creating a process in which employee will provide his details and in return his data will be provided to him.

So i will modify my xsd as follows.

<element name="BPELProcess1ProcessRequest">
<complexType>
<sequence>
<element name="first_name" type="string"/>
<element name="last_name" type="string"/>
<element name="date_of_birth" type="string"/>
<element name="branch" type="string"/>
<element name="location" type="string"/>
<element name="conatct_number" type="string"/>
</sequence>
</complexType>
</element>
<element name="BPELProcess1ProcessResponse">
<complexType>
<sequence>
<element name="name" type="string"/>
<element name="department" type="string"/>
<element name="Manager" type="string"/>
<element name="emp_id" type="string"/>
<element name="salary" type="string"/>
</sequence>
</complexType>
</element>

SAve the changes and now click on the .bpel project that you have created.

From the component pallete choose assign activity




and drop this activity in between the receive input and call back client so that it should appear as



now doulbe click on the assign activity and from the drop down box choose copy operation.



We will be checking here three types

XML Fragment,variables and expression.Partnerlink we will check later when we will see the partnerlink activity.

First we will see the XML fragment.

The xml fragment should be a valid xml document.

Now we will see how to design a valid fragment of xml document.Just go to the other and expand it fully as shown



As per seen the root element of the output document is

client:BPELProcess1ProcessResponse

client is a suffix name so we have the root element as

BPELProcess1ProcessResponse

again this root element must contain all the fileds of the output i.e it must include name,department,manager,emp_id and salary.

So our xml document should look something like this

<BPELProcess1ProcessResponse>
<name/>
<department/>
<Manager/>
<emp_id/>
<salary/>
</BPELProcess1ProcessResponse>

but we also need to include the name space tag for this xml document.

We will jsut assing it the target namespace for the bpel.Just go to the source code for the bpel process and you will find the targetnamespace for the xml

xmlns ="http://xmlns.oracle.com/BPELProcess1"

so now our xml document fragment should look like this.

<BPELProcess1ProcessResponse xmlns ="http://xmlns.oracle.com/BPELProcess1">
<name/>
<department/>
<Manager>Arpit</Manager>
<emp_id/>
<salary/>
</BPELProcess1ProcessResponse>

We will just assign the manager name from here manaully to show how does it work.so it should finally look like this.




Now again choose expression type and pass some value to the emp_id field



Similarly to salary.

Again choose variable as type and assign brach from input to department from output as shown.




Again create one new copy operation and select type as expression .click on xpath expression builder and following window will come up



Now we will just use here some prebuild functionality.I will be using the simplest one that is to concatenate the two fileds.I will concatenate the first and last name and will assign that value to the output variable name.

Just select the string function in the function and double click on concat so that it will appear in the top window.Now move your curser in between the braces and select the two input variable from input variables.Ther should be separated with a comman.So finally your xpath expression should look something like this



Assign it to the name output variable.



say ok and apply those changes in the activity and save your project.Now your project is complete.Now we will deploy and check what is the output we are getting.

I believe you know how to create connection from jdeveloper.If not please refer to my previous post.Just do a search and you will get how to make a connetion.

ONce deployed log in to the bpel console

http://host:port/BPELConsole

Invoke the process with input and verify the output

i provided the following output




and got following results

<outputVariable>
- <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
- <BPELProcess1ProcessResponse xmlns="http://xmlns.oracle.com/BPELProcess1">

<name>

arpitrahi

</name>

<department>

electronics

</department>

<Manager>

Arpit

</Manager>

<emp_id>

420

</emp_id>

<salary>

650000

</salary>

</BPELProcess1ProcessResponse>

</part>
</outputVariable>

this is just a simple use of assing activity you can use it many other ways as per your requirement.

1 comment:

pavan said...

it's pretty good and more over thank u