The travel booking sample business process invokes services implemented as Java classes. To build the travel booking sample, follow these steps:
To create a new module, complete the following steps:
The New Module window opens.
TravelBooking
.To create a data type, complete the following steps:
bpc/samples
for the folder.To add an attribute to a business object, complete the following steps:
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 |
To create an interface, complete the following steps:
bpc/samples
for the folder.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:
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 |
To generate Java implementations, perform the following steps for each of the interfaces CarReservation, CreditCardChecking, FlightReservation and HotelReservation:
The assembly editor opens.
A new component is added to the assembly editor.
The Generate Implementation window opens.
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; } |
To create a new business process, complete the following steps:
The New Business Process window opens.
http://bpc/samples
.bpc/samples
.TravelBooking
.To set the properties of the process, perform the following steps:
In order to add an interface partner to the process, perform the following steps:
Client
.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:
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 |
To add variables to your process, complete the following steps:
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:
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 |
Follow theses steps to add a Parallel Activities activity to your process:
The Parallel Activities figure is added:
Follow these steps to add additional activities to the Parallel Activities activity:
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:
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:
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.
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.
To complete the implementation of an invoke activity, you have to specify the reference partner, the operation, and the process variables for the activity.
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 |
To implement a snippet activity, complete the following steps:
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); |
To specify the while condition, complete the following steps:
Complete the implementation of the while condition with the following Java code:
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:
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 |
To add control links between activities, complete the following steps:
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 |
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:
Error
.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:
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:
To finish the implementation of the travel booking process, you have to create the module assembly. Complete the following steps:
To create an installable application, complete the following steps: