diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java index 95c16873c..3b04dd0f8 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/config/PropertiesManager.java @@ -64,6 +64,10 @@ public class PropertiesManager { @Value("${egov.user.search.endpoint}") public String userSearchEndpoint; + + @Value("${egov.user.search.tenant.endpoint}") + public String userSearchByTenantEndpoint; + @Value("${egov.user.create.endpoint}") public String userCreateEndpoint; @@ -110,4 +114,7 @@ public class PropertiesManager { @Value("${state.level.tenant.id}") public String stateLevelTenantId; + + @Value("${sms.user.creation.enabled}") + public boolean isSMSForUserCreationEnable; } \ No newline at end of file diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/model/Employee.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/model/Employee.java index e75d2f8bb..291094387 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/model/Employee.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/model/Employee.java @@ -85,7 +85,7 @@ public class Employee { @Valid @NotEmpty - @Size(min = 1,max = 50) + @Size(min = 1,max = 5000) private List jurisdictions = new ArrayList<>(); @@ -132,4 +132,4 @@ public class Employee { private User user; -} \ No newline at end of file +} diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/model/SMSRequest.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/model/SMSRequest.java index 31c92e38e..730289fca 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/model/SMSRequest.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/model/SMSRequest.java @@ -15,5 +15,5 @@ public class SMSRequest { private String mobileNumber; private String message; - + private String tenantId; } diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java index 7126b3535..f75cf0cb9 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/EmployeeService.java @@ -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 getEmployeeCountResponse(RequestInfo requestInfo, Stri return response; } + public Map getEmployeeCountResponseV1(RequestInfo requestInfo, List 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 results = new HashMap<>(); + Map response = new HashMap<>(); + ResponseInfo responseInfo = factory.createResponseInfoFromRequestInfo(requestInfo, true); + + response.put("ResponseInfo",responseInfo); + + if(totalcount == 0){ + Map 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; + } + + public EmployeeResponse searchListOfEmployee(EmployeeSearchCriteria criteria, RequestInfo requestInfo) { + boolean userChecked = false; + /*if(null == criteria.getIsActive() || criteria.getIsActive()) + criteria.setIsActive(true); + else + criteria.setIsActive(false);*/ + Map mapOfUsers = new HashMap(); + if((!CollectionUtils.isEmpty(criteria.getRoles())) && !CollectionUtils.isEmpty(criteria.getTenantIds())) { + Map 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 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 employees = new ArrayList<>(); + employees = repository.fetchEmployees(criteria, requestInfo); + List uuids = employees.stream().map(Employee :: getUuid).collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(uuids)){ + Map 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(); + } + } \ No newline at end of file diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/NotificationService.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/NotificationService.java index 1168d41fb..9285e191b 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/NotificationService.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/NotificationService.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.egov.common.contract.request.RequestInfo; +import org.egov.hrms.config.PropertiesManager; import org.egov.hrms.model.Employee; import org.egov.hrms.model.SMSRequest; import org.egov.hrms.producer.HRMSProducer; @@ -35,6 +36,9 @@ public class NotificationService { @Autowired private RestTemplate restTemplate; + @Autowired + private PropertiesManager propertiesManager; + @Value("${kafka.topics.notification.sms}") private String smsTopic; @@ -57,7 +61,6 @@ public class NotificationService { private String envHost; - /** * Sends notification by putting the sms content onto the core-sms topic * @@ -65,15 +68,18 @@ public class NotificationService { * @param pwdMap */ public void sendNotification(EmployeeRequest request, Map pwdMap) { - String message = getMessage(request,HRMSConstants.HRMS_EMP_CREATE_LOCLZN_CODE); + String message = getMessage(request,HRMSConstants.ON_BOARD_EMPLOYEE); if(StringUtils.isEmpty(message)) { log.info("SMS content has not been configured for this case"); return; } for(Employee employee: request.getEmployees()) { message = buildMessage(employee, message, pwdMap); - SMSRequest smsRequest = SMSRequest.builder().mobileNumber(employee.getUser().getMobileNumber()).message(message).build(); - producer.push(smsTopic, smsRequest); + SMSRequest smsRequest = SMSRequest.builder().mobileNumber(employee.getUser().getMobileNumber()).message(message).tenantId(employee.getTenantId()).build(); + if(propertiesManager.isSMSForUserCreationEnable()) + { + producer.push(smsTopic, smsRequest); + } } } @@ -149,9 +155,14 @@ public String getMessage(EmployeeRequest request,String msgCode) { * @return */ public String buildMessage(Employee employee, String message, Map pwdMap) { - message = message.replace("$username", employee.getCode()).replace("$password", pwdMap.get(employee.getUuid())) - .replace("$employeename", employee.getUser().getName()); - message = message.replace("$applink", appLink); +// message = message.replace("$username", employee.getCode()).replace("$password", pwdMap.get(employee.getUuid())) +// .replace("$employeename", employee.getUser().getName()); +// message = message.replace("$applink", appLink); + message=message.replace("{USER}", employee.getUser().getName()); + message=message.replace("{LINK}",appLink); + message=message.replace("{PHNO}",employee.getUser().getMobileNumber()); + message=message.replace("{PASSWORD}",pwdMap.get(employee.getUuid())); + log.info("Message send to user at time of onboard "+message); return message; } diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/UserService.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/UserService.java index 3cd3a8e0e..f367601e1 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/service/UserService.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/service/UserService.java @@ -78,6 +78,9 @@ public class UserService { @Value("${egov.user.search.endpoint}") private String userSearchEndpoint; + @Value("${egov.user.search.tenant.endpoint}") + private String userSearchByTenantEndpoint; + @Value("${egov.user.update.endpoint}") private String userUpdateEndpoint; @@ -124,6 +127,23 @@ public UserResponse getUser(RequestInfo requestInfo, Map UserSea return userResponse; } + public UserResponse getUserByTenantids(RequestInfo requestInfo, Map UserSearchCriteria ) { + StringBuilder uri = new StringBuilder(); + Map userSearchReq = new HashMap<>(); + userSearchReq.put("RequestInfo", requestInfo); + userSearchReq.put(HRMSConstants.HRMS_USER_SERACH_CRITERIA_USERTYPE_CODE,HRMSConstants.HRMS_USER_SERACH_CRITERIA_USERTYPE); + for( String key: UserSearchCriteria.keySet()) + userSearchReq.put(key, UserSearchCriteria.get(key)); + uri.append(propertiesManager.getUserHost()).append(propertiesManager.getUserSearchByTenantEndpoint()); + UserResponse userResponse = new UserResponse(); + try { + userResponse = userCall(userSearchReq,uri); + }catch(Exception e) { + log.error("User search failed: ",e); + } + + return userResponse; + } /** @@ -135,7 +155,7 @@ public UserResponse getUser(RequestInfo requestInfo, Map UserSea @SuppressWarnings("all") private UserResponse userCall(Object userRequest, StringBuilder uri) { String dobFormat = null; - if(uri.toString().contains(userSearchEndpoint) || uri.toString().contains(userUpdateEndpoint)) + if(uri.toString().contains(userSearchEndpoint) || uri.toString().contains(userUpdateEndpoint) || uri.toString().contains(userSearchByTenantEndpoint)) dobFormat="yyyy-MM-dd"; else if(uri.toString().contains(userCreateEndpoint)) dobFormat = "dd/MM/yyyy"; @@ -192,4 +212,4 @@ private Long dateTolong(String date,String format){ } -} \ No newline at end of file +} diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSConstants.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSConstants.java index a0643ba7c..645f6f288 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSConstants.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/utils/HRMSConstants.java @@ -9,6 +9,10 @@ public class HRMSConstants { public static final String HRMS_MDMS_HR_MASTERS_CODE = "egov-hrms"; public static final String HRMS_AC_ROLES_MASTERS_CODE = "ACCESSCONTROL-ROLES"; public static final String HRMS_MDMS_EGOV_LOCATION_MASTERS_CODE = "egov-location"; + + public static final String HRMS_IS_STATE_LEVEL_SEARCH_CODE = "isStateLevelSearch"; + + public static final String HRMS_IS_ACTIVE_SEARCH_CODE="active"; public static final String HRMS_MDMS_DEPT_CODE = "Department"; public static final String HRMS_MDMS_DESG_CODE = "Designation"; @@ -28,6 +32,7 @@ public class HRMSConstants { public static final String HRMS_EMP_CREATE_LOCLZN_CODE = "hrms.employee.create.notification"; + public static final String ON_BOARD_EMPLOYEE ="SMS_ON_BOARD_EMPLOYEE"; public static final String HRMS_EMP_REACTIVATE_LOCLZN_CODE = "hrms.employee.reactivation.notification"; public static final String HRMS_LOCALIZATION_MODULE_CODE = "egov-hrms"; public static final String HRMS_LOCALIZATION_ENG_LOCALE_CODE = "en_IN"; @@ -41,6 +46,7 @@ public class HRMSConstants { public static final String HRMS_USER_SEARCH_CRITERA_UUID = "uuid"; public static final String HRMS_USER_SEARCH_CRITERA_ROLECODES = "roleCodes"; public static final String HRMS_USER_SEARCH_CRITERA_TENANTID = "tenantId"; + public static final String HRMS_USER_SEARCH_CRITERA_TENANTIDS = "tenantIds"; public static final String HRMS_USER_SEARCH_CRITERA_MOBILENO = "mobileNumber"; public static final String HRMS_USER_SEARCH_CRITERA_NAME = "name"; public static final String HRMS_USER_SEARCH_CRITERA_USERNAME = "UserName"; diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/web/contract/EmployeeSearchByTenantRequestWrapper.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/contract/EmployeeSearchByTenantRequestWrapper.java new file mode 100644 index 000000000..7f2d67d25 --- /dev/null +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/contract/EmployeeSearchByTenantRequestWrapper.java @@ -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; + +} + + diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/web/contract/EmployeeSearchCriteria.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/contract/EmployeeSearchCriteria.java index cce024177..eed0dd147 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/web/contract/EmployeeSearchCriteria.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/contract/EmployeeSearchCriteria.java @@ -47,8 +47,12 @@ public class EmployeeSearchCriteria { public Boolean isActive; + public Boolean isStateLevelSearch; + @Size(max = 250) public String tenantId; + + public List tenantIds; public String phone; diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/web/controller/EmployeeController.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/controller/EmployeeController.java index 99a12ff50..1bf065440 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/web/controller/EmployeeController.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/controller/EmployeeController.java @@ -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.*; 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 roles , @RequestParam("isStateLevelSearch") boolean isStateLevelSearch, @RequestBody RequestInfo requestInfo) { + + Map response = new HashMap<>(); + validator.validateEmployeeCountRequest(tenantId); + response = employeeService.getEmployeeCountResponseV1(requestInfo,roles,tenantId,isStateLevelSearch); + return new ResponseEntity<>(response,HttpStatus.OK); + } + } \ No newline at end of file diff --git a/business-services/egov-hrms/src/main/java/org/egov/hrms/web/validator/EmployeeValidator.java b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/validator/EmployeeValidator.java index d20b81405..8238ae857 100644 --- a/business-services/egov-hrms/src/main/java/org/egov/hrms/web/validator/EmployeeValidator.java +++ b/business-services/egov-hrms/src/main/java/org/egov/hrms/web/validator/EmployeeValidator.java @@ -234,7 +234,7 @@ private void validateMdmsData(Employee employee, Map errorMap, M validateEmployee(employee, errorMap, mdmsData); validateAssignments(employee, errorMap, mdmsData); validateServiceHistory(employee, errorMap, mdmsData); - validateJurisdicton(employee, errorMap, mdmsData, boundaryMap); + //validateJurisdicton(employee, errorMap, mdmsData, boundaryMap); validateEducationalDetails(employee, errorMap, mdmsData); validateDepartmentalTest(employee, errorMap, mdmsData); } @@ -251,7 +251,7 @@ private void validateMdmsData(Employee employee, Map errorMap, M public void validateDataConsistency(Employee employee, Map errorMap, Map> mdmsData, Employee existingEmp, RequestInfo requestInfo) { validateUserData(existingEmp,employee,errorMap, requestInfo); validateConsistencyAssignment(existingEmp,employee,errorMap); - validateConsistencyJurisdiction(existingEmp,employee,errorMap); + //validateConsistencyJurisdiction(existingEmp,employee,errorMap); validateConsistencyDepartmentalTest(existingEmp,employee,errorMap); validateConsistencyEducationalDetails(existingEmp,employee,errorMap); validateConsistencyServiceHistory(existingEmp, employee, errorMap); @@ -465,12 +465,15 @@ private void validateJurisdicton(Employee employee, Map errorMap List hierarchyTypes = JsonPath.read(boundaryMap,hierarchy_type_path); List boundaryTypes = JsonPath.read(boundaryMap,boundary_type_path); List 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); + } } diff --git a/business-services/egov-hrms/src/main/resources/application.properties b/business-services/egov-hrms/src/main/resources/application.properties index 85dace878..bbeb4a68a 100644 --- a/business-services/egov-hrms/src/main/resources/application.properties +++ b/business-services/egov-hrms/src/main/resources/application.properties @@ -30,6 +30,8 @@ egov.services.data_sync_employee.required = false egov.mdms.host=https://dev.digit.org egov.mdms.search.endpoint=/egov-mdms-service/v1/_search #egov.mdms.search.endpoint=/egov-mdms-service-test/v1/_search +egov.mdms.search.endpoint.old= /egov-mdms-service/v1/_search +egov.mdms.host.old=https://dev.digit.org #filestore urls egov.filestore.host=https://dev.digit.org @@ -48,6 +50,7 @@ egov.environment.domain=https://dev.digit.org/ #user egov.user.host=https://dev.digit.org egov.user.search.endpoint=/user/v1/_search +egov.user.search.tenant.endpoint=/user/_searchByTenant egov.user.create.endpoint=/user/users/_createnovalidate egov.user.update.endpoint=/user/users/_updatenovalidate @@ -99,4 +102,5 @@ logging.pattern.console=%clr(%X{CORRELATION_ID:-}) %clr(%d{yyyy-MM-dd HH:mm:ss.S log4j.logger.org.springframework.jdbc.core = TRACE -state.level.tenant.id=pb \ No newline at end of file +state.level.tenant.id=pb +sms.user.creation.enabled=true \ No newline at end of file diff --git a/core-services/egov-user/src/main/java/org/egov/user/config/UserServiceConstants.java b/core-services/egov-user/src/main/java/org/egov/user/config/UserServiceConstants.java index 78e1c2ff1..82d0f9e54 100644 --- a/core-services/egov-user/src/main/java/org/egov/user/config/UserServiceConstants.java +++ b/core-services/egov-user/src/main/java/org/egov/user/config/UserServiceConstants.java @@ -59,7 +59,7 @@ public class UserServiceConstants { public static final String PATTERN_GENDER = "^[a-zA-Z ]*$"; public static final String PATTERN_MOBILE = "(^$|[0-9]{10})"; public static final String PATTERN_CITY = "^[a-zA-Z. ]*$"; - public static final String PATTERN_TENANT = "^[a-zA-Z. ]*$"; + public static final String PATTERN_TENANT = "^[a-zA-Z.0-9 ]*$"; public static final String PATTERN_PINCODE = "^[1-9][0-9]{5}$"; } diff --git a/core-services/egov-user/src/main/java/org/egov/user/domain/model/UserSearchCriteria.java b/core-services/egov-user/src/main/java/org/egov/user/domain/model/UserSearchCriteria.java index a0dae3277..1445c6a09 100644 --- a/core-services/egov-user/src/main/java/org/egov/user/domain/model/UserSearchCriteria.java +++ b/core-services/egov-user/src/main/java/org/egov/user/domain/model/UserSearchCriteria.java @@ -29,6 +29,8 @@ public class UserSearchCriteria { private List sort; private UserType type; private String tenantId; + private List tenantIds; + private Boolean isStateLevelSearch; private List roleCodes; public void validate(boolean isInterServiceCall) { diff --git a/core-services/egov-user/src/main/java/org/egov/user/domain/service/UserService.java b/core-services/egov-user/src/main/java/org/egov/user/domain/service/UserService.java index 34bf135d8..2cc31af39 100644 --- a/core-services/egov-user/src/main/java/org/egov/user/domain/service/UserService.java +++ b/core-services/egov-user/src/main/java/org/egov/user/domain/service/UserService.java @@ -37,6 +37,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.util.ObjectUtils; import org.springframework.web.client.RestTemplate; import java.io.IOException; @@ -180,11 +181,17 @@ public List searchUsers(UserSearchCriteria sear boolean isInterServiceCall, RequestInfo requestInfo) { searchCriteria.validate(isInterServiceCall); - - searchCriteria.setTenantId(getStateLevelTenantForCitizen(searchCriteria.getTenantId(), searchCriteria.getType())); + if(!ObjectUtils.isEmpty(searchCriteria.getIsStateLevelSearch())) { + if (searchCriteria.getIsStateLevelSearch()) { + searchCriteria.setTenantId(getStateLevelTenantForCitizen(searchCriteria.getTenantId(), searchCriteria.getType())); + } + } else { + searchCriteria.setTenantId(getStateLevelTenantForCitizen(searchCriteria.getTenantId(), searchCriteria.getType())); + } /* encrypt here / encrypted searchcriteria will be used for search*/ + searchCriteria = encryptionDecryptionUtil.encryptObject(searchCriteria, "UserSearchCriteria", UserSearchCriteria.class); List list = userRepository.findAll(searchCriteria); @@ -649,6 +656,24 @@ public void validatePassword(String password) { throw new CustomException(errorMap); } } + public List searchUsersByTenants(UserSearchCriteria searchCriteria, RequestInfo requestInfo) { + //searchCriteria.validate(isInterServiceCall); + if(ObjectUtils.isEmpty(searchCriteria.getTenantIds())) { + return null; + } + + //searchCriteria.setTenantId(getStateLevelTenantForCitizen(searchCriteria.getTenantId(), searchCriteria.getType())); + /* encrypt here / encrypted searchcriteria will be used for search*/ + searchCriteria = encryptionDecryptionUtil.encryptObject(searchCriteria, "UserSearchCriteria", UserSearchCriteria.class); + List list = userRepository.findUserByTenant(searchCriteria); + + /* decrypt here / final reponse decrypted*/ + + list = encryptionDecryptionUtil.decryptObject(list, "UserList", User.class, requestInfo); + + setFileStoreUrlsByFileStoreIds(list); + return list; + } } diff --git a/core-services/egov-user/src/main/java/org/egov/user/persistence/repository/UserRepository.java b/core-services/egov-user/src/main/java/org/egov/user/persistence/repository/UserRepository.java index 99856a8c4..0f6e5685f 100644 --- a/core-services/egov-user/src/main/java/org/egov/user/persistence/repository/UserRepository.java +++ b/core-services/egov-user/src/main/java/org/egov/user/persistence/repository/UserRepository.java @@ -86,7 +86,7 @@ public List findAll(UserSearchCriteria userSearch) { } } String queryStr = userTypeQueryBuilder.getQuery(userSearch, preparedStatementValues); - log.debug(queryStr); + log.info(queryStr); users = jdbcTemplate.query(queryStr, preparedStatementValues.toArray(), userResultSetExtractor); enrichRoles(users); @@ -105,8 +105,6 @@ public List findUsersWithRole(UserSearchCriteria userSearch) { final List preparedStatementValues = new ArrayList<>(); List usersIds = new ArrayList<>(); String queryStr = userTypeQueryBuilder.getQueryUserRoleSearch(userSearch, preparedStatementValues); - log.debug(queryStr); - usersIds = jdbcTemplate.queryForList(queryStr, preparedStatementValues.toArray(), Long.class); return usersIds; @@ -574,4 +572,37 @@ private String getStateLevelTenant(String tenantId) { return tenantId.split("\\.")[0]; } + public List findUserByTenant(UserSearchCriteria userSearch) { + final List preparedStatementValues = new ArrayList<>(); + boolean RoleSearchHappend = false; + List userIds = new ArrayList<>(); + if (!isEmpty(userSearch.getRoleCodes()) && userSearch.getTenantIds() != null) { + userIds = findUsersWithRole(userSearch); + RoleSearchHappend = true; + } + List users = new ArrayList<>(); + if (RoleSearchHappend) { + if (!CollectionUtils.isEmpty(userIds)) { + if (CollectionUtils.isEmpty(userSearch.getId())) + userSearch.setId(userIds); + else { + userSearch.setId(userSearch.getId().stream().filter(userIds::contains).collect(Collectors.toList())); + if (CollectionUtils.isEmpty(userSearch.getId())) + return users; + } + userSearch.setTenantId(null); + userSearch.setRoleCodes(null); + } else { + + return users; + } + } + String queryStr = userTypeQueryBuilder.getQuery(userSearch, preparedStatementValues); + log.info("SEARCH USER QUERY"+queryStr); + + users = jdbcTemplate.query(queryStr, preparedStatementValues.toArray(), userResultSetExtractor); + enrichRoles(users); + return users; + } + } diff --git a/core-services/egov-user/src/main/java/org/egov/user/repository/builder/UserTypeQueryBuilder.java b/core-services/egov-user/src/main/java/org/egov/user/repository/builder/UserTypeQueryBuilder.java index f61a23a65..0c523c5e6 100644 --- a/core-services/egov-user/src/main/java/org/egov/user/repository/builder/UserTypeQueryBuilder.java +++ b/core-services/egov-user/src/main/java/org/egov/user/repository/builder/UserTypeQueryBuilder.java @@ -45,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; import java.util.Iterator; import java.util.List; @@ -137,6 +138,11 @@ private void addWhereClause(final StringBuilder selectQuery, final List prepared selectQuery.append(" u.tenantid like ?"); preparedStatementValues.add("%"+userSearchCriteria.getTenantId().trim()+"%"); } + if (userSearchCriteria.getTenantIds() != null) { + isAppendAndClause = addAndClauseIfRequired(isAppendAndClause, selectQuery); + selectQuery.append(" ur.role_tenantid IN (").append(getQueryForCollection(userSearchCriteria.getTenantIds(), + preparedStatementValues)).append(" )"); + } if (userSearchCriteria.getUserName() != null) { isAppendAndClause = addAndClauseIfRequired(isAppendAndClause, selectQuery); @@ -235,10 +241,29 @@ private void addWhereClauseUserRoles(final StringBuilder selectQuery, final List selectQuery.append(" WHERE"); boolean isAppendAndClause = false; - if (userSearchCriteria.getTenantId() != null) { + if (userSearchCriteria.getTenantId() != null ) { + if(ObjectUtils.isEmpty(userSearchCriteria.getIsStateLevelSearch()) ){ + isAppendAndClause = addAndClauseIfRequired(false, selectQuery); + selectQuery.append(" ur.role_tenantid like ? "); + preparedStatementValues.add( '%' + userSearchCriteria.getTenantId().trim() + '%'); + } else { + if(!userSearchCriteria.getIsStateLevelSearch()) { + isAppendAndClause = addAndClauseIfRequired(false, selectQuery); + selectQuery.append(" ur.role_tenantid = ?"); + preparedStatementValues.add(userSearchCriteria.getTenantId()); + } else { + isAppendAndClause = addAndClauseIfRequired(false, selectQuery); + selectQuery.append(" ur.role_tenantid like ? "); + preparedStatementValues.add( '%' + userSearchCriteria.getTenantId().trim() + '%'); + } + + } + } + + if (userSearchCriteria.getTenantIds() != null) { isAppendAndClause = addAndClauseIfRequired(false, selectQuery); - selectQuery.append(" ur.role_tenantid like ? "); - preparedStatementValues.add( '%' + userSearchCriteria.getTenantId().trim() + '%'); + selectQuery.append(" ur.role_tenantid IN (" ).append(getQueryForCollection(userSearchCriteria.getTenantIds(), + preparedStatementValues)).append(" )"); } diff --git a/core-services/egov-user/src/main/java/org/egov/user/web/contract/UserSearchByTenantsRequest.java b/core-services/egov-user/src/main/java/org/egov/user/web/contract/UserSearchByTenantsRequest.java new file mode 100644 index 000000000..2bc1d4f0b --- /dev/null +++ b/core-services/egov-user/src/main/java/org/egov/user/web/contract/UserSearchByTenantsRequest.java @@ -0,0 +1,106 @@ +package org.egov.user.web.contract; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.egov.common.contract.request.RequestInfo; +import org.egov.user.config.UserServiceConstants; +import org.egov.user.domain.model.UserSearchCriteria; +import org.egov.user.domain.model.enums.UserType; + +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import java.util.Collections; +import java.util.List; + +@Getter +@Setter +@ToString +public class UserSearchByTenantsRequest { + + @JsonProperty("RequestInfo") + private RequestInfo requestInfo; + + @JsonProperty("id") + private List id; + + @JsonProperty("uuid") + private List uuid; + + @Size(max = 64) + @JsonProperty("userName") + private String userName; + + @Size(max = 100) + @JsonProperty("name") + private String name; + + @Pattern(regexp = UserServiceConstants.PATTERN_MOBILE) + @JsonProperty("mobileNumber") + private String mobileNumber; + + @Size(max = 20) + @JsonProperty("aadhaarNumber") + private String aadhaarNumber; + + @Size(max = 10) + @JsonProperty("pan") + private String pan; + + @Size(max = 128) + @JsonProperty("emailId") + private String emailId; + + @JsonProperty("fuzzyLogic") + private boolean fuzzyLogic; + + @JsonProperty("active") + @Setter + private Boolean active; + + @Pattern(regexp = UserServiceConstants.PATTERN_TENANT) + @Size(max = 256) + @JsonProperty("tenantId") + private String tenantId; + + @JsonProperty("tenantIds") + private List tenantIds; + + @JsonProperty("pageSize") + private int pageSize; + + @JsonProperty("pageNumber") + private int pageNumber = 0; + + @JsonProperty("sort") + private List sort = Collections.singletonList("name"); + + @Size(max = 50) + @JsonProperty("userType") + private String userType; + + @JsonProperty("roleCodes") + private List roleCodes; + + public UserSearchCriteria toDomain() { + return UserSearchCriteria.builder() + .id(id) + .userName(userName) + .name(name) + .mobileNumber(mobileNumber) +// .pan(pan) + .emailId(emailId) + .fuzzyLogic(fuzzyLogic) + .active(active) + .limit(pageSize) + .offset(pageNumber) + .sort(sort) + .type(UserType.fromValue(userType)) + .tenantId(tenantId) + .tenantIds(tenantIds) + .roleCodes(roleCodes) + .uuid(uuid) + .build(); + } +} diff --git a/core-services/egov-user/src/main/java/org/egov/user/web/contract/UserSearchRequest.java b/core-services/egov-user/src/main/java/org/egov/user/web/contract/UserSearchRequest.java index 6dabfec0e..f02a0edcc 100644 --- a/core-services/egov-user/src/main/java/org/egov/user/web/contract/UserSearchRequest.java +++ b/core-services/egov-user/src/main/java/org/egov/user/web/contract/UserSearchRequest.java @@ -70,6 +70,9 @@ public class UserSearchRequest { @JsonProperty("pageNumber") private int pageNumber = 0; + @JsonProperty("isStateLevelSearch") + private Boolean isStateLevelSearch; + @JsonProperty("sort") private List sort = Collections.singletonList("name"); @@ -95,6 +98,7 @@ public UserSearchCriteria toDomain() { .sort(sort) .type(UserType.fromValue(userType)) .tenantId(tenantId) + .isStateLevelSearch(isStateLevelSearch) .roleCodes(roleCodes) .uuid(uuid) .build(); diff --git a/core-services/egov-user/src/main/java/org/egov/user/web/controller/UserController.java b/core-services/egov-user/src/main/java/org/egov/user/web/controller/UserController.java index c16bd2201..26dd4992b 100644 --- a/core-services/egov-user/src/main/java/org/egov/user/web/controller/UserController.java +++ b/core-services/egov-user/src/main/java/org/egov/user/web/controller/UserController.java @@ -219,4 +219,27 @@ private boolean isMobileValidationRequired(HttpHeaders headers) { return true; } + @PostMapping("/_searchByTenant") + public UserSearchResponse getUserBytenant(@RequestBody @Valid UserSearchByTenantsRequest request, @RequestHeader HttpHeaders headers) { + + log.info("Received User search Request " + request); + return searchUsersBytenant(request, headers); + } + + private UserSearchResponse searchUsersBytenant(UserSearchByTenantsRequest request, HttpHeaders headers) { + UserSearchCriteria searchCriteria = request.toDomain(); + + if (!isInterServiceCall(headers)) { + if ((isEmpty(searchCriteria.getId()) && isEmpty(searchCriteria.getUuid())) && (searchCriteria.getLimit() > defaultSearchSize + || searchCriteria.getLimit() == 0)) + searchCriteria.setLimit(defaultSearchSize); + } + + List userModels = userService.searchUsersByTenants(searchCriteria, request.getRequestInfo()); + List userContracts = userModels.stream().map(UserSearchResponseContent::new) + .collect(Collectors.toList()); + ResponseInfo responseInfo = ResponseInfo.builder().status(String.valueOf(HttpStatus.OK.value())).build(); + return new UserSearchResponse(responseInfo, userContracts); + } + } diff --git a/frontend/mgramseva/lib/utils/common_methods.dart b/frontend/mgramseva/lib/utils/common_methods.dart index 9b057d4cb..e249214ac 100644 --- a/frontend/mgramseva/lib/utils/common_methods.dart +++ b/frontend/mgramseva/lib/utils/common_methods.dart @@ -166,6 +166,7 @@ class CommonMethods { .toList(); return list; } + static List getPastMonthIncludingCurrentMonthUntilFinancialYTD( DatePeriod ytd) { var monthList = [];