Tags

, , , , , , ,

In an earlier example I wrote an article on how do we use the ForEach BPEL, but this example will be showing a more practical or more usual form that is used in everyday life, where we do the invocation of a service that will return a list of Employees Oracle XE and will later work in the iteration of the list.

In this first step download the file ForEachMaisPratico.zip and extract our WSDL we will use for our example.

Create a new project called ForEachMaisPratico

Imagem Blog UansCarvalho

Within your composite.xml drag a Database Adapter for External References and name of ListaEmpregadosDbAdapter

Here quickly explain the options that I am selecting as we focus on our ForEach

Select the Select option

Imagem Blog UansCarvalho

I am here importing the table EMPLOYEE

Imagem Blog UansCarvalho

Below clicked Remove to remove the two relationships that this case is NOT required.

Imagem Blog UansCarvalho

Below are the fields that we will Select.

Imagem Blog UansCarvalho

Imagem Blog UansCarvalho

Then we have our DBAdapter created.

Imagem Blog UansCarvalho

Copy the file ForEachMaisPratico.wsdl into your BPEL project

Imagem Blog UansCarvalho

Now drag a BPEL Process and select the option Base on the WSDL to select this WSDL

Imagem Blog UansCarvalho

Then connect the BPEL in our DBAdapter

Imagem Blog UansCarvalho

Open ForEachBPEL and inside Invoke and drag a point to our Partner Link

Name it Invoke_ListaEmpregados, create the variables of input and OutPut

Imagem Blog UansCarvalho

You should be as follows:

Imagem Blog UansCarvalho

Let’s now create a variable to reference our Response WSDL

Then click the (X) as follows to create this variable

Imagem Blog UansCarvalho

Name it var_consultarEmpregadosResponse and choose the Element option and clicking on the magnifying glass browse the folders as follows to reach within our WSDL operation in ConsultarEmpregadosResponse

Imagem Blog UansCarvalho

Click OK and above will be as follows:

Imagem Blog UansCarvalho

Click now even in this case, the Initialize tab to initialize our listaEmpregado according to ConsultarEmpregadosResponse operation in our WSDL

In the Initialize tab on the Type option select Literal and paste in the XML snippet below:

<ConsultarEmpregadosResponse xmlns="br.com.uanscarvalho.model">
<listaEmpregado>
</listaEmpregado>
</ConsultarEmpregadosResponse>

Imagem Blog UansCarvalho

So that you understand the XML:

I’m putting the tags of our Response operation and in front of her place in xmlns the targetNamespace of our WSDL

Response within the operation put the listaEmpregado as it is in the WSDL

After clicking OK above, will be as follows:

Imagem Blog UansCarvalho

Now drag a ForEach below our Invoke_ListaEmpregados

Imagem Blog UansCarvalho

Double click on our ForEach box to edit it

In Name: Place ForEach and Counter Name: Place ForEachCounter

Imagem Blog UansCarvalho

Click now in the Counter Values tab and in the first Expression place the number 1 and the second Expression click next to the icon which appears to be a calculator

Imagem Blog UansCarvalho

Below make parts for the following:

First place the tool ora:countNodes()

Imagem Blog UansCarvalho

Now inside the function put two single quotes and WITHIN the single quotes press CONTROL + SPACE key and select the option Invoke_ListaEmpregados_ListaEmpregadosDbAdapterSelect_OutputVariable on your keyboard

Imagem Blog UansCarvalho

Continuing, now beside the single quotes put a comma and another single quote, press CONTROL + SPACE key again and then choose the option EmployeeCollection

Imagem Blog UansCarvalho

Again beside the single quotes put another comma and another single quotes and choose ns3:Employee/

Imagem Blog UansCarvalho

Now beside / retighten CONTROL + SPACE on your keyboard and select the option ns3:empno and next to close the tag by adding a single quotation mark and will be as follows (See and entire expression)

Note: Here put step by step the expression is very important because the single quotes and commas between them or our ForEach not work

countNodes('Invoke_ListaEmpregados_ListaEmpregadosDbAdapterSelect_OutputVariable','EmployeeCollection','ns3:Employee/ns3:empno')

Imagem Blog UansCarvalho

Then you will be as follows:

Imagem Blog UansCarvalho

Inside the ForEach left click on the (X) to add another variable (This (X) It is within our scope) as follows:

Imagem Blog UansCarvalho

This variable will make reference to tipoEmpregado which also references the EmpregadoType as line below our WSDL:

