Integration with IdGen Service

b. Integration with IdGen - Integration with Idgen requires the following steps -

i) Add the Id Format that needs to be generated in this file - Id Format Mdms File

ii) For this tutorial, the following Id format has been added as part of this PR - Tutorial Id Format

iii) Now, restart IDGen service and Mdms service and port-forward IDGen service to port 8285 using -

kubectl port-forward <IDGEN_SERVICE_POD_NAME> 8285:8080

iv) Hit the following curl to verify that the format is added properly -

curl --location --request POST 'http://localhost:8285/egov-idgen/id/_generate' \ --header 'Content-Type: application/json' \ --data-raw '{ "RequestInfo": { "apiId": "string", "ver": "string", "ts": null, "action": "string", "did": "string", "key": "string", "msgId": "string", "authToken": "6456b2cf-49ca-47c7-b7b6-c179f19614c7", "correlationId": "e721639b-c095-40b3-86e2-acecb2cb6efb", "userInfo": { "id": 23299, "uuid": "e721639b-c095-40b3-86e2-acecb2cb6efb", "userName": "9337682030", "name": "Abhilash Seth", "type": "EMPLOYEE", "mobileNumber": "9337682030", "emailId": "abhilash.seth@gmail.com", "roles": [ { "id": 281, "name": "Employee" } ] } }, "idRequests": [ { "tenantId": "pb.amritsar", "idName": "vtr.registrationid" } ] }'

v) Once verified, we can call idgen service from within our application and generate registrationId. For this, create a java class by the name of IdgenUtil under utils folder. Annotate this class with @Component and put the following content in the class -

@Component public class IdgenUtil { @Value("${egov.idgen.host}") private String idGenHost; @Value("${egov.idgen.path}") private String idGenPath; @Autowired private ObjectMapper mapper; @Autowired private ServiceRequestRepository restRepo; public List<String> getIdList(RequestInfo requestInfo, String tenantId, String idName, String idformat, Integer count) { List<IdRequest> reqList = new ArrayList<>(); for (int i = 0; i < count; i++) { reqList.add(IdRequest.builder().idName(idName).format(idformat).tenantId(tenantId).build()); } IdGenerationRequest request = IdGenerationRequest.builder().idRequests(reqList).requestInfo(requestInfo).build(); StringBuilder uri = new StringBuilder(idGenHost).append(idGenPath); IdGenerationResponse response = mapper.convertValue(restRepo.fetchResult(uri, request), IdGenerationResponse.class); List<IdResponse> idResponses = response.getIdResponses(); if (CollectionUtils.isEmpty(idResponses)) throw new CustomException("IDGEN ERROR", "No ids returned from idgen Service"); return idResponses.stream().map(IdResponse::getId).collect(Collectors.toList()); } }

Add the following model POJOs under models folder -

vi) Add the following properties in application.properties file -