Skip to content

Commit

Permalink
Merge branch 'console-v0.3.1' into phone-number-length
Browse files Browse the repository at this point in the history
  • Loading branch information
jagankumar-egov committed Feb 19, 2025
2 parents fc08f37 + 6bb8a40 commit bf0924b
Show file tree
Hide file tree
Showing 561 changed files with 19,242 additions and 3,037 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* @kavi-egov @sathishp-eGov

health-services/project-factory/ @jagankumar-egov
health-services/project-factory/ @jagankumar-egov
4 changes: 2 additions & 2 deletions build/build-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ config:
- name: "builds/health-campaign-services/core-services/service-request"
build:
- work-dir: "core-services/service-request"
image-name: "service-request"
image-name: "health-service-request"
dockerfile: "build/maven/Dockerfile"
- work-dir: "core-services/service-request/src/main/resources/db"
image-name: "service-request-db"
image-name: "health-service-request-db"
- name: "builds/health-campaign-services/health-services/libraries/health-services-models"
build:
- work-dir: "health-services/libraries/health-services-models"
Expand Down
4 changes: 2 additions & 2 deletions core-services/egov-hrms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>org.egov</groupId>
<artifactId>egov-hrms</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.3.0</version>
<name>egov-hrms</name>
<description>HR Management System</description>
<properties>
Expand Down 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 @@ -103,6 +103,9 @@ public class EmployeeService {
@Autowired
private ObjectMapper objectMapper;

@Autowired
private IndividualService individualService;

/**
* Service method for create employee. Does following:
* 1. Sets ids to all the objects using idgen service.
Expand All @@ -121,8 +124,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 +144,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 +164,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 +187,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 +201,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 +243,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 +254,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 All @@ -231,7 +269,14 @@ private void createUser(Employee employee, RequestInfo requestInfo) {
enrichUser(employee);
UserRequest request = UserRequest.builder().requestInfo(requestInfo).user(employee.getUser()).build();
try {
UserResponse response = userService.createUser(request);
UserResponse response;
if(userService instanceof IndividualService) {
String localityCode = (employee.getJurisdictions()!=null && !employee.getJurisdictions().isEmpty())? employee.getJurisdictions().get(0).getBoundary() : null;
response = individualService.createUserByLocality(request, localityCode);
}
else{
response = userService.createUser(request);
}
User user = response.getUser().get(0);
employee.setId(UUID.fromString(user.getUuid()).getMostSignificantBits());
employee.setUuid(user.getUuid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,19 @@
import org.apache.commons.lang3.StringUtils;
import org.egov.common.contract.request.RequestInfo;
import org.egov.common.models.core.Role;
import org.egov.common.models.individual.Address;
import org.egov.common.models.individual.AddressType;
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;
import org.egov.common.models.individual.UserDetails;
import org.egov.common.models.individual.*;
import org.egov.hrms.config.PropertiesManager;
import org.egov.hrms.repository.RestCallRepository;
import org.egov.hrms.utils.HRMSConstants;
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 All @@ -56,7 +49,7 @@ public IndividualService(PropertiesManager propertiesManager,

@Override
public UserResponse createUser(UserRequest userRequest) {
IndividualRequest request = mapToIndividualRequest(userRequest);
IndividualRequest request = mapToIndividualRequest(userRequest, null);
StringBuilder uri = new StringBuilder();
uri.append(propertiesManager.getIndividualHost());
uri.append(propertiesManager.getIndividualCreateEndpoint());
Expand All @@ -70,6 +63,21 @@ public UserResponse createUser(UserRequest userRequest) {
return userResponse;
}

public UserResponse createUserByLocality(UserRequest userRequest, String localityCode) {
IndividualRequest request = mapToIndividualRequest(userRequest,localityCode);
StringBuilder uri = new StringBuilder();
uri.append(propertiesManager.getIndividualHost());
uri.append(propertiesManager.getIndividualCreateEndpoint());
IndividualResponse response = restCallRepository
.fetchResult(uri, request, IndividualResponse.class);
UserResponse userResponse = null;
if (response != null && response.getIndividual() != null) {
log.info("response received from individual service");
userResponse = mapToUserResponse(response);
}
return userResponse;
}

/**
* Updates a user by searching for the corresponding individual and updating their details.
*
Expand Down Expand Up @@ -210,6 +218,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 @@ -256,7 +265,7 @@ private static Date convertMillisecondsToDate(long milliseconds) {
}
}

private static IndividualRequest mapToIndividualRequest(UserRequest userRequest) {
private static IndividualRequest mapToIndividualRequest(UserRequest userRequest, String localityCode) {
Individual individual = Individual.builder()
.id(userRequest.getUser().getUuid())
.userId(userRequest.getUser().getId() != null ?
Expand All @@ -276,6 +285,7 @@ private static IndividualRequest mapToIndividualRequest(UserRequest userRequest)
.type(AddressType.CORRESPONDENCE)
.addressLine1(userRequest.getUser().getCorrespondenceAddress())
.clientReferenceId(String.valueOf(UUID.randomUUID()))
.locality((localityCode!=null) ? Boundary.builder().code(localityCode).build() : null)
.isDeleted(Boolean.FALSE)
.build()))
/*
Expand Down Expand Up @@ -306,6 +316,9 @@ private static IndividualRequest mapToIndividualRequest(UserRequest userRequest)
.build()).collect(Collectors.toList()))
.userType(UserType.fromValue(userRequest.getUser().getType()))
.build())
.skills(userRequest.getUser().getRoles().stream().map(role -> Skill.builder()
.type(role.getCode()).level(role.getCode())
.build()).collect(Collectors.toList()))
.isDeleted(Boolean.FALSE)
.clientAuditDetails(AuditDetails.builder().createdBy(userRequest.getRequestInfo().getUserInfo().getUuid()).lastModifiedBy(userRequest.getRequestInfo().getUserInfo().getUuid()).build())
.rowVersion(userRequest.getUser().getRowVersion())
Expand All @@ -331,6 +344,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");
}
}
}
Loading

0 comments on commit bf0924b

Please sign in to comment.