Build it yourself

The travel booking sample business process invokes services implemented as Java classes. To build the travel booking sample, follow these steps:

Create a new module

To create a new module, complete the following steps:

  1. In the Business Integration view, right-click the canvas.
  2. From the pop-up menu, select New > Module.
  3. The New Module window opens.

  4. In the Module Name field, enter TravelBooking.
  5. Leave the other fields unchanged.
  6. Click Finish.

Define the data types

To create a data type, complete the following steps:

  1. In the Business Integration view, right-click Data Types.
  2. From the pop-up menu, select New > Business Object.
  3. In the Business Object panel, uncheck the Default checkbox next to the Namespace field.
  4. Enter values for Name, Folder, and Namespace. See the table below for the name and namespace, and use bpc/samples for the folder.
  5. Click Finish.

To add an attribute to a business object, complete the following steps:

  1. In the business object editor, click the Add Attribute button .
  2. To edit the name, click the name in the business object figure.
  3. To edit the type, click the type in the business object figure, then select a type from the list. If the type of the attribute is a business object, select the business object, or click Browse to browse for and select a data type.
  4. On the toolbar, click the Save button .

In the folder bpc/samples, create the business objects that are listed in the following table:

Business Object Namespace Attribute Name Attribute Type
CarReservationRequest http://bpc/samples company string
    category string
    pickupDate string
    dropoffDate string
    pickupLocation string
    dropoffLocation string
    creditCardNumber string
    creditCardCompany string
CheckCreditCardRequest http://bpc/samples cardNumber string
    cardCompany string
FlightReservationRequest http://bpc/samples airline string
    departureAirport string
    destinationAirport string
    departureDate string
    departureTime string
    creditCardNumber string
    creditCardCompany string
HotelReservationRequest http://bpc/samples city string
    hotelCompany string
    checkinDate string
    checkoutDate string
    creditCardNumber string
    creditCardCompany string
InvalidRequest http://bpc/samples message string
TravelBookingRequest http://bpc/samples residence string
    destination string
    dateOfDeparture string
    dateOfReturn string
    creditCardNumber string
    creditCardCompany string
    departureAirport string
    departureTime string
    destinationAirport string
    airline string
    hotelCompany string
    carRentalCompany string
    carCategory string

Define the interfaces

To create an interface, complete the following steps:

  1. In the Business Integration view, right-click Interfaces.
  2. From the pop-up menu, select New > Interface.
  3. In the Create a new interface panel, uncheck the Default checkbox next to the Namespace field.
  4. Enter values for Name, Folder, and Namespace. See the table below for the name and namespace, and use bpc/samples for the folder.
  5. Click Finish.

You can add two types of operations to an interface: request response operations and one way operations. To add operations to an interface, complete the following steps:

  1. In the interface editor, click either the Add Request Response Operation button , or the Add One Way Operation button , depending on the kind of operation that you want to add.
  2. To edit the name of the operation, click the operation name. See the table below for the operation name.
  3. To add an input message to an operation, select the operation and click the Add Input button .
  4. To edit the name of an input message, click the message name. See the table below for the message name.
  5. To edit the type of an input message, click the message type and select a type from the list. In the list, select Browse if you want to assign a custom business object as the type. In the Data Type Selection dialog, browse for and select a business object.
  6. To add an output message to an operation, select the operation and click the Add Output button .
  7. Repeat steps 4 and 5 to edit the name and type of the output message.
  8. To add a fault message to an operation, select the operation and click the Add Fault button .
  9. Repeat steps 4 and 5 to edit the name and type of the fault message.
  10. On the toolbar, click the Save button .

In the folder bpc/samples, create the interfaces that are listed in the following table:

Interface Namespace Operation Name Message Name Type
CarReservation http://bpc/samples/CarReservation reserve Input request CarReservationRequest
      Output response boolean
CreditCardChecking http://bpc/samples/CreditCardChecking check Input request CheckCreditCardRequest
      Output response boolean
      Fault error InvalidRequest
