/
Integration with MDMS service

Integration with MDMS service

a. Integration with MDMS - Integration with MDMS requires the following steps to be followed:

i) Add a new MDMS file in MDMS repo. For this guide, a sample MDMS file has already been added which can be found here - https://github.com/egovernments/egov-mdms-data/blob/DEV/data/pb/DIGIT-DEVELOPER-TUTORIAL/VtrCharges.json

ii) Restart MDMS service after adding the new file.

iii) Once restarted, hit the curl mentioned below to verify that the new file has been properly added -

curl --location --request POST 'https://dev.digit.org/egov-mdms-service/v1/_search' \ --header 'Content-Type: application/json' \ --data-raw '{ "RequestInfo": { "apiId": "asset-services", "ver": null, "ts": null, "action": null, "did": null, "key": null, "msgId": "search with from and to values", "authToken": "{{devAuth}}" }, "MdmsCriteria": { "tenantId": "pb", "moduleDetails": [ { "moduleName": "VTR", "masterDetails": [ { "name": "RegistrationCharges" } ] } ] } }'

iv) Once verified, we can call mdms service from within our application and fetch the required master data. For this, create a java class by the name of MdmsUtil under utils folder. Annotate this class with @Component and put the following content in the class -

@Autowired private RestTemplate restTemplate; @Value("${egov.mdms.host}") private String mdmsHost; @Value("${egov.mdms.search.endpoint}") private String mdmsUrl; public Integer fetchRegistrationChargesFromMdms(RequestInfo requestInfo, String tenantId) { StringBuilder uri = new StringBuilder(); uri.append(mdmsHost).append(mdmsUrl); MdmsCriteriaReq mdmsCriteriaReq = getMdmsRequestForCategoryList(requestInfo, tenantId); Object response = new HashMap<>(); Integer rate = 0; try { response = restTemplate.postForObject(uri.toString(), mdmsCriteriaReq, Map.class); rate = JsonPath.read(response, "$.MdmsRes.VTR.RegistrationCharges.[0].amount"); }catch(Exception e) { log.error("Exception occurred while fetching category lists from mdms: ",e); } return rate; } private MdmsCriteriaReq getMdmsRequestForCategoryList(RequestInfo requestInfo, String tenantId) { MasterDetail masterDetail = new MasterDetail(); masterDetail.setName("RegistrationCharges"); List<MasterDetail> masterDetailList = new ArrayList<>(); masterDetailList.add(masterDetail); ModuleDetail moduleDetail = new ModuleDetail(); moduleDetail.setMasterDetails(masterDetailList); moduleDetail.setModuleName("VTR"); List<ModuleDetail> moduleDetailList = new ArrayList<>(); moduleDetailList.add(moduleDetail); MdmsCriteria mdmsCriteria = new MdmsCriteria(); mdmsCriteria.setTenantId(tenantId.split("\\.")[0]); mdmsCriteria.setModuleDetails(moduleDetailList); MdmsCriteriaReq mdmsCriteriaReq = new MdmsCriteriaReq(); mdmsCriteriaReq.setMdmsCriteria(mdmsCriteria); mdmsCriteriaReq.setRequestInfo(requestInfo); return mdmsCriteriaReq; }

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

#mdms urls egov.mdms.host=https://dev.digit.org egov.mdms.search.endpoint=/egov-mdms-service/v1/_search

Related content

Adding MDMS data
Adding MDMS data
More like this
Integration with IdGen Service
Integration with IdGen Service
Read with this
MDMS Overview
MDMS Overview
More like this
Adding workflow configuration
Adding workflow configuration
Read with this
Integration with other microservices
Integration with other microservices
Read with this