-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pfm 1419 user search #610
Pfm 1419 user search #610
Changes from all commits
bc3c95a
d8efbbe
38c64d2
a83165e
28aaa5d
80d93b6
30fb7f9
a7dc60b
b5fadc0
48088cc
35cf7c8
17cf93f
15a5995
8c5c9b3
e426c46
5f4efbe
a62c7a5
dd2d07b
6865753
3aa9929
394b66b
4b62b2d
5cd4320
489f99f
ef09429
95588ec
70674cf
11d9bd4
11e5284
562d975
022ad7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ | |
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.CollectionUtils; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
import java.util.*; | ||
import java.util.function.Function; | ||
|
@@ -149,6 +150,11 @@ public EmployeeResponse search(EmployeeSearchCriteria criteria, RequestInfo requ | |
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_MOBILENO,criteria.getPhone()); | ||
if( !CollectionUtils.isEmpty(criteria.getRoles()) ) | ||
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_ROLECODES,criteria.getRoles()); | ||
if(!ObjectUtils.isEmpty(criteria.isStateLevelSearch)) | ||
userSearchCriteria.put(HRMSConstants.HRMS_IS_STATE_LEVEL_SEARCH_CODE, criteria.getIsStateLevelSearch()); | ||
if(!ObjectUtils.isEmpty(criteria.getIsActive())) | ||
userSearchCriteria.put(HRMSConstants.HRMS_IS_ACTIVE_SEARCH_CODE, criteria.getIsActive()); | ||
|
||
UserResponse userResponse = userService.getUser(requestInfo, userSearchCriteria); | ||
userChecked =true; | ||
if(!CollectionUtils.isEmpty(userResponse.getUser())) { | ||
|
@@ -228,7 +234,6 @@ private void createUser(Employee employee, RequestInfo requestInfo) { | |
employee.getUser().setUuid(user.getUuid()); | ||
}catch(Exception e) { | ||
log.error("Exception while creating user: ",e); | ||
log.error("request: "+request); | ||
throw new CustomException(ErrorConstants.HRMS_USER_CREATION_FAILED_CODE, ErrorConstants.HRMS_USER_CREATION_FAILED_MSG); | ||
} | ||
|
||
|
@@ -245,6 +250,7 @@ private void enrichUser(Employee employee) { | |
pwdParams.add(employee.getUser().getMobileNumber()); | ||
pwdParams.add(employee.getTenantId()); | ||
pwdParams.add(employee.getUser().getName().toUpperCase()); | ||
//TODO:Add localition of sms and add template to register SMS | ||
employee.getUser().setPassword(hrmsUtils.generatePassword(pwdParams)); | ||
employee.getUser().setUserName(employee.getCode()); | ||
employee.getUser().setActive(true); | ||
|
@@ -354,7 +360,6 @@ private void updateUser(Employee employee, RequestInfo requestInfo) { | |
userService.updateUser(request); | ||
}catch(Exception e) { | ||
log.error("Exception while updating user: ",e); | ||
log.error("request: "+request); | ||
throw new CustomException(ErrorConstants.HRMS_USER_UPDATION_FAILED_CODE, ErrorConstants.HRMS_USER_UPDATION_FAILED_MSG); | ||
} | ||
|
||
|
@@ -561,4 +566,77 @@ public Map<String,Object> getEmployeeCountResponse(RequestInfo requestInfo, Stri | |
return response; | ||
} | ||
|
||
public Map<String,Object> getEmployeeCountResponseV1(RequestInfo requestInfo, List<String> roles, String tenantId, boolean isStateLevelSearch){ | ||
EmployeeSearchCriteria activeEmployeeCriteria= EmployeeSearchCriteria.builder().roles(roles).tenantId(tenantId).isStateLevelSearch(isStateLevelSearch).isActive(true).build(); | ||
EmployeeResponse activeEmployeeResponse = search(activeEmployeeCriteria, requestInfo); | ||
EmployeeSearchCriteria inActiveEmployeeCriteria= EmployeeSearchCriteria.builder().roles(roles).tenantId(tenantId).isStateLevelSearch(isStateLevelSearch).isActive(false).build(); | ||
EmployeeResponse inActiveEmployeeResponse = search(inActiveEmployeeCriteria, requestInfo); | ||
Integer activeEmployeeCount= activeEmployeeResponse.getEmployees().size(); | ||
Integer inActiveEmployeeCount = inActiveEmployeeResponse.getEmployees().size(); | ||
Integer totalcount = activeEmployeeCount + inActiveEmployeeCount; | ||
Map<String,String> results = new HashMap<>(); | ||
Map<String,Object> response = new HashMap<>(); | ||
ResponseInfo responseInfo = factory.createResponseInfoFromRequestInfo(requestInfo, true); | ||
|
||
response.put("ResponseInfo",responseInfo); | ||
|
||
if(totalcount == 0){ | ||
Map<String,String> error = new HashMap<>(); | ||
error.put("NO_RECORDS","No records found for the tenantId: "+tenantId); | ||
throw new CustomException(error); | ||
} | ||
results.put("totalEmployee",totalcount.toString()); | ||
results.put("activeEmployee",activeEmployeeCount.toString()); | ||
results.put("inactiveEmployee",inActiveEmployeeCount.toString()); | ||
|
||
response.put("EmployeCount",results); | ||
return response; | ||
} | ||
Comment on lines
+569
to
+594
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
public EmployeeResponse searchListOfEmployee(EmployeeSearchCriteria criteria, RequestInfo requestInfo) { | ||
boolean userChecked = false; | ||
/*if(null == criteria.getIsActive() || criteria.getIsActive()) | ||
criteria.setIsActive(true); | ||
else | ||
criteria.setIsActive(false);*/ | ||
Map<String, User> mapOfUsers = new HashMap<String, User>(); | ||
if((!CollectionUtils.isEmpty(criteria.getRoles())) && !CollectionUtils.isEmpty(criteria.getTenantIds())) { | ||
Map<String, Object> userSearchCriteria = new HashMap<>(); | ||
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_TENANTIDS,criteria.getTenantIds()); | ||
if( !CollectionUtils.isEmpty(criteria.getRoles()) ) | ||
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_ROLECODES,criteria.getRoles()); | ||
UserResponse userResponse = userService.getUserByTenantids(requestInfo, userSearchCriteria); | ||
userChecked =true; | ||
if(!CollectionUtils.isEmpty(userResponse.getUser())) { | ||
mapOfUsers.putAll(userResponse.getUser().stream() | ||
.collect(Collectors.toMap(User::getUuid, Function.identity()))); | ||
} | ||
List<String> userUUIDs = userResponse.getUser().stream().map(User :: getUuid).collect(Collectors.toList()); | ||
if(!CollectionUtils.isEmpty(criteria.getUuids())) | ||
criteria.setUuids(criteria.getUuids().stream().filter(userUUIDs::contains).collect(Collectors.toList())); | ||
else | ||
criteria.setUuids(userUUIDs); | ||
} | ||
//checks if above criteria met and result is not null will check for name search if list of names are given as user search on name is not bulk api | ||
List <Employee> employees = new ArrayList<>(); | ||
employees = repository.fetchEmployees(criteria, requestInfo); | ||
List<String> uuids = employees.stream().map(Employee :: getUuid).collect(Collectors.toList()); | ||
if(!CollectionUtils.isEmpty(uuids)){ | ||
Map<String, Object> UserSearchCriteria = new HashMap<>(); | ||
UserSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_UUID,uuids); | ||
if(mapOfUsers.isEmpty()){ | ||
UserResponse userResponse = userService.getUser(requestInfo, UserSearchCriteria); | ||
if(!CollectionUtils.isEmpty(userResponse.getUser())) { | ||
mapOfUsers = userResponse.getUser().stream() | ||
.collect(Collectors.toMap(User :: getUuid, Function.identity())); | ||
} | ||
} | ||
for(Employee employee: employees){ | ||
employee.setUser(mapOfUsers.get(employee.getUuid())); | ||
} | ||
} | ||
return EmployeeResponse.builder().responseInfo(factory.createResponseInfoFromRequestInfo(requestInfo, true)) | ||
.employees(employees).build(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.egov.hrms.web.contract; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.egov.common.contract.request.RequestInfo; | ||
import org.egov.hrms.model.Employee; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
@Validated | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class EmployeeSearchByTenantRequestWrapper { | ||
@NotNull | ||
@JsonProperty("RequestInfo") | ||
private RequestInfo requestInfo; | ||
|
||
@Valid | ||
@JsonProperty("criteria") | ||
private EmployeeSearchCriteria criteria; | ||
|
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,12 @@ public class EmployeeSearchCriteria { | |
|
||
public Boolean isActive; | ||
|
||
public Boolean isStateLevelSearch; | ||
|
||
@Size(max = 250) | ||
public String tenantId; | ||
|
||
public List<String> tenantIds; | ||
Comment on lines
+50
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of @NotNull
public Boolean isStateLevelSearch;
@NotEmpty
public List<String> tenantIds; |
||
|
||
public String phone; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,10 +43,7 @@ | |
import lombok.extern.slf4j.Slf4j; | ||
import org.egov.common.contract.request.RequestInfo; | ||
import org.egov.hrms.service.EmployeeService; | ||
import org.egov.hrms.web.contract.EmployeeRequest; | ||
import org.egov.hrms.web.contract.EmployeeResponse; | ||
import org.egov.hrms.web.contract.EmployeeSearchCriteria; | ||
import org.egov.hrms.web.contract.RequestInfoWrapper; | ||
import org.egov.hrms.web.contract.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using wildcard imports ( |
||
import org.egov.hrms.web.validator.EmployeeValidator; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
|
@@ -56,6 +53,7 @@ | |
|
||
import javax.validation.Valid; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
|
@@ -120,6 +118,14 @@ public ResponseEntity<?> search(@RequestBody @Valid RequestInfoWrapper requestIn | |
return new ResponseEntity<>(employeeResponse,HttpStatus.OK); | ||
} | ||
|
||
@PostMapping(value = "/_searchListOfEmployee") | ||
@ResponseBody | ||
public ResponseEntity<?> _searchListOfEmployee(@RequestBody @Valid EmployeeSearchByTenantRequestWrapper employeeSearchByTenantRequestWrapper) { | ||
EmployeeResponse employeeResponse = employeeService.searchListOfEmployee(employeeSearchByTenantRequestWrapper.getCriteria(), employeeSearchByTenantRequestWrapper.getRequestInfo()); | ||
return new ResponseEntity<>(employeeResponse,HttpStatus.OK); | ||
} | ||
|
||
|
||
@PostMapping("_count") | ||
@ResponseBody | ||
private ResponseEntity<?> count(@RequestParam("tenantId") String tenantId, @RequestBody RequestInfo requestInfo) { | ||
|
@@ -130,5 +136,15 @@ private ResponseEntity<?> count(@RequestParam("tenantId") String tenantId, @Requ | |
return new ResponseEntity<>(response,HttpStatus.OK); | ||
} | ||
|
||
@PostMapping("v1/_count") | ||
@ResponseBody | ||
private ResponseEntity<?> countV1(@RequestParam("tenantId") String tenantId, @RequestParam("roles") List<String> roles , @RequestParam("isStateLevelSearch") boolean isStateLevelSearch, @RequestBody RequestInfo requestInfo) { | ||
|
||
Map<String,Object> response = new HashMap<>(); | ||
validator.validateEmployeeCountRequest(tenantId); | ||
response = employeeService.getEmployeeCountResponseV1(requestInfo,roles,tenantId,isStateLevelSearch); | ||
return new ResponseEntity<>(response,HttpStatus.OK); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,7 +234,7 @@ private void validateMdmsData(Employee employee, Map<String, String> errorMap, M | |
validateEmployee(employee, errorMap, mdmsData); | ||
validateAssignments(employee, errorMap, mdmsData); | ||
validateServiceHistory(employee, errorMap, mdmsData); | ||
validateJurisdicton(employee, errorMap, mdmsData, boundaryMap); | ||
//validateJurisdicton(employee, errorMap, mdmsData, boundaryMap); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commenting out the call to |
||
validateEducationalDetails(employee, errorMap, mdmsData); | ||
validateDepartmentalTest(employee, errorMap, mdmsData); | ||
} | ||
|
@@ -251,7 +251,7 @@ private void validateMdmsData(Employee employee, Map<String, String> errorMap, M | |
public void validateDataConsistency(Employee employee, Map<String, String> errorMap, Map<String, List<String>> mdmsData, Employee existingEmp, RequestInfo requestInfo) { | ||
validateUserData(existingEmp,employee,errorMap, requestInfo); | ||
validateConsistencyAssignment(existingEmp,employee,errorMap); | ||
validateConsistencyJurisdiction(existingEmp,employee,errorMap); | ||
//validateConsistencyJurisdiction(existingEmp,employee,errorMap); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, commenting out the call to |
||
validateConsistencyDepartmentalTest(existingEmp,employee,errorMap); | ||
validateConsistencyEducationalDetails(existingEmp,employee,errorMap); | ||
validateConsistencyServiceHistory(existingEmp, employee, errorMap); | ||
|
@@ -465,12 +465,15 @@ private void validateJurisdicton(Employee employee, Map<String, String> errorMap | |
List<String> hierarchyTypes = JsonPath.read(boundaryMap,hierarchy_type_path); | ||
List <String> boundaryTypes = JsonPath.read(boundaryMap,boundary_type_path); | ||
List <String> boundaryValues = JsonPath.read(boundaryMap,boundary_value_path); | ||
if(!hierarchyTypes.contains(jurisdiction.getHierarchy())) | ||
if(!hierarchyTypes.contains(jurisdiction.getHierarchy())) { | ||
errorMap.put(ErrorConstants.HRMS_INVALID_JURISDICTION_HEIRARCHY_CODE, ErrorConstants.HRMS_INVALID_JURISDICTION_HEIRARCHY_MSG); | ||
if(!boundaryTypes.contains(jurisdiction.getBoundaryType())) | ||
} | ||
if(!boundaryTypes.contains(jurisdiction.getBoundaryType())) { | ||
errorMap.put(ErrorConstants.HRMS_INVALID_JURISDICTION_BOUNDARY_TYPE_CODE, ErrorConstants.HRMS_INVALID_JURISDICTION_BOUNDARY_TYPE_MSG); | ||
if(!boundaryValues.contains(jurisdiction.getBoundary())) | ||
} | ||
if(!boundaryValues.contains(jurisdiction.getBoundary())) { | ||
errorMap.put(ErrorConstants.HRMS_INVALID_JURISDICTION_BOUNDARY_CODE, ErrorConstants.HRMS_INVALID_JURISDICTION_BOUNDARY_MSG); | ||
} | ||
Comment on lines
+468
to
+476
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The adjustments within the Consider revising the approach to jurisdiction validation to ensure it is both efficient and comprehensive, covering all necessary boundary and hierarchy checks without introducing performance bottlenecks. |
||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of checks for
isStateLevelSearch
andisActive
in the search criteria is crucial for supporting the new search functionalities. However, ensure that theObjectUtils.isEmpty
method is correctly used to check fornull
or default values, as it might not be the most intuitive choice for boolean fields. Consider using more explicit checks for boolean fields to improve code readability.Committable suggestion