FlightReservation http://bpc/samples/FlightReservation reserve Input request FlightReservationRequest
      Output response boolean
HotelReservation http://bpc/samples/HotelReservation reserve Input request HotelReservationRequest
      Output response boolean
TravelBooking http://bpc/samples/TravelBooking book Input request TravelBookingRequest
      Output information string

Create the Java services

To generate Java implementations, perform the following steps for each of the interfaces CarReservation, CreditCardChecking, FlightReservation and HotelReservation:

  1. In the Business Integration view, double-click TravelBooking > Assembly Diagram.
  2. The assembly editor opens.

  3. In the Business Integration view, expand Interfaces > bpc\samples.
  4. Select the interface, drag it to the assembly editor, and drop it on the canvas. The Component Creation window opens.
  5. Select Component with No Implementation Type, then click OK.

    A new component is added to the assembly editor.

  6. Click the component.
  7. In the Properties view, select the Description tab.
  8. In the Name field, enter a name for the component. This automatically changes that Display name as well. See the table below for the names.
  9. In the assembly editor, right-click the component.
  10. From the pop-up menu, select Generate Implementation > Java.
  11. The Generate Implementation window opens.

  12. Select bpc.samples, then click OK. The Java source editor opens.
  13. Continue with the implementation of the generated methods. Refer to the table below for the required service implementation and replace the methods accordingly.
  14. On the toolbar, click the Save button .
  15. Switch to the assembly editor. On the toolbar, click the Save button .

To your assembly diagram, add the Java services that are listed in the following table:

Java Service Name Service Implementation
CarReservation CarReservationImpl

public Boolean reserve(DataObject request) {
    System.out.print("CarReservation ");
    if(request != null) {
        String category = request.getString("category");
        System.out.print("for category \'" + category + "\' ");
        if(category != null && category.equals("Luxury")) {
            System.out.println("was successful.");
            return Boolean.TRUE;
        }
    }
    System.out.println("failed.");
    return Boolean.FALSE;
}

CreditCardChecking CreditCardCheckingImpl

import commonj.sdo.DataObject;
import com.ibm.websphere.sca.ServiceBusinessException;
import com.ibm.websphere.sca.ServiceManager;
import com.ibm.websphere.bo.BOFactory;

public Boolean check(DataObject request) {
    System.out.print("CreditCardChecking ");
    if(request != null){
        String cardNumber = request.getString("cardNumber");
        String cardCompany = request.getString("cardCompany");
        if(cardNumber == null || cardNumber.equals("") || cardCompany == null || cardCompany.equals("")) {
            ServiceManager sm = ServiceManager.INSTANCE;
            BOFactory bofactory = (BOFactory) sm.locateService("com/ibm/websphere/bo/BOFactory");
            DataObject invalidRequest = bofactory.create( "http://bpc/samples", "InvalidRequest");
            invalidRequest.setString("message", "Input data invalid.");
            throw new ServiceBusinessException(invalidRequest);
        }
        else if(cardNumber.equals("1")) {
            System.out.println("failed for credit card number: 1.");
            return Boolean.FALSE;
        }
        else {
            System.out.println("was successful.");
            return Boolean.TRUE;
        }
    }
    ServiceManager sm = ServiceManager.INSTANCE;
    BOFactory bofactory = (BOFactory) sm.locateService("com/ibm/websphere/bo/BOFactory");
    DataObject invalidRequest = bofactory.create( "http://bpc/samples", "InvalidRequest");
    invalidRequest.setString("message", "Input data must not be null.");
    throw new ServiceBusinessException(invalidRequest);
}

FlightReservation FlightReservationImpl

public Boolean reserve(DataObject request) {
    System.out.print("FlightReservation ");
    if(request != null) {
        String departure = request.getString("departureAirport");
        System.out.print("from departure airport: \'" + departure + "\' ");
        if(departure != null && !departure.equals("Boeblingen")) {
            System.out.println("was successful.");
            return Boolean.TRUE;
        }
    }
    System.out.println("failed.");
    return Boolean.FALSE;
}