<xsd:element name=”tipoEmpregado” type=”inter:EmpregadoType”/>

Note: This element is designed exclusively for use in our ForEach to represent our EmpregadoType which has the other elements that make up our EmpregadoType as codigoEmpregado, nomeEmpregado and etc ..

<xsd:element name=”tipoEmpregado” type=”inter:EmpregadoType”/>

<xsd:complexType name=”EmpregadoType”>
     <xsd:sequence>
          <xsd:element name=”codigoEmpregado” type=”xsd:integer”/>
          <xsd:element name=”nomeEmpregado”   type=”xsd:string” />
          ...
     </xsd:sequence>
</xsd:complexType

Name it var_tipoEmpregado and choose the Element option and clicking on the magnifying glass browse the folders as follows to reach within our WSDL in tipoEmpregado

Imagem Blog UansCarvalho

Click OK and will be as follows:

Imagem Blog UansCarvalho

Click OK again

Imagem Blog UansCarvalho

Now drag an Assign below our ForEach and name it Seta_Index_Nas_Variaveis

Imagem Blog UansCarvalho

Now open this Seta_Index_Nas_Variaveis and inside call our ns3:empno which is on the left side which is the response element of our Invoke for ns1:codigoEmpregado the right that is within the var_tipoEmpregado variable we created in the Scope1 as follows:

Imagem Blog UansCarvalho

Give now double-click the line that he created but on the side of the From and you will see the screen below:

Imagem Blog UansCarvalho

In empression place next to the ns3:Employee the [$ForEachCounter].

See the expression will look like:

Note: See the [$ForEachCounter] is bracketed and is before the slash / the ns3:empno

$Invoke_ListaEmpregados_ListaEmpregadosDbAdapterSelect_OutputVariable.EmployeeCollection/ns3:Employee[$ForEachCounter]/ns3:empnovoke_ListaEmpregados_ListaEmpregadosDbAdapterSelect_OutputVariable.EmployeeCollection/ns3:Employee[$ForEachCounter]/ns3:empno

Imagem Blog UansCarvalho

Click OK and now repeat this procedure for all the other elements also putting the name [$ForEachCounter] before each element within the Expression

Imagem Blog UansCarvalho

Click OK and below Seta_Index_Nas_Variaveis drag an IF

Imagem Blog UansCarvalho

Here I will add a simple logic just so you understand that here should be your logic

IF this will be putting the SE Employee name equals UANS, is expected to add 100 to the salary also showing the other list elements

But it’s interesting you watch I’m wearing the var_tipoEmpregado variable because it was there that we attribute our response to our consultation (Invoke) as above steps

Imagem Blog UansCarvalho

Imagem Blog UansCarvalho

Within the IF if it is true adding an Assign so we can add 100 to the wage

Imagem Blog UansCarvalho

Here I called salary with salary but by adding the value +100 himself plays this line to the ns1:tipoEmpregado (this is normal)

I called for this Assign to Adicona_100_salario_UANS and right in the ELSE drag a EMPTY and name of Continua_Fluxo

Imagem Blog UansCarvalho

Even within your ForEach below its IF add another Assign and then name it Adiciona_na_Lista

Imagem Blog UansCarvalho

Open this Assign and then we will make the allocation of our var_tipoEmpregado variable to our variable var_ConstaEmpregadosResponse we created in the beginning of our flow:

So that you understand:

The variable var_tipoEmpregado already being written in each run of the Loop and then we are adding this information in our listaEmpregado which is the element within our Response WSDL if the ConsultaEmpregadosResponse

Imagem Blog UansCarvalho

After this link next to the From you should click the right button and a small menu should appear as below, then go to Change rule type and select the Append option

Imagem Blog UansCarvalho

After the above step, now to finish, beyond our ForEach add another Assign and name of Seta_OutPut

Imagem Blog UansCarvalho

Assign this just add the contents of our var_ConstaEmpregadosResponse variable that was already all filled because of our FOR to our OutPut and return this result

Imagem Blog UansCarvalho

Here I called the var_consultarEmpregadosResponse to ns1:ConsultarEmpregadosResponse the outputVariable but it’s normal he connected the parameters as above

Okay, now it’s just to deploy our design and test.

PART below show the XML returned after our test.

Imagem Blog UansCarvalho

See above that where the salary for the UANS nomeEmpregado it added 100, returning the value 1100.

Below the Select Table:

Imagem Blog UansCarvalho

Doubts? Leave your comment and download this Projet :-)

Hugs and see you next

/:-D