Done ticket GEPAFINBE-210

This commit is contained in:
Piyush
2025-05-02 18:26:22 +05:30
parent 21158b0ee4
commit 23ed5df464
44 changed files with 636 additions and 75 deletions

View File

@@ -140,6 +140,12 @@ public class ApplicationAmendmentRequestDao {
@Autowired
private ApplicationDao applicationDao;
@Autowired
private EmailLogRepository emailLogRepository;
@Autowired
private EmailDao emailDao;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
@@ -300,6 +306,8 @@ public class ApplicationAmendmentRequestDao {
log.info("Application submitted successfully for amendment", applicationAmendmentRequestResponse);
if (Boolean.TRUE.equals(applicationAmendmentRequestResponse.getIsSendEmail())) {
emailNotificationDao.sendMailToNotifyBeneficiaryRegardingNewAmendment(applicationAmendmentRequestEntity);
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
applicationAmendmentRequestResponse.setEmailSendResponse(emailSendResponse);
}
return applicationAmendmentRequestResponse;
}
@@ -1168,12 +1176,13 @@ public class ApplicationAmendmentRequestDao {
return response;
}
public void sendReminderEmail(Long amendmentId) {
public EmailReminderResponse sendReminderEmail(Long amendmentId) {
ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentId)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG)));
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId());
EmailReminderResponse emailReminderResponse = new EmailReminderResponse();
if (entityOptional.isPresent()) {
ApplicationEntity applicationEntity = applicationService.validateApplication(entityOptional.get().getApplicationId());
UserEntity beneficiaryUser = userService.validateUser(applicationEntity.getUserId());
@@ -1186,10 +1195,13 @@ public class ApplicationAmendmentRequestDao {
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(emailTemplate.getEmailScenario(), RecipientTypeEnum.USER, beneficiaryUser.getId(), email,
beneficiaryUser.getId(), applicationEntity.getId(), amendment.getId(), applicationEntity.getCall().getId());
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email), emailLogRequest);
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
emailReminderResponse.setEmailSendResponse(emailSendResponse);
} else {
throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.BENEFICIARY_EMAIL_NOT_FOUND_MSG));
}
}
return emailReminderResponse;
}
private String prepareSubject(SystemEmailTemplateResponse template, ApplicationAmendmentRequestEntity amendment, UserEntity beneficiary) {

View File

@@ -1109,7 +1109,7 @@ public class ApplicationDao {
if (userEntity.getBeneficiary() != null) {
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
email = userEntity.getBeneficiary().getEmail();
emailLogRequest.setUserId(userEntity.getBeneficiary().getId());
emailLogRequest.setRecipientId(userEntity.getBeneficiary().getId());
}
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
List<String> recipientEmails = new ArrayList<>();
@@ -2134,4 +2134,42 @@ public class ApplicationDao {
}
public void sendApplicationSubmissionFailureEmail(EmailLogRequest emailLogRequest){
Long callId = emailLogRequest.getCallId();
CallEntity call = callService.validateCall(callId);
HubEntity hub = call.getHub();
Long userId = emailLogRequest.getUserId();
UserEntity user = userService.validateUser(userId);
Long applicationId = emailLogRequest.getApplicatioId();
ApplicationEntity applicationEntity = validateApplication(applicationId);
CompanyEntity company = companyService.validateCompany(applicationEntity.getCompanyId());
SystemEmailTemplateResponse systemEmailTemplateResponse = systemEmailTemplatesService
.retrieveTemplateByTypeAndCall(SystemEmailTemplatesEntityTypeEnum.APPLICATION_SUBMISSION_FAILURE_NOTIFICATION,
hub, null);
Map<String, String> subjectPlaceholders = new HashMap<>();
subjectPlaceholders.put("{{call_name}}", call.getName());
Map<String, String> bodyPlaceholders = new HashMap<>();
bodyPlaceholders.put("{{scenario}}",emailLogRequest.getEmailType().getValue());
bodyPlaceholders.put("{{call_name}}", call.getName());
bodyPlaceholders.put("{{application_id}}", applicationEntity.getId().toString());
bodyPlaceholders.put("{{company_name}}", company.getCompanyName());
bodyPlaceholders.put("{{protocol_number}}", applicationEntity.getProtocol().getProtocolNumber().toString());
bodyPlaceholders.put("{{user_action_id}}",emailLogRequest.getUserActionId().toString());
String subject = Utils.replacePlaceholders(systemEmailTemplateResponse.getSubject(), subjectPlaceholders);
String body = Utils.replacePlaceholders(systemEmailTemplateResponse.getHtmlContent(), bodyPlaceholders);
emailLogRequest=emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(),RecipientTypeEnum.PROPERTIES,null,user.getEmail(),user.getId(),applicationEntity.getId(),null,callId);
emailLogRequest.setRecipientEmails(GepafinConstant.RINALDO_EMAIL);
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(GepafinConstant.RINALDO_EMAIL),emailLogRequest);
}
}

