Implementing service tasks

If you need to communicate to other processes and services, you can use service tasks. You have added a service task (Save Quote) while modeling as a Process Analyst, as you were aware at that point of time that your process will need to invoke a service. Now, as a Process Developer, you can implement the necessary services. You can use the service task to invoke other BPMN processes, BPEL processes, SOA service adapters, and Mediators that are exposed as services.

In our example, the SaveQuote activity is a service task. It represents an automated (or system) invocation step.

The service task has similar behavior to the Send and Receive task pair and the Message throw and Catch event pair. The primary difference is that the service task is used to invoke processes and services synchronously.

How to do it...

You can use a composite editor to create services, and the SOA resource palette lists the type of service components and adapters you can configure. You will find that you have many options in the component palette. For example, you could define a BPEL Process Service if you want to call a BPEL Process, a Database Adapter service if you want to write to a database, or even a File Adapter service if you want to write to a file on the disk.

You can even find a Web Service Adapter, which is generic it's for web services that are not already listed. You can use a wizard to configure a Web Service adapter from scratch. You need to define a service and bind it to the activity. Configuration of the service varies according to which kind of service is selected. Then you need to map data input and output. Hence the steps can be summed up as follows:

  • Define a service (configure the operation)
  • Bind it to the activity
  • Map data input and output

You will be defining a service for the Save Quote activity, which will save the quote payload to a local filesystem. The Save Quote service task is bound to a File Adapter Service

  1. Go to Application Navigator | SalesToContract | SOA Content and click composite.xml, as shown in the following screenshot:
    How to do it...
  2. Go to the Component Palette on right-hand side of the Composite Editor and drag-and-drop File Adapter from Component Palette into the composite editor's External Reference panel:
    How to do it...

    This will open the FILE Adapter Configuration Wizard.

  3. Complete the Configuration Wizard to create a Save Quote service to write to a file location. Click Next on the Welcome page of the wizard.
  4. Enter Service Name: SaveQuote.
  5. On the Define Interface dialog, click the radio Define From Operation and schema.

    WSDL is used to define the adapter interface. This WSDL is generated by the operation and schema, which we will choose later in this wizard. By choosing this option, you are directing WSDL to define an adapter interface that will be generated later.

  6. Click Next.
  7. Chose the Operation type—Write File, and click Next.
    How to do it...
  8. While configuring the file, you can choose the logical name of the directory where the file will be kept. Say QuoteOutputFileLoc and give a File Naming Convention:Quote_%SEQ%.xml.
    How to do it...
  9. While defining the message schema, click on Browse Schema in front of the URL in the Message Schema section. This will open the Type Chooser. Expand Project Schema Files.
    How to do it...
  10. Choose QuoteRequest in Quote.xsd and click OK.
    How to do it...
  11. Click Next, and then Finish in the last dialog box of the file configuration wizard.
  12. When you have finished following the preceding steps, click Save.
    How to do it...
  13. Go to BPM Project Navigator | SalesToContractDemo(Project) | Business Catalog | Services | Externals.

    You can find the SaveQuote External service to verify its creation.

    How to do it...
  14. In the BPM Project navigator, open the process SalesToContract, right-click the Save Quote activity, and select Properties.
  15. Click on the Implementation tab in the Properties dialog.
  16. In the Service task section, choose Service Call as the Implementation.

    Click on the browsing icon to the right to search for the service:

    How to do it...
  17. From the search result of the Service, choose the service you have created to write to a file&madash; SaveQuote. This will bind the activity with the service.
  18. In Operation, choose Write. (However, as the service has only one operation, it will get automatically populated).

    Go to the Data Associations section. You can check the Use Associations to perform input-output mappings.

  19. Click the pencil icon to the right of Use Associations to edit it. This will open the Data Association dialog.
  20. Drag-and-drop the quote Data object from the right-hand panel to the Inputs area and click OK.
    How to do it...
  21. Click OK to complete the Save Quote service task.
  22. When you have finished following the preceding steps, click Save.

How it works...

When the service task invokes a process or service, the token waits at the service task until a response is returned. After the response is received, the token continues to the next sequence flow in the process. You use service tasks to invoke synchronous operations in services and BPMN processes. By synchronous, we mean that when the BPMN service engine runs a service task, it invokes the operation specified in the service task and waits for a response. In this case, data for quote is provided to the SaveQuote file service, which writes it to a file location.

Note

Services are not reserved for service tasks; they can also be used to implement message events as well as the Send and Receive tasks.

Assigning the outcome of an Interactive task to Data objects Interactive tasks come with outcomes. You have defined these outcomes when you configured the Human Task Implementation artifact. Like you have set Submit as the outcome for Enter Quote Human Task, you have to assign these outcome values to Data objects to be used in the process, as shown in the following screenshot:

How it works...

How to do it...

You can remember that you have already created BusinessAnalystOutcome, approveDealOutcome, and approveTermsOutcome as a Data object in Chapter 1, Process Modeling, to hold values while you modeled the process. You will assign the outcome of the Business Analyst Review activity to the BusinessAnalystOutcome Data object, and similarly you will assign the outcomes of the Approve Deal and Approve Terms activities to the approveDealOutcome and approveTermsOutcome Data objects, respectively.

  1. Go to the Application Navigator | Project | SalesToContract Process | Business Analyst Review activity.
  2. Right-click the Business Analyst Review activity, select Properties, open the Implementation tab, and then click the pencil icon next to Use Associations to bring up the Data Associations window.
  3. Drag-and-drop the BusinessAnalystOutcome Data object from the right-hand panel to the box indicated on the Output panel.
    How to do it...
  4. Click OK to return to the Properties dialog.
  5. Click OK to return to the designer.
  6. Similarly, you will repeat the steps for the Approve Deal and Approve Terms activities too.
  7. Right-click on Approve Deal | Properties | Implementation Tab | Data Association and assign the approveDealOutcome Data object to the outcome of the Approve Deal activity and click OK twice to return to the designer:
    How to do it...
  8. Right-click on Approve Terms | Properties | Implementation Tab | Data Association, assign the approveTermsOutcome Data object to the outcome of the Approve Terms activity, and click OK twice to return to the designer.
    How to do it...
  9. When you have finished following the preceding steps, click Save.

How it works...

When the token returns back to the process from the Human Task, it brings the outcome with it. These outcomes will be assigned to the Data objects, based on the Data association defined in the properties of the activities.

Note

You created a script task in Chapter 1, Process Modeling, to initialize values. You have created a process Data object, BusinessAnalystReviewRequired, and assigned the values of false () in the section Changing the Value of Data Objects in Your Process in Chapter 1, Process Modeling. These values will be required while conditionally branching from the Gateways.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.99.71