Merge pull request #278 from Kitzanos/feature/GEPAFINBE-210

GEPAFINBE-210 ( Manage error in PEC )
This commit is contained in:
Rinaldo
2025-05-02 15:41:11 +02:00
committed by GitHub
44 changed files with 636 additions and 75 deletions

View File

@@ -537,6 +537,14 @@ public class GepafinConstant {
public static final String APPLICATION_STATUS="applicationStatus"; public static final String APPLICATION_STATUS="applicationStatus";
public static final String RINALDO_EMAIL = "rinaldo.bonazzo@bflows.net"; public static final String RINALDO_EMAIL = "rinaldo.bonazzo@bflows.net";
public static final String RESEND_EMAIL_SENT_SUCCESS_MSG = "resend.email.sent.success.msg";
public static final String RESEND_EMAIL_SENT_FAILED_MSG = "resend.email.sent.failed.msg";
public static final String REMINDER_EMAIL_FAILED_MSG = "reminder.email.sent.failed.msg";
} }

View File

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

View File

@@ -1109,7 +1109,7 @@ public class ApplicationDao {
if (userEntity.getBeneficiary() != null) { if (userEntity.getBeneficiary() != null) {
emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY); emailLogRequest.setRecipientType(RecipientTypeEnum.BENEFICIARY);
email = userEntity.getBeneficiary().getEmail(); email = userEntity.getBeneficiary().getEmail();
emailLogRequest.setUserId(userEntity.getBeneficiary().getId()); emailLogRequest.setRecipientId(userEntity.getBeneficiary().getId());
} }
emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest); emailNotificationDao.sendMail(hub.getId(), subject, body, List.of(email),emailLogRequest);
List<String> recipientEmails = new ArrayList<>(); 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 @Autowired
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@Autowired
private EmailDao emailDao;
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) { private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
@@ -1876,7 +1879,7 @@ public class ApplicationEvaluationDao {
assignedApplicationsEntity.getId()); assignedApplicationsEntity.getId());
ApplicationEvaluationEntity entity; ApplicationEvaluationEntity entity;
EmailSendResponse emailSendResponse = new EmailSendResponse();
if (existingEntityOptional.isPresent()) { if (existingEntityOptional.isPresent()) {
ApplicationEvaluationEntity existingEntity = existingEntityOptional.get(); ApplicationEvaluationEntity existingEntity = existingEntityOptional.get();
// UserEntity userEntity = userService.validateUser(application.getUserId()); // UserEntity userEntity = userService.validateUser(application.getUserId());
@@ -1888,6 +1891,8 @@ public class ApplicationEvaluationDao {
application.setStatus(newStatus.getValue()); application.setStatus(newStatus.getValue());
log.info("Status updated to ADMISSIBLE for applicationId: " + application.getId()); log.info("Status updated to ADMISSIBLE for applicationId: " + application.getId());
emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(application); emailNotificationDao.sendAdmissibilityNotificationEmailForAdmissibleApplication(application);
emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
} }
if(newStatus.equals(ApplicationStatusForEvaluation.TECHNICAL_EVALUATION) && Boolean.TRUE.equals(application.getStatus().equals(ApplicationStatusTypeEnum.ADMISSIBLE.getValue()))){ 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.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
application = applicationRepository.save(application); application = applicationRepository.save(application);
emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity); emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
} }
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT); Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_RESULT);
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_RESULT); notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_RESULT);
notificationDao.sendNotificationToInstructor(placeHolders,existingEntity,NotificationTypeEnum.EVALUATION_RESULT); notificationDao.sendNotificationToInstructor(placeHolders,existingEntity,NotificationTypeEnum.EVALUATION_RESULT);
return convertToResponse(entity); ApplicationEvaluationResponse response = convertToResponse(entity);
response.setEmailSendResponse(emailSendResponse);
return response;
} }
return null; 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; package net.gepafin.tendermanagement.dao;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.EmailLogEntity; import net.gepafin.tendermanagement.entities.EmailLogEntity;
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum; import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
import net.gepafin.tendermanagement.enums.EmailEntityTypeEnum; 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.EmailLogRequest;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest; import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.repositories.EmailLogRepository; import net.gepafin.tendermanagement.repositories.EmailLogRepository;
import net.gepafin.tendermanagement.repositories.UserActionsRepository;
import net.gepafin.tendermanagement.util.DateTimeUtil; import net.gepafin.tendermanagement.util.DateTimeUtil;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +24,12 @@ public class EmailLogDao {
@Autowired @Autowired
private EmailLogRepository emailLogRepository; private EmailLogRepository emailLogRepository;
@Autowired
private HttpServletRequest request;
@Autowired
private LoggingUtil loggingUtil;
public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest) { public EmailLogEntity createEmailLog(EmailLogRequest emailLogRequest) {
@@ -42,8 +50,8 @@ public class EmailLogDao {
emailLogEntity.setApplicationId(emailLogRequest.getApplicatioId()); emailLogEntity.setApplicationId(emailLogRequest.getApplicatioId());
emailLogEntity.setAmendmentId(emailLogRequest.getAmendmentId()); emailLogEntity.setAmendmentId(emailLogRequest.getAmendmentId());
emailLogEntity.setCallId(emailLogRequest.getCallId()); emailLogEntity.setCallId(emailLogRequest.getCallId());
emailLogEntity.setUserAction(loggingUtil.getUserActionLogById(emailLogRequest.getUserActionId()));
emailLogEntity = saveEmailLogEntity(emailLogEntity); emailLogEntity = saveEmailLogEntity(emailLogEntity);
return emailLogEntity; return emailLogEntity;
} }
public EmailLogEntity saveEmailLogEntity(EmailLogEntity emailLogEntity){ public EmailLogEntity saveEmailLogEntity(EmailLogEntity emailLogEntity){
@@ -52,6 +60,7 @@ public class EmailLogDao {
public EmailLogRequest createEmailLogRequest(EmailScenarioTypeEnum emailType, RecipientTypeEnum recipientType, Long recipientId, public EmailLogRequest createEmailLogRequest(EmailScenarioTypeEnum emailType, RecipientTypeEnum recipientType, Long recipientId,
String recipientEmails, Long userId,Long applicationId,Long amendmentId,Long callId) { String recipientEmails, Long userId,Long applicationId,Long amendmentId,Long callId) {
EmailLogRequest emailLogRequest = new EmailLogRequest(); EmailLogRequest emailLogRequest = new EmailLogRequest();
Long userActionId =(Long) request.getAttribute(GepafinConstant.USER_ACTION_ID);
emailLogRequest.setEmailType(emailType); emailLogRequest.setEmailType(emailType);
emailLogRequest.setRecipientType(recipientType); emailLogRequest.setRecipientType(recipientType);
emailLogRequest.setRecipientId(recipientId); emailLogRequest.setRecipientId(recipientId);
@@ -60,6 +69,7 @@ public class EmailLogDao {
emailLogRequest.setApplicatioId(applicationId); emailLogRequest.setApplicatioId(applicationId);
emailLogRequest.setAmendmentId(amendmentId); emailLogRequest.setAmendmentId(amendmentId);
emailLogRequest.setCallId(callId); emailLogRequest.setCallId(callId);
emailLogRequest.setUserActionId(userActionId);
return emailLogRequest; 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 , EmailLogRequest emailLogRequest = emailLogDao.createEmailLogRequest(systemEmailTemplateResponse.getEmailScenario(), RecipientTypeEnum.PROPERTIES,null ,
rinaldoEmail, userEntity.getId(), applicationEntity.getId(), amendmentId, applicationEntity.getCall().getId()); 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))) { if (recipientEmails.stream().anyMatch(email -> email.equals(GepafinConstant.RINALDO_EMAIL))) {
emailConfig.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue()); emailConfig.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE.getValue());
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType()); EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType());
emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest); emailService.sendEmail(subject, body, recipientEmails, emailConfig, emailLogRequest);
} else { } else {
emailConfig = retrieveEmailConfig(hubId); emailConfig = retrieveEmailConfig(hubId);
EmailService emailService = emailServiceFactory.getEmailService(emailConfig.getEmailServiceType()); 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.JWTToken;
import net.gepafin.tendermanagement.model.util.SortBy; import net.gepafin.tendermanagement.model.util.SortBy;
import net.gepafin.tendermanagement.repositories.BeneficiaryRepository; import net.gepafin.tendermanagement.repositories.BeneficiaryRepository;
import net.gepafin.tendermanagement.repositories.EmailLogRepository;
import net.gepafin.tendermanagement.repositories.UserRepository; import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.HubService; import net.gepafin.tendermanagement.service.HubService;
import net.gepafin.tendermanagement.service.RoleService; import net.gepafin.tendermanagement.service.RoleService;
@@ -109,9 +110,15 @@ public class UserDao {
@Autowired @Autowired
private EmailNotificationDao emailNotificationDao; private EmailNotificationDao emailNotificationDao;
@Autowired
private EmailLogRepository emailLogRepository;
@Value("${fe.base.url}") @Value("${fe.base.url}")
private String feBaseUrl; private String feBaseUrl;
@Autowired
EmailDao emailDao;
public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) { public JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq) {
if (StringUtils.isEmpty(userReq.getHubUuid())) { if (StringUtils.isEmpty(userReq.getHubUuid())) {
@@ -134,7 +141,6 @@ public class UserDao {
authenticationService.createSuccessLoginAttempt(loginAttemptEntity); 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. **/ /** 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()); 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. **/ /** 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()); 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()))){ if(Boolean.FALSE.equals(roleEntity.getRoleType().equals(RoleStatusEnum.ROLE_BENEFICIARY.getValue()))){
sendEmailToOnboardingUser(userEntity, userReq ); 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; 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; SystemEmailTemplateResponse emailTemplate;
RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType()); RoleStatusEnum roleStatus = RoleStatusEnum.valueOf(userEntity.getRoleEntity().getRoleType());
@@ -459,7 +483,7 @@ public class UserDao {
return user; return user;
} }
public void initiatePasswordReset(InitiatePasswordResetReq resetReq) { public InitiatePasswordResetResponse initiatePasswordReset(InitiatePasswordResetReq resetReq) {
UserEntity user = userRepository.findUserExcludingRoleType( UserEntity user = userRepository.findUserExcludingRoleType(
resetReq.getEmail(), resetReq.getEmail(),
resetReq.getHubUuid(), resetReq.getHubUuid(),
@@ -478,8 +502,11 @@ public class UserDao {
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build()); loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldUserEntity).newData(user).build());
log.info("Password reset token generated for user: {}", resetReq.getEmail()); log.info("Password reset token generated for user: {}", resetReq.getEmail());
sendResetPasswordTokenEmail(user, token); sendResetPasswordTokenEmail(user, token);
InitiatePasswordResetResponse initiatePasswordResetResponse = new InitiatePasswordResetResponse();
EmailSendResponse emailSendResponse = emailDao.buildEmailSendResponseFromRequest(request);
initiatePasswordResetResponse.setEmailSendResponse(emailSendResponse);
return initiatePasswordResetResponse;
} }
public void sendResetPasswordTokenEmail(UserEntity user, String token) { public void sendResetPasswordTokenEmail(UserEntity user, String token) {

View File

@@ -56,5 +56,9 @@ public class EmailLogEntity extends BaseEntity{
@Column(name = "is_deleted") @Column(name = "is_deleted")
private Boolean isDeleted; private Boolean isDeleted;
@ManyToOne
@JoinColumn(name = "user_action_id")
private UserActionEntity userAction;
} }

View File

@@ -55,7 +55,8 @@ public class SystemEmailTemplatesEntity extends BaseEntity {
USER_ONBOARDING_CONFIDI("USER_ONBOARDING_CONFIDI"), USER_ONBOARDING_CONFIDI("USER_ONBOARDING_CONFIDI"),
USER_ONBOARDING_BANDI("USER_ONBOARDING_BANDI"), USER_ONBOARDING_BANDI("USER_ONBOARDING_BANDI"),
PASSWORD_RESET("PASSWORD_RESET"), PASSWORD_RESET("PASSWORD_RESET"),
INADMISSIBILITY_TEMPLATE("INADMISSIBILITY_NOTIFICATION"); INADMISSIBILITY_TEMPLATE("INADMISSIBILITY_NOTIFICATION"),
APPLICATION_SUBMISSION_FAILURE_NOTIFICATION("APPLICATION_SUBMISSION_FAILURE_NOTIFICATION");
private String value; private String value;
SystemEmailTemplatesEntityTypeEnum(String value) { SystemEmailTemplatesEntityTypeEnum(String value) {

View File

@@ -11,7 +11,8 @@ public enum EmailScenarioTypeEnum {
APPLICATION_ADMISSIBLE("APPLICATION_ADMISSIBLE"), APPLICATION_ADMISSIBLE("APPLICATION_ADMISSIBLE"),
USER_CREATION("USER_CREATION"), USER_CREATION("USER_CREATION"),
PASSWORD_RESET_REQUEST("PASSWORD_RESET_REQUEST"), PASSWORD_RESET_REQUEST("PASSWORD_RESET_REQUEST"),
APPLICATION_REJECTED("APPLICATION_REJECTED"); APPLICATION_REJECTED("APPLICATION_REJECTED"),
APPLICATION_SUBMISSION_FAILURE("APPLICATION_SUBMISSION_FAILURE");
private final String value; private final String value;

View File

@@ -14,7 +14,8 @@ public enum NotificationTypeEnum {
EVALUATION_EXPIRED("EVALUATION_EXPIRED"), EVALUATION_EXPIRED("EVALUATION_EXPIRED"),
AMENDMENT_EXPIRATION_REMINDER("AMENDMENT_EXPIRATION_REMINDER"), AMENDMENT_EXPIRATION_REMINDER("AMENDMENT_EXPIRATION_REMINDER"),
EVALUATION_EXPIRATION_REMINDER("EVALUATION_EXPIRATION_REMINDER"), EVALUATION_EXPIRATION_REMINDER("EVALUATION_EXPIRATION_REMINDER"),
COMPANY_DOCUMENT_EXPIRATION_REMINDER("COMPANY_DOCUMENT_EXPIRATION_REMINDER"); COMPANY_DOCUMENT_EXPIRATION_REMINDER("COMPANY_DOCUMENT_EXPIRATION_REMINDER"),
PEC_EMAIL_SENDING_FAILURE("PEC_EMAIL_SENDING_FAILURE");
private final String value; private final String value;

View File

@@ -215,7 +215,9 @@ public enum UserActionContextEnum {
GET_ALL_USER_ACTION_BY_PAGINATION("GET_ALL_USER_ACTION_BY_PAGINATION"), GET_ALL_USER_ACTION_BY_PAGINATION("GET_ALL_USER_ACTION_BY_PAGINATION"),
GET_ALL_USER_BY_PAGINATION("GET_ALL_USER_BY_PAGINATION"), GET_ALL_USER_BY_PAGINATION("GET_ALL_USER_BY_PAGINATION"),
UPDATE_CALL_END_DATE_AND_TIME("UPDATE_CALL_END_DATE_AND_TIME"), UPDATE_CALL_END_DATE_AND_TIME("UPDATE_CALL_END_DATE_AND_TIME"),
UPDATE_EXPIRED_CALL("UPDATE_EXPIRED_CALL") ; UPDATE_EXPIRED_CALL("UPDATE_EXPIRED_CALL"),
RESEND_EMAIL("RESEND_EMAIL"),
SEND_REMINDER_EMAIL("SEND_REMINDER_EMAIL");
private final String value; private final String value;

View File

@@ -12,7 +12,8 @@ public enum UserActionLogsEnum {
DOWNLOAD("DOWNLOAD"), DOWNLOAD("DOWNLOAD"),
UPLOAD("UPLOAD"), UPLOAD("UPLOAD"),
SCHEDULER("SCHEDULER"), SCHEDULER("SCHEDULER"),
SCRIPT("SCRIPT"); SCRIPT("SCRIPT"),
EMAIL("EMAIL");
private final String value; private final String value;

View File

@@ -37,4 +37,6 @@ public class EmailLogRequest {
private Long callId; private Long callId;
private Long userActionId;
} }

View File

@@ -32,4 +32,5 @@ public class ApplicationAmendmentRequestResponse {
private String internalNote; private String internalNote;
private ApplicationAmendmentRequestEnum status; private ApplicationAmendmentRequestEnum status;
private String emailTemplate; private String emailTemplate;
private EmailSendResponse emailSendResponse;
} }

View File

@@ -49,5 +49,6 @@ public class ApplicationEvaluationResponse {
private EvaluationVersionEnum evaluationVersion; private EvaluationVersionEnum evaluationVersion;
private String companyVatNumber; private String companyVatNumber;
private String companyCodiceAteco; private String companyCodiceAteco;
private EmailSendResponse emailSendResponse;
} }

View File

@@ -0,0 +1,16 @@
package net.gepafin.tendermanagement.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EmailReminderResponse {
@JsonProperty("emailSendResponse")
private EmailSendResponse emailSendResponse;
}

View File

@@ -0,0 +1,12 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class EmailResendResponseBean {
private EmailSendResponse emailSendResponse;
}

View File

@@ -0,0 +1,9 @@
package net.gepafin.tendermanagement.model.response;
import lombok.Data;
@Data
public class EmailSendResponse {
private Boolean isEmailSend;
private Long userActionId;
}

View File

@@ -0,0 +1,13 @@
package net.gepafin.tendermanagement.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class InitiatePasswordResetResponse {
private EmailSendResponse emailSendResponse;
}

View File

@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.model.util;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
import net.gepafin.tendermanagement.model.response.EmailSendResponse;
import net.gepafin.tendermanagement.model.response.LoginResponse; import net.gepafin.tendermanagement.model.response.LoginResponse;
/** /**
@@ -15,10 +16,20 @@ public class JWTToken {
@JsonProperty("user") @JsonProperty("user")
private LoginResponse loginResponse; private LoginResponse loginResponse;
@JsonProperty("emailSendResponse")
private EmailSendResponse emailSendResponse;
public JWTToken(String token, LoginResponse loginResponse) { public JWTToken(String token, LoginResponse loginResponse) {
this.token = token; this.token = token;
this.loginResponse = loginResponse; this.loginResponse = loginResponse;
} }
public JWTToken(String token, LoginResponse loginResponse, EmailSendResponse emailSendResponse) {
this.token = token;
this.loginResponse = loginResponse;
this.emailSendResponse = emailSendResponse;
}
} }

View File

@@ -1,11 +1,18 @@
package net.gepafin.tendermanagement.repositories; package net.gepafin.tendermanagement.repositories;
import net.gepafin.tendermanagement.entities.EmailLogEntity; import net.gepafin.tendermanagement.entities.EmailLogEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; import java.util.List;
import java.util.Optional;
public interface EmailLogRepository extends JpaRepository<EmailLogEntity,Long> { public interface EmailLogRepository extends JpaRepository<EmailLogEntity,Long> {
List<EmailLogEntity> findByUserIdAndAmendmentIdAndIsDeletedFalse(Long userId,Long amendmentId); List<EmailLogEntity> findByUserIdAndAmendmentIdAndIsDeletedFalse(Long userId,Long amendmentId);
List<EmailLogEntity> findByUserActionId(Long userActionId);
List<EmailLogEntity> findByUserActionIdAndEmailServiceType(Long userActionId, String emailServiceType);
Optional<EmailLogEntity> findTopByUserIdAndEmailTypeAndIsDeletedFalseOrderByCreatedDateDesc(Long userId, String emailType);
} }

View File

@@ -8,10 +8,7 @@ import net.gepafin.tendermanagement.model.request.ApplicationAmendmentPagination
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean;
import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest; import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestViewResponse;
import net.gepafin.tendermanagement.model.response.PageableResponseBean;
import net.gepafin.tendermanagement.model.response.GetAllAmendmentResponseBean;
import java.util.List; import java.util.List;
@@ -29,6 +26,6 @@ public interface ApplicationAmendmentRequestService {
public List<ApplicationAmendmentRequestResponse> getAmendmentByApplicationId(HttpServletRequest request,Long applicationId,List<ApplicationAmendmentRequestEnum> statuses); public List<ApplicationAmendmentRequestResponse> getAmendmentByApplicationId(HttpServletRequest request,Long applicationId,List<ApplicationAmendmentRequestEnum> statuses);
public ApplicationAmendmentRequestResponse updateApplicationAmendmentStatus(HttpServletRequest request, Long applicationAmendmentId, ApplicationAmendmentRequestEnum status); public ApplicationAmendmentRequestResponse updateApplicationAmendmentStatus(HttpServletRequest request, Long applicationAmendmentId, ApplicationAmendmentRequestEnum status);
void sendReminderEmail(HttpServletRequest request,Long amendmentId); EmailReminderResponse sendReminderEmail(HttpServletRequest request, Long amendmentId);
PageableResponseBean<List<ApplicationAmendmentRequestViewResponse>> getApplicationAmendmentByPaginnation(HttpServletRequest request, Long userId, ApplicationAmendmentPaginationRequestBean amendmentPaginationRequestBean); PageableResponseBean<List<ApplicationAmendmentRequestViewResponse>> getApplicationAmendmentByPaginnation(HttpServletRequest request, Long userId, ApplicationAmendmentPaginationRequestBean amendmentPaginationRequestBean);
} }

View File

@@ -0,0 +1,9 @@
package net.gepafin.tendermanagement.service;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.model.response.EmailResendResponseBean;
public interface ResendEmailService {
EmailResendResponseBean resendEmail(HttpServletRequest request , Long userActionId);
}

View File

@@ -8,9 +8,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import net.gepafin.tendermanagement.enums.UserStatusEnum; import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.PageableResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.JWTToken; import net.gepafin.tendermanagement.model.util.JWTToken;
import java.util.List; import java.util.List;
@@ -28,7 +26,7 @@ public interface UserService {
UserEntity validateUser(Long userId); UserEntity validateUser(Long userId);
void initiatePasswordReset(InitiatePasswordResetReq resetReq); InitiatePasswordResetResponse initiatePasswordReset(InitiatePasswordResetReq resetReq);
Boolean resetPassword(ResetPasswordReq resetPasswordReq); Boolean resetPassword(ResetPasswordReq resetPasswordReq);

View File

@@ -12,10 +12,7 @@ import net.gepafin.tendermanagement.model.request.ApplicationAmendmentPagination
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest; import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequest;
import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean; import net.gepafin.tendermanagement.model.request.ApplicationAmendmentRequestBean;
import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest; import net.gepafin.tendermanagement.model.request.CloseAmendmentRequest;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestViewResponse;
import net.gepafin.tendermanagement.model.response.PageableResponseBean;
import net.gepafin.tendermanagement.model.response.GetAllAmendmentResponseBean;
import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository; import net.gepafin.tendermanagement.repositories.ApplicationAmendmentRequestRepository;
import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository; import net.gepafin.tendermanagement.repositories.ApplicationEvaluationRepository;
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
@@ -145,17 +142,18 @@ public class ApplicationAmendmentRequestServiceImpl implements ApplicationAmendm
} }
@Override @Override
public void sendReminderEmail(HttpServletRequest request,Long amendmentId) { public EmailReminderResponse sendReminderEmail(HttpServletRequest request, Long amendmentId) {
ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentId) ApplicationAmendmentRequestEntity amendment = applicationAmendmentRequestRepository.findByIdAndIsDeletedFalse(amendmentId)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, .orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG))); Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_NOT_FOUND_MSG)));
EmailReminderResponse response = new EmailReminderResponse();
Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId()); Optional<ApplicationEvaluationEntity> entityOptional = applicationEvaluationRepository.findByIdAndIsDeletedFalse(amendment.getApplicationEvaluationEntity().getId());
if (entityOptional.isPresent()) { if (entityOptional.isPresent()) {
UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId()); UserEntity user = validator.validatePreInstructor(request, entityOptional.get().getUserId());
response = applicationAmendmentRequestDao.sendReminderEmail(amendmentId);
applicationAmendmentRequestDao.sendReminderEmail(amendmentId);
} }
return response;
} }
@Override @Override

View File

@@ -15,10 +15,7 @@ import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.*; import net.gepafin.tendermanagement.enums.*;
import net.gepafin.tendermanagement.model.request.LoginReq; import net.gepafin.tendermanagement.model.request.LoginReq;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest; import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.CompanyResponse; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.LoginResponse;
import net.gepafin.tendermanagement.model.response.RoleResponseBean;
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
import net.gepafin.tendermanagement.model.util.JWTToken; import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.repositories.LoginAttemptRepository; import net.gepafin.tendermanagement.repositories.LoginAttemptRepository;
import net.gepafin.tendermanagement.repositories.SamlResponseRepository; import net.gepafin.tendermanagement.repositories.SamlResponseRepository;
@@ -122,7 +119,7 @@ public class AuthenticationService {
createFailedLoginAttempt(loginAttemptEntity, e.getMessage()); createFailedLoginAttempt(loginAttemptEntity, e.getMessage());
throw e; throw e;
} }
return getJWTTokenBean(user, loginReq.getRememberMe(), loginAttemptEntity.getId()); return getJWTTokenBean(user, loginReq.getRememberMe(), loginAttemptEntity.getId(),null);
} }
public LoginAttemptEntity prepareLoginAttemptEntity(LoginReq loginUserReq, HttpServletRequest request) { public LoginAttemptEntity prepareLoginAttemptEntity(LoginReq loginUserReq, HttpServletRequest request) {
@@ -145,7 +142,7 @@ public class AuthenticationService {
loginAttemptEntity.setErrorMsg(errorMsg); loginAttemptEntity.setErrorMsg(errorMsg);
loginAttemptDao.createLoginAttempt(loginAttemptEntity); loginAttemptDao.createLoginAttempt(loginAttemptEntity);
} }
public JWTToken getJWTTokenBean(UserEntity user, Boolean rememberMe, Long loginAttemptId) { public JWTToken getJWTTokenBean(UserEntity user, Boolean rememberMe, Long loginAttemptId, EmailSendResponse emailSendResponse) {
UserEntity oldUserEntity = Utils.getClonedEntityForData(user); UserEntity oldUserEntity = Utils.getClonedEntityForData(user);
user.setLastLogin(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); user.setLastLogin(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
user = userRepository.save(user); user = userRepository.save(user);
@@ -156,7 +153,7 @@ public class AuthenticationService {
LoginResponse loginResponse = getLoginResponse(user, roleResponseBean); LoginResponse loginResponse = getLoginResponse(user, roleResponseBean);
JWTToken jwtToken = new JWTToken(token, loginResponse); JWTToken jwtToken = new JWTToken(token, loginResponse , emailSendResponse);
/** This code is responsible for adding a version history log for the "Create user Or Update user" operation. **/ /** This code is responsible for adding a version history log for the "Create user Or Update user" operation. **/
loggingUtil.addVersionHistoryWithoutToken(VersionHistoryRequest.builder().request(request).oldData(oldUserEntity).newData(user).actionType(VersionActionTypeEnum.UPDATE).build()); loggingUtil.addVersionHistoryWithoutToken(VersionHistoryRequest.builder().request(request).oldData(oldUserEntity).newData(user).actionType(VersionActionTypeEnum.UPDATE).build());
@@ -238,7 +235,7 @@ public class AuthenticationService {
loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request); loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
loginAttemptEntity.setUserId(userEntity.getId()); loginAttemptEntity.setUserId(userEntity.getId());
LoginAttemptEntity loginAttempt = createSuccessLoginAttempt(loginAttemptEntity); LoginAttemptEntity loginAttempt = createSuccessLoginAttempt(loginAttemptEntity);
return getJWTTokenBean(userEntity, Boolean.TRUE, loginAttempt.getId()); return getJWTTokenBean(userEntity, Boolean.TRUE, loginAttempt.getId(),null);
} catch (Exception e) { } catch (Exception e) {
log.info("Authentication login failed for email: {}",e.getMessage()); log.info("Authentication login failed for email: {}",e.getMessage());
loginAttemptEntity.setUserId(userId); loginAttemptEntity.setUserId(userId);

View File

@@ -1,25 +1,32 @@
package net.gepafin.tendermanagement.service.impl; package net.gepafin.tendermanagement.service.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.Unirest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.dao.ApplicationDao;
import net.gepafin.tendermanagement.dao.EmailLogDao; import net.gepafin.tendermanagement.dao.EmailLogDao;
import net.gepafin.tendermanagement.entities.EmailLogEntity; import net.gepafin.tendermanagement.dao.NotificationDao;
import net.gepafin.tendermanagement.enums.EmailScenarioTypeEnum;
import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum; import net.gepafin.tendermanagement.enums.EmailServiceTypeEnum;
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
import net.gepafin.tendermanagement.enums.StatusTypeEnum; import net.gepafin.tendermanagement.enums.StatusTypeEnum;
import net.gepafin.tendermanagement.model.request.EmailConfig; import net.gepafin.tendermanagement.model.request.EmailConfig;
import net.gepafin.tendermanagement.model.request.EmailLogRequest; import net.gepafin.tendermanagement.model.request.EmailLogRequest;
import net.gepafin.tendermanagement.model.request.NotificationReq;
import net.gepafin.tendermanagement.model.request.PecEmailRequest; import net.gepafin.tendermanagement.model.request.PecEmailRequest;
import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.util.Validator; import net.gepafin.tendermanagement.util.Validator;
import org.opensaml.xmlsec.signature.G;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Slf4j @Slf4j
@Service @Service
@@ -30,20 +37,26 @@ public class PecEmailService implements EmailService {
@Value("${isPecServiceEnabled}") @Value("${isPecServiceEnabled}")
private String isPecServiceEnabled; private String isPecServiceEnabled;
@Autowired @Autowired
private Validator validator; private Validator validator;
@Autowired @Autowired
private EmailLogDao emailLogDao; private EmailLogDao emailLogDao;
@Autowired
private NotificationDao notificationDao;
@Autowired
private ApplicationDao applicationDao;
@Override @Override
public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest) { public void sendEmail(String subject, String body, List<String> recipientEmails, EmailConfig emailConfig, EmailLogRequest emailLogRequest) {
if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) { if (Boolean.FALSE.equals(Boolean.parseBoolean(isEmailSendingEnabled))) {
return; return;
} }
PecEmailRequest emailRequest = new PecEmailRequest(); PecEmailRequest emailRequest = new PecEmailRequest();
emailRequest.setSender(emailConfig.getSender()); emailRequest.setSender(emailConfig.getSender());
emailRequest.setSubject(subject); emailRequest.setSubject(subject);
@@ -67,13 +80,27 @@ public class PecEmailService implements EmailService {
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.body(Utils.convertObjectToJson(emailRequest)) // Serialize the emailRequest object to JSON .body(Utils.convertObjectToJson(emailRequest)) // Serialize the emailRequest object to JSON
.asString(); .asString();
if (!isSuccessfulPecResponse(response2.getBody())) {
String errorMsg = "PEC sending failed: " + response2.getBody();
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
emailLogRequest.setErrorMessage(errorMsg);
sendNotificationOnFailure(emailLogRequest.getUserId(),emailLogRequest.getEmailType());
if (EmailScenarioTypeEnum.APPLICATION_SUBMITTED.equals(emailLogRequest.getEmailType())) {
applicationDao.sendApplicationSubmissionFailureEmail(emailLogRequest);
}
}
} }
}catch(Exception e) { }catch(Exception e) {
emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue()); emailLogRequest.setSendStatus(StatusTypeEnum.FAILED.getValue());
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE); emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
emailLogRequest.setErrorMessage(e.getMessage()); emailLogRequest.setErrorMessage(e.getMessage());
emailLogDao.createEmailLog(emailLogRequest); sendNotificationOnFailure(emailLogRequest.getUserId(),emailLogRequest.getEmailType());
throw new RuntimeException("Failed to send email via PEC: " + response2.getStatus()); if (EmailScenarioTypeEnum.APPLICATION_SUBMITTED.equals(emailLogRequest.getEmailType())) {
applicationDao.sendApplicationSubmissionFailureEmail(emailLogRequest);
}
} }
if(response2 != null) { if(response2 != null) {
emailLogRequest.setEmailServiceResponse(response2.getBody()); emailLogRequest.setEmailServiceResponse(response2.getBody());
@@ -82,6 +109,57 @@ public class PecEmailService implements EmailService {
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE); emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.PEC_SERVICE);
emailLogDao.createEmailLog(emailLogRequest); emailLogDao.createEmailLog(emailLogRequest);
} }
private void sendNotificationOnFailure(Long userId, EmailScenarioTypeEnum emailScenarioTypeEnum) {
if (userId == null) {
log.warn("Cannot send notification: userId is null.");
return;
}
Map<String, String> placeholders = new HashMap<>();
placeholders.put("{{email_scenario}}", emailScenarioTypeEnum.getValue());
NotificationReq notificationReq = notificationDao.createNotificationReq(
NotificationTypeEnum.PEC_EMAIL_SENDING_FAILURE.getValue(),
placeholders,
userId,
null,
null
);
try {
notificationDao.sendNotification(notificationReq);
log.info("Sent PEC failure notification to user {}", userId);
} catch (Exception e) {
log.error("Failed to send PEC failure notification to user {}: {}", userId, e.getMessage());
}
}
private boolean isSuccessfulPecResponse(String responseBody) {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(responseBody);
boolean success = jsonNode.has("success") && jsonNode.get("success").asBoolean();
boolean hasNoError = !jsonNode.has("error") || jsonNode.get("error").isNull();
if (jsonNode.has("success") && !success) {
log.error("PEC response indicates failure: {}", responseBody);
return false;
}
if (responseBody.contains("403") || responseBody.toLowerCase().contains("<html") || responseBody.toLowerCase().contains("<!doctype html>")) {
log.error("PEC response is a 403 HTML Forbidden page or invalid format: {}", responseBody);
return false;
}
return success && hasNoError;
} catch (Exception e) {
log.error("Invalid PEC response format: {}", responseBody);
return false;
}
}
} }

