All content on this page by eGov Foundation is licensed under a Creative Commons Attribution 4.0 International License.
Integrate Workflow Service
Overview
Steps
Integration with workflow service requires the following steps -
Create Workflow service - Create a class to transition the workflow object across its states. For this, create a class by the name of WorkflowService.java under the service directory and annotate it with @Service annotation.
Add the below content to this class -
Add workflow to BirthRegistrationService.
Add the below field to BirthRegistrationService.java
Transition the workflow - Modify the following methods in BirthRegistrationService.java as follows. Note that we are adding calls into the workflow service in each of these methods.
registerBtRequest
updateBtApplication
searchBtApplications
Configure application.properties - Add the following properties to application.properties file of the birth registration module. Depending on whether you are port forwarding or using the service directly on the host, please update the host name.
Run the workflow service locally - the application will call into it to create the necessary tables in the DB and effect the workflow transitions.
The birth registration module follows a simple workflow derived from the swimlane diagrams. Please check the section for correlation as well as the for info on how the workflow configuration is derived.
publicList<BirthRegistrationApplication>registerBtRequest(BirthRegistrationRequest birthRegistrationRequest) {// Validate applicationsvalidator.validateBirthApplication(birthRegistrationRequest);// Enrich applicationsenrichmentUtil.enrichBirthApplication(birthRegistrationRequest);// Enrich/Upsert user in upon birth registrationuserService.callUserService(birthRegistrationRequest);//// Initiate workflow for the new applicationworkflowService.updateWorkflowStatus(birthRegistrationRequest);// Push the application to the topic for persister to listen and persistproducer.push("save-bt-application", birthRegistrationRequest);// Return the response back to userreturnbirthRegistrationRequest.getBirthRegistrationApplications(); }
publicBirthRegistrationApplicationupdateBtApplication(BirthRegistrationRequest birthRegistrationRequest) {// Validate whether the application that is being requested for update indeed exists BirthRegistrationApplication existingApplication = validator.validateApplicationExistence(birthRegistrationRequest.getBirthRegistrationApplications().get(0));
existingApplication.setWorkflow(birthRegistrationRequest.getBirthRegistrationApplications().get(0).getWorkflow());
log.info(existingApplication.toString());birthRegistrationRequest.setBirthRegistrationApplications(Collections.singletonList(existingApplication));// Enrich application upon updateenrichmentUtil.enrichBirthApplicationUponUpdate(birthRegistrationRequest);workflowService.updateWorkflowStatus(birthRegistrationRequest);// Just like create request, update request will be handled asynchronously by the persisterproducer.push("update-bt-application", birthRegistrationRequest);returnbirthRegistrationRequest.getBirthRegistrationApplications().get(0); }
public List<BirthRegistrationApplication> searchBtApplications(RequestInfo requestInfo, BirthApplicationSearchCriteria birthApplicationSearchCriteria) {
// Fetch applications from database according to the given search criteria List<BirthRegistrationApplication> applications = birthRegistrationRepository.getApplications(birthApplicationSearchCriteria);
// If no applications are found matching the given criteria, return an empty listif(CollectionUtils.isEmpty(applications))returnnewArrayList<>();// Enrich mother and father of applicant objectsapplications.forEach(application -> {enrichmentUtil.enrichFatherApplicantOnSearch(application);enrichmentUtil.enrichMotherApplicantOnSearch(application); });// Otherwise return the found applicationsreturn applications; }