Tags
11G, BPEL, Concatenação, Deploy, For, ForEach, JDeveloper, loop
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
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
I am here importing the table EMPLOYEE
Below clicked Remove to remove the two relationships that this case is NOT required.
Below are the fields that we will Select.
Then we have our DBAdapter created.
Copy the file ForEachMaisPratico.wsdl into your BPEL project
Now drag a BPEL Process and select the option Base on the WSDL to select this WSDL
Then connect the BPEL in our DBAdapter
Open ForEachBPEL and inside Invoke and drag a point to our Partner Link
Name it Invoke_ListaEmpregados, create the variables of input and OutPut
You should be as follows:
Let’s now create a variable to reference our Response WSDL
Then click the (X) as follows to create this variable
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
Click OK and above will be as follows:
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>
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:
Now drag a ForEach below our Invoke_ListaEmpregados
Double click on our ForEach box to edit it
In Name: Place ForEach and Counter Name: Place ForEachCounter
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
Below make parts for the following:
First place the tool ora:countNodes()
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
Continuing, now beside the single quotes put a comma and another single quote, press CONTROL + SPACE key again and then choose the option EmployeeCollection
Again beside the single quotes put another comma and another single quotes and choose ns3:Employee/
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')
Then you will be as follows:
Inside the ForEach left click on the (X) to add another variable (This (X) It is within our scope) as follows:
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
Click OK and will be as follows:
Click OK again
Now drag an Assign below our ForEach and name it Seta_Index_Nas_Variaveis
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:
Give now double-click the line that he created but on the side of the From and you will see the screen below:
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
Click OK and now repeat this procedure for all the other elements also putting the name [$ForEachCounter] before each element within the Expression
Click OK and below Seta_Index_Nas_Variaveis drag an IF
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
Within the IF if it is true adding an Assign so we can add 100 to the wage
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
Even within your ForEach below its IF add another Assign and then name it Adiciona_na_Lista
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
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
After the above step, now to finish, beyond our ForEach add another Assign and name of Seta_OutPut
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
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.
See above that where the salary for the UANS nomeEmpregado it added 100, returning the value 1100.
Below the Select Table:
Doubts? Leave your comment and download this Projet
Hugs and see you next
/:-D