Skip to content

Commit

Permalink
Merge pull request #292 from odisha-muktasoft/PFM-4646
Browse files Browse the repository at this point in the history
Updated code for TE SMS
  • Loading branch information
manastanmay-eGov authored Mar 13, 2024
2 parents d934105 + 4cae2a0 commit 3cbd1e2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -140,8 +142,18 @@ private void pushNotificationToOriginator (ContractRequest request, String messa
List<Contract> 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<String,String> officerInChargeMobileNumberMap =hrmsUtils.getEmployeeDetailsByUuid(request.getRequestInfo(), request.getContract().getTenantId(),officerInChargeUuid);
ObjectMapper objectMapper = new ObjectMapper();
String officerInchargeCode = null;
try{
Map<String, Object> addtionalDetailsMap = objectMapper.convertValue(originalContractFromDB.getAdditionalDetails(), Map.class);
if (addtionalDetailsMap.containsKey("officerInChargeName")) {
Map<String, String> officerInChargeNameMap = (Map<String, String>) addtionalDetailsMap.get("officerInChargeName");
officerInchargeCode = officerInChargeNameMap.get("code");
}
}catch (Exception e){
throw new CustomException("OFFICER_INCHARGE_NOT_FOUND","Failed tp fetch officerInCharge details");
}
Map<String,String> officerInChargeMobileNumberMap =hrmsUtils.getEmployeeDetailsByCode(request.getRequestInfo(), request.getContract().getTenantId(),officerInchargeCode);
String officerInChargeMobileNumber = officerInChargeMobileNumberMap.get(MOBILE_NUMBER);
Map<String, String> smsDetailsMap = new HashMap<>();

Expand Down
41 changes: 41 additions & 0 deletions backend/contracts/src/main/java/org/egov/works/util/HRMSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,7 @@ public List<String> getRoleCodesByEmployeeId(RequestInfo requestInfo, String ten
return roles;
}


public Map<String, String> getEmployeeDetailsByUuid(RequestInfo requestInfo, String tenantId, String uuid) {
StringBuilder url = getHRMSURIWithUUid(tenantId, uuid);

Expand Down Expand Up @@ -84,6 +86,34 @@ public Map<String, String> getEmployeeDetailsByUuid(RequestInfo requestInfo, Str
return userDetailsForSMS;
}

public Map<String, String> 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<String, String> userDetailsForSMS = new HashMap<>();
List<String> userNames = null;
List<String> mobileNumbers = null;
List<String> 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<String> employeeIds) {

StringBuilder builder = new StringBuilder(config.getHrmsHost());
Expand All @@ -95,6 +125,17 @@ private StringBuilder getHRMSURI(String tenantId, List<String> 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) {

Expand Down

0 comments on commit 3cbd1e2

Please sign in to comment.