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

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldevgarg authored Mar 13, 2024
2 parents 1ecd146 + 9f7297a commit 6698791
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,4 +114,7 @@ public class PropertiesManager {

@Value("${state.level.tenant.id}")
public String stateLevelTenantId;

@Value("${sms.user.creation.enabled}")
public boolean isSMSForUserCreationEnable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class Employee {

@Valid
@NotEmpty
@Size(min = 1,max = 50)
@Size(min = 1,max = 5000)
private List<Jurisdiction> jurisdictions = new ArrayList<>();


Expand Down Expand Up @@ -132,4 +132,4 @@ public class Employee {
private User user;


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
public class SMSRequest {
private String mobileNumber;
private String message;

private String tenantId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

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
Expand Up @@ -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;
Expand Down Expand Up @@ -35,6 +36,9 @@ public class NotificationService {
@Autowired
private RestTemplate restTemplate;

@Autowired
private PropertiesManager propertiesManager;

@Value("${kafka.topics.notification.sms}")
private String smsTopic;

Expand All @@ -57,23 +61,25 @@ public class NotificationService {
private String envHost;



/**
* Sends notification by putting the sms content onto the core-sms topic
*
* @param request
* @param pwdMap
*/
public void sendNotification(EmployeeRequest request, Map<String, String> 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);
}
}
}

Expand Down Expand Up @@ -149,9 +155,14 @@ public String getMessage(EmployeeRequest request,String msgCode) {
* @return
*/
public String buildMessage(Employee employee, String message, Map<String, String> 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;
}

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

Expand Down Expand Up @@ -124,6 +127,23 @@ public UserResponse getUser(RequestInfo requestInfo, Map<String, Object> UserSea

return userResponse;
}
public UserResponse getUserByTenantids(RequestInfo requestInfo, Map<String, Object> UserSearchCriteria ) {
StringBuilder uri = new StringBuilder();
Map<String, Object> 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;
}


/**
Expand All @@ -135,7 +155,7 @@ public UserResponse getUser(RequestInfo requestInfo, Map<String, Object> 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";
Expand Down Expand Up @@ -192,4 +212,4 @@ private Long dateTolong(String date,String format){
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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";
Expand Down
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
Expand Up @@ -47,8 +47,12 @@ public class EmployeeSearchCriteria {

public Boolean isActive;

public Boolean isStateLevelSearch;

@Size(max = 250)
public String tenantId;

public List<String> tenantIds;

public String phone;

Expand Down
Loading

0 comments on commit 6698791

Please sign in to comment.