Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #881 from palak-egov/hrms-fuzzy
Browse files Browse the repository at this point in the history
adding user data
  • Loading branch information
debasishchakraborty-egovt authored Aug 6, 2024
2 parents e24ea4f + bc093ed commit 3915763
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +34,11 @@ public class FuzzySearchService {
private EmployeeRepository employeeRepository;
@Autowired
private PropertiesManager config;
@Autowired
private UserService userService;
@Autowired
private HRMSUtils hrmsUtils;


public List<Employee> getEmployees(RequestInfo requestInfo, EmployeeSearchCriteria criteria) {

Expand Down Expand Up @@ -54,7 +66,13 @@ public List<Employee> getEmployees(RequestInfo requestInfo, EmployeeSearchCriter
EmployeeSearchCriteria employeeSearchCriteria = EmployeeSearchCriteria.builder().tenantId(tenantId).codes(empList).build();

employees.addAll(employeeRepository.fetchEmployees(employeeSearchCriteria, requestInfo));

Set<String> uuids = employees.stream().map(Employee::getUuid).collect(Collectors.toSet());
Map<String,Object> map = new HashMap<>();
map.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_UUID,uuids);
UserResponse userResponse = userService.getUser(requestInfo, map);
log.info("userResponse {}",userResponse);
List<User> users = userResponse.getUser();
hrmsUtils.enrichOwner(users, employees);
}

return employees;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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<User> users, List<Employee> employees) {

Map<String, User> 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);
}
});
}
}

0 comments on commit 3915763

Please sign in to comment.