4.3 Overview of the Example Application

We now delve into an example application that uses session beans. This application uses the concepts discussed in previous sections, including stateful and stateless session beans and their local and remote interfaces. Chapter 9 looks at a session bean example that has a Web service client view.

Our example application, called Benefits Enrollment, is an employee self-service Web application through which an employee manages his or her benefits enrollment selections. The application lets employees enter, review, and change their employer-provided benefits selections.

The Star Enterprise IT department developed the Benefits Enrollment application. The IT department relied on its knowledge of the human resources related databases payroll, employee, and benefits databases and their schemas when developing the application.

4.3.1 User View of the Application

An employee invokes the application by pointing his or her browser at a specific Uniform Resource Locator (URL). The application displays a sequence of HTML pages that contain the various benefits choices available to the employee. On each page, the employee can select from one of the displayed choices. After the employee makes a selection, the application displays the next page. After the employee makes all applicable selections, the application displays a summary of the employee's selections and prompts the employee to confirm them. If the employee confirms the selections, the application updates the user's benefits record in the benefits database.

When the application displays choices to the user, it also indicates the most recent benefits selection, which it obtains from the user's benefits record. Before confirming selections, the employee may click the browser's Back button to return to previous pages and change previous selections. The application updates the user's benefits record only if the user successfully completes all the pages and confirms the selections at the end of the page sequence. Otherwise, the application leaves unmodified the previous selections stored in the benefits database.

Figure 4.5 illustrates the sequence of pages displayed by the application. The figure does not show two pages: the initial login page and the final page, which confirms that the user's changes have been accepted and that they become effective as of the next paycheck.

Figure 4.5. Benefits Enrollment HTML Page Sequence

graphics/04fig05.gif

4.3.2 Main Parts of the Application

Figure 4.6 illustrates the main parts of the Benefits Enrollment application. The EnrollmentEJB session bean implements the business rules of the benefits enrollment business process. The business process consists of a conversation between one user and the server. Therefore, we implement it as a stateful session bean. The EnrollmentWeb Web application is a set of JSPs that implements the presentation logic of the Benefits Enrollment application.

Figure 4.6. Parts of the Benefits Enrollment Application

graphics/04fig06.gif

The Enrollment bean accesses a number of corporate databases: EmployeeDatabase, PayrollDatabase, and BenefitsDatabase.

  • EmployeeDatabase EmployeeDatabase contains information about employees, such as first name, last name, birth date, department, manager, and so on. EmployeeDatabase also maintains information about how the enterprise is organized into various departments.

  • PayrollDatabase PayrollDatabase keeps payroll data for each employee, such as salary and various paycheck-related information. Employees are responsible for a portion of their benefit costs, which is handled by a payroll deduction. The payroll information includes the amount deducted from each employee's paycheck to cover the employee's portion of the premium paid by the company to the benefits providers.

  • BenefitsDatabase The BenefitsDatabase includes the information about available benefits and providers. It also contains the employee's current benefits selections.

Because of the sensitivity of the payroll information, the payroll department does not allow applications outside of the payroll system to access PayrollDatabase directly. Applications, including the Benefits Enrollment application, must go through the PayrollEJB stateless session bean to access payroll information. The Payroll bean allows client applications to access only those parts of the payroll information to which they have been authorized by the payroll department.

The application is deployed as a distributed application across multiple servers. Figure 4.7 illustrates the application deployment.

Figure 4.7. Deployment of the Benefits Enrollment Application

graphics/04fig07.gif

The EnrollmentWeb Web application is deployed in a Web container on an application server maintained by the benefits department. The EnrollmentEJB enterprise bean is deployed in an EJB container on the same application server owned by the benefits department. The Benefits application server provides an integrated environment for the deployment of both Web applications and enterprise beans. (Because they use local interfaces, our session beans must be colocated on the same server. If the beans used remote component interfaces, the Web and application servers could be two different servers or the same server.)

The PayrollEJB enterprise bean is deployed on an application server owned by the payroll department. The three databases accessed by the benefits enrollment process may reside on three different database servers, as illustrated in Figure 4.7.

4.3.3 The Benefits Enrollment Business Process

Figures 4.8 and 4.9 illustrate the interactions that occur among the parts of the application during the benefits enrollment business process. Note how the interactions correspond to the sequence of pages shown in Figure 4.5 on page 74. (The numbers to the left of the interactions correspond to the page numbers in Figure 4.5, as well as to steps in the business process.) A step-by-step explanation of these interactions follows the diagrams.

  • Login Screen From a browser, the user starts by entering the URL of the EnrollmentWeb's starting JSP. Before invoking the EnrollmentWeb Web application, the Web container displays a login page to the user. The user logs in by entering his or her ID and password, and the Web container authenticates the user. (Note that the authentication logic is implemented by the Web container, not by the EnrollmentWeb Web application.) Then the Web container invokes the EnrollmentWeb Web application. EnrollmentWeb invokes the create method on the EnrollmentHome interface, the home interface for the EnrollmentEJB enterprise bean, which creates a new Enrollment bean session object and a corresponding instance of the EnrollmentBean class, which sets up its initial state by reading the information from the corporate databases. The EnrollmentBean instance also creates a PayrollEJB object so that it can later update the payroll information. EnrollmentWeb invokes the Enrollment bean's getEmployeeInfo method, which uses the helper type EmployeeInfo to return the pertinent employee identification information. In a similar fashion, EnrollmentWeb next invokes the bean's getCoverageOptions method, which uses the helper type Options to return the available coverage options to EnrollmentWeb.

  • Step 1: Coverage Categories EnrollmentWeb displays the first HTML page of the benefits enrollment process. This page displays available coverage categories and asks the user to select a particular category. The employee makes a selection and clicks the Next button to send the selection to EnrollmentWeb. EnrollmentWeb calls Enrollment bean's setCoverageOption, passing it the coverage category, so that the bean keeps the selected coverage category. EnrollmentWeb then invokes the bean's getSmokerStatus method, formats the returned data into an HTML page, and displays the next page to the user.

  • Step 2: Smoker Status The user indicates whether he or she smokes, clicking the Next button to send the smoker status to EnrollmentWeb, which in turn invokes the setSmokerStatus method to store the status. Then, EnrollmentWeb invokes the bean's getMedicalOptions method, which uses the helper object Options to return the available medical insurance options to EnrollmentWeb. EnrollmentWeb formats the returned data into an HTML page for display to the user.

  • Step 3: Medical Options After the user selects from the displayed list of medical options and clicks the Next button to send the selection, EnrollmentWeb calls the setMedicalOption bean method to store the selection. EnrollmentWeb next invokes the bean's getDentalOptions method, which returns to EnrollmentWeb the helper object Options with available dental options. EnrollmentWeb formats the returned data into an HTML page for display to the user.

  • Step 4: Dental Options The user selects one of the dental options and clicks the Next button to send the selection to EnrollmentWeb. EnrollmentWeb calls the setDentalOption bean method, passing it the selected option, and stores the selection. EnrollmentWeb calls the bean's getSummary method, which returns all selections and their total costs in the Summary helper object. EnrollmentWeb formats the data into an HTML page and displays the selection summary page.

  • Step 5: Selection Summary and Confirmation After the user confirms his or her selections and sends the confirmation to EnrollmentWeb, it in turn calls the bean's commitSelections method, which updates the benefits record and the payroll deduction in the respective databases.

  • Acknowledgment Page (not shown in Figure 4.5) EnrollmentWeb sends an HTML page to the user's browser with a message acknowledging that the user's changes have been permanently recorded in the corporate databases. EnrollmentWeb also calls the remove method on the Enrollment object to end the enrollment business process. As part of processing the remove method, the Enrollment object invokes the remove method on the Payroll object.

Figure 4.8. Benefits Enrollment Process Interactions, Part 1

graphics/04fig08.gif

Figure 4.9. Benefits Enrollment Process Interactions, Part 2

graphics/04fig09.gif



Applying Enterprise Javabeans
Applying Enterprise JavaBeans(TM): Component-Based Development for the J2EE(TM) Platform
ISBN: 0201702673
EAN: 2147483647
Year: 2003
Pages: 110

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net