Updated code for notification

This commit is contained in:
Piyush
2024-12-23 11:24:25 +05:30
parent 91ec063327
commit 288fde0a88
11 changed files with 144 additions and 22 deletions

View File

@@ -105,6 +105,12 @@ public class ApplicationAmendmentRequestDao {
@Autowired
private AssignedApplicationsDao assignedApplicationsDao;
@Autowired
private NotificationDao notificationDao;
@Autowired
private UserRepository userRepository;
public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) {
log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId);
ApplicationEvaluationEntity applicationEvaluationEntity = applicationEvaluationService.validateApplicationEvaluation(applicationEvaluationId);
@@ -294,6 +300,10 @@ public class ApplicationAmendmentRequestDao {
assignedApplicationsEntity.setStatus(AssignedApplicationEnum.SOCCORSO.getValue());
assignedApplicationsRepository.save(assignedApplicationsEntity);
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(applicationEntity, NotificationTypeEnum.AMENDMENT_CREATION);
notificationDao.sendNotificationToInstructor(placeHolders,applicationAmendmentRequestEntity.getApplicationEvaluationEntity(),NotificationTypeEnum.AMENDMENT_CREATION);
/** This code is responsible for adding a version history log for the "Update Assigned Application" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAssignedApplication).newData(assignedApplicationsEntity).build());
}
@@ -829,8 +839,7 @@ public class ApplicationAmendmentRequestDao {
ApplicationAmendmentRequestEntity existingApplicationAmendment = validateApplicationAmendmentRequest(id);
//cloned entity for old data and versioning
ApplicationAmendmentRequestEntity oldApplicationAmendmentEntity = Utils.getClonedEntityForData(existingApplicationAmendment);
List<ApplicationAmendmentRequestEntity> amendmentRequestList = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
List<ApplicationAmendmentRequestEntity> amendmentRequestList = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse(
existingApplicationAmendment.getApplicationEvaluationEntity().getId()
);
@@ -875,6 +884,11 @@ public class ApplicationAmendmentRequestDao {
AssignedApplicationsEntity oldAssignedApplicationData = Utils.getClonedEntityForData(assignedApplicationsEntity);
assignedApplicationsEntity = assignedApplicationsRepository.save(existingApplicationAmendment.getApplicationEvaluationEntity().getAssignedApplicationsEntity());
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.AMENDMENT_CLOSED);
notificationDao.sendNotificationToInstructor(placeHolders,existingApplicationAmendment.getApplicationEvaluationEntity(),NotificationTypeEnum.AMENDMENT_CLOSED);
/** This code is responsible for adding a version history log for the "Update Application Evaluation" operation. **/
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity)
.newData(existingApplicationEvaluationEntity).build());
@@ -894,6 +908,7 @@ public class ApplicationAmendmentRequestDao {
return response;
}
public ApplicationAmendmentRequestResponse extendResponseDays(Long id, Long newResponseDays) {
ApplicationAmendmentRequestEntity applicationAmendmentRequestEntity = validateApplicationAmendmentRequest(id);

View File

@@ -10,6 +10,7 @@ import net.gepafin.tendermanagement.model.request.ApplicationFormFieldRequestBea
import net.gepafin.tendermanagement.model.request.ApplicationRequest;
import net.gepafin.tendermanagement.model.request.ApplicationRequestBean;
import net.gepafin.tendermanagement.model.request.EmailLogRequest;
import net.gepafin.tendermanagement.model.request.NotificationReq;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.*;
import net.gepafin.tendermanagement.repositories.*;
@@ -162,6 +163,15 @@ public class ApplicationDao {
@Autowired
private ApplicationEvaluationService applicationEvaluationService;
@Autowired
private NotificationDao notificationDao;
@Autowired
private UserRepository userRepository;
@Autowired
private RoleRepository roleRepository;
public ApplicationResponseBean createApplication(HttpServletRequest request, ApplicationRequestBean applicationRequestBean, Long formId, Long applicationId) {
FormEntity formEntity = formService.validateForm(formId);
// callService.validatePublishedCall(formEntity.getCall().getId());
@@ -818,6 +828,8 @@ public class ApplicationDao {
applicationEntity.setStatus(ApplicationStatusTypeEnum.SUBMIT.getValue());
applicationEntity.setSubmissionDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
applicationEntity = applicationRepository.save(applicationEntity);
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(applicationEntity,NotificationTypeEnum.APPLICATION_SUBMISSION);
notificationDao.sendNotificationToSuperUser(applicationEntity,placeHolders,NotificationTypeEnum.APPLICATION_SUBMISSION);
/** This code is responsible for adding a version history log for "Update application status" operation. **/
loggingUtil.addVersionHistory(

View File

@@ -92,6 +92,12 @@ public class ApplicationEvaluationDao {
@Autowired
private CompanyService companyService;
@Autowired
private NotificationDao notificationDao;
@Autowired
private UserRepository userRepository;
private ApplicationEvaluationEntity convertToEntity(UserEntity user, ApplicationEvaluationRequest req, Long assignedApplciationId) {
@@ -493,8 +499,14 @@ public class ApplicationEvaluationDao {
setIfUpdated(entity::getMotivation, entity::setMotivation, req.getMotivation());
actionType = VersionActionTypeEnum.UPDATE;
} else {
ApplicationEntity application=entity.getAssignedApplicationsEntity().getApplication();
entity = convertToEntity(user, req, assignedApplicationId);
actionType = VersionActionTypeEnum.INSERT;
Map<String, String> placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_CREATION);
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_CREATION);
notificationDao.sendNotificationToInstructor(placeHolders,entity,NotificationTypeEnum.EVALUATION_CREATION);
}
ApplicationStatusForEvaluation status = req.getApplicationStatus();
@@ -1442,12 +1454,17 @@ public class ApplicationEvaluationDao {
if (Boolean.TRUE.equals(statusType.equals((ApplicationStatusTypeEnum.REJECTED.getValue())))) {
emailNotificationDao.sendInadmissibilityEmailForRejectedApplication(application,existingEntity);
}
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);
}
return null;
}
public ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId) {
public ApplicationEvaluationEntity validateApplicationEvaluationByApplicationId(Long applicationId) {
return applicationEvaluationRepository
.findByApplicationIdAndIsDeletedFalse(applicationId)
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,

View File

@@ -16,14 +16,18 @@ import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.CompanyEntity;
import net.gepafin.tendermanagement.entities.DocumentEntity;
import net.gepafin.tendermanagement.entities.HubEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.ApplicationStatusTypeEnum;
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
import net.gepafin.tendermanagement.model.request.AppointmentCreationRequest;
import net.gepafin.tendermanagement.model.request.AppointmentNdgRequest;
import net.gepafin.tendermanagement.model.request.AppointmentVisuraListRequest;
import net.gepafin.tendermanagement.model.request.AppointmentVisuraRequest;
import net.gepafin.tendermanagement.model.request.CreateAppointmentRequest;
import net.gepafin.tendermanagement.model.request.NotificationReq;
import net.gepafin.tendermanagement.model.request.UploadDocToExternalSystemRequest;
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
import net.gepafin.tendermanagement.model.response.AppointmentCreationResponse;
@@ -34,6 +38,7 @@ import net.gepafin.tendermanagement.repositories.ApplicationRepository;
import net.gepafin.tendermanagement.repositories.CompanyRepository;
import net.gepafin.tendermanagement.repositories.DocumentRepository;
import net.gepafin.tendermanagement.repositories.HubRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.service.ApplicationService;
import net.gepafin.tendermanagement.service.CompanyService;
import net.gepafin.tendermanagement.service.feignClient.AppointmentApiService;
@@ -58,6 +63,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -130,6 +136,12 @@ public class AppointmentDao {
@Autowired
private TokenProvider tokenProvider;
@Autowired
private NotificationDao notificationDao;
@Autowired
private UserRepository userRepository;
private final Map<Long, ExecutorService> executorMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Long, ExecutorService> threadForDocumentMap = new ConcurrentHashMap<>();
@@ -312,6 +324,8 @@ public class AppointmentDao {
company.setNdg(ndg);
companyRepository.save(company);
applicationRepository.save(application);
Map<String ,String> placeHolders=notificationDao.sendNotificationToBeneficiary(application,NotificationTypeEnum.NDG_GENERATION);
notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.NDG_GENERATION);
// /** This code is responsible for adding a version history log for the "update application ndg code, status, and Id visura" operation. **/
// loggingUtil.addVersionHistory(

View File

@@ -2,18 +2,25 @@ package net.gepafin.tendermanagement.dao;
import lombok.extern.slf4j.Slf4j;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.ApplicationEntity;
import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity;
import net.gepafin.tendermanagement.entities.NotificationEntity;
import net.gepafin.tendermanagement.entities.NotificationTypeEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.NotificationEnum;
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
import net.gepafin.tendermanagement.model.request.NotificationReq;
import net.gepafin.tendermanagement.repositories.NotificationRepository;
import net.gepafin.tendermanagement.repositories.NotificationTypeRepository;
import net.gepafin.tendermanagement.repositories.UserRepository;
import net.gepafin.tendermanagement.repositories.UserWithCompanyRepository;
import net.gepafin.tendermanagement.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -33,6 +40,9 @@ public class NotificationDao {
@Autowired
private UserWithCompanyRepository userWithCompanyRepository;
@Autowired
private UserRepository userRepository;
public NotificationReq sendNotification(NotificationReq notificationReq) {
// Ensure userId is properly set in notificationReq if not already
@@ -113,4 +123,28 @@ public class NotificationDao {
notificationReq.setUserId(userId);
return notificationReq;
}
public Map<String, String> sendNotificationToBeneficiary(ApplicationEntity application, NotificationTypeEnum notificationTypeEnum) {
Map<String, String> placeHolders = new HashMap<>();
placeHolders.put("{{call_name}}", application.getCall().getName());
placeHolders.put("{{protocol_number}}", String.valueOf(application.getProtocol().getProtocolNumber()));
NotificationReq notificationReq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, application.getUserId());
sendNotification(notificationReq);
return placeHolders;
}
public void sendNotificationToInstructor(Map<String, String> placeHolders, ApplicationEvaluationEntity applicationEvaluationEntity, NotificationTypeEnum notificationTypeEnum) {
Long instructorId=applicationEvaluationEntity.getUserId();
if(instructorId != null){
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders,instructorId);
sendNotification(notificationreq);
}
}
public void sendNotificationToSuperUser(ApplicationEntity application,Map<String,String> placeHolders,NotificationTypeEnum notificationTypeEnum) {
List<UserEntity> user=userRepository.findByRoleEntity_RoleTypeAndHubId(RoleStatusEnum.ROLE_SUPER_ADMIN.getValue(), application.getHubId());
UserEntity userEntity1=user.get(0);
if(userEntity1 != null) {
NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders,userEntity1.getId());
sendNotification(notificationreq);
}
}
}