View File

@@ -143,6 +143,9 @@ public class ApplicationEvaluationDao {
@Autowired
private ObjectMapper objectMapper;
@Autowired
private EmailDao emailDao;
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
@@ -1876,7 +1879,7 @@ public class ApplicationEvaluationDao {
assignedApplicationsEntity.getId());
ApplicationEvaluationEntity entity;
EmailSendResponse emailSendResponse = new EmailSendResponse();
if (existingEntityOptional.isPresent()) {
ApplicationEvaluationEntity existingEntity = existingEntityOptional.get();
// UserEntity userEntity = userService.validateUser(application.getUserId());
@@ -1888,6 +1891,8 @@ public class ApplicationEvaluationDao {
application.setStatus(newStatus.getValue());
log.info("Status updated to ADMISSIBLE for applicationId: " + application.getId());
emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(application);
emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
}
if(newStatus.equals(ApplicationStatusForEvaluation.TECHNICAL_EVALUATION) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.ADMISSIBLE.getValue()))){
@@ -1944,13 +1949,16 @@ public class ApplicationEvaluationDao {
application.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
application = applicationRepository.save(application);
emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
}
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT);
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_RESULT);
notificationDao.sendNotificationToInstructor(placeHolders,existingEntity,NotificationTypeEnum.EVALUATION_RESULT);
return convertToResponse(entity);
ApplicationEvaluationResponse response = convertToResponse(entity);
response.setEmailSendResponse(emailSendResponse);
return response;
}
return null;
}

View File