HotelReservation HotelReservationImpl

public Boolean reserve(DataObject request) {
    System.out.print("HotelReservation ");
    if(request != null) {
        String name = request.getString("hotelCompany");
        System.out.print("for hotel \'" + name + "\' ");
        if(name != null && !name.equals("Venus")) {
            System.out.println("was successful.");
            return Boolean.TRUE;
        }
    }
    System.out.println("failed.");
    return Boolean.FALSE;
}

Develop the business process

Create a new business process

To create a new business process, complete the following steps:

  1. Switch to the Business Integration view.
  2. In the navigation tree, right-click TravelBooking > Business Logic.
  3. From the pop-up menu, select New > Business Process.
  4. The New Business Process window opens.

  5. Uncheck the Default checkbox next to the Namespace field.
  6. In the Namespace field, enter http://bpc/samples.
  7. In the Folder field, enter bpc/samples.
  8. In the Name field, enter TravelBooking.
  9. Click Next.
  10. In the Select a Business Process Type panel, select Microflow.
  11. Click Next.
  12. In the Select an Interface panel, select Select an existing Interface.
  13. Click Browse. The Interface Selection window opens.
  14. Select TravelBooking, then click OK.
  15. In the Operations field, select book.
  16. Click Finish.
  17. In the business process editor, delete the Receive and the Reply activity.
  18. Delete the request and the information variable, as well as the TravelBooking interface partner.
  19. On the toolbar, click the Save button .

Define process properties

To set the properties of the process, perform the following steps:

  1. Switch to the Properties view and select the Details tab.
  2. Make sure that the option Select date (UTC) when the process becomes valid is set. If this is not the case, check the checkbox and accept the default values for the date and time.
  3. Select the tab Java Imports to define imports required by the process' snippets.
  4. Insert the following lines:
  5. import commonj.sdo.DataObject;
    import com.ibm.websphere.bo.BOFactory;
    import com.ibm.websphere.sca.ServiceManager;

  6. On the toolbar, click the Save button .

Define an interface partner

In order to add an interface partner to the process, perform the following steps:

  1. In the business process editor, click the Add Interface Partner button .
  2. The "Add an Interface Partner" window opens.
  3. In the Name field, enter Client.
  4. Select TravelBooking below "Matching interfaces" and click OK.
  5. On the toolbar, click the Save button .

Define process partners

There are two types of partners: interface partners and reference partners. Define interface partners for parties that interact with the process. Define reference partners for services with which the process interacts.

To define a reference partner, complete the following steps:

  1. In the business process editor, click the Add Reference Partner button .
  2. The "Add an Reference Partner" window opens.
  3. In the Name field, enter a name for the partner. See the table below for the name.
  4. Select the matching interface (see the table below) and click OK.
  5. On the toolbar, click the Save button .

Define the partners that are listed in the following table:

Name Type Interface
CarReservation Reference partner CarReservation
CreditCardChecking Reference partner CreditCardChecking
FlightReservation Reference partner FlightReservation
HotelReservation Reference partner HotelReservation

Define process variables

To add variables to your process, complete the following steps:

  1. In the business process editor, click the Add Variable button .
  2. The "Add a Variable" window opens.
  3. In the Name field, enter a name for the variable. See the table below for the name.
  4. Keep the Default Values and click OK

You can assign to a variable either an XSD type or a type derived from an existing interface.

To assign an interface type to a variable, complete the following steps:

  1. In the Description section of the Properties view, select the option Interface variable.
  2. Click Browse. The Interface Selection window opens.
  3. Select the matching interface, then click OK. Refer to the table below for the interface types.
  4. Select the appropriate operation in the Operation field.
  5. To select the appropriate direction, click either Input or Output.
  6. On the toolbar, click the Save button .

Add to your process the variables that are listed in the following table:

Name Interface Type Operation Direction
Input TravelBooking book Input
Output TravelBooking book Output
CarReservationInput CarReservation reserve Input
CarReservationOutput CarReservation reserve Output
CreditCardCheckingInput CreditCardChecking check Input
CreditCardCheckingOutput CreditCardChecking check Output
FlightReservationInput FlightReservation reserve Input
FlightReservationOutput FlightReservation reserve Output
HotelReservationInput HotelReservation reserve Input
HotelReservationOutput HotelReservation reserve Output

Add activities to the process

Follow theses steps to add a Parallel Activities activity to your process:

  1. In the business process editor, click the Parallel Activities symbol on the palette. This icon can be found here.
  2. Click the link between the start and end symbol of the process.
  3. The Parallel Activities figure is added:

Follow these steps to add additional activities to the Parallel Activities activity:

  1. On the palette, click the icon of the activity that has to be added. See the table below for the activities to add.
  2. Click the empty area of the Parallel Activities activity. The activity will be added.
  3. Switch to the Properties view and select the Description tab.
  4. Enter the name of the activity in the Display Name field. See the table below for the name. (Note: the name changes automatically)
  5. On the toolbar, click the Save button .

Add to your Parallel Activities activity the activities that are listed in the following table:

Activity Name Activity Type Symbol
Receive Receive
DataMap1 Assign
CheckCreditCard Invoke
DataMap2 Assign
DataMap3 Assign
DataMap4 Assign
CheckFlightReservation Invoke
CheckHotelReservation Invoke
While While Loop
Confirmation Snippet
Reply Reply

The next step is to add activities to the while loop. The while loop has an implicit sequence. You can add activities at a specific position. Follow these steps to add activities to the while loop:

  1. On the palette, click the icon of the activity that has to be added to the while loop. See the table below for the activities to add.
  2. In the while loop figure, click the position where you want to add the activity. The activity will be added.
  3. Switch to the Properties view and select the Description tab.
  4. Enter the name of the activity in the Display Name field. See the table below for the name. (Note: the name changes automatically)
  5. On the toolbar, click the Save button .

Add to the while loop the activities that are listed in the following table:

Activity Name Activity Type Symbol
CheckCarReservation Invoke
EvaluateReservationResult Snippet

After all activities have been added, the process looks similar to this:

Activity implementation

Receive

To complete the implementation of a receive activity, you have to specify the interface partner, the operation and a process variable for the activity. Furthermore, you can specify whether a new process instance is created when this receive activity is called.

  1. In the business process editor, click the Receive activity.
  2. In the Properties view, click the Details tab.
  3. Select Create a new Process instance if one does not already exist.
  4. To select an interface partner, click Browse next to the Partner field. The Select a Partner window opens.
  5. Select Client, then click OK.
  6. As Operation, select book.
  7. Deselect Use Data Type Variables.
  8. Click Browse next to the Request field. The Select a Request Variable window opens.
  9. Select Input, then click OK.
  10. On the toolbar, click the Save button .

Reply

To complete the implementation of a reply activity, you have to specify the interface partner, the operation, and a process variable for the activity. If the operation supports fault messages, you can choose to return either a response or a fault message.

  1. In the business process editor, click the Reply activity.
  2. In the Properties view, click the Details tab.
  3. To select an interface partner, click Browse next to the Partner field. The Select a Partner window opens.
  4. Select Client, then click OK.
  5. As Operation, select book.
  6. If the operation supports fault messages, select the appropriate Reply Type: Normal or Fault.
  7. Deselect Use Data Type Variables.
  8. Click Browse next to the Response field. The Select a Response Variable window opens.
  9. Select Output, then click OK.
  10. On the toolbar, click the Save button .

Invoke

To complete the implementation of an invoke activity, you have to specify the reference partner, the operation, and the process variables for the activity.

  1. In the business process editor, click the invoke activity.
  2. In the Properties view, click the Details tab.
  3. To select a reference partner, click Browse next to the Partner field. The Select a Partner window opens.
  4. Select the matching partner, then click OK. See the table below for the partners.
  5. Select the appropriate Operation.
  6. Deselect Use Data Type Variables.
  7. Click Browse next to the Request field. The Select a Request Variable window opens.
  8. Select the matching variable, then click OK.
  9. Click Browse next to the Response field. The Select a Response Variable window opens.
  10. Select the matching variable, then click OK.
  11. On the toolbar, click the Save button .

Implement the invoke activities with the settings that are listed in the following table:

Name Partner Interface Operation Request Response
CheckCreditCard CreditCardChecking CreditCardChecking check CreditCardCheckingInput CreditCardCheckingOutput
CheckFlightReservation FlightReservation FlightReservation reserve FlightReservationInput FlightReservationOutput
CheckHotelReservation HotelReservation HotelReservation reserve HotelReservationInput HotelReservationOutput
CheckCarReservation CarReservation CarReservation reserve CarReservationInput CarReservationOutput

Snippet

To implement a snippet activity, complete the following steps:

  1. In the business process editor, click the snippet activity.
  2. In the Properties view, click the Details tab.
  3. Select Java.
  4. If the Question dialog appears, click Yes.
  5. In the text area, enter the Java code of the snippet implementation. See below for the Java code that has to be entered.
  6. On the toolbar, click the Save button .

Complete the implementation of the following snippet activities:

Snippet Name Java Code
EvaluateReservationResult
System.out.print("EvaluateReservationResult");
if(!CarReservationOutput.getBoolean("response")) {
    DataObject carReservationRequest = (DataObject)CarReservationInput.get("request");
    carReservationRequest.setString("category","Luxury");
    System.out.print(" - set category to \'Luxury\'");
}
System.out.println(".");

Confirmation
String msg = null;
if(CarReservationOutput != null &&
  CreditCardCheckingOutput.getBoolean("response")&&
  FlightReservationOutput.getBoolean("response")&&
  HotelReservationOutput.getBoolean("response")&&
  CarReservationOutput.getBoolean("response")) {
    msg = "Travel was booked. Your confirmation no. is: " + System.currentTimeMillis() + ".";
}
else {
    msg = "Your travel could not be booked.";
}
System.out.println("Confirmation: " + msg);
//initialize the Output variable:
BOFactory factory = (BOFactory)ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOFactory");
Output = factory.createByType( getVariableType( "Output") );

//assign a value to the Output variable:
Output.setString("information",msg);

While

To specify the while condition, complete the following steps:

  1. In the business process editor, click the while loop.
  2. In the Properties view, click the Details tab.
  3. As Expression language, select Same as Process (Java).
  4. As Expression Type, select Java.
  5. If the Question dialog appears, click Yes.
  6. In the text area, replace the default Java code. See below for the Java code that has to be entered to define the while condition.
  7. On the toolbar, click the Save button .

Complete the implementation of the while condition with the following Java code:

boolean condition = false;
if(CarReservationOutput != null) {
    condition = CarReservationOutput.getBoolean("response");
}
System.out.println("While: condition is " + condition + ". Returning: " + !condition);
return !condition;

Assign

To complete the implementation of an assign activity, you have to specify one or more data mappings. To specify data mappings for variables, complete the following steps:

  1. In the business process editor, click the assign activity.
  2. In the Properties view, click the Details tab.
  3. To select the variable that will be mapped, click Select From. A drop-down list is shown that lists all variables.
  4. In the variable list, select the appropriate variable or part.
  5. To select the target of the mapping, click Select To.
  6. Select the appropriate variable or part in the drop-down list.
  7. If you want to specify more mappings, click Add, then repeat steps 3 through 6.
  8. On the toolbar, click the Save button .

Complete your assign activities with the mappings that are listed in the following tables:

DataMap1

From Variable Part Attribute To Variable Part Attribute
Input request creditCardNumber CreditCardCheckingInput request cardNumber
    creditCardCompany     cardCompany

DataMap2

From Variable Part Attribute To Variable Part Attribute
Input request creditCardNumber FlightReservationInput request creditCardNumber
    creditCardCompany     creditCardCompany
    airline     airline
    departureAirport     departureAirport
    destinationAirport     destinationAirport
    dateOfDeparture     departureDate
    departureTime     departureTime

DataMap3

