diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/FuzzySearchService.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/FuzzySearchService.java index b2cfc027c..e8e464343 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/FuzzySearchService.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/FuzzySearchService.java @@ -2,21 +2,28 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.JsonPath; +import lombok.extern.slf4j.Slf4j; import org.egov.common.contract.request.RequestInfo; import org.egov.hrms.config.PropertiesManager; import org.egov.hrms.model.Employee; import org.egov.hrms.repository.ElasticSearchRepository; import org.egov.hrms.repository.EmployeeRepository; +import org.egov.hrms.utils.HRMSConstants; +import org.egov.hrms.utils.HRMSUtils; import org.egov.hrms.web.contract.EmployeeSearchCriteria; +import org.egov.hrms.web.contract.User; +import org.egov.hrms.web.contract.UserResponse; import org.egov.tracer.model.CustomException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.stream.Collectors; import static org.egov.hrms.utils.HRMSConstants.ES_DATA_PATH; +@Slf4j @Service public class FuzzySearchService { @Autowired @@ -27,6 +34,11 @@ public class FuzzySearchService { private EmployeeRepository employeeRepository; @Autowired private PropertiesManager config; + @Autowired + private UserService userService; + @Autowired + private HRMSUtils hrmsUtils; + public List getEmployees(RequestInfo requestInfo, EmployeeSearchCriteria criteria) { @@ -54,7 +66,13 @@ public List getEmployees(RequestInfo requestInfo, EmployeeSearchCriter EmployeeSearchCriteria employeeSearchCriteria = EmployeeSearchCriteria.builder().tenantId(tenantId).codes(empList).build(); employees.addAll(employeeRepository.fetchEmployees(employeeSearchCriteria, requestInfo)); - + Set uuids = employees.stream().map(Employee::getUuid).collect(Collectors.toSet()); + Map map = new HashMap<>(); + map.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_UUID,uuids); + UserResponse userResponse = userService.getUser(requestInfo, map); + log.info("userResponse {}",userResponse); + List users = userResponse.getUser(); + hrmsUtils.enrichOwner(users, employees); } return employees; diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSUtils.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSUtils.java index d9a9f1c8f..64e768b7f 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSUtils.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSUtils.java @@ -1,14 +1,20 @@ package org.egov.hrms.utils; import java.security.SecureRandom; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Random; +import lombok.extern.slf4j.Slf4j; +import org.egov.hrms.model.Employee; import org.egov.hrms.web.contract.EmployeeSearchCriteria; +import org.egov.hrms.web.contract.User; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +@Slf4j @Service public class HRMSUtils { @@ -61,4 +67,19 @@ public boolean isAssignmentSearchReqd(EmployeeSearchCriteria criteria) { return (! CollectionUtils.isEmpty(criteria.getPositions()) || null != criteria.getAsOnDate() || !CollectionUtils.isEmpty(criteria.getDepartments()) || !CollectionUtils.isEmpty(criteria.getDesignations())); } + + public void enrichOwner(List users, List employees) { + + Map uuidToUserMap = new HashMap<>(); + users.forEach(user -> uuidToUserMap.put(user.getUuid(), user)); + + employees.forEach(employee -> { + User user = uuidToUserMap.get(employee.getUuid()); + if (user == null) { + log.info("USER SEARCH ERROR: The user with UUID : \"" + employee.getUuid() + "\" for the employee with Id \"" + employee.getId() + "\" is not present in user search response"); + } else { + employee.setUser(user); + } + }); + } }