View File

@@ -0,0 +1,25 @@
package net.gepafin.tendermanagement.service.impl;
import jakarta.servlet.http.HttpServletRequest;
import net.gepafin.tendermanagement.dao.EmailDao;
import net.gepafin.tendermanagement.model.response.EmailResendResponseBean;
import net.gepafin.tendermanagement.service.ResendEmailService;
import net.gepafin.tendermanagement.util.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ResendEmailServiceImpl implements ResendEmailService {
@Autowired
Validator validator;
@Autowired
EmailDao emailDao;
@Override
public EmailResendResponseBean resendEmail(HttpServletRequest request, Long userActionId) {
validator.validateUser(request);
return emailDao.resendEmail(request,userActionId);
}
}

View File

@@ -55,7 +55,7 @@ public class SystemEmailService implements EmailService {
emailLogRequest.setEmailBody(body); emailLogRequest.setEmailBody(body);
emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue()); emailLogRequest.setSendStatus(StatusTypeEnum.SUCCESS.getValue());
emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails)); emailLogRequest.setRecipientEmails(Utils.listToCommaSeparatedString(recipientEmails));
emailLogRequest.setEmailServiceType(EmailServiceTypeEnum.SYSTEM_EMAIL_SERVICE);
if (Boolean.FALSE.equals(validator.isTestProfileActivated())) { if (Boolean.FALSE.equals(validator.isTestProfileActivated())) {
MessageResponse response = null; MessageResponse response = null;
try { try {

View File

@@ -11,9 +11,7 @@ import net.gepafin.tendermanagement.model.request.UpdateUserReq;
import net.gepafin.tendermanagement.model.request.UserReq; import net.gepafin.tendermanagement.model.request.UserReq;
import net.gepafin.tendermanagement.enums.UserStatusEnum; import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.PageableResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.JWTToken; import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.service.UserService; import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
@@ -78,8 +76,8 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
public void initiatePasswordReset(InitiatePasswordResetReq resetReq) { public InitiatePasswordResetResponse initiatePasswordReset(InitiatePasswordResetReq resetReq) {
userDao.initiatePasswordReset(resetReq); return userDao.initiatePasswordReset(resetReq);
} }
@Override @Override

View File

@@ -1011,5 +1011,15 @@ public class Utils {
} }
} }
public static List<String> commaSeparatedStringToList(String emails) {
if (emails == null || emails.isEmpty()) {
return new ArrayList<>();
}
return Arrays.stream(emails.split(","))
.map(String::trim)
.collect(Collectors.toList());
}
} }

View File

@@ -183,7 +183,7 @@ public interface ApplicationAmendmentRequestApi {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })) @ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) }))
}) })
@PostMapping(value = "/{amendmentId}/reminder", produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/{amendmentId}/reminder", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Response<Void>> sendReminderEmail(HttpServletRequest request, ResponseEntity<Response<EmailReminderResponse>> sendReminderEmail(HttpServletRequest request,
@Parameter( required = true) @Parameter( required = true)
@PathVariable(value = "amendmentId") Long amendmentId); @PathVariable(value = "amendmentId") Long amendmentId);

View File

@@ -0,0 +1,40 @@
package net.gepafin.tendermanagement.web.rest.api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import net.gepafin.tendermanagement.model.request.CreateCallRequestStep1;
import net.gepafin.tendermanagement.model.response.CallResponse;
import net.gepafin.tendermanagement.model.response.EmailResendResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@Validated
public interface EmailApi {
@Operation(summary = "Api to resend the email",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
})
@PostMapping(value = "/resend", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Response<EmailResendResponseBean>> resendEmail(
HttpServletRequest request,
@Parameter(description = "The User Action ID", required = true)
@RequestParam("userActionId") Long userActionId);
}

View File

@@ -10,10 +10,7 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import net.gepafin.tendermanagement.enums.UserStatusEnum; import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.PageableResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.SummaryPageResponseBean;
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.JWTToken; import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants; import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants;
@@ -121,8 +118,8 @@ public interface UserApi {
@RequestMapping(value = "/reset-password/initiate", @RequestMapping(value = "/reset-password/initiate",
produces = {"application/json"}, produces = {"application/json"},
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Response<Void>> initiatePasswordReset(HttpServletRequest request, ResponseEntity<Response<InitiatePasswordResetResponse>> initiatePasswordReset(HttpServletRequest request,
@Parameter(description = "Initiate password reset request object", required = true) @Valid @RequestBody InitiatePasswordResetReq initiatePasswordResetReq); @Parameter(description = "Initiate password reset request object", required = true) @Valid @RequestBody InitiatePasswordResetReq initiatePasswordResetReq);
@Operation(summary = "Api to reset password", @Operation(summary = "Api to reset password",
responses = { responses = {

View File

@@ -8,10 +8,7 @@ import net.gepafin.tendermanagement.enums.ApplicationAmendmentRequestEnum;
import net.gepafin.tendermanagement.enums.UserActionContextEnum; import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestResponse; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.ApplicationAmendmentRequestViewResponse;
import net.gepafin.tendermanagement.model.response.PageableResponseBean;
import net.gepafin.tendermanagement.model.response.GetAllAmendmentResponseBean;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService; import net.gepafin.tendermanagement.service.ApplicationAmendmentRequestService;
import net.gepafin.tendermanagement.util.LoggingUtil; import net.gepafin.tendermanagement.util.LoggingUtil;
@@ -176,15 +173,25 @@ public class ApplicationAmendmentRequestController implements ApplicationAmendme
.body(new Response<>(applicationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_UPDATE_SUCCESSFULLY_MSG))); .body(new Response<>(applicationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.APPLICATION_AMENDMENT_UPDATE_SUCCESSFULLY_MSG)));
} }
@Override @Override
public ResponseEntity<Response<Void>> sendReminderEmail( public ResponseEntity<Response<EmailReminderResponse>> sendReminderEmail(
HttpServletRequest request, HttpServletRequest request,
Long amendmentId) { Long amendmentId) {
log.info("Sending reminder email for Amendment ID: {}", amendmentId); log.info("Sending reminder email for Amendment ID: {}", amendmentId);
applicationAmendmentRequestService.sendReminderEmail(request,amendmentId);
/** This code is responsible for "sending reminder email" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.EMAIL)
.actionContext(UserActionContextEnum.SEND_REMINDER_EMAIL).build());
EmailReminderResponse emailSendResponse = applicationAmendmentRequestService.sendReminderEmail(request,amendmentId);
if (!emailSendResponse.getEmailSendResponse().getIsEmailSend()) {
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(emailSendResponse, Status.EXCEPTION_ERROR, Translator.toLocale(GepafinConstant.REMINDER_EMAIL_FAILED_MSG)));
}
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.REMINDER_EMAIL_SENT_SUCCESS_MSG))); .body(new Response<>(emailSendResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.REMINDER_EMAIL_SENT_SUCCESS_MSG)));
} }
@Override @Override

View File

@@ -0,0 +1,52 @@
package net.gepafin.tendermanagement.web.rest.api.impl;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.EmailResendResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.ResendEmailService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.web.rest.api.EmailApi;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("${openapi.gepafin.base-path:/v1/email}")
@Log4j2
public class EmailApiController implements EmailApi {
@Autowired
LoggingUtil loggingUtil;
@Autowired
ResendEmailService emailService;
@Override
public ResponseEntity<Response<EmailResendResponseBean>> resendEmail(HttpServletRequest request, Long userActionId) {
/** This code is responsible for creating user action logs for the "Resend Email" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT)
.actionContext(UserActionContextEnum.RESEND_EMAIL).build());
EmailResendResponseBean emailResendResponseBean = emailService.resendEmail(request, userActionId);
if (!emailResendResponseBean.getEmailSendResponse().getIsEmailSend()) {
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(emailResendResponseBean, Status.EXCEPTION_ERROR, Translator.toLocale(GepafinConstant.RESEND_EMAIL_SENT_FAILED_MSG)));
}
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(emailResendResponseBean, Status.SUCCESS, Translator.toLocale(GepafinConstant.RESEND_EMAIL_SENT_SUCCESS_MSG)));
}
}

View File

@@ -11,9 +11,7 @@ import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.enums.UserStatusEnum; import net.gepafin.tendermanagement.enums.UserStatusEnum;
import net.gepafin.tendermanagement.model.request.*; import net.gepafin.tendermanagement.model.request.*;
import net.gepafin.tendermanagement.model.response.PageableResponseBean; import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.model.response.UserSamlResponse;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.JWTToken; import net.gepafin.tendermanagement.model.util.JWTToken;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.UserService; import net.gepafin.tendermanagement.service.UserService;
@@ -135,16 +133,16 @@ public class UserApiController implements UserApi {
return ResponseEntity.ok(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.SUCCESS_PASSWORD_CHANGED))); return ResponseEntity.ok(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.SUCCESS_PASSWORD_CHANGED)));
} }
@Override @Override
public ResponseEntity<Response<Void>> initiatePasswordReset(HttpServletRequest httpServletRequest,InitiatePasswordResetReq request) { public ResponseEntity<Response<InitiatePasswordResetResponse>> initiatePasswordReset(HttpServletRequest httpServletRequest, InitiatePasswordResetReq request) {
log.info("Initiating password reset for email: {}", request.getEmail()); log.info("Initiating password reset for email: {}", request.getEmail());
/** This code is responsible for "Initiating Password Reset Request" operation. **/ /** This code is responsible for "Initiating Password Reset Request" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE) loggingUtil.logUserAction(UserActionRequest.builder().request(httpServletRequest).actionType(UserActionLogsEnum.UPDATE)
.actionContext(UserActionContextEnum.INITIATE_PASSWORD_RESET_REQUEST).build()); .actionContext(UserActionContextEnum.INITIATE_PASSWORD_RESET_REQUEST).build());
userService.initiatePasswordReset(request); InitiatePasswordResetResponse emailSendResponse = userService.initiatePasswordReset(request);
log.info("Password reset token generated for email: {}", request.getEmail()); log.info("Password reset token generated for email: {}", request.getEmail());
return ResponseEntity.ok(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.RESET_PASSWORD_INITIATED))); return ResponseEntity.ok(new Response<>(emailSendResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.RESET_PASSWORD_INITIATED)));
} }
@Override @Override

View File

@@ -2746,4 +2746,23 @@
<sqlFile dbms="postgresql" <sqlFile dbms="postgresql"
path="db/dump/update_system_email_template_28_04_2025.sql"/> path="db/dump/update_system_email_template_28_04_2025.sql"/>
</changeSet> </changeSet>
<changeSet id="22-04-2025_PK_192400" author="Piyush Kag">
<sqlFile dbms="postgresql"
path="db/dump/update_json_template_for_notification_22_04_2025.sql"/>
</changeSet>
<changeSet id="24-04-2025_PK_121820" author="Piyush Kag">
<addColumn tableName="email_log">
<column name="user_action_id" type="INTEGER">
<constraints foreignKeyName="fk_email_log_user_action" references="user_action(id)"/>
</column>
</addColumn>
</changeSet>
<changeSet id="30-04-2025_PK_125515" author="Piyush Kag">
<sqlFile dbms="postgresql"
path="db/dump/insert_system_email_template_for_application_submission_failure_30_04_2025.sql"/>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View File

@@ -0,0 +1,46 @@
INSERT INTO gepafin_schema.system_email_template (
template_name,
"type",
html_content,
subject,
"json",
"system",
is_deleted,
created_date,
updated_date,
email_scenario)
VALUES (
'Application submission failure notification',
'APPLICATION_SUBMISSION_FAILURE_NOTIFICATION',
'<html>
<body style="font-family: Arial, sans-serif; color: #333; line-height: 1.6;">
<div style="padding: 20px; border: 1px solid #ddd; border-radius: 8px; max-width: 650px; margin: auto;">
<p>Buongiorno,</p>
<p>
Si prega di notare che si è verificato un errore durante linvio dell email "{{scenario}}" per la chiamata: <strong>{{call_name}}</strong>. </p>
<p>
<strong>Dettagli:</strong><br/>
- ID Applicazione: {{application_id}}<br/>
- Nome Azienda: {{company_name}}<br/>
- Numero Protocollo: {{protocol_number}}<br/>
- ID Azione Utente: {{user_action_id}}
</p>
<p>
Si prega di effettuare i controlli appropriati e di adottare le misure correttive necessarie.
</p>
<p>Cordiali saluti,</p>
<p><strong>Gepafin S.p.a.</strong></p>
</div>
</body>
</html>',
'ERRORE INVIO EMAIL - BANDO {{call_name}}',
NULL,
true,
false,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
'APPLICATION_SUBMISSION_FAILURE'
);

View File

@@ -0,0 +1,9 @@
INSERT INTO notification_type (notification_name, title, json_template, created_date, updated_date, is_deleted)
VALUES
('PEC_EMAIL_SENDING_FAILURE',
'Invio Email Fallito',
'Non è stato possibile inviare lemail per lo scenario: {{email_scenario}}.',
'2025-01-03T10:16:26.472Z',
'2025-01-03T10:16:26.472Z',
'false'
);

View File

@@ -400,3 +400,7 @@ insufficient.score.msg = Insufficient score to pass to the technical and economi
password.expired.for.login.to.odessa = Odessa login password has been expired. password.expired.for.login.to.odessa = Odessa login password has been expired.
invalid.user=Invalid user. invalid.user=Invalid user.
reminder.email.sent.failed.msg = Failed to send reminder email
resend.email.sent.success.msg = Email resend successfully
resend.email.sent.failed.msg = Failed to resend the email.

View File

@@ -390,4 +390,8 @@ insufficient.score.msg = Punteggio non sufficiente per passaggio alla valutazion
validation.table.message=I dati per il campo {0} non sono presenti. validation.table.message=I dati per il campo {0} non sono presenti.
password.expired.for.login.to.odessa = La password di accesso a Odessa è scaduta password.expired.for.login.to.odessa = La password di accesso a Odessa è scaduta
invalid.user=Utente non valido. invalid.user=Utente non valido.
reminder.email.sent.failed.msg = Impossibile inviare l'e-mail di promemoria
resend.email.sent.success.msg = Email reinviata con successo
resend.email.sent.failed.msg = Impossibile inviare nuovamente l'e-mail.