From Variable Part Attribute To Variable Part Attribute
Input request creditCardNumber HotelReservationInput request creditCardNumber
    creditCardCompany     creditCardCompany
    destination     city
    dateOfDeparture     checkinDate
    dateOfReturn     checkOutDate
    hotelCompany     hotelCompany

DataMap4

From Variable Part Attribute To Variable Part Attribute
Input request creditCardNumber CarReservationInput request creditCardNumber
    creditCardCompany     creditCardCompany
    carRentalCompany     company
    carCategory     category
    dateOfDeparture     pickupDate
    dateOfReturn     dropoffDate
    destination     pickupLocation
    destination     dropoffLocation

Add control links between activities

To add control links between activities, complete the following steps:

  1. Hover the mouse pointer over the source activity. The link handle of the activity is displayed.
  2. Click the handle, then drag it to the target activity. When you release the mouse button, a control link is added.
  3. On the toolbar, click the Save button .

Add to your process the control links that are listed in the following table:

Source Activity Target Activity
Receive DataMap1
DataMap1 CheckCreditCard
CheckCreditCard DataMap2
CheckCreditCard DataMap3
CheckCreditCard DataMap4
DataMap2 CheckFlightReservation
DataMap3 CheckHotelReservation
DataMap4 While
CheckFlightReservation Confirmation
CheckHotelReservation Confirmation
While Confirmation
Confirmation Reply

Add a fault handler to the process

In this sample, an error was defined in the CreditCardCheckingService interface. This error can be handled by a user-defined error handler. To define such an error handler, complete the following steps:

  1. In the business process editor, click the start symbol of the process. The add handler symbols are displayed.
  2. Click the Add Fault Handler button . A fault handler is added.
  3. Click Catch structure inside the added fault handler.
  4. In the Properties view, click the Details tab.
  5. For Fault Type, select User-defined.
  6. For Fault Name, select {http://bpc/samples/CreditCardChecking}error.
  7. In the Variable Name field, enter Error.
  8. Select Data type variable.
  9. Click Browse. The Data Type Selection window opens.
  10. Select InvalidRequest, then click OK.
  11. Continue adding activities to your fault handler.
  12. On the toolbar, click the Save button .

Adding activities to the fault handler

Add to the fault handler of your process the activities that are listed in the following table:

Parent Activity Activity Name Activity Type Symbol
error HandleFault Snippet
error ReplyFault Reply

Complete the implementation of the HandleFault activity by adding the following Java code:

System.out.print("HandleFault: ");
String msg = Error.getString("message");
//initialize the Output variable:
BOFactory factory = (BOFactory)ServiceManager.INSTANCE.locateService("com/ibm/websphere/bo/BOFactory");
Output = factory.createByType( getVariableType( "Output") );
//assign a value to the Output variable:
Output.setString("information",msg);
System.out.println(msg);

Complete the implementation of the ReplyFault activity with the settings that are listed in the following table:

Name Partner Interface Operation Use Data Type Variables Response
ReplyFault Client TravelBooking book No Output

The completed business process with the added fault handler now looks like this:

Module assembly

To finish the implementation of the travel booking process, you have to create the module assembly. Complete the following steps:

  1. In the Business Integration view, double-click TravelBooking > Assembly Diagram. The assembly editor opens.
  2. Drag the TravelBooking process from the Business Integration view to the assembly editor.
  3. Hover with the mouse pointer over the reference sections of the TravelBooking component to view the required references.
  4. For each reference section of the process component, drag the reference handle to the interface section of the corresponding Java component.
  5. On the toolbar, click the Save button .

Export process application

To create an installable application, complete the following steps:

  1. Switch to the Business Integration view.
  2. In the navigation tree, right-click the TravelBooking module.
  3. From the pop-up menu, select Export. The Export window opens.
  4. In the Export window, select J2EE > EAR file.
  5. Click Next.
  6. In the EAR application field of the EAR Export panel, select TravelBookingApp.
  7. In the Destination field, specify your destination directory.
  8. Click Finish.