@@ -0,0 +1,91 @@
package net.gepafin.tendermanagement.dao;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.CallEntity;
import net.gepafin.tendermanagement.entities.EmailLogEntity;
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
import net.gepafin.tendermanagement.enums.RecipientTypeEnum;
import net.gepafin.tendermanagement.enums.StatusTypeEnum;
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
import net.gepafin.tendermanagement.model.response.EmailResendResponseBean;
import net.gepafin.tendermanagement.model.response.EmailSendResponse;
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
import net.gepafin.tendermanagement.service.CallService;
import net.gepafin.tendermanagement.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
@Component
@Log4j2
public class EmailDao {
@Autowired
EmailLogRepository emailLogRepository;
@Autowired
EmailNotificationDao emailNotificationDao;
@Autowired
private CallService callService;
public EmailResendResponseBean resendEmail(HttpServletRequest request , Long userActionId){
List<EmailLogEntity> emailLogs = emailLogRepository.findByUserActionIdAndEmailServiceType(userActionId,EmailServiceTypeEnum.PEC_SERVICE.getValue());
if (emailLogs.isEmpty()) {
log.info("No emails found for given userActionId.");
}
EmailResendResponseBean emailResendResponseBean = new EmailResendResponseBean();
for (EmailLogEntity log : emailLogs){
EmailLogRequest emailLogRequest = new EmailLogRequest();
emailLogRequest.setEmailType(EmailScenarioTypeEnum.valueOf(log.getEmailType()));
emailLogRequest.setRecipientType(RecipientTypeEnum.valueOf(log.getRecipientType()));
emailLogRequest.setRecipientId(log.getRecipientId());
emailLogRequest.setUserId(log.getUserId());
emailLogRequest.setApplicatioId(log.getApplicationId());
emailLogRequest.setCallId(log.getCallId());
emailLogRequest.setAmendmentId(log.getAmendmentId());
List<String> recipients = Utils.commaSeparatedStringToList(log.getRecipientEmails());
CallEntity call = callService.validateCall(log.getCallId());
emailNotificationDao.sendMail(
call.getHub().getId(),
log.getEmailSubject(),
log.getEmailBody(),
recipients,
emailLogRequest
);
}
EmailSendResponse emailSendResponse = buildEmailSendResponseFromRequest(request);
emailResendResponseBean.setEmailSendResponse(emailSendResponse);
return emailResendResponseBean;
}
public EmailSendResponse buildEmailSendResponseFromRequest(HttpServletRequest request) {
Long userActionId = (Long) request.getAttribute(GepafinConstant.USER_ACTION_ID);
boolean isEmailSendSuccess = isEmailSentSuccessfully(userActionId);
EmailSendResponse emailSendResponse = new EmailSendResponse();
emailSendResponse.setIsEmailSend(isEmailSendSuccess);
emailSendResponse.setUserActionId(userActionId);
return emailSendResponse;
}
public boolean isEmailSentSuccessfully(Long userActionId) {
List<EmailLogEntity> emailLogs = emailLogRepository.findByUserActionId(userActionId);
for (EmailLogEntity log : emailLogs) {
if (EmailServiceTypeEnum.PEC_SERVICE.getValue().equals(log.getEmailServiceType()) &&
StatusTypeEnum.SUCCESS.getValue().equals(log.getSendStatus())) {
return true;
}
}
return false;
}
}

View File

