The user service provides the capabilities of creating a user, searching for a user and retrieving the details of a user. This module will search for a user and if not found, create that user with the user service.
DIGIT's user service masks PII that gets stored in the database using the encryption service.
Steps
Create the following POJOs under the model directory:
Create a class by the name of UserService under service folder and add the following content to it:
UserService.java
Changes to BirthApplicationEnrichment.java
Add the below methods to the enrichment class we created. When we search for an application, the code below will search for the users associated with the application and add in their details to the response object.
enrichFatherApplicantOnSearch
Changes to BirthRegistrationService.java
Add in a userService object:
And enhance the following two methods in BirthRegistrationService.java:
registerBtRequestsearchBtApplications
Add the following properties in application.properties file:
Note that if you are port-forwarding using k8s, you will use localhost. Else, if you have a valid auth token, please provide the name of the host here.
public List<BirthRegistrationApplication> registerBtRequest(BirthRegistrationRequest birthRegistrationRequest) {
birthApplicationValidator.validateBirthApplication(birthRegistrationRequest);
birthApplicationEnrichment.enrichBirthApplication(birthRegistrationRequest);
// Enrich/Upsert user in upon birth registration
userService.callUserService(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();
}
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);
});
// Otherwise, return the found applications
return applications;
}