In the previous chapter, you created processes to deal with modifying or cancelling a vacation request.
This chapter explains how to add connections from your process to external systems. These connections are not part of the BPMN standard, but most BPM software includes features for exchanging information with external systems. In Bonita BPM, these features are called connectors.
You will use two connectors, one to send email and another to create and manage a calendar entry corresponding to each vacation request.
When you created the processes, you added several service tasks that send an email message. At each of these tasks, you must configure an email connector with the message header (To, Sender, and Subject) and the message content.
To make the process more flexible, the values that are static for a deployment or that are used in more than one connector can be stored in a parameter. A parameter is declared for a process, and the value is the same each time it is used in the process. Parameters are configured when you prepare a process for deployment, so it is easy to update them. For example, if you use a parameter for the email server address, you can use your local email server for testing during development, but use the company email server in production without changing the process definition, simply by changing the parameter value.
First define the parameters, then define the email connectors, as described in the following sections.
Note that you can save time when configuring a connector by creating a copy of a connector of the same type that is already configured in the same pool. Select the configured connector and click Move/Copy. In the dialog, check the Copy box, then choose the target task where you want to add a connector that is a copy. After you have copied the connector, you can edit it.
These parameters are used in all the email connectors in the Tahiti processes. You need to set them to the appropriate values for your email server:
emailServerAddress
emailServerPassword
emailServerPort
emailServerUsername
emailServerUseSSL
There is also a parameter, emailNotificationSender
, that defines the Sender address for email sent from the Tahiti application.
Finally, there is a parameter, emailHRAddress
, that defines the To address for email sent to HR.
Define each parameter as follows:
emailServerPort
, Boolean for emailServerUseSSL
, text for the rest). You need to define these email parameters in both the Tahiti-NewVacationRequest and the Tahiti-CancelVacationRequest processes.
Now you can configure the email connectors. In some cases, the service task where the connector is defined is already created in the diagram. In others, you need to add the service task first.
This section explains how to configure the email connectors in the Tahiti-NewVacationRequest process.
This connector sends a message to a manager when someone in their team has submitted a vacation request. It informs the manager that there is a pending request to review. The message is sent on behalf of the employee, asking the manager to review the vacation request. Add a service task, Notify manager request pending, in the Employee lane after the Deduct requested days from available days service task.
To define the email connector in the Notify manager request pending service task, follow these steps:
emailNotifyManagerRequestPending
.Configure the connection information. This is where you will use the parameters that you have defined:
emailServerUseSSL
.For the other fields, click the pencil icon, go to the Parameters list, and choose the relevant parameter:
Field | Parameter |
---|---|
SMTP Host | emailServerAddress |
SMTP Port | emailServerPort |
Authentication > Username | emailServerUsername |
Authentication > Password | emailServerPassword |
emailNotificationSender
.The To field defines the address to which the email will be sent. This is the manager of the employee who submitted the vacation request. This information depends on the request, and could change during the lifetime of the application if the organization reporting structure changes, so the value is defined with a script, as follows:
Enter this script:
import
org.bonitasoft.engine.identity.ContactData
import
org.bonitasoft.engine.identity.User
User
requesterUserInfo
=
BonitaUsers
.
getUser
(
apiAccessor
,
vacationRequest
.
requesterBonitaBPMId
)
ContactData
managerProfessionalContactInfo
=
BonitaUsers
.
getUserProfessionalContactInfo
(
apiAccessor
,
requesterUserInfo
.
managerUserId
)
return
managerProfessionalContactInfo
.
The email connector for this service task is now configured. An icon is added to the service task showing that it contains a connector. This part of the Tahiti-NewVacationRequest diagram now looks something like Figure 12-1:
Configure this connector on the Send reminder service task in the Tahiti-NewVacationRequest process diagram. It sends a reminder to a manager when a pending request has been waiting for review for more than seven days.
Follow the same steps to configure this email connector (or copy a connector you have already created in the same diagram). This is the specific information for this connector:
import
org.bonitasoft.engine.identity.ContactData
import
org.bonitasoft.engine.identity.User
User
requesterUserInfo
=
BonitaUsers
.
getUser
(
apiAccessor
,
vacationRequest
.
bonitaEmployeeId
)
ContactData
managerProfessionalContactInfo
=
BonitaUsers
.
getUserProfessionalContactInfo
(
apiAccessor
,
requesterUserInfo
.
managerUserId
)
return
managerProfessionalContactInfo
.
The other information required is the same as for the email connector on the Inform manager request pending task.
This connector sends a message to the requester when a vacation request is approved.
Follow the same steps as before (or copy a connector you have already created) to configure this email connector. This is the specific information for this connector:
return
BonitaUsers
.
getProcessInstanceInitiatorProfessionalContactInfo
(
apiAccessor
,
processInstanceId
).
This connector sends a message to the requester when a vacation request is refused.
Follow the same steps as before to configure this email connector. This is the specific information for this connector:
return
BonitaUsers
.
getProcessInstanceInitiatorProfessionalContactInfo
(
apiAccessor
,
processInstanceId
).
This connector sends a message to the HR team when a vacation request is refused.
Follow the same steps as before to configure this email connector. This is the specific information for this connector:
import
java.text.SimpleDateFormat
import
org.bonitasoft.engine.api.IdentityAPI
import
org.bonitasoft.engine.identity.User
// Create a date formatter that will format the date stored in
// business data to a user readable format
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"MM-dd-yyyy"
,
Locale
.
US
)
formatter
.
timezone
=
TimeZone
.
getTimeZone
(
"UTC"
)
// Get a reference to IdentityAPI in order to retrieve user
// information using user id
IdentityAPI
identityAPI
=
apiAccessor
.
identityAPI
// Requester user information
User
requester
=
identityAPI
.
getUser
(
vacationRequest
.
requesterBonitaBPMId
)
// Reviewer user information
User
reviewer
=
identityAPI
.
getUser
(
vacationRequest
.
reviewerBonitaBPMId
)
return
"The vacation request submitted by
${requester.getFirstName()} ${requester.getLastName()}
for ${formatter.format(vacationRequest.getStartDate())} to
${formatter.format(vacationRequest.getReturnDate())}
(${vacationRequest.getNumberOfDays()} days)
has been rejected by ${reviewer.getFirstName()}
${reviewer.getLastName()}
with the following comment: ${vacationRequest.getComments()}"
This section explains how to configure the email connectors in the Tahiti-CancelVacationRequest process. First add these service tasks for the connectors:
When you have added these service tasks, this part of the diagram will look something like Figure 12-2:
This connector sends a message to a manager when someone in their team has submitted a request to cancel a vacation request that is already approved. It informs the manager that there is a cancellation request to review.
Follow the steps in the previous section to configure the connector (including parameters declaration in the pool). This is the specific information for this connector:
import
org.bonitasoft.engine.identity.ContactData
import
org.bonitasoft.engine.identity.User
User
requesterUserInfo
=
BonitaUsers
.
getUser
(
apiAccessor
,
vacationRequest
.
bonitaEmployeeId
)
ContactData
managerProfessionalContactInfo
=
BonitaUsers
.
getUserProfessionalContactInfo
(
apiAccessor
,
requesterUserInfo
.
managerUserId
)
return
managerProfessionalContactInfo
.
The other information required is the same as for the email connector on the Inform manager request pending task.
This connector sends a message to the requester when a vacation cancellation request is approved.
Follow the same steps as before (or copy a connector you have already created in this diagram) to configure this email connector. This is the specific information for this connector:
return
BonitaUsers
.
getProcessInstanceInitiatorProfessionalContactInfo
(
apiAccessor
,
processInstanceId
).
This connector sends a message to the requester when a vacation cancellation request is refused.
Follow the same steps as before (or copy the emailNotifyEmployeeCancellationApproved connector you have already created in this diagram) to configure this email connector. This is the specific information for this connector:
return
BonitaUsers
.
getProcessInstanceInitiatorProfessionalContactInfo
(
apiAccessor
,
processInstanceId
).
Calendar connectors manage entries in a Google calendar. There are connectors for each type of interaction with the calendar. You have not yet added the service tasks that update the calendar, so in the following sections you need to add the task and then configure the connector.
The processes in the Tahiti application create, update, and delete calendar events, as follows:
The calendar connector uses Google Data API feeds. Before you can use the connector, you need to create a Google Apps service account and get connection credentials. This can either be a paid account or a time-limited trial account. You then need to configure the calendar client to authorize access to calendar events in your Google domain. See the Bonita BPM documentation for details of how to create a service account and configure the client. When you create the service account, be sure to note the Client ID and Email address from the Credentials page, and to keep a copy of the private key .p12 file.
Use parameters to make it easier to configure the calendar connectors, to avoid repeating information, and to make it easier to update settings later. Define the following parameters:
You need to define these calendar parameters in the Tahiti-newVacationRequest, Tahiti-ModifyPendingVacationRequest, and Tahiti-CancelVacationRequest processes.
Google Calendar APIs require a specific date format: yyyy-MM-dd.
This means that you need to convert between the format used in the business data and the one required by the Google Calendar APIs. The conversion needs to happen when providing start and end dates in the Calendar connectors.
We will use a Groovy script to define this format conversion. The same conversion is needed each time we configure a Calendar connector, so we will define a Groovy script that can be used by all processes defined in the workspace:
Enter the following script content:
public
static
String
formatForGoogle
(
Date
date
)
{
// Create a date formatter that will format the date stored
// in business data to the format expected by
// Google Calendar API
java
.
text
.
SimpleDateFormat
formatter
=
new
java
.
text
.
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
US
)
formatter
.
timeZone
=
TimeZone
.
getTimeZone
(
"UTC"
)
// Returns the formatted date
return
formatter
.
format
(
date
)
}
After an employee submits a vacation request, there needs to be a service task that creates a vacation calendar entry, so that the request is visible to the whole team. In the Tahiti-NewVacationRequest diagram, add a service task called Update calendar request pending. Your diagram will look something like Figure 12-3.
To configure the calendar connector, follow these steps:
Configure the connection information. This is where you will use the parameters that you have defined. For each field, click the arrow to open the drop-down list and choose the relevant parameter:
Field | Parameter |
---|---|
Application name | calendarApplicationName |
Calendar ID | calendarCalendarId |
Service Account ID | calendarServiceAccountId |
Service Account P12 file | calendarServiceAccountP12File |
Service Account User | calendarServiceAccountUser |
Click Next to go to the event parameters screen. Enter the following information:
Summary: The title of the event that is displayed in the calendar. Specify this as a Groovy script called Requester first name and last name + pending status, with the following content:
import
org.bonitasoft.engine.api.IdentityAPI
import
org.bonitasoft.engine.identity.User
// Get reference to IdentityAPI to access user's first and
// last name using the user id stored in the VacationRequest
IdentityAPI
identityAPI
=
apiAccessor
.
identityAPI
// Retrieve user information using the API and user id stored
// in business data
User
user
=
identityAPI
.
getUser
(
vacationRequest
.
requesterBonitaBPMId
)
// Aggregate user first and last name and return the result
return
user
.
firstName
+
" "
+
user
.
lastName
+
" "
+
vacationRequest
.
status
Start Date: The first date of the requested vacation. Specify this as a Groovy script called format start date, with the following content:
DateTimeScripts
.
formatForGoogle
(
vacationRequest
.
startDate
)
End Date: The return to work day (because a Google Calendar end date is exclusive). Specify this as a Groovy script called format return date, with the following content:
DateTimeScripts
.
formatForGoogle
(
vacationRequest
.
returnDate
)
In the Extra Event Parameters screen, specify the Attendee, as follows:
import
org.bonitasoft.engine.identity.ContactData
Long
userId
=
vacationRequest
.
requesterBonitaBPMId
ContactData
professionalContactInfo
=
BonitaUsers
.
getUserProfessionalContactInfo
(
apiAccessor
,
userId
)
return
professionalContactInfo
.
In the Output operations screen, define an operation to store the calendar event ID in the vacation request, as follows:
If a user modifies a vacation request, the associated calendar event needs to be updated. In the Tahiti-ModifyPendingRequest diagram, add the service task Update calendar to update the calendar event with the new dates. Your diagram will look something like Figure 12-4.
Configure a calendar connector on this service task to modify the calendar event. Follow the same steps as for the “Update calendar request pending”, with the following differences:
Event ID: The ID of the calendar event, specified as follows:
vacationRequest
.getCalendarEventId()
.Start Date: The new start date for the vacation request, specified as follows:
Enter the following script:
DateTimeScripts
.
formatForGoogle
(
vacationRequest
.
startDate
)
End Date: The new end date for the vacation request, specified as follows:
Enter the following script:
DateTimeScripts
.
formatForGoogle
(
vacationRequest
.
returnDate
)
When a manager approves a vacation request, the associated calendar event needs to be updated to show that the request is no longer pending but is approved. In the Tahiti-NewVacationRequest diagram, add a service task called Update calendar request approved on the yes flow from the Request approved? gateway (see Figure 12-5).
On this service task, configure a calendar connector to update the calendar event to change the status from pending to approved.
Follow the same steps as for the “Update calendar request pending”, with the following differences:
Event ID: The ID of the calendar event, specified as follows:
vacationRequest
.getCalendarEventId()
.Summary: The updated event title. Specify this as a Groovy script called new status approved, with the following content:
import
org.bonitasoft.engine.api.IdentityAPI
import
org.bonitasoft.engine.identity.User
// Get reference to IdentityAPI to access user's first and last
// name using the user id stored in the VacationRequest
IdentityAPI
identityAPI
=
apiAccessor
.
identityAPI
// Retrieve user information using the API and user id stored in
// business data
User
user
=
identityAPI
.
getUser
(
vacationRequest
.
requesterBonitaBPMId
)
// Aggregate user first and last name and return the result
return
user
.
firstName
+
" "
+
user
.
lastName
+
" "
+
vacationRequest
.
status
When a manager refuses a vacation request, the associated calendar event needs to be removed from the calendar. In the Tahiti-NewVacationRequest diagram, add a service task called Update calendar request refused on the no flow from the Request approved? gateway (see Figure 12-6).
Configure a calendar Delete event connector called calRemoveRefusedVacationEvent. Define the Event ID as in the previous section.
If a vacation request is cancelled, it must be removed from the calendar. In the Tahiti-CancelVacationRequest process diagram, add a service task called Update calendar request cancelled before the gateway at the end of the flow handling a successful cancellation (see Figure 12-7).
Configure a Delete event connector called calRemoveCancelledVacationEvent. Define the Event ID as in the previous section using the vacationRequestToCancel
object.
You have updated the diagram to specify the email and calendar connectors required in the New Vacation Request process. The services tasks with connectors now display the connector icon.
The next chapter describes how to create the complete version of the Tahiti vacation management application.
3.145.186.147