@@ -1,6 +1,7 @@
package net.gepafin.tendermanagement.dao;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.EmailLogEntity;
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum;
@@ -9,6 +10,7 @@ import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
import net.gepafin.tendermanagement.repositories.UserActionsRepository;
import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.LoggingUtil;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +24,12 @@ public class EmailLogDao {
@Autowired
private EmailLogRepository emailLogRepository;
@Autowired
private HttpServletRequest request;
@Autowired
private LoggingUtil loggingUtil;
public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest) {
@@ -42,8 +50,8 @@ public class EmailLogDao {
emailLogEntity.setApplicationId(emailLogRequest.getApplicatioId());
emailLogEntity.setAmendmentId(emailLogRequest.getAmendmentId());
emailLogEntity.setCallId(emailLogRequest.getCallId());
emailLogEntity.setUserAction(loggingUtil.getUserActionLogById(emailLogRequest.getUserActionId()));
emailLogEntity = saveEmailLogEntity(emailLogEntity);
return emailLogEntity;
}
public EmailLogEntity saveEmailLogEntity(EmailLogEntity emailLogEntity){
@@ -52,6 +60,7 @@ public class EmailLogDao {
public EmailLogRequest createEmailLogRequest(EmailScenarioTypeEnum emailType, RecipientTypeEnum recipientType, Long recipientId,
String recipientEmails, Long userId,Long applicationId,Long amendmentId,Long callId) {
EmailLogRequest emailLogRequest = new EmailLogRequest();
Long userActionId =(Long) request.getAttribute(GepafinConstant.USER_ACTION_ID);
emailLogRequest.setEmailType(emailType);
emailLogRequest.setRecipientType(recipientType);
emailLogRequest.setRecipientId(recipientId);
@@ -60,6 +69,7 @@ public class EmailLogDao {
emailLogRequest.setApplicatioId(applicationId);
emailLogRequest.setAmendmentId(amendmentId);
emailLogRequest.setCallId(callId);
emailLogRequest.setUserActionId(userActionId);
return emailLogRequest;
}
}

View File

@@ -139,7 +139,7 @@ public class EmailNotificationDao {
}
}
}
if (rinaldoEmail != null) {
if (GepafinConstant.RINALDO_EMAIL.equals(rinaldoEmail)) {
EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null ,
rinaldoEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId());
@@ -283,12 +283,11 @@ public class EmailNotificationDao {
if (recipientEmails.stream().anyMatch(email -> email.equals(GepafinConstant.RINALDO_EMAIL))) {
emailConfig.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
} else {
emailConfig = retrieveEmailConfig(hubId);
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
}
}

View File

@@ -15,6 +15,7 @@ import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.model.util.SortBy;
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.HubService;
import net.gepafin.tendermanagement.service.RoleService;
@@ -109,9 +110,15 @@ public class UserDao {
@Autowired
private EmailNotificationDao emailNotificationDao;
@Autowired
private EmailLogRepository emailLogRepository;
@Value("${fe.base.url}")
private String feBaseUrl;
@Autowired
EmailDao emailDao;
public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
if (StringUtils.isEmpty(userReq.getHubUuid())) {
@@ -134,7 +141,6 @@ public class UserDao {
authenticationService.createSuccessLoginAttempt(loginAttemptEntity);
}
JWTToken token = authService.getJWTTokenBean(userEntity, Boolean.TRUE, loginAttemptEntity.getId());
/** This code is responsible for adding a version history log for the "Create beneficiary" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).newData(beneficiary).build());
@@ -142,12 +148,30 @@ public class UserDao {
/** This code is responsible for adding a version history log for the "Create user" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.INSERT).newData(userEntity).build());
EmailSendResponse emailSendResponse = new EmailSendResponse();
if(Boolean.FALSE.equals(roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()))){
sendEmailToOnboardingUser(userEntity, userReq );
boolean isEmailSendSuccess = isEmailSentSuccessfully(userEntity.getId());
emailSendResponse.setIsEmailSend(isEmailSendSuccess);
Long userActionId =(Long)request.getAttribute(GepafinConstant.USER_ACTION_ID);
emailSendResponse.setUserActionId(userActionId);
}
JWTToken token = authService.getJWTTokenBean(userEntity, Boolean.TRUE, loginAttemptEntity.getId(),emailSendResponse);
return token;
}
public void sendEmailToOnboardingUser(UserEntity userEntity,UserReq userReq){
public boolean isEmailSentSuccessfully(Long userId) {
Optional<EmailLogEntity> latestLogOpt = emailLogRepository
.findTopByUserIdAndEmailTypeAndIsDeletedFalseOrderByCreatedDateDesc(userId, EmailScenarioTypeEnum.USER_CREATION.getValue());
return latestLogOpt
.map(log -> StatusTypeEnum.SUCCESS.getValue().equals(log.getSendStatus()))
.orElse(false);
}
public void sendEmailToOnboardingUser(UserEntity userEntity,UserReq userReq){
SystemEmailTemplateResponse emailTemplate;
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
@@ -459,7 +483,7 @@ public class UserDao {
return user;
}
public void initiatePasswordReset(InitiatePasswordResetReq resetReq) {
public InitiatePasswordResetResponse initiatePasswordReset(InitiatePasswordResetReq resetReq) {
UserEntity user = userRepository.findUserExcludingRoleType(
resetReq.getEmail(),
resetReq.getHubUuid(),
@@ -478,8 +502,11 @@ public class UserDao {
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
log.info("Password reset token generated for user: {}", resetReq.getEmail());
sendResetPasswordTokenEmail(user, token);
InitiatePasswordResetResponse initiatePasswordResetResponse = new InitiatePasswordResetResponse();
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
initiatePasswordResetResponse.setEmailSendResponse(emailSendResponse);
return initiatePasswordResetResponse;
}
public void sendResetPasswordTokenEmail(UserEntity user, String token) {