Handling Business Exception in a subprocess

You will explore the exception handling for a subprocess, in this section. You will create a subprocess and that subprocess will end with an Error event.

When the process ends with an Error event, it's handled by the parent process only when the subprocess has a boundary catch event attached to it. If the process cannot handle the exception, then it propagates it to its parent process. If there is no parent process, then the exception is logged to the Enterprise Manager fault recovery system.

Event subprocesses enable you to define a cleaner process with less effort, because the Catch Error event is located within the event subprocess. To reuse an exception handling flow using boundary catch events, you must define a boundary catch event for each of the tasks and then connect those boundary events to the exception handling flow. If the exception handled in the event subprocess occurs while running any of the tasks in the process, then the BPMN Service Engine continues running the exception handling flow defined in the event subprocess.

How to do it...

You will first create a Sub Process, and then use an Error End Event to Throw a business error, and finally, you will create Event Sub Process to catch the business exception.

How to do it...

You have a Business Analyst User task to perform business reviews. Let's recreate the same task in a subprocess, and if the Business Analyst task has the outcome REJECT, then the subprocess throws an error. This error would be caught in Event Sub Process.

I. Create Business Exception

  1. Go to BPM Project Navigator | SalesToContractDemo Project | Business Catalog and right-click Business Catalog.
  2. Click New | Business Exception.
    How to do it...
  3. In the Create Business Exception dialog, click on the Browse Modules button.
  4. Click on the "create module" (+) icon to create a module.
  5. Enter BusinessException as the name for a new module.
    How to do it...
  6. Click OK twice to go back to the Create Business Exception dialog.
  7. Enter BusinessReviewRejectionFault as the name for the Exception and click OK.
    How to do it...

II. Create Subprocess

  1. Go to Component Palette | BPM | Activities and click on Subprocess.
  2. Click to the right of the Is Business Analyst Review Required? gateway, in the businessanalyst swimlane. This will open up the Properties dialog for the subprocess.
  3. Enter name of the subprocess as BusinessAnalystReviewSubprocess, in the Basic tab.
    How to do it...
  4. Name the Start and End activities in the subprocess StartBusinessAnalystReview and EndBusinessAnalystReview, respectively.
  5. Click on User task in Component Palette | BPM | Interactive Activities.
  6. Click between the Start and End activities in the subprocess.
  7. In the Properties dialog, enter BusinessAnalystReview as the name for the task.
  8. In the Implementation tab of the Properties dialog, browse Human Task, select the BusinessAnalystUI task and click OK.
  9. Enter the title BusinessAnalystReview, as shown in the following screenshot:
    How to do it...
  10. Place a checkmark next to the options for Data Associations, drag quote into the Input and Output sections, and drag the BusinessAnalystOutcome Data object into the Output section of the task outcome.
    How to do it...
  11. Click OK twice, to reach the subprocess.
  12. Go to Component Palette | BPM | Gateways and click on Exclusive Gateway.
  13. Click to the right of the BusinessAnalystReview User task and enter the name BusinessAnalystOutcome in the Basic tab of the Properties dialog of the gateway.
  14. Go to Component Palette | BPM | Events and click Error End Event.
  15. Click to the right of the BusinessAnalystOutcome gateway and this will open the Properties dialog for Error End Event.
  16. Enter OutcomeRejected as the name for Error End Event, in the Basic tab.
  17. Click on the Implementation tab in the Properties dialog and select Error from the Implementation Type drop-down list.
    How to do it...
  18. Click the "browse" button to browse for Exceptions and select the BusinessReviewRejectFault exception, which you have created in this section. Click OK twice.

III. Create sequence flows

  1. Create an unconditional sequence flow from the StartBusinessAnalystReview activity to the BusinessAnalystReview task, and then to the BusinessAnalystOutcome gateway.
  2. Create a conditional flow from the BusinessAnalystOutcome gateway to the EndBusinessAnalystReview activity.
  3. In the Properties dialog for the conditional sequence flow in the Description tab, enter APPROVE as the name, and in the Properties tab, select Condition as the Type. Enter a simple expression(Simple Exp) based on the BusinessAnalystReview outcome Data object, as follows:
    BusinessAnalystOutcome == "APPROVE".
    
    How to do it...
  4. Click OK.
  5. Create a unconditional sequence flow from the BusinessAnalystOutcome gateway to the Error End Event, Outcome Rejected and click OK.
  6. The subprocess will look like the following screenshot:
    How to do it...
  7. Create a conditional sequence flow from the gateway Is Business Analyst Review Required? to the subprocess BusinessAnalystReviewSubprocess.
  8. Name this flow as Yes and enter a simple expression condition, as follows:
    ApprovalFlow.businessPracticesReviewNeeded == true
    
  9. Remember, you did the same when the BusinessAnalystReview task was a simple task. You are now doing it for the subprocess.
  10. Create an unconditional sequence flow from BusinessAnalystReviewSubprocess | SubProcess to the Approvals gateway.
    How to do it...
  11. When you have finished the preceding steps, click Save.

IV. Create an Event Process

  1. In the designer, right-click just below the contracts swimlane to create a new swimlane.
  2. Select Add Role and in Role Properties and click the New button. Enter Admin as the role name and click OK twice.
  3. You can find an Admin swimlane created just below the contracts swimlane.
    How to do it...
  4. Go to Component Palette | BPM | Activities and click on Event Subprocess.
  5. Now click anywhere in the Admin swimlane. This will create an Event subprocess.
  6. Right-click the start of the Event Sub Process and select Properties.
  7. In the Basic tab, enter the Start Event name as CatchBusinessFault, and in the Implementation tab, select Error from the Implementation Type drop-down menu.
    How to do it...
  8. Click the "browse" button, as shown in the following screenshot, to browse for Exceptions and select BusinessReviewRejectionFault.
    How to do it...
  9. Click OK twice to return back to Event Sub process.
  10. Click on the End activity in Event Subprocess and name it EndBusinessFault.
  11. Go to Component Palette | BPM | Activities and click Scripts.
  12. Click between CatchBusinessFault and EndBusinessFault, and in the Properties | Basic tab, enter the name of the script as AssignRejectionStatus.
  13. Click Data Association, and in the Edit panel, drag the Data object quote and assign Rejected to quoteRequestStatus.
    How to do it...
  14. Click OK twice, to get back to Event Subprocess.
  15. Create a sequence flow from CatchBusinessFault | AssignRejectionStatus | EndBusinessFault.
  16. When you have finished, click Save.

How it works...

When the Business Analyst rejects the quote, the process token reaches Error End Event. It will then throw the exception BusinessReviewRejectionFault. BPMN Service Engine interrupts the process and throws the exception to the parent process. The parent process will have the Event Subprocess called CatchBusinessFault defined. It can catch BusinessReviewRejectionFault, and hence the subprocess CatchBusinessFault, defined in the parent process, will handle the exception.

How it works...

There's more...

You have used the Event Subprocess activity to catch a specific error—BusinessReviewRejectionFault. However, you can even implement this event subprocess to handle all system or business exceptions.

Implementing Catch All

  1. Go to Implementation properties at the beginning of Event subprocess.
  2. Select Error as the Implementation Type.
  3. Tick Catch all business exceptions; or tick Catch all system exceptions, if you want to handle all business or system exceptions, rather than a specific exception.
    Implementing Catch All
..................Content has been hidden....................

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