Skip to content

Commit

Permalink
[HCMPRE-857, HCMPRE-1139, HCMPRE-1303, HCMPRE-1158] Changes in hrms-s…
Browse files Browse the repository at this point in the history
…ervice for email notification feature, UUID and role search changes, Pagination and case insensitive fuzzy search in user name (#1337)

* Total count enhancement in HRMS

* Corrected count query logic

* Fixed HRMS total count

* Fixed hrms uuids search

* Fixed HRMS search response

* added email notification service

* added email notification service

* changing implementation partner

* Adding last modified date sorting clause in HRMS search query

* Adding case insensitive search

* Revert "Adding last modified date sorting clause in HRMS search query"

This reverts commit c287376.

* changing implementation partner

* HCMPRE-1333- Removed dense rank query; using sequential calls to get child table data. (#1210)

* Revert "HCMPRE-1333- Removed dense rank query; using sequential calls to get child table data. (#1210)"

This reverts commit 2d2d4cc.

* Added comments and resolved some coderabbit review comments

* Removing IndividualBulkResponse class and importing from library

* updating version for org.egov.services.services-common

* using IndividualBulkResponse class in egov-hrms

---------

Co-authored-by: Shashwat Mishra <shashwat.mishra@egovernments.org>
Co-authored-by: Shashwat Mishra <71879793+shashwat-egov@users.noreply.github.com>
Co-authored-by: shubhang-eGov <70943369+shubhang-eGov@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 27, 2025
1 parent 93df243 commit 235cb3e
Show file tree
Hide file tree
Showing 16 changed files with 401 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core-services/egov-hrms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>9.22.3</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.1</version>
</dependency>
<dependency>
<groupId>org.egov.services</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ public class PropertiesManager {

@Value("${egov.idgen.path}")
public String idGenEndpoint;


// Email
@Value("${kafka.topics.notification.email}")
private String emailNotifTopic;

@Value("${notification.email.enabled}")
private Boolean isEmailNotificationEnabled;

//Kafka Topics
@Value("${kafka.topics.save.service}")
Expand All @@ -96,7 +102,9 @@ public class PropertiesManager {

@Value("${kafka.topics.hrms.updateData}")
public String updateTopic;


@Value("${kafka.topics.hrms.email.notification}")
public String hrmsEmailNotifTopic;

//Variables
@Value("${egov.idgen.ack.name}")
Expand Down Expand Up @@ -140,4 +148,10 @@ public class PropertiesManager {

@Value("${egov.boundary.search.url}")
private String boundarySearchUrl;

@Value("${hrms.email.notification.implementation.partner}")
public String emailNotificationImplementationPartner;

@Value("${hrms.email.notification.website.link}")
public String emailNotificationWebsiteLink;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ public class HrmsConsumer {
@Autowired
private PropertiesManager propertiesManager;

@KafkaListener(topics = {"${kafka.topics.hrms.updateData}"})
@KafkaListener(topics = {"${kafka.topics.hrms.updateData}", "${kafka.topics.hrms.email.notification}"})
public void listenUpdateEmployeeData(final HashMap<String, Object> record,@Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
try {
EmployeeRequest employeeRequest = mapper.convertValue(record, EmployeeRequest.class);
hrmsProducer.push(propertiesManager.getUpdateEmployeeTopic(), employeeRequest);
notificationService.sendReactivationNotification(employeeRequest);

if(topic.equals(propertiesManager.getHrmsEmailNotifTopic())) {
notificationService.processEmailNotification(employeeRequest);
} else {
hrmsProducer.push(propertiesManager.getUpdateEmployeeTopic(), employeeRequest);
notificationService.sendReactivationNotification(employeeRequest);
}
} catch (final Exception e) {

log.error("Error while listening to value: " + record + " on topic: " + topic + ": ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ public EmployeeResponse create(EmployeeRequest employeeRequest) {
enrichCreateRequest(employee, requestInfo);
createUser(employee, requestInfo);
pwdMap.put(employee.getUuid(), employee.getUser().getPassword());
employee.getUser().setPassword(null);
});
hrmsProducer.push(propertiesManager.getHrmsEmailNotifTopic(), employeeRequest);

// Setting password as null after sending employeeRequest to email notification topic to send email.
employeeRequest.getEmployees().forEach(employee -> employee.getUser().setPassword(null));

hrmsProducer.push(propertiesManager.getSaveEmployeeTopic(), employeeRequest);
notificationService.sendNotification(employeeRequest, pwdMap);
return generateResponse(employeeRequest);
Expand All @@ -137,6 +141,7 @@ public EmployeeResponse create(EmployeeRequest employeeRequest) {
*/
public EmployeeResponse search(EmployeeSearchCriteria criteria, RequestInfo requestInfo) {
boolean userChecked = false;
Long totalCount = 0L;
/*if(null == criteria.getIsActive() || criteria.getIsActive())
criteria.setIsActive(true);
else
Expand All @@ -156,6 +161,7 @@ public EmployeeResponse search(EmployeeSearchCriteria criteria, RequestInfo requ
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_USERNAME, criteria.getCodes().get(0));
}
UserResponse userResponse = userService.getUser(requestInfo, userSearchCriteria);
totalCount = userResponse.getTotalCount();
userChecked =true;
if(!CollectionUtils.isEmpty(userResponse.getUser())) {
mapOfUsers.putAll(userResponse.getUser().stream()
Expand All @@ -178,6 +184,7 @@ public EmployeeResponse search(EmployeeSearchCriteria criteria, RequestInfo requ
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_TENANTID,criteria.getTenantId());
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_NAME,name);
UserResponse userResponse = userService.getUser(requestInfo, userSearchCriteria);
totalCount = userResponse.getTotalCount();
userChecked =true;
if(!CollectionUtils.isEmpty(userResponse.getUser())) {
mapOfUsers.putAll(userResponse.getUser().stream()
Expand All @@ -191,6 +198,32 @@ public EmployeeResponse search(EmployeeSearchCriteria criteria, RequestInfo requ
else
criteria.setUuids(userUUIDs);
}

if(!CollectionUtils.isEmpty(criteria.getUserServiceUuids())) {
List<String> userUUIDs = new ArrayList<>();
Map<String, Object> userSearchCriteria = new HashMap<>();

userSearchCriteria.put(HRMSConstants.HRMS_USER_SERACH_CRITERIA_USERTYPE_CODE, HRMSConstants.HRMS_USER_SERACH_CRITERIA_USERTYPE);
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_TENANTID, criteria.getTenantId());
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_USER_SERVICE_UUIDS, criteria.getUserServiceUuids());
if(!CollectionUtils.isEmpty(criteria.getNames()))
userSearchCriteria.put(HRMSConstants.HRMS_USER_SEARCH_CRITERA_NAME, criteria.getNames().get(0));
UserResponse userResponse = userService.getUser(requestInfo, userSearchCriteria);
totalCount = userResponse.getTotalCount();
userChecked =true;
if(!CollectionUtils.isEmpty(userResponse.getUser())) {
mapOfUsers.putAll(userResponse.getUser().stream()
.collect(Collectors.toMap(User::getUuid, Function.identity())));
}

List<String> uuids = userResponse.getUser().stream().map(User :: getUuid).collect(Collectors.toList());
userUUIDs.addAll(uuids);

if(!CollectionUtils.isEmpty(criteria.getUuids()))
criteria.setUuids(criteria.getUuids().stream().filter(userUUIDs::contains).collect(Collectors.toList()));
else
criteria.setUuids(userUUIDs);
}
}
if(userChecked)
criteria.setTenantId(null);
Expand All @@ -207,6 +240,7 @@ public EmployeeResponse search(EmployeeSearchCriteria criteria, RequestInfo requ
if(mapOfUsers.isEmpty()){
log.info("searching in user service");
UserResponse userResponse = userService.getUser(requestInfo, userSearchCriteria);
totalCount = userResponse.getTotalCount();
if(!CollectionUtils.isEmpty(userResponse.getUser())) {
mapOfUsers = userResponse.getUser().stream()
.collect(Collectors.toMap(User :: getUuid, Function.identity()));
Expand All @@ -217,7 +251,8 @@ public EmployeeResponse search(EmployeeSearchCriteria criteria, RequestInfo requ
}
}
return EmployeeResponse.builder().responseInfo(factory.createResponseInfoFromRequestInfo(requestInfo, true))
.employees(employees).build();
.employees(employees)
.totalCount(totalCount).build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.egov.common.models.individual.Gender;
import org.egov.common.models.individual.Identifier;
import org.egov.common.models.individual.Individual;
import org.egov.common.models.individual.IndividualBulkResponse;
import org.egov.common.models.individual.IndividualRequest;
import org.egov.common.models.individual.IndividualResponse;
import org.egov.common.models.individual.Name;
Expand All @@ -33,10 +32,12 @@
import org.egov.hrms.web.contract.User;
import org.egov.hrms.web.contract.UserRequest;
import org.egov.hrms.web.contract.UserResponse;
import org.egov.hrms.web.models.IndividualBulkResponse;
import org.egov.hrms.web.models.IndividualSearch;
import org.egov.hrms.web.models.IndividualSearchRequest;
import org.springframework.beans.factory.annotation.Autowired;

import static org.egov.hrms.utils.HRMSConstants.HRMS_USER_SEARCH_CRITERA_USER_SERVICE_UUIDS;
import static org.egov.hrms.utils.HRMSConstants.SYSTEM_GENERATED;

@Slf4j
Expand Down Expand Up @@ -210,6 +211,7 @@ public UserResponse getUser(RequestInfo requestInfo, Map<String, Object> userSea
mobileNumberList
)
.id((List<String>) userSearchCriteria.get("uuid"))
.userUuid((List<String>) userSearchCriteria.get(HRMS_USER_SEARCH_CRITERA_USER_SERVICE_UUIDS))
.roleCodes((List<String>) userSearchCriteria.get("roleCodes"))
.username(usernameList)
// given name
Expand Down Expand Up @@ -331,6 +333,7 @@ private static UserResponse mapToUserResponse(IndividualBulkResponse response) {
.responseInfo(response.getResponseInfo())
.user(response.getIndividual().stream()
.map(IndividualService::getUser).collect(Collectors.toList()))
.totalCount(response.getTotalCount())
.build();
return userResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,40 @@
import org.egov.hrms.producer.HRMSProducer;
import org.egov.hrms.repository.RestCallRepository;
import org.egov.hrms.utils.HRMSConstants;
import org.egov.hrms.utils.NotificationUtil;
import org.egov.hrms.web.contract.EmailRequest;
import org.egov.hrms.web.contract.EmployeeRequest;
import org.egov.hrms.web.contract.RequestInfoWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.jayway.jsonpath.JsonPath;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;

import static org.egov.hrms.utils.HRMSConstants.HEALTH_HRMS_EMAIL_LOCALIZATION_CODE;

@Service
@Slf4j
public class NotificationService {

@Autowired

private HRMSProducer producer;

@Autowired

private RestCallRepository repository;

@Autowired
private RestTemplate restTemplate;

private NotificationUtil notificationUtil;

public NotificationService(HRMSProducer producer, RestCallRepository repository, RestTemplate restTemplate, NotificationUtil notificationUtil) {
this.producer = producer;
this.repository = repository;
this.restTemplate = restTemplate;
this.notificationUtil = notificationUtil;
}

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

Expand Down Expand Up @@ -193,4 +203,26 @@ public Map<String, Map<String, String>> getLocalisedMessages(RequestInfo request
return localizedMessageMap;
}

/**
* Creates and sends email notification to the employees whose details are provided in the employeeRequest.
*
* @param employeeRequest The employee request with employee details.
*/
public void processEmailNotification(EmployeeRequest employeeRequest) {
if (employeeRequest == null || CollectionUtils.isEmpty(employeeRequest.getEmployees())) {
log.error("Invalid employee request received for email notification");
return;
}
try {
// Fetch localization messages and get email message template for HEALTH_HRMS_EMAIL_LOCALIZATION_CODE template code.
String localizationMessages = notificationUtil.getLocalizationMessages(employeeRequest);
String messageTemplate = notificationUtil.getMessageTemplate(HEALTH_HRMS_EMAIL_LOCALIZATION_CODE, localizationMessages);

// Create email requests from the employee details provided in the employeeRequest.
List<EmailRequest> emailRequests = notificationUtil.createEmailRequest(employeeRequest, messageTemplate);
notificationUtil.sendEmail(emailRequests);
} catch (Exception e) {
log.error("Error processing email notification for given employees");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class HRMSConstants {
public static final String HRMS_EMP_CREATE_LOCLZN_CODE = "hrms.employee.create.notification";
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 HEALTH_HRMS_LOCALIZATION_MODULE_CODE = "rainmaker-hr";
public static final String HEALTH_HRMS_EMAIL_LOCALIZATION_CODE = "HEALTH_HRMS_EMAIL_CODE";
public static final String HRMS_LOCALIZATION_ENG_LOCALE_CODE = "en_IN";
public static final String HRMS_TENANTBOUNDARY_HIERARCHY_JSONPATH = "$.TenantBoundary[?(@.boundary.code ==\"%s\")].hierarchyType.code";
public static final String HRMS_TENANTBOUNDARY_BOUNDARY_TYPE_JSONPATH ="$.TenantBoundary[?(@.hierarchyType.name==\"%1$s\" && @.boundary.code ==\"%2$s\")]..label";
Expand All @@ -39,6 +41,7 @@ public class HRMSConstants {
public static final String HRMS_MDMS_CODE_FLITER = "[?(@.active == true)].code";

public static final String HRMS_USER_SEARCH_CRITERA_UUID = "uuid";
public static final String HRMS_USER_SEARCH_CRITERA_USER_SERVICE_UUIDS = "userServiceUuids";
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_MOBILENO = "mobileNumber";
Expand Down
Loading

0 comments on commit 235cb3e

Please sign in to comment.