The birth registration module follows a simple workflow derived from the swimlane diagrams. Please check the design inputs section for correlation as well as the design guide for info on how the workflow configuration is derived.
Steps
Integration with workflow service requires the following steps -
Add a workflow object to BirthRegistrationApplication POJO (this may already exist. Do not add if it exists already).
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.
public List<BirthRegistrationApplication> registerBtRequest(BirthRegistrationRequest birthRegistrationRequest) {
birthApplicationValidator.validateBirthApplication(birthRegistrationRequest);
birthApplicationEnrichment.enrichBirthApplication(birthRegistrationRequest);
// Enrich/Upsert user in upon birth registration
userService.callUserService(birthRegistrationRequest);
// WORKFLOW INTEGRATION HERE: Initiate workflow for the new application
workflowService.updateWorkflowStatus(birthRegistrationRequest);
// Push the application to the topic for persister to listen and persist
producer.push(configuration.getCreateTopic(), birthRegistrationRequest);
// Return the response back to user
return birthRegistrationRequest.getBirthRegistrationApplications();
}Java
public List<BirthRegistrationApplication> updateBtApplication(BirthRegistrationRequest birthRegistrationRequest) {
// Validate whether the application that is being requested for update indeed exists
List<BirthRegistrationApplication> existingApplication = birthApplicationValidator.validateApplicationUpdateRequest(birthRegistrationRequest);
// Enrich application upon update
birthApplicationEnrichment.enrichBirthApplicationUponUpdate(birthRegistrationRequest);
//Workflow integration
workflowService.updateWorkflowStatus(birthRegistrationRequest);
// Just like create request, update request will be handled asynchronously by the persister
producer.push(configuration.getUpdateTopic(), birthRegistrationRequest);
return birthRegistrationRequest.getBirthRegistrationApplications();
}
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 list
if(CollectionUtils.isEmpty(applications))
return new ArrayList<>();
// Enrich mother and father of applicant objects
applications.forEach(application -> {
birthApplicationEnrichment.enrichFatherApplicantOnSearch(application);
birthApplicationEnrichment.enrichMotherApplicantOnSearch(application);
});
//WORKFLOW INTEGRATION
applications.forEach(application -> {
application.setWorkflow(Workflow.builder().status(workflowService.getCurrentWorkflow(requestInfo, application.getTenantId(), application.getApplicationNumber()).getState().getState()).build());
});
// Otherwise, return the found applications
return applications;
}