diff --git a/backend/contracts/src/main/java/org/egov/works/service/NotificationService.java b/backend/contracts/src/main/java/org/egov/works/service/NotificationService.java index bae5419b91..d127f0ec4e 100644 --- a/backend/contracts/src/main/java/org/egov/works/service/NotificationService.java +++ b/backend/contracts/src/main/java/org/egov/works/service/NotificationService.java @@ -1,11 +1,13 @@ package org.egov.works.service; +import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.JsonPath; import digit.models.coremodels.RequestInfoWrapper; import digit.models.coremodels.SMSRequest; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.egov.common.contract.request.RequestInfo; +import org.egov.tracer.model.CustomException; import org.egov.works.config.ContractServiceConfiguration; import org.egov.works.kafka.ContractProducer; import org.egov.works.repository.ServiceRequestRepository; @@ -140,8 +142,18 @@ private void pushNotificationToOriginator (ContractRequest request, String messa List contractsFromDB = contractService.getContracts(contractCriteria); Contract originalContractFromDB = contractsFromDB.stream().filter(contract -> (contract.getBusinessService() != null && contract.getBusinessService().equalsIgnoreCase(CONTRACT_TIME_EXTENSION_BUSINESS_SERVICE))).collect(Collectors.toList()).get(0); log.info("Getting officer-in-charge for contract :: " + originalContractFromDB.getContractNumber()); - String officerInChargeUuid = originalContractFromDB.getAuditDetails().getCreatedBy(); - Map officerInChargeMobileNumberMap =hrmsUtils.getEmployeeDetailsByUuid(request.getRequestInfo(), request.getContract().getTenantId(),officerInChargeUuid); + ObjectMapper objectMapper = new ObjectMapper(); + String officerInchargeCode = null; + try{ + Map addtionalDetailsMap = objectMapper.convertValue(originalContractFromDB.getAdditionalDetails(), Map.class); + if (addtionalDetailsMap.containsKey("officerInChargeName")) { + Map officerInChargeNameMap = (Map) addtionalDetailsMap.get("officerInChargeName"); + officerInchargeCode = officerInChargeNameMap.get("code"); + } + }catch (Exception e){ + throw new CustomException("OFFICER_INCHARGE_NOT_FOUND","Failed tp fetch officerInCharge details"); + } + Map officerInChargeMobileNumberMap =hrmsUtils.getEmployeeDetailsByCode(request.getRequestInfo(), request.getContract().getTenantId(),officerInchargeCode); String officerInChargeMobileNumber = officerInChargeMobileNumberMap.get(MOBILE_NUMBER); Map smsDetailsMap = new HashMap<>(); diff --git a/backend/contracts/src/main/java/org/egov/works/util/HRMSUtils.java b/backend/contracts/src/main/java/org/egov/works/util/HRMSUtils.java index fc473336b1..afa80ba769 100644 --- a/backend/contracts/src/main/java/org/egov/works/util/HRMSUtils.java +++ b/backend/contracts/src/main/java/org/egov/works/util/HRMSUtils.java @@ -14,6 +14,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -56,6 +57,7 @@ public List getRoleCodesByEmployeeId(RequestInfo requestInfo, String ten return roles; } + public Map getEmployeeDetailsByUuid(RequestInfo requestInfo, String tenantId, String uuid) { StringBuilder url = getHRMSURIWithUUid(tenantId, uuid); @@ -84,6 +86,34 @@ public Map getEmployeeDetailsByUuid(RequestInfo requestInfo, Str return userDetailsForSMS; } + public Map getEmployeeDetailsByCode(RequestInfo requestInfo, String tenantId, String code) { + StringBuilder url = getHRMSURIWithCode(tenantId,code); + + RequestInfoWrapper requestInfoWrapper = RequestInfoWrapper.builder().requestInfo(requestInfo).build(); + + Object res = serviceRequestRepository.fetchResult(url, requestInfoWrapper); + + Map userDetailsForSMS = new HashMap<>(); + List userNames = null; + List mobileNumbers = null; + List designations=null; + + try { + designations = JsonPath.read(res, HRMS_USER_DESIGNATION); + userNames = JsonPath.read(res, HRMS_USER_USERNAME_CODE); + mobileNumbers = JsonPath.read(res, HRMS_USER_MOBILE_NO); + + } catch (Exception e) { + throw new CustomException("PARSING_ERROR", "Failed to parse HRMS response"); + } + + userDetailsForSMS.put("userName", userNames.get(0)); + userDetailsForSMS.put("mobileNumber", mobileNumbers.get(0)); + userDetailsForSMS.put("designation", designations.get(0)); + + return userDetailsForSMS; + } + private StringBuilder getHRMSURI(String tenantId, List employeeIds) { StringBuilder builder = new StringBuilder(config.getHrmsHost()); @@ -95,6 +125,17 @@ private StringBuilder getHRMSURI(String tenantId, List employeeIds) { return builder; } + private StringBuilder getHRMSURIWithCode(String tenantId, String code) { + + StringBuilder builder = new StringBuilder(config.getHrmsHost()); + builder.append(config.getHrmsEndPoint()); + builder.append("?tenantId="); + builder.append(tenantId); + builder.append("&codes="); + builder.append(code); + + return builder; + } private StringBuilder getHRMSURIWithUUid(String tenantId, String employeeUuid) {