From d8e51f3a706a93a5e382aa16a6345d9aaa7fbe4b Mon Sep 17 00:00:00 2001 From: piyushkag Date: Fri, 13 Dec 2024 20:57:58 +0530 Subject: [PATCH 01/13] Notification Code. --- pom.xml | 14 +++ .../TendermanagementApplication.java | 4 +- .../config/SecurityConfig.java | 1 + .../config/WebSocketConfig.java | 32 ++++++ .../constants/GepafinConstant.java | 4 + .../constants/NotificationConstant.java | 5 + .../gepafin/tendermanagement/dao/CallDao.java | 41 +++++++- .../tendermanagement/dao/NotificationDao.java | 97 +++++++++++++++++++ .../entities/NotificationEntity.java | 31 ++++++ .../entities/NotificationTypeEntity.java | 21 ++++ .../enums/NotificationEnum.java | 27 ++++++ .../enums/NotificationTypeEnum.java | 29 ++++++ .../model/request/NotificationReq.java | 37 +++++++ .../model/response/UserResponseBean.java | 1 + .../repositories/BeneficiaryRepository.java | 5 + .../repositories/NotificationRepository.java | 7 ++ .../NotificationTypeRepository.java | 8 ++ .../service/NotificationService.java | 7 ++ .../service/impl/NotificationServiceImpl.java | 26 +++++ .../gepafin/tendermanagement/util/Utils.java | 4 + .../web/rest/api/NotificationApi.java | 30 ++++++ .../api/impl/NotificationApiController.java | 32 ++++++ .../resources/application-local.properties | 13 ++- .../db/changelog/db.changelog-1.0.0.xml | 45 +++++++++ ...n_template_for_notification_13_12_2024.sql | 5 + 25 files changed, 520 insertions(+), 6 deletions(-) create mode 100644 src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java create mode 100644 src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java create mode 100644 src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java create mode 100644 src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java create mode 100644 src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java create mode 100644 src/main/java/net/gepafin/tendermanagement/enums/NotificationEnum.java create mode 100644 src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java create mode 100644 src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java create mode 100644 src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java create mode 100644 src/main/java/net/gepafin/tendermanagement/repositories/NotificationTypeRepository.java create mode 100644 src/main/java/net/gepafin/tendermanagement/service/NotificationService.java create mode 100644 src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java create mode 100644 src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java create mode 100644 src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java create mode 100644 src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql diff --git a/pom.xml b/pom.xml index 93a592ed..c463be91 100644 --- a/pom.xml +++ b/pom.xml @@ -231,6 +231,20 @@ spring-test + + + org.springframework.boot + spring-boot-starter-websocket + + + org.springframework.boot + spring-boot-starter-amqp + + + io.projectreactor.netty + reactor-netty + + diff --git a/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java b/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java index 7ec98464..1465ad7e 100644 --- a/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java +++ b/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java @@ -23,7 +23,9 @@ public class TendermanagementApplication { @Override public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**").allowedOrigins("http://localhost:3000") + //remove after testing +//add url for a demo html and js project created on Vs code and ran it from go live on right bottim corner user gepafin_dev_local backup DB for gettng notification on FE. + registry.addMapping("/**").allowedOrigins("http://127.0.0.1:5500", "http://localhost:3000", "http://localhost:5500") .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true); } } diff --git a/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java b/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java index 090f3688..8c11eac2 100644 --- a/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java +++ b/src/main/java/net/gepafin/tendermanagement/config/SecurityConfig.java @@ -109,6 +109,7 @@ public class SecurityConfig { .requestMatchers("/v1/api-docs/**").permitAll() // API docs .requestMatchers("/v1/user/reset-password/initiate").permitAll() .requestMatchers("/v1/user/reset-password").permitAll() + .requestMatchers("/wss/**").permitAll() // if this is not running use this /gs-guide-websocket .anyRequest().authenticated()) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)) .exceptionHandling(exceptionHandling -> exceptionHandling diff --git a/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java new file mode 100644 index 00000000..b12207e6 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java @@ -0,0 +1,32 @@ +package net.gepafin.tendermanagement.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; +import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; + +@Configuration +@EnableWebSocketMessageBroker +public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { + + @Override + public void configureMessageBroker(MessageBrokerRegistry config) { + // Enable a simple broker for both /topic (broadcast messages) and /queue (user-specific messages) + config.enableStompBrokerRelay("/topic") + .setRelayHost("localhost") + .setRelayPort(61613) // RabbitMQ is running on port 61613 + .setClientLogin("guest") + .setClientPasscode("guest"); + + // Prefix for application messages (user sends messages to /app endpoints) + config.setApplicationDestinationPrefixes("/app"); + } + + @Override + public void registerStompEndpoints(StompEndpointRegistry registry) { + + registry.addEndpoint("/gs-guide-websocket").setAllowedOrigins("http://127.0.0.1:5501/", "http://localhost:5500", "http://localhost:5501", "http://127.0.0.1:5500/") + .withSockJS(); + } +} diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index 14d82b91..f0d9a617 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -341,5 +341,9 @@ public class GepafinConstant { public static final String POLLING_THREAD_NAME = "Ndg-Polling-Thread-"; public static final String DOCUMENT_UPLOADING_IN_PROGRESS = "document.uploading.is.in.progress"; public static final String ASYNC_DOCUMENT_UPLOAD_NAME = "AsyncDocumentUpload-"; + + //Notification + public static final String COMMON_SINGLE_CHANNEL_PREFIX = "/topic/notifications_user_"; + public static final String COMPANY_PREFIX = "_company_"; } diff --git a/src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java new file mode 100644 index 00000000..3f5c1cdc --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java @@ -0,0 +1,5 @@ +package net.gepafin.tendermanagement.constants; + +public class NotificationConstant { + public static final String NOTIFICATION_SENT_SUCCESSFULLY = "Notification Sent Successfully."; +} diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index 9b3b12a5..772538bb 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -15,7 +15,9 @@ import java.util.zip.ZipOutputStream; import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.entities.*; import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum; +import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import net.gepafin.tendermanagement.enums.VersionActionTypeEnum; +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.*; @@ -108,6 +110,18 @@ public class CallDao { @Autowired private HttpServletRequest request; + @Autowired + private NotificationDao notificationDao; + + @Autowired + private BeneficiaryRepository beneficiaryRepository; + + @Autowired + private NotificationTypeRepository notificationTypeRepository; + + @Autowired + private UserWithCompanyRepository userWithCompanyRepository; + public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) { createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId()); CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity); @@ -828,13 +842,36 @@ public class CallDao { validateStatusChange(currentStatus, statusReq); callEntity.setStatus(statusReq.getValue()); callEntity = callRepository.save(callEntity); - + + //Creating notification. + List userIds = beneficiaryRepository.findUserIdsByHubIdAndBeneficiaryId(callEntity.getHub().getId()); + Map placeholders = new HashMap<>(); + placeholders.put("{{call_name}}", callEntity.getName()); + userIds.forEach(userId -> { + NotificationReq notificationReq = createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId); + List companyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(notificationReq.getUserId()); + notificationReq.setCompanyIds(companyIds); + notificationDao.sendNotification(notificationReq); + }); + /** This code is responsible for adding a version history log for the "update call status" operation **/ loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCallEntity).newData(callEntity).build()); - + return convertToCallResponseBean(callEntity); } + public NotificationReq createNotificationReq(String notificationType, Map placeholders, Long userId) { + // Create NotificationReq object + NotificationReq notificationReq = new NotificationReq(); + NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType); + notificationReq.setNotificationType(notificationType); + String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders); + notificationReq.setMessage(message); + notificationReq.setUserId(userId); + return notificationReq; + } + + private void validateStatusChange(CallStatusEnum currentStatus, CallStatusEnum newStatus) { if (currentStatus == newStatus) { throw new CustomValidationException(Status.VALIDATION_ERROR, diff --git a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java new file mode 100644 index 00000000..17c5a3c8 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java @@ -0,0 +1,97 @@ +package net.gepafin.tendermanagement.dao; + +import lombok.extern.slf4j.Slf4j; +import net.gepafin.tendermanagement.constants.GepafinConstant; +import net.gepafin.tendermanagement.entities.NotificationEntity; +import net.gepafin.tendermanagement.enums.NotificationEnum; +import net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.repositories.NotificationRepository; +import net.gepafin.tendermanagement.repositories.NotificationTypeRepository; +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.List; + +@Component +@Slf4j +public class NotificationDao { + + @Autowired + private SimpMessagingTemplate messagingTemplate; + + @Autowired + private NotificationRepository notificationRepository; + + @Autowired + private NotificationTypeRepository notificationTypeRepository; + + public NotificationReq sendNotification(NotificationReq notificationReq) { + + // Ensure userId is properly set in notificationReq if not already + Long userId = notificationReq.getUserId(); + if (userId == null) { + log.error("User ID is missing in the notification request."); + return null; + } + NotificationEntity notificationEntity = saveNotification(notificationReq); + log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage()); + List companyIds = notificationReq.getCompanyIds(); + + if (companyIds.isEmpty()) { + sendToUser(userId, notificationEntity); + } else { + sendToCompanies(userId, companyIds, notificationEntity); + } + + return convertToNotificationReq(notificationEntity); + } + + private NotificationEntity saveNotification(NotificationReq notificationReq) { + + NotificationEntity notificationEntity = convertToNotificationEntity(notificationReq); + return notificationRepository.save(notificationEntity); + } + + private void sendToUser(Long userId, NotificationEntity notificationEntity) { + + String userChannel = GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId; + log.info("Channel for User {}", userChannel); + messagingTemplate.convertAndSend(userChannel, notificationEntity); + } + + private void sendToCompanies(Long userId, List companyIds, NotificationEntity notificationEntity) { + // Send notification to each company provided in the companyIds list + companyIds.forEach(companyId -> { + String companyChannel = Utils.createChannelForUserAndCompany(userId, companyId); + log.info("Channel for User and Company {}, {}", userId, companyChannel); + messagingTemplate.convertAndSend(companyChannel, notificationEntity); + }); + } + + private NotificationReq convertToNotificationReq(NotificationEntity notificationEntity) { + + NotificationReq notificationReq = new NotificationReq(); + notificationReq.setId(notificationEntity.getId()); + notificationReq.setUserId(notificationEntity.getUserId()); + notificationReq.setStatus(NotificationEnum.UNREAD.getValue()); + notificationReq.setMessage(notificationEntity.getMessage()); + notificationReq.setCreatedDate(notificationEntity.getCreatedDate()); + notificationReq.setUpdatedDate(notificationEntity.getUpdatedDate()); + return notificationReq; + + } + + private NotificationEntity convertToNotificationEntity(NotificationReq notificationReq) { + + NotificationEntity notificationEntity = new NotificationEntity(); + String message = notificationReq.getMessage(); + notificationEntity.setNotificationType(notificationReq.getNotificationType()); + notificationEntity.setUserId(notificationReq.getUserId()); + notificationEntity.setStatus(NotificationEnum.UNREAD.getValue()); + notificationEntity.setIsDeleted(Boolean.FALSE); + notificationEntity.setMessage(message); + return notificationEntity; + } +} diff --git a/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java new file mode 100644 index 00000000..74131d4c --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java @@ -0,0 +1,31 @@ +package net.gepafin.tendermanagement.entities; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Data; + +@Entity +@Table(name = "NOTIFICATION") +@Data +public class NotificationEntity extends BaseEntity { + + @Column(name = "USER_ID") + Long userId; + + @Column(name = "MESSAGE") + String message; + + @Column(name = "STATUS") + String status; + + @Column(name = "IS_DELETED") + Boolean isDeleted; + + @Column(name = "NOTIFICATION_TYPE") + String notificationType; + + @Column(name = "REDIRECT_LINK") + String redirectLink; + +} diff --git a/src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java new file mode 100644 index 00000000..5202c97a --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java @@ -0,0 +1,21 @@ +package net.gepafin.tendermanagement.entities; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Data; + +@Entity +@Data +@Table(name = "NOTIFICATION_TYPE") +public class NotificationTypeEntity extends BaseEntity { + + @Column(name = "NOTIFICATION_NAME") + String notificationName; + + @Column(name = "JSON_TEMPLATE") + String jsonTemplate; + + @Column(name="IS_DELETED") + private Boolean isDeleted; +} diff --git a/src/main/java/net/gepafin/tendermanagement/enums/NotificationEnum.java b/src/main/java/net/gepafin/tendermanagement/enums/NotificationEnum.java new file mode 100644 index 00000000..5b8bf633 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/enums/NotificationEnum.java @@ -0,0 +1,27 @@ +package net.gepafin.tendermanagement.enums; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum NotificationEnum { + //status + READ("READ"), UNREAD("UNREAD"); + + private final String value; + + NotificationEnum(String value) { + + this.value = value; + } + + @JsonValue + public String getValue() { + + return value; + } + + @Override + public String toString() { + + return String.valueOf(value); + } +} diff --git a/src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java b/src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java new file mode 100644 index 00000000..86fd75dc --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java @@ -0,0 +1,29 @@ +package net.gepafin.tendermanagement.enums; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum NotificationTypeEnum { + CALL_CREATED("CALL_CREATED"), + APPLICATION_SUBMISSION("APPLICATION_SUBMISSION"), + AMENDMENT_CREATION("AMENDMENT_CREATION"), + EVALUATION_RESULT("EVALUATION_RESULT"); + + private final String value; + + NotificationTypeEnum(String value) { + + this.value = value; + } + + @JsonValue + public String getValue() { + + return value; + } + + @Override + public String toString() { + + return String.valueOf(value); + } +} diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java b/src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java new file mode 100644 index 00000000..8506694a --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java @@ -0,0 +1,37 @@ +package net.gepafin.tendermanagement.model.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Data +public class NotificationReq { + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + Long id; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + Long userId; + + String message; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + String notificationType; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + String status; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private LocalDateTime createdDate; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private LocalDateTime updatedDate; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + String redirectUrl; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + List companyIds; +} diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/UserResponseBean.java b/src/main/java/net/gepafin/tendermanagement/model/response/UserResponseBean.java index b0a5ef38..c8724d43 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/UserResponseBean.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/UserResponseBean.java @@ -40,6 +40,7 @@ public class UserResponseBean extends BaseBean { private List companies; private Boolean privacy; + private Boolean terms; private Boolean marketing; diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/BeneficiaryRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/BeneficiaryRepository.java index ecb6ed7d..984e477a 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/BeneficiaryRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/BeneficiaryRepository.java @@ -1,11 +1,16 @@ package net.gepafin.tendermanagement.repositories; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import net.gepafin.tendermanagement.entities.BeneficiaryEntity; +import java.util.List; + @Repository public interface BeneficiaryRepository extends JpaRepository { + @Query("SELECT u.id FROM UserEntity u JOIN u.beneficiary b WHERE b.id = u.beneficiary.id AND b.hubId = :hubId") + List findUserIdsByHubIdAndBeneficiaryId(Long hubId); } diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java new file mode 100644 index 00000000..a52c39de --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java @@ -0,0 +1,7 @@ +package net.gepafin.tendermanagement.repositories; + +import net.gepafin.tendermanagement.entities.NotificationEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationRepository extends JpaRepository { +} diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationTypeRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationTypeRepository.java new file mode 100644 index 00000000..78cef54d --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationTypeRepository.java @@ -0,0 +1,8 @@ +package net.gepafin.tendermanagement.repositories; + +import net.gepafin.tendermanagement.entities.NotificationTypeEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationTypeRepository extends JpaRepository { + NotificationTypeEntity findByNotificationNameAndIsDeletedFalse(String value); +} diff --git a/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java new file mode 100644 index 00000000..0b6914c2 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java @@ -0,0 +1,7 @@ +package net.gepafin.tendermanagement.service; + +import net.gepafin.tendermanagement.model.request.NotificationReq; + +public interface NotificationService { + NotificationReq sendNotification(Long userId, NotificationReq notificationReq); +} diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java new file mode 100644 index 00000000..7928f166 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java @@ -0,0 +1,26 @@ +package net.gepafin.tendermanagement.service.impl; + +import lombok.extern.slf4j.Slf4j; +import net.gepafin.tendermanagement.dao.NotificationDao; +import net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.service.NotificationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class NotificationServiceImpl implements NotificationService { + + @Autowired + private NotificationDao notificationDao; + + @Override + public NotificationReq sendNotification(Long userId, NotificationReq notificationReq) { + + log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage()); + notificationReq.setUserId(userId); + notificationReq = notificationDao.sendNotification(notificationReq); + return notificationReq; + } + +} \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/util/Utils.java b/src/main/java/net/gepafin/tendermanagement/util/Utils.java index e93c8ed9..4290bfff 100644 --- a/src/main/java/net/gepafin/tendermanagement/util/Utils.java +++ b/src/main/java/net/gepafin/tendermanagement/util/Utils.java @@ -669,4 +669,8 @@ public class Utils { } return null; } + + public static String createChannelForUserAndCompany(Long userId, Long companyId) { + return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId; + } } \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java new file mode 100644 index 00000000..85a4ab27 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java @@ -0,0 +1,30 @@ +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 net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean; +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.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +public interface NotificationApi { + @Operation(summary = "Api to send notification.", 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 = "/{userId}", consumes = "application/json", produces = "application/json") + ResponseEntity> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq, + @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId); +} diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java new file mode 100644 index 00000000..054c4c63 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java @@ -0,0 +1,32 @@ +package net.gepafin.tendermanagement.web.rest.api.impl; + +import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.config.Translator; +import net.gepafin.tendermanagement.constants.NotificationConstant; +import net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.model.util.Response; +import net.gepafin.tendermanagement.service.NotificationService; +import net.gepafin.tendermanagement.web.rest.api.NotificationApi; +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/notification}") +public class NotificationApiController implements NotificationApi { + + @Autowired + private NotificationService notificationService; + + public ResponseEntity> sendNotification(HttpServletRequest request, NotificationReq notificationReq, Long userId) { + + NotificationReq notificationData = notificationService.sendNotification(userId, notificationReq); + + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(notificationData, Status.SUCCESS, Translator.toLocale(NotificationConstant.NOTIFICATION_SENT_SUCCESSFULLY))); + } + +} \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 37bcabad..11f3d75e 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,6 +1,6 @@ # DataSource Configuration -spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_local -spring.datasource.username=postgres +spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_dev_local +spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=org.postgresql.Driver @@ -20,4 +20,11 @@ appointment.portal.user=UtenzaAPIPortal@621 appointment.portal.password=u13nzaAP1P0rtal appointment.portal.source=GEPAFINPORTAL appointment.portal.context=GEPAFINPORTAL -flagDaFirmare=false \ No newline at end of file +flagDaFirmare=false + +# RabbitMQ properties for STOMP broker relay +spring.rabbitmq.host=localhost +spring.rabbitmq.port=5672 +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest +spring.rabbitmq.virtual-host=/ \ No newline at end of file diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index eb77049e..fde4441d 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -1992,4 +1992,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql b/src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql new file mode 100644 index 00000000..50caaefa --- /dev/null +++ b/src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql @@ -0,0 +1,5 @@ +INSERT INTO notification_type (notification_name, json_template) VALUES +('CALL_CREATED', 'Un nuovo bando intitolato {{call_name}} è stato pubblicato. Controllalo e invia le tue candidature prima della scadenza.'), +('APPLICATION_SUBMISSION', 'La tua richiesta per {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stata presentata con successo. È ora in fase di valutazione.'), +('AMENDMENT_CREATION', 'È stato creato un emendamento per la tua domanda in {{call_name}} ai sensi del protocollo n. {{protocol_number}}. Esamina le modifiche e procedi di conseguenza.'), +('EVALUATION_RESULT', 'Il risultato della valutazione per la tua domanda ai sensi del protocollo n. {{protocol_number}} è ora disponibile. Fai clic qui per visualizzare il tuo feedback.'); From 91ec06332715f14a172dd7d5cf070b9ede5c12f4 Mon Sep 17 00:00:00 2001 From: piyushkag Date: Fri, 13 Dec 2024 22:09:23 +0530 Subject: [PATCH 02/13] Updated code. --- .../gepafin/tendermanagement/dao/CallDao.java | 19 +------------------ .../tendermanagement/dao/NotificationDao.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index 772538bb..45d81d9c 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -119,9 +119,6 @@ public class CallDao { @Autowired private NotificationTypeRepository notificationTypeRepository; - @Autowired - private UserWithCompanyRepository userWithCompanyRepository; - public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) { createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId()); CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity); @@ -848,9 +845,7 @@ public class CallDao { Map placeholders = new HashMap<>(); placeholders.put("{{call_name}}", callEntity.getName()); userIds.forEach(userId -> { - NotificationReq notificationReq = createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId); - List companyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(notificationReq.getUserId()); - notificationReq.setCompanyIds(companyIds); + NotificationReq notificationReq = notificationDao.createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId); notificationDao.sendNotification(notificationReq); }); @@ -860,18 +855,6 @@ public class CallDao { return convertToCallResponseBean(callEntity); } - public NotificationReq createNotificationReq(String notificationType, Map placeholders, Long userId) { - // Create NotificationReq object - NotificationReq notificationReq = new NotificationReq(); - NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType); - notificationReq.setNotificationType(notificationType); - String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders); - notificationReq.setMessage(message); - notificationReq.setUserId(userId); - return notificationReq; - } - - private void validateStatusChange(CallStatusEnum currentStatus, CallStatusEnum newStatus) { if (currentStatus == newStatus) { throw new CustomValidationException(Status.VALIDATION_ERROR, diff --git a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java index 17c5a3c8..1b02b144 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java @@ -3,16 +3,19 @@ package net.gepafin.tendermanagement.dao; import lombok.extern.slf4j.Slf4j; import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.entities.NotificationEntity; +import net.gepafin.tendermanagement.entities.NotificationTypeEntity; import net.gepafin.tendermanagement.enums.NotificationEnum; import net.gepafin.tendermanagement.model.request.NotificationReq; import net.gepafin.tendermanagement.repositories.NotificationRepository; import net.gepafin.tendermanagement.repositories.NotificationTypeRepository; +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.List; +import java.util.Map; @Component @Slf4j @@ -27,6 +30,9 @@ public class NotificationDao { @Autowired private NotificationTypeRepository notificationTypeRepository; + @Autowired + private UserWithCompanyRepository userWithCompanyRepository; + public NotificationReq sendNotification(NotificationReq notificationReq) { // Ensure userId is properly set in notificationReq if not already @@ -94,4 +100,17 @@ public class NotificationDao { notificationEntity.setMessage(message); return notificationEntity; } + + public NotificationReq createNotificationReq(String notificationType, Map placeholders, Long userId) { + // Create NotificationReq object + NotificationReq notificationReq = new NotificationReq(); + List companyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(notificationReq.getUserId()); + notificationReq.setCompanyIds(companyIds); + NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType); + notificationReq.setNotificationType(notificationType); + String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders); + notificationReq.setMessage(message); + notificationReq.setUserId(userId); + return notificationReq; + } } From 288fde0a8812d7df79a54a5612d148e18b3ac392 Mon Sep 17 00:00:00 2001 From: Piyush Date: Mon, 23 Dec 2024 11:24:25 +0530 Subject: [PATCH 03/13] Updated code for notification --- .../dao/ApplicationAmendmentRequestDao.java | 19 +++++++++-- .../tendermanagement/dao/ApplicationDao.java | 12 +++++++ .../dao/ApplicationEvaluationDao.java | 19 ++++++++++- .../tendermanagement/dao/AppointmentDao.java | 14 ++++++++ .../tendermanagement/dao/NotificationDao.java | 34 +++++++++++++++++++ .../enums/NotificationTypeEnum.java | 7 +++- .../repositories/UserRepository.java | 3 ++ .../ApplicationAmendmentScheduler.java | 13 ++++++- .../ApplicationEvaluationScheduler.java | 14 +++++++- .../db/changelog/db.changelog-1.0.0.xml | 16 +++------ ...n_template_for_notification_13_12_2024.sql | 15 +++++--- 11 files changed, 144 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index 41d43b1e..e6ccd62b 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -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 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 amendmentRequestList = applicationAmendmentRequestRepository.findAllByApplicationEvaluationIdAndIsDeletedFalse( + List 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 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); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index dbccf3b3..c687fd67 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -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 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( diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java index 924999f2..6c5e46c7 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java @@ -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 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 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, diff --git a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java index 1b644d6e..49a672a8 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/AppointmentDao.java @@ -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 executorMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap threadForDocumentMap = new ConcurrentHashMap<>(); @@ -312,6 +324,8 @@ public class AppointmentDao { company.setNdg(ndg); companyRepository.save(company); applicationRepository.save(application); + Map 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( diff --git a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java index 1b02b144..6d95a77a 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java @@ -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 sendNotificationToBeneficiary(ApplicationEntity application, NotificationTypeEnum notificationTypeEnum) { + Map 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 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 placeHolders,NotificationTypeEnum notificationTypeEnum) { + List 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); + } + } } diff --git a/src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java b/src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java index 86fd75dc..54a13768 100644 --- a/src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java +++ b/src/main/java/net/gepafin/tendermanagement/enums/NotificationTypeEnum.java @@ -6,7 +6,12 @@ public enum NotificationTypeEnum { CALL_CREATED("CALL_CREATED"), APPLICATION_SUBMISSION("APPLICATION_SUBMISSION"), AMENDMENT_CREATION("AMENDMENT_CREATION"), - EVALUATION_RESULT("EVALUATION_RESULT"); + EVALUATION_RESULT("EVALUATION_RESULT"), + AMENDMENT_EXPIRED("AMENDMENT_EXPIRED"), + AMENDMENT_CLOSED("AMENDMENT_CLOSED"), + NDG_GENERATION("NDG_GENERATION"), + EVALUATION_CREATION("EVALUATION_CREATION"), + EVALUATION_EXPIRED("EVALUATION_EXPIRED"); private final String value; diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java index 47ab16b8..bce13359 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/UserRepository.java @@ -25,4 +25,7 @@ public interface UserRepository extends JpaRepository { Optional findByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); boolean existsByBeneficiaryCodiceFiscaleAndHubId(String codiceFiscale, Long hubId); + + List findByRoleEntity_RoleTypeAndHubId(String roleType, Long hubId); + } diff --git a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java index a3112a1c..1b6ed976 100644 --- a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java +++ b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationAmendmentScheduler.java @@ -2,10 +2,16 @@ package net.gepafin.tendermanagement.scheduler; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import net.gepafin.tendermanagement.dao.NotificationDao; +import net.gepafin.tendermanagement.entities.ApplicationEntity; +import net.gepafin.tendermanagement.enums.NotificationTypeEnum; +import net.gepafin.tendermanagement.model.request.NotificationReq; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -49,6 +55,9 @@ public class ApplicationAmendmentScheduler { @Autowired private LoggingUtil loggingUtil; + @Autowired + private NotificationDao notificationDao; + private static final Logger log = LoggerFactory.getLogger(ApplicationAmendmentScheduler.class); @Scheduled(cron = "0 0 1 * * ?") @@ -80,8 +89,10 @@ public class ApplicationAmendmentScheduler { try { ApplicationAmendmentRequestEntity oldAmendmentRequestEntity = Utils.getClonedEntityForData(request); request.setStatus(ApplicationAmendmentRequestEnum.CLOSE.getValue()); + ApplicationEntity application=oldAmendmentRequestEntity.getApplicationEvaluationEntity().getAssignedApplicationsEntity().getApplication(); request = applicationAmendmentRepository.save(request); - + Map placeHolders=notificationDao.sendNotificationToBeneficiary(application,NotificationTypeEnum.AMENDMENT_EXPIRED); + notificationDao.sendNotificationToInstructor(placeHolders,oldAmendmentRequestEntity.getApplicationEvaluationEntity(),NotificationTypeEnum.AMENDMENT_EXPIRED); /** This code is responsible for adding a version history log for the "Update Application Amendment" operation. **/ loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(httpServletRequest).actionType(VersionActionTypeEnum.UPDATE).oldData(oldAmendmentRequestEntity).newData(request).build()); diff --git a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java index a0444349..e7249645 100644 --- a/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java +++ b/src/main/java/net/gepafin/tendermanagement/scheduler/ApplicationEvaluationScheduler.java @@ -1,8 +1,11 @@ package net.gepafin.tendermanagement.scheduler; import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.dao.NotificationDao; +import net.gepafin.tendermanagement.entities.ApplicationEntity; import net.gepafin.tendermanagement.entities.ApplicationEvaluationEntity; import net.gepafin.tendermanagement.enums.ApplicationEvaluationStatusTypeEnum; +import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import net.gepafin.tendermanagement.enums.UserActionContextEnum; import net.gepafin.tendermanagement.enums.UserActionLogsEnum; import net.gepafin.tendermanagement.enums.VersionActionTypeEnum; @@ -22,6 +25,7 @@ import org.springframework.stereotype.Component; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; +import java.util.Map; @Component public class ApplicationEvaluationScheduler { @@ -35,6 +39,9 @@ public class ApplicationEvaluationScheduler { @Autowired private HttpServletRequest httpServletRequest; + @Autowired + private NotificationDao notificationDao; + private static final Logger log = LoggerFactory.getLogger(ApplicationEvaluationScheduler.class); @Scheduled(cron = "0 0 2 * * ?") // Runs daily at midnight @@ -76,10 +83,15 @@ public class ApplicationEvaluationScheduler { ApplicationEvaluationEntity oldApplicationEvaluationEntity = Utils .getClonedEntityForData(evaluation); - + ApplicationEntity application=evaluation.getAssignedApplicationsEntity().getApplication(); evaluation.setStatus(ApplicationEvaluationStatusTypeEnum.EXPIRED.getValue()); evaluation = applicationEvaluationRepository.save(evaluation); + Map placeHolders = notificationDao.sendNotificationToBeneficiary(application, NotificationTypeEnum.EVALUATION_EXPIRED); + notificationDao.sendNotificationToSuperUser(application,placeHolders,NotificationTypeEnum.EVALUATION_EXPIRED); + notificationDao.sendNotificationToInstructor(placeHolders,evaluation,NotificationTypeEnum.EVALUATION_EXPIRED); + + // Logging version history for the update operation loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(httpServletRequest) .actionType(VersionActionTypeEnum.UPDATE).oldData(oldApplicationEvaluationEntity) diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index fde4441d..b93ffa9c 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -2003,6 +2003,7 @@ + @@ -2015,9 +2016,13 @@ primaryKeyName="pk_notification_type"/> + + + + @@ -2026,15 +2031,4 @@ path="db/dump/insert_json_template_for_notification_13_12_2024.sql"/> - - - - - - - - - - - diff --git a/src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql b/src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql index 50caaefa..9856d855 100644 --- a/src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql +++ b/src/main/resources/db/dump/insert_json_template_for_notification_13_12_2024.sql @@ -1,5 +1,10 @@ -INSERT INTO notification_type (notification_name, json_template) VALUES -('CALL_CREATED', 'Un nuovo bando intitolato {{call_name}} è stato pubblicato. Controllalo e invia le tue candidature prima della scadenza.'), -('APPLICATION_SUBMISSION', 'La tua richiesta per {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stata presentata con successo. È ora in fase di valutazione.'), -('AMENDMENT_CREATION', 'È stato creato un emendamento per la tua domanda in {{call_name}} ai sensi del protocollo n. {{protocol_number}}. Esamina le modifiche e procedi di conseguenza.'), -('EVALUATION_RESULT', 'Il risultato della valutazione per la tua domanda ai sensi del protocollo n. {{protocol_number}} è ora disponibile. Fai clic qui per visualizzare il tuo feedback.'); +INSERT INTO notification_type (notification_name,title, json_template,created_date,updated_date,is_deleted) VALUES +('CALL_CREATED', 'Un Nuovo Bando È Stato Pubblicato','Un nuovo bando intitolato {{call_name}} è stato pubblicato. Controllalo e invia le candidature prima della scadenza.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('APPLICATION_SUBMISSION','Candidatura Inviata con Successo per la Valutazione', 'La richiesta per {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stata presentata con successo. È ora in fase di valutazione.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('AMENDMENT_CREATION','È Stato Creato un Emendamento per la Richiesta', 'È stato creato un emendamento per la richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}}. Esamina le modifiche e procedi di conseguenza.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('EVALUATION_RESULT','Il Risultato della Valutazione per la Richiesta È Disponibile','Il risultato della valutazione per la richiesta ai sensi del protocollo n. {{protocol_number}} è ora disponibile.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('AMENDMENT_EXPIRED','L Emendamento per la Richiesta È Scaduto', 'L’emendamento per la richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}} è scaduto.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('AMENDMENT_CLOSED','L Emendamento È Stato Chiuso ed È Ora Inattivo','L’emendamento per {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stato chiuso ed è ora inattivo.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('NDG_GENERATION','È Stato Generato un Nuovo NDG per la Richiesta','È stato generato un nuovo NDG per {{call_name}} ai sensi del protocollo n. {{protocol_number}}.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('EVALUATION_CREATION','La Richiesta È Stata Assegnata per la Valutazione','La richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}} è stata assegnata alla fase di valutazione.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'), +('EVALUATION_EXPIRED','La Valutazione per la Richiesta È Scaduta','La valutazione per la richiesta in {{call_name}} ai sensi del protocollo n. {{protocol_number}} è scaduta.','2024-12-19T10:16:26.472Z','2024-12-19T10:16:26.472Z','false'); \ No newline at end of file From d7e2e35746fe0e5d135bbab6a1374967b4b7087c Mon Sep 17 00:00:00 2001 From: piyushkag Date: Mon, 23 Dec 2024 13:15:56 +0530 Subject: [PATCH 04/13] Updated notification code. --- .../entities/NotificationEntity.java | 2 ++ .../model/response/NotificationResponse.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java diff --git a/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java index 74131d4c..c0571fab 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java @@ -28,4 +28,6 @@ public class NotificationEntity extends BaseEntity { @Column(name = "REDIRECT_LINK") String redirectLink; + @Column(name = "USER_WITH_COMPANY_ID") + Long userWithCompanyId; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java new file mode 100644 index 00000000..655fa905 --- /dev/null +++ b/src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java @@ -0,0 +1,18 @@ +package net.gepafin.tendermanagement.model.response; + +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class NotificationResponse { + private Long id; + private Long userId; + private String message; + private String notificationType; + private String status; + private LocalDateTime createdDate; + private LocalDateTime updatedDate; + private String redirectUrl; + private Long companyId; +} From db48cf950285d92c8ff532d0e93a40900ad2bde4 Mon Sep 17 00:00:00 2001 From: Piyush Date: Mon, 23 Dec 2024 19:28:37 +0530 Subject: [PATCH 05/13] Created endpoint for get,update,delete --- .../constants/GepafinConstant.java | 11 +++ .../constants/NotificationConstant.java | 5 - .../tendermanagement/dao/NotificationDao.java | 93 ++++++++++++++++++- .../repositories/NotificationRepository.java | 12 +++ .../service/NotificationService.java | 15 ++- .../service/impl/NotificationServiceImpl.java | 32 ++++++- .../web/rest/api/NotificationApi.java | 66 ++++++++++++- .../api/impl/NotificationApiController.java | 42 ++++++++- .../db/changelog/db.changelog-1.0.0.xml | 6 +- src/main/resources/message_en.properties | 8 ++ src/main/resources/message_it.properties | 8 ++ 11 files changed, 279 insertions(+), 19 deletions(-) delete mode 100644 src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index f0d9a617..d7b8e6a7 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -1,5 +1,7 @@ package net.gepafin.tendermanagement.constants; +import com.amazonaws.services.dynamodbv2.xspec.S; + public class GepafinConstant { public static final String USER_CREATED_SUCCESS_MSG = "user.created.success"; @@ -345,5 +347,14 @@ public class GepafinConstant { //Notification public static final String COMMON_SINGLE_CHANNEL_PREFIX = "/topic/notifications_user_"; public static final String COMPANY_PREFIX = "_company_"; + public static final String NOTIFICATION_SENT_SUCCESSFULLY = "notification.sent.successfully"; + public static final String NOTIFICATION_FETCHED_SUCCESSFULLY= "notification.fetched.successfully"; + public static final String NOTIFICATION_NOT_FOUND= "notification.not.found"; + public static final String NOTIFICATION_ALREADY_IN_THAT_STATE="notification.already.in.state"; + public static final String NOTIFICATION_DELETED_SUCCESSFULLY="notification.deleted.successfully"; + public static final String NOTIFICATION_UPDATED_SUCCESSFULLY="notification.updated.successfully"; + + } + diff --git a/src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java deleted file mode 100644 index 3f5c1cdc..00000000 --- a/src/main/java/net/gepafin/tendermanagement/constants/NotificationConstant.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.gepafin.tendermanagement.constants; - -public class NotificationConstant { - public static final String NOTIFICATION_SENT_SUCCESSFULLY = "Notification Sent Successfully."; -} diff --git a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java index 6d95a77a..97e9b568 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java @@ -1,28 +1,38 @@ package net.gepafin.tendermanagement.dao; +import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; +import net.gepafin.tendermanagement.config.Translator; 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.entities.UserWithCompanyEntity; 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.model.response.NotificationResponse; 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.DateTimeUtil; import net.gepafin.tendermanagement.util.Utils; +import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; +import net.gepafin.tendermanagement.web.rest.api.errors.Status; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Component @Slf4j @@ -43,7 +53,10 @@ public class NotificationDao { @Autowired private UserRepository userRepository; - public NotificationReq sendNotification(NotificationReq notificationReq) { + @Autowired + private CompanyDao companyDao; + + public NotificationResponse sendNotification(NotificationReq notificationReq) { // Ensure userId is properly set in notificationReq if not already Long userId = notificationReq.getUserId(); @@ -55,13 +68,13 @@ public class NotificationDao { log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage()); List companyIds = notificationReq.getCompanyIds(); - if (companyIds.isEmpty()) { + if (companyIds==null || companyIds.isEmpty()) { sendToUser(userId, notificationEntity); } else { sendToCompanies(userId, companyIds, notificationEntity); } - return convertToNotificationReq(notificationEntity); + return convertNotificationEntityToNotificationResponse(notificationEntity); } private NotificationEntity saveNotification(NotificationReq notificationReq) { @@ -147,4 +160,78 @@ public class NotificationDao { sendNotification(notificationreq); } } + public NotificationResponse getNotificationById(Long id) { + NotificationEntity notificationEntity = validateNotificationEntity(id); + NotificationResponse notificationReq=convertNotificationEntityToNotificationResponse(notificationEntity); + return notificationReq; + } + + private NotificationEntity validateNotificationEntity(Long id) { + NotificationEntity notificationEntity=notificationRepository.findByIdAndIsDeletedFalse(id); + if(notificationEntity ==null){ + throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.NOTIFICATION_NOT_FOUND)); + } + return notificationEntity; + } + + public List getNotificationByUserId(Long userId, Long companyId, List statuses) { + List notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId); + UserWithCompanyEntity userWithCompany=null; + List statusStrings=new ArrayList<>(); + if(companyId!=null){ + userWithCompany=companyDao.validateUserWithCompny(userId,companyId); + } + + if (statuses != null ) { + statusStrings = statuses.stream() + .map(NotificationEnum::name) // Convert enum to its name as String + .toList(); + notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId,statusStrings); + + if(userWithCompany != null){ + notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings); + } + } + + List notificationReq= notificationEntities.stream() + .map(this::convertNotificationEntityToNotificationResponse) + .collect(Collectors.toList()); + + return notificationReq; + } + + public NotificationResponse convertNotificationEntityToNotificationResponse(NotificationEntity entity) { + if (entity == null) { + return null; // Handle null entity gracefully + } + + NotificationResponse response = new NotificationResponse(); + response.setId(entity.getId()); + response.setUserId(entity.getUserId()); + response.setMessage(entity.getMessage()); + response.setNotificationType(entity.getNotificationType()); + response.setStatus(entity.getStatus()); + response.setCreatedDate(entity.getCreatedDate()); + response.setUpdatedDate(entity.getUpdatedDate()); + response.setRedirectUrl(entity.getRedirectLink()); + response.setCompanyId(entity.getUserWithCompanyId()); + + return response; + } + public NotificationResponse updateNotificationStatus(Long id,NotificationEnum status){ + NotificationEntity notificationEntity=validateNotificationEntity(id); + if(notificationEntity.getStatus().equals(status.getValue())){ + throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.NOTIFICATION_ALREADY_IN_THAT_STATE)); + } + notificationEntity.setStatus(status.getValue()); + notificationEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); + notificationRepository.save(notificationEntity); + return convertNotificationEntityToNotificationResponse(notificationEntity); + } + + public void deleteNotification(Long id){ + NotificationEntity notificationEntity=validateNotificationEntity(id); + notificationEntity.setIsDeleted(true); + notificationRepository.save(notificationEntity); + } } diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java index a52c39de..91374bf7 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java @@ -1,7 +1,19 @@ package net.gepafin.tendermanagement.repositories; import net.gepafin.tendermanagement.entities.NotificationEntity; +import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface NotificationRepository extends JpaRepository { + + NotificationEntity findByIdAndIsDeletedFalse(Long id); + + List findByUserIdAndIsDeletedFalse(Long userId); + + List findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(Long userId,Long + userWithCompanyId,List statuses); + + List findByUserIdAndIsDeletedFalseAndStatusIn(Long userId, List statuses); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java index 0b6914c2..7dd37193 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java @@ -1,7 +1,20 @@ package net.gepafin.tendermanagement.service; +import jakarta.servlet.http.HttpServletRequest; +import net.gepafin.tendermanagement.enums.NotificationEnum; import net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.model.response.NotificationResponse; + +import java.util.List; public interface NotificationService { - NotificationReq sendNotification(Long userId, NotificationReq notificationReq); + NotificationResponse sendNotification(Long userId, NotificationReq notificationReq); + + public NotificationResponse getNotificationById(HttpServletRequest servletRequest,Long id); + + public List getNotificationByUserId(HttpServletRequest servletRequest, Long userId, Long companyId, List statuses); + + public NotificationResponse updateNotificationStatus(HttpServletRequest request,Long id,NotificationEnum status); + + public void deleteNotification(HttpServletRequest request, Long id); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java index 7928f166..99c35092 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java @@ -1,12 +1,17 @@ package net.gepafin.tendermanagement.service.impl; +import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import net.gepafin.tendermanagement.dao.NotificationDao; +import net.gepafin.tendermanagement.enums.NotificationEnum; import net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.model.response.NotificationResponse; import net.gepafin.tendermanagement.service.NotificationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + @Service @Slf4j public class NotificationServiceImpl implements NotificationService { @@ -15,12 +20,33 @@ public class NotificationServiceImpl implements NotificationService { private NotificationDao notificationDao; @Override - public NotificationReq sendNotification(Long userId, NotificationReq notificationReq) { + public NotificationResponse sendNotification(Long userId, NotificationReq notificationReq) { log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage()); notificationReq.setUserId(userId); - notificationReq = notificationDao.sendNotification(notificationReq); - return notificationReq; + NotificationResponse notificationResponse = notificationDao.sendNotification(notificationReq); + return notificationResponse; + } + + @Override + public NotificationResponse getNotificationById(HttpServletRequest servletRequest, Long id) { + return notificationDao.getNotificationById(id); + } + + @Override + public List getNotificationByUserId(HttpServletRequest servletRequest, Long userId, Long companyId, List statuses) { + return notificationDao.getNotificationByUserId(userId,companyId,statuses); + } + + @Override + public NotificationResponse updateNotificationStatus(HttpServletRequest request, Long id,NotificationEnum status) { + return notificationDao.updateNotificationStatus(id,status); + } + + @Override + public void deleteNotification(HttpServletRequest request, Long id) { + notificationDao.deleteNotification(id); + return; } } \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java index 85a4ab27..7e3c4caa 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java @@ -6,15 +6,25 @@ 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 net.gepafin.tendermanagement.enums.NotificationEnum; +import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.model.response.ApplicationGetResponseBean; import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean; +import net.gepafin.tendermanagement.model.response.NotificationResponse; 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.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; public interface NotificationApi { @Operation(summary = "Api to send notification.", responses = { @ApiResponse(responseCode = "200", description = "OK"), @@ -24,7 +34,59 @@ public interface NotificationApi { 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 = "/{userId}", consumes = "application/json", produces = "application/json") - ResponseEntity> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq, + @PostMapping(value = "/user/{userId}/sent", consumes = "application/json", produces = "application/json") + ResponseEntity> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq, @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId); + + @Operation(summary = "Api to get notification by id", + 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) })) }) + @GetMapping(value = "/{id}", produces = "application/json") + ResponseEntity> getNotificationById(HttpServletRequest request, @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id); + + @Operation(summary = "Api to get notification by user id", + 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) })) }) + @GetMapping(value = "/user/{userId}", produces = "application/json") + ResponseEntity>> getNotificationByUserId(HttpServletRequest request, @Parameter(description = "The user id", required = true) @PathVariable(value = "userId", required = true) Long userId,@Parameter(description = "The company id", required = false) @RequestParam(value = "companyId",required = false) Long companyId,@Parameter(description = "The notification status", required = false) @RequestParam(value = "status",required = false) List statuses); + + @Operation(summary = "Api to update notification status", + 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) })) }) + @PutMapping(value = "/{id}", produces = "application/json") + ResponseEntity> updateNotificationStatus(HttpServletRequest request, @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id,@Parameter(description = "The notification status", required = true) @RequestParam(value = "status",required = true) NotificationEnum status); + + + @Operation(summary = "Api to delete notification", + 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) })) }) + @DeleteMapping(value = "/{id}", produces = "application/json") + ResponseEntity> deleteNotification(HttpServletRequest request, @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id); + } + + diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java index 054c4c63..7b065b8c 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java @@ -2,8 +2,11 @@ package net.gepafin.tendermanagement.web.rest.api.impl; import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.config.Translator; -import net.gepafin.tendermanagement.constants.NotificationConstant; +import net.gepafin.tendermanagement.constants.GepafinConstant; +import net.gepafin.tendermanagement.enums.NotificationEnum; +import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import net.gepafin.tendermanagement.model.request.NotificationReq; +import net.gepafin.tendermanagement.model.response.NotificationResponse; import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.service.NotificationService; import net.gepafin.tendermanagement.web.rest.api.NotificationApi; @@ -14,6 +17,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequestMapping("${openapi.gepafin.base-path:/v1/notification}") public class NotificationApiController implements NotificationApi { @@ -21,12 +26,41 @@ public class NotificationApiController implements NotificationApi { @Autowired private NotificationService notificationService; - public ResponseEntity> sendNotification(HttpServletRequest request, NotificationReq notificationReq, Long userId) { + public ResponseEntity> sendNotification(HttpServletRequest request, NotificationReq notificationReq, Long userId) { - NotificationReq notificationData = notificationService.sendNotification(userId, notificationReq); + NotificationResponse notificationData = notificationService.sendNotification(userId, notificationReq); return ResponseEntity.status(HttpStatus.OK) - .body(new Response<>(notificationData, Status.SUCCESS, Translator.toLocale(NotificationConstant.NOTIFICATION_SENT_SUCCESSFULLY))); + .body(new Response<>(notificationData, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_SENT_SUCCESSFULLY))); + } + + @Override + public ResponseEntity> getNotificationById(HttpServletRequest request, Long id) { + NotificationResponse notificationResponse=notificationService.getNotificationById(request,id); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(notificationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY))); + } + + @Override + public ResponseEntity>> getNotificationByUserId(HttpServletRequest request, Long userId, Long companyId, List statuses) { + List notificationResponses=notificationService.getNotificationByUserId(request,userId,companyId,statuses); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY))); + + } + + @Override + public ResponseEntity> updateNotificationStatus(HttpServletRequest request, Long id,NotificationEnum notificationEnums) { + NotificationResponse notificationResponse=notificationService.updateNotificationStatus(request,id,notificationEnums); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(notificationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_UPDATED_SUCCESSFULLY))); + } + + @Override + public ResponseEntity> deleteNotification(HttpServletRequest request, Long id) { + notificationService.deleteNotification(request,id); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_DELETED_SUCCESSFULLY))); } } \ No newline at end of file diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index b93ffa9c..61ba0949 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -2030,5 +2030,9 @@ - + + + + + diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 24150081..966358df 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -335,3 +335,11 @@ upload.document.is.only.for.gepafin = Document cant be uploaded, this is only av appointment.created.successfully = Appointment created successfully. error.try.again = Service call error while performing the operation. Please try again. document.uploading.is.in.progress = Document uploading is in progress. + +#notification messsages +notification.already.in.state=Notification is already in provided status. +notification.fetched.successfully=Notification fetched successfully. +notification.not.found=Notification not found. +notification.sent.successfully=Notification sent successfully. +notification.deleted.successfully=Notification deleted successfully. +notification.updated.successfully=Notification updated successfully. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index 084fe6aa..da111f9f 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -325,3 +325,11 @@ upload.document.is.only.for.gepafin = Il documento non pu? essere caricato, ques appointment.created.successfully = Appuntamento creato con successo. error.try.again = Errore di chiamata di servizio durante l'esecuzione dell'operazione. Riprovare. document.uploading.is.in.progress = Il documento è in fase di caricamento. + +#notification messsages +notification.already.in.state=La notifica è già nello stato fornito. +notification.fetched.successfully=Notifica recuperata con successo. +notification.not.found=Notifica non trovata. +notification.sent.successfully=Notifica inviata con successo. +notification.deleted.successfully=Notifica eliminata con successo. +notification.updated.successfully=Notifica aggiornata con successo. \ No newline at end of file From 96b57519fbe6f243653049b662e2026946bf89fd Mon Sep 17 00:00:00 2001 From: piyushkag Date: Tue, 24 Dec 2024 16:07:42 +0530 Subject: [PATCH 06/13] Updated Apis, Code, Configurations for Notification. --- .../TendermanagementApplication.java | 5 +- .../config/WebSocketConfig.java | 24 ++- .../constants/GepafinConstant.java | 5 +- .../gepafin/tendermanagement/dao/CallDao.java | 4 +- .../tendermanagement/dao/NotificationDao.java | 155 ++++++++++-------- .../entities/NotificationEntity.java | 22 ++- .../entities/NotificationTypeEntity.java | 7 +- .../model/request/NotificationReq.java | 12 +- .../model/response/NotificationResponse.java | 19 ++- .../repositories/NotificationRepository.java | 6 +- .../UserWithCompanyRepository.java | 19 ++- .../service/NotificationService.java | 6 +- .../service/impl/NotificationServiceImpl.java | 22 ++- .../gepafin/tendermanagement/util/Utils.java | 5 - .../web/rest/api/NotificationApi.java | 84 +++++----- .../api/impl/NotificationApiController.java | 26 +-- src/main/resources/application-dev.properties | 9 +- .../resources/application-local.properties | 6 +- .../application-production.properties | 9 +- .../resources/application-testing.properties | 16 +- .../db/changelog/db.changelog-1.0.0.xml | 14 +- src/main/resources/message_en.properties | 1 + src/main/resources/message_it.properties | 3 +- 23 files changed, 278 insertions(+), 201 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java b/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java index 1465ad7e..c220b176 100644 --- a/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java +++ b/src/main/java/net/gepafin/tendermanagement/TendermanagementApplication.java @@ -23,10 +23,7 @@ public class TendermanagementApplication { @Override public void addCorsMappings(CorsRegistry registry) { - //remove after testing -//add url for a demo html and js project created on Vs code and ran it from go live on right bottim corner user gepafin_dev_local backup DB for gettng notification on FE. - registry.addMapping("/**").allowedOrigins("http://127.0.0.1:5500", "http://localhost:3000", "http://localhost:5500") - .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true); + registry.addMapping("/**").allowedOrigins("http://localhost:3000").allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD").allowCredentials(true); } } diff --git a/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java index b12207e6..8aa01986 100644 --- a/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java +++ b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java @@ -1,5 +1,6 @@ package net.gepafin.tendermanagement.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; @@ -10,23 +11,28 @@ import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerCo @EnableWebSocketMessageBroker public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { + @Value("${spring.rabbitmq.host}") + private String relayHost; + + @Value("${spring.rabbitmq.port}") + private int relayPort; + + @Value("${spring.rabbitmq.username}") + private String clientUserName; + + @Value("${spring.rabbitmq.password}") + private String clientPassword; + @Override public void configureMessageBroker(MessageBrokerRegistry config) { - // Enable a simple broker for both /topic (broadcast messages) and /queue (user-specific messages) - config.enableStompBrokerRelay("/topic") - .setRelayHost("localhost") - .setRelayPort(61613) // RabbitMQ is running on port 61613 - .setClientLogin("guest") - .setClientPasscode("guest"); - // Prefix for application messages (user sends messages to /app endpoints) + config.enableStompBrokerRelay("/topic").setRelayHost(relayHost).setRelayPort(relayPort).setClientLogin(clientUserName).setClientPasscode(clientPassword); config.setApplicationDestinationPrefixes("/app"); } @Override public void registerStompEndpoints(StompEndpointRegistry registry) { - registry.addEndpoint("/gs-guide-websocket").setAllowedOrigins("http://127.0.0.1:5501/", "http://localhost:5500", "http://localhost:5501", "http://127.0.0.1:5500/") - .withSockJS(); + registry.addEndpoint("/wss").setAllowedOrigins("http://localhost:3000").withSockJS(); } } diff --git a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java index d7b8e6a7..f0ebabeb 100644 --- a/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java +++ b/src/main/java/net/gepafin/tendermanagement/constants/GepafinConstant.java @@ -1,7 +1,5 @@ package net.gepafin.tendermanagement.constants; -import com.amazonaws.services.dynamodbv2.xspec.S; - public class GepafinConstant { public static final String USER_CREATED_SUCCESS_MSG = "user.created.success"; @@ -353,8 +351,7 @@ public class GepafinConstant { public static final String NOTIFICATION_ALREADY_IN_THAT_STATE="notification.already.in.state"; public static final String NOTIFICATION_DELETED_SUCCESSFULLY="notification.deleted.successfully"; public static final String NOTIFICATION_UPDATED_SUCCESSFULLY="notification.updated.successfully"; - - + public static final String USER_WITH_COMPANY_NOT_FOUND = "user.with.company.not.found"; } diff --git a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java index 45d81d9c..7382f1c6 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/CallDao.java @@ -51,6 +51,7 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status; import static net.gepafin.tendermanagement.enums.RoleStatusEnum.ROLE_SUPER_ADMIN; import static net.gepafin.tendermanagement.util.Utils.setIfUpdated; +import static org.hibernate.internal.util.collections.CollectionHelper.listOf; @Component public class CallDao { @@ -845,7 +846,8 @@ public class CallDao { Map placeholders = new HashMap<>(); placeholders.put("{{call_name}}", callEntity.getName()); userIds.forEach(userId -> { - NotificationReq notificationReq = notificationDao.createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId); + List companyIds = notificationDao.getAllCompanyIdsForUser(userId); + NotificationReq notificationReq = notificationDao.createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId, null, companyIds); notificationDao.sendNotification(notificationReq); }); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java index 97e9b568..5f7d700f 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java @@ -1,6 +1,5 @@ package net.gepafin.tendermanagement.dao; -import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.constants.GepafinConstant; @@ -19,6 +18,7 @@ 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.service.ApplicationService; import net.gepafin.tendermanagement.util.DateTimeUtil; import net.gepafin.tendermanagement.util.Utils; import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; @@ -34,6 +34,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static org.hibernate.internal.util.collections.CollectionHelper.listOf; + @Component @Slf4j public class NotificationDao { @@ -56,6 +58,9 @@ public class NotificationDao { @Autowired private CompanyDao companyDao; + @Autowired + private ApplicationService applicationService; + public NotificationResponse sendNotification(NotificationReq notificationReq) { // Ensure userId is properly set in notificationReq if not already @@ -68,7 +73,7 @@ public class NotificationDao { log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage()); List companyIds = notificationReq.getCompanyIds(); - if (companyIds==null || companyIds.isEmpty()) { + if (companyIds == null || companyIds.isEmpty()) { sendToUser(userId, notificationEntity); } else { sendToCompanies(userId, companyIds, notificationEntity); @@ -79,40 +84,50 @@ public class NotificationDao { private NotificationEntity saveNotification(NotificationReq notificationReq) { - NotificationEntity notificationEntity = convertToNotificationEntity(notificationReq); - return notificationRepository.save(notificationEntity); + return notificationRepository.save(convertNotificationRequestToNotificationEntity(notificationReq)); } private void sendToUser(Long userId, NotificationEntity notificationEntity) { String userChannel = GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId; log.info("Channel for User {}", userChannel); - messagingTemplate.convertAndSend(userChannel, notificationEntity); + NotificationResponse notificationResponse = convertNotificationEntityToNotificationResponse(notificationEntity); + messagingTemplate.convertAndSend(userChannel, notificationResponse); } private void sendToCompanies(Long userId, List companyIds, NotificationEntity notificationEntity) { // Send notification to each company provided in the companyIds list companyIds.forEach(companyId -> { + UserWithCompanyEntity userWithCompany = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(userId, companyId); String companyChannel = Utils.createChannelForUserAndCompany(userId, companyId); log.info("Channel for User and Company {}, {}", userId, companyChannel); - messagingTemplate.convertAndSend(companyChannel, notificationEntity); + if (userWithCompany == null) { + throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.USER_WITH_COMPANY_NOT_FOUND); + } + notificationEntity.setUserWithCompany(userWithCompany); + notificationRepository.save(notificationEntity); + NotificationResponse notificationResponse = convertNotificationEntityToNotificationResponse(notificationEntity); + messagingTemplate.convertAndSend(companyChannel, notificationResponse); }); } - private NotificationReq convertToNotificationReq(NotificationEntity notificationEntity) { - - NotificationReq notificationReq = new NotificationReq(); - notificationReq.setId(notificationEntity.getId()); - notificationReq.setUserId(notificationEntity.getUserId()); - notificationReq.setStatus(NotificationEnum.UNREAD.getValue()); - notificationReq.setMessage(notificationEntity.getMessage()); - notificationReq.setCreatedDate(notificationEntity.getCreatedDate()); - notificationReq.setUpdatedDate(notificationEntity.getUpdatedDate()); - return notificationReq; + private NotificationResponse convertNotificationEntityToNotificationResponse(NotificationEntity notificationEntity) { + NotificationResponse notificationResponse = new NotificationResponse(); + notificationResponse.setId(notificationEntity.getId()); + notificationResponse.setUserId(notificationEntity.getUserId()); + notificationResponse.setStatus(notificationEntity.getStatus()); + notificationResponse.setMessage(notificationEntity.getMessage()); + notificationResponse.setCreatedDate(notificationEntity.getCreatedDate()); + notificationResponse.setUpdatedDate(notificationEntity.getUpdatedDate()); + notificationResponse.setRedirectUrl(notificationEntity.getNotificationType()); + notificationResponse.setCompanyId(notificationEntity.getUserWithCompany() != null ? notificationEntity.getUserWithCompany().getCompanyId() : null); + notificationResponse.setNotificationType(notificationEntity.getNotificationType()); + notificationResponse.setTitle(notificationEntity.getTitle()); + return notificationResponse; } - private NotificationEntity convertToNotificationEntity(NotificationReq notificationReq) { + private NotificationEntity convertNotificationRequestToNotificationEntity(NotificationReq notificationReq) { NotificationEntity notificationEntity = new NotificationEntity(); String message = notificationReq.getMessage(); @@ -120,108 +135,107 @@ public class NotificationDao { notificationEntity.setUserId(notificationReq.getUserId()); notificationEntity.setStatus(NotificationEnum.UNREAD.getValue()); notificationEntity.setIsDeleted(Boolean.FALSE); + notificationEntity.setUserWithCompany(notificationReq.getUserWithCompanyEntity() != null ? notificationReq.getUserWithCompanyEntity() : null); notificationEntity.setMessage(message); + notificationEntity.setTitle(notificationReq.getTitle()); return notificationEntity; } - public NotificationReq createNotificationReq(String notificationType, Map placeholders, Long userId) { + public NotificationReq createNotificationReq(String notificationType, Map placeholders, Long userId, UserWithCompanyEntity userWithCompanyEntity, + List companyIds) { // Create NotificationReq object NotificationReq notificationReq = new NotificationReq(); - List companyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(notificationReq.getUserId()); - notificationReq.setCompanyIds(companyIds); NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType); notificationReq.setNotificationType(notificationType); String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders); notificationReq.setMessage(message); notificationReq.setUserId(userId); + notificationReq.setCompanyIds(companyIds); + String title = Utils.replacePlaceholders(notificationTypeEntity.getTitle(), placeholders); + notificationReq.setTitle(title); + notificationReq.setUserWithCompanyEntity(userWithCompanyEntity); return notificationReq; } + public Map sendNotificationToBeneficiary(ApplicationEntity application, NotificationTypeEnum notificationTypeEnum) { + Map 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()); + NotificationReq notificationReq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, application.getUserId(), application.getUserWithCompany(), + listOf(application.getCompanyId())); sendNotification(notificationReq); return placeHolders; } public void sendNotificationToInstructor(Map placeHolders, ApplicationEvaluationEntity applicationEvaluationEntity, NotificationTypeEnum notificationTypeEnum) { - Long instructorId=applicationEvaluationEntity.getUserId(); - if(instructorId != null){ - NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders,instructorId); + + Long instructorId = applicationEvaluationEntity.getUserId(); + ApplicationEntity application = applicationService.validateApplication(applicationEvaluationEntity.getApplicationId()); + if (instructorId != null) { + NotificationReq notificationreq = createNotificationReq(notificationTypeEnum.getValue(), placeHolders, instructorId, application.getUserWithCompany(), + listOf(application.getCompanyId())); sendNotification(notificationreq); } } - public void sendNotificationToSuperUser(ApplicationEntity application,Map placeHolders,NotificationTypeEnum notificationTypeEnum) { - List 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()); + public void sendNotificationToSuperUser(ApplicationEntity application, Map placeHolders, NotificationTypeEnum notificationTypeEnum) { + + List 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(), application.getUserWithCompany(), + listOf(application.getCompanyId())); sendNotification(notificationreq); } } + + public List getAllCompanyIdsForUser(Long userId) { + + return userWithCompanyRepository.findActiveCompanyIdsByUserId(userId); + } + public NotificationResponse getNotificationById(Long id) { + NotificationEntity notificationEntity = validateNotificationEntity(id); - NotificationResponse notificationReq=convertNotificationEntityToNotificationResponse(notificationEntity); - return notificationReq; + return convertNotificationEntityToNotificationResponse(notificationEntity); } private NotificationEntity validateNotificationEntity(Long id) { - NotificationEntity notificationEntity=notificationRepository.findByIdAndIsDeletedFalse(id); - if(notificationEntity ==null){ + + NotificationEntity notificationEntity = notificationRepository.findByIdAndIsDeletedFalse(id); + if (notificationEntity == null) { throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.NOTIFICATION_NOT_FOUND)); } return notificationEntity; } public List getNotificationByUserId(Long userId, Long companyId, List statuses) { + List notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalse(userId); - UserWithCompanyEntity userWithCompany=null; - List statusStrings=new ArrayList<>(); - if(companyId!=null){ - userWithCompany=companyDao.validateUserWithCompny(userId,companyId); + UserWithCompanyEntity userWithCompany = null; + List statusStrings = new ArrayList<>(); + if (companyId != null) { + userWithCompany = companyDao.validateUserWithCompny(userId, companyId); } - if (statuses != null ) { - statusStrings = statuses.stream() - .map(NotificationEnum::name) // Convert enum to its name as String + if (statuses != null) { + statusStrings = statuses.stream().map(NotificationEnum::name) // Convert enum to its name as String .toList(); - notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId,statusStrings); + notificationEntities = notificationRepository.findByUserIdAndIsDeletedFalseAndStatusIn(userId, statusStrings); - if(userWithCompany != null){ + if (userWithCompany != null) { notificationEntities = notificationRepository.findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(userId, userWithCompany.getId(), statusStrings); } } - List notificationReq= notificationEntities.stream() - .map(this::convertNotificationEntityToNotificationResponse) - .collect(Collectors.toList()); - - return notificationReq; + return notificationEntities.stream().map(this::convertNotificationEntityToNotificationResponse).collect(Collectors.toList()); } - public NotificationResponse convertNotificationEntityToNotificationResponse(NotificationEntity entity) { - if (entity == null) { - return null; // Handle null entity gracefully - } + public NotificationResponse updateNotificationStatus(Long id, NotificationEnum status) { - NotificationResponse response = new NotificationResponse(); - response.setId(entity.getId()); - response.setUserId(entity.getUserId()); - response.setMessage(entity.getMessage()); - response.setNotificationType(entity.getNotificationType()); - response.setStatus(entity.getStatus()); - response.setCreatedDate(entity.getCreatedDate()); - response.setUpdatedDate(entity.getUpdatedDate()); - response.setRedirectUrl(entity.getRedirectLink()); - response.setCompanyId(entity.getUserWithCompanyId()); - - return response; - } - public NotificationResponse updateNotificationStatus(Long id,NotificationEnum status){ - NotificationEntity notificationEntity=validateNotificationEntity(id); - if(notificationEntity.getStatus().equals(status.getValue())){ - throw new CustomValidationException(Status.BAD_REQUEST,Translator.toLocale(GepafinConstant.NOTIFICATION_ALREADY_IN_THAT_STATE)); + NotificationEntity notificationEntity = validateNotificationEntity(id); + if (notificationEntity.getStatus().equals(status.getValue())) { + throw new CustomValidationException(Status.BAD_REQUEST, Translator.toLocale(GepafinConstant.NOTIFICATION_ALREADY_IN_THAT_STATE)); } notificationEntity.setStatus(status.getValue()); notificationEntity.setUpdatedDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now())); @@ -229,8 +243,9 @@ public class NotificationDao { return convertNotificationEntityToNotificationResponse(notificationEntity); } - public void deleteNotification(Long id){ - NotificationEntity notificationEntity=validateNotificationEntity(id); + public void deleteNotification(Long id) { + + NotificationEntity notificationEntity = validateNotificationEntity(id); notificationEntity.setIsDeleted(true); notificationRepository.save(notificationEntity); } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java index c0571fab..718a7367 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/NotificationEntity.java @@ -2,6 +2,8 @@ package net.gepafin.tendermanagement.entities; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.Data; @@ -11,23 +13,27 @@ import lombok.Data; public class NotificationEntity extends BaseEntity { @Column(name = "USER_ID") - Long userId; + private Long userId; @Column(name = "MESSAGE") - String message; + private String message; + + @Column(name = "TITLE") + private String title; @Column(name = "STATUS") - String status; + private String status; @Column(name = "IS_DELETED") - Boolean isDeleted; + private Boolean isDeleted; @Column(name = "NOTIFICATION_TYPE") - String notificationType; + private String notificationType; @Column(name = "REDIRECT_LINK") - String redirectLink; + private String redirectLink; - @Column(name = "USER_WITH_COMPANY_ID") - Long userWithCompanyId; + @ManyToOne + @JoinColumn(name = "USER_WITH_COMPANY_ID") + private UserWithCompanyEntity userWithCompany; } diff --git a/src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java b/src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java index 5202c97a..40d3f220 100644 --- a/src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java +++ b/src/main/java/net/gepafin/tendermanagement/entities/NotificationTypeEntity.java @@ -11,10 +11,13 @@ import lombok.Data; public class NotificationTypeEntity extends BaseEntity { @Column(name = "NOTIFICATION_NAME") - String notificationName; + private String notificationName; @Column(name = "JSON_TEMPLATE") - String jsonTemplate; + private String jsonTemplate; + + @Column(name = "TITLE") + private String title; @Column(name="IS_DELETED") private Boolean isDeleted; diff --git a/src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java b/src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java index 8506694a..9582d700 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java +++ b/src/main/java/net/gepafin/tendermanagement/model/request/NotificationReq.java @@ -1,7 +1,9 @@ package net.gepafin.tendermanagement.model.request; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import net.gepafin.tendermanagement.entities.UserWithCompanyEntity; import java.time.LocalDateTime; import java.util.List; @@ -30,8 +32,14 @@ public class NotificationReq { private LocalDateTime updatedDate; @JsonProperty(access = JsonProperty.Access.READ_ONLY) - String redirectUrl; + private String redirectUrl; @JsonProperty(access = JsonProperty.Access.READ_ONLY) - List companyIds; + private String title; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + private List companyIds; + + @JsonIgnore + private UserWithCompanyEntity userWithCompanyEntity; } diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java index 655fa905..0383cd25 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/NotificationResponse.java @@ -1,18 +1,21 @@ package net.gepafin.tendermanagement.model.response; import lombok.Data; - -import java.time.LocalDateTime; +import net.gepafin.tendermanagement.model.BaseBean; @Data -public class NotificationResponse { - private Long id; +public class NotificationResponse extends BaseBean { private Long userId; + + private String title; + private String message; - private String notificationType; + private String status; - private LocalDateTime createdDate; - private LocalDateTime updatedDate; - private String redirectUrl; + private Long companyId; + + private String redirectUrl; + + private String notificationType; } diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java index 91374bf7..f3c1d037 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java @@ -1,19 +1,17 @@ package net.gepafin.tendermanagement.repositories; import net.gepafin.tendermanagement.entities.NotificationEntity; -import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface NotificationRepository extends JpaRepository { - NotificationEntity findByIdAndIsDeletedFalse(Long id); + NotificationEntity findByIdAndIsDeletedFalse(Long id); List findByUserIdAndIsDeletedFalse(Long userId); - List findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(Long userId,Long - userWithCompanyId,List statuses); + List findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(Long userId, Long userWithCompanyId, List statuses); List findByUserIdAndIsDeletedFalseAndStatusIn(Long userId, List statuses); } diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/UserWithCompanyRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/UserWithCompanyRepository.java index ec93f2f6..13a197f1 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/UserWithCompanyRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/UserWithCompanyRepository.java @@ -1,22 +1,23 @@ package net.gepafin.tendermanagement.repositories; -import java.util.List; -import java.util.Optional; - +import net.gepafin.tendermanagement.entities.UserWithCompanyEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import net.gepafin.tendermanagement.entities.UserWithCompanyEntity; - +import java.util.List; +import java.util.Optional; public interface UserWithCompanyRepository extends JpaRepository { - void deleteByCompanyIdAndIsDeletedFalse(Long companyId); + void deleteByCompanyIdAndIsDeletedFalse(Long companyId); - @Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false") - List findActiveCompanyIdsByUserId(@Param("userId") Long userId); + @Query("SELECT u.companyId FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.isDeleted = false") + List findActiveCompanyIdsByUserId(@Param("userId") Long userId); - Optional findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId); + Optional findByUserIdAndCompanyIdAndIsDeletedFalse(Long userId, Long companyId); + + @Query("SELECT u FROM UserWithCompanyEntity u WHERE u.userId = :userId AND u.companyId = :companyId AND u.isDeleted = false") + UserWithCompanyEntity findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(Long userId, Long companyId); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java index 7dd37193..4657883d 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java @@ -8,13 +8,13 @@ import net.gepafin.tendermanagement.model.response.NotificationResponse; import java.util.List; public interface NotificationService { - NotificationResponse sendNotification(Long userId, NotificationReq notificationReq); + NotificationResponse sendNotification(Long userId, NotificationReq notificationReq, Long companyId); - public NotificationResponse getNotificationById(HttpServletRequest servletRequest,Long id); + public NotificationResponse getNotificationById(HttpServletRequest servletRequest, Long id); public List getNotificationByUserId(HttpServletRequest servletRequest, Long userId, Long companyId, List statuses); - public NotificationResponse updateNotificationStatus(HttpServletRequest request,Long id,NotificationEnum status); + public NotificationResponse updateNotificationStatus(HttpServletRequest request, Long id, NotificationEnum status); public void deleteNotification(HttpServletRequest request, Long id); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java index 99c35092..2a725935 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java @@ -12,6 +12,8 @@ import org.springframework.stereotype.Service; import java.util.List; +import static org.hibernate.internal.util.collections.CollectionHelper.listOf; + @Service @Slf4j public class NotificationServiceImpl implements NotificationService { @@ -20,33 +22,37 @@ public class NotificationServiceImpl implements NotificationService { private NotificationDao notificationDao; @Override - public NotificationResponse sendNotification(Long userId, NotificationReq notificationReq) { + public NotificationResponse sendNotification(Long userId, NotificationReq notificationReq, Long companyId) { log.info("Sending notification to user {} with content: {}", userId, notificationReq.getMessage()); notificationReq.setUserId(userId); - NotificationResponse notificationResponse = notificationDao.sendNotification(notificationReq); - return notificationResponse; + notificationReq.setCompanyIds(listOf(companyId)); + return notificationDao.sendNotification(notificationReq); } @Override public NotificationResponse getNotificationById(HttpServletRequest servletRequest, Long id) { + return notificationDao.getNotificationById(id); } @Override public List getNotificationByUserId(HttpServletRequest servletRequest, Long userId, Long companyId, List statuses) { - return notificationDao.getNotificationByUserId(userId,companyId,statuses); + + return notificationDao.getNotificationByUserId(userId, companyId, statuses); } @Override - public NotificationResponse updateNotificationStatus(HttpServletRequest request, Long id,NotificationEnum status) { - return notificationDao.updateNotificationStatus(id,status); + public NotificationResponse updateNotificationStatus(HttpServletRequest request, Long id, NotificationEnum status) { + + return notificationDao.updateNotificationStatus(id, status); } @Override public void deleteNotification(HttpServletRequest request, Long id) { - notificationDao.deleteNotification(id); - return; + + notificationDao.deleteNotification(id); + return; } } \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/util/Utils.java b/src/main/java/net/gepafin/tendermanagement/util/Utils.java index 4290bfff..486ddd02 100644 --- a/src/main/java/net/gepafin/tendermanagement/util/Utils.java +++ b/src/main/java/net/gepafin/tendermanagement/util/Utils.java @@ -19,19 +19,15 @@ import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.node.ObjectNode; -import io.jsonwebtoken.Claims; import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; import jakarta.servlet.http.HttpServletRequest; -import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.constants.GepafinConstant; -import net.gepafin.tendermanagement.web.rest.api.errors.CustomValidationException; import org.apache.commons.collections4.MapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import com.fasterxml.jackson.core.JsonProcessingException; @@ -48,7 +44,6 @@ import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientForbiddenExce import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientNotFoundException; import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientUnauthorizedException; import net.gepafin.tendermanagement.web.rest.api.errors.FeignClientValidationException; -import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java index 7e3c4caa..739a1516 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java @@ -7,10 +7,7 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.enums.NotificationEnum; -import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import net.gepafin.tendermanagement.model.request.NotificationReq; -import net.gepafin.tendermanagement.model.response.ApplicationGetResponseBean; -import net.gepafin.tendermanagement.model.response.LookUpDataResponseBean; import net.gepafin.tendermanagement.model.response.NotificationResponse; import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.web.rest.api.errors.ErrorConstants; @@ -36,56 +33,55 @@ public interface NotificationApi { ErrorConstants.BADREQUEST_ERROR_EXAMPLE))) }) @PostMapping(value = "/user/{userId}/sent", consumes = "application/json", produces = "application/json") ResponseEntity> sendNotification(HttpServletRequest request, @RequestBody NotificationReq notificationReq, + @Parameter(description = "The company id", required = false) @RequestParam(value = "companyId", required = false) Long companyId, @Parameter(description = "The user id", required = true) @PathVariable("userId") Long userId); - @Operation(summary = "Api to get notification by id", - 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) })) }) + @Operation(summary = "Api to get notification by id", 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) })) }) @GetMapping(value = "/{id}", produces = "application/json") - ResponseEntity> getNotificationById(HttpServletRequest request, @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id); + ResponseEntity> getNotificationById(HttpServletRequest request, + @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id); - @Operation(summary = "Api to get notification by user id", - 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) })) }) + @Operation(summary = "Api to get notification by user id", 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) })) }) @GetMapping(value = "/user/{userId}", produces = "application/json") - ResponseEntity>> getNotificationByUserId(HttpServletRequest request, @Parameter(description = "The user id", required = true) @PathVariable(value = "userId", required = true) Long userId,@Parameter(description = "The company id", required = false) @RequestParam(value = "companyId",required = false) Long companyId,@Parameter(description = "The notification status", required = false) @RequestParam(value = "status",required = false) List statuses); + ResponseEntity>> getNotificationByUserId(HttpServletRequest request, + @Parameter(description = "The user id", required = true) @PathVariable(value = "userId", required = true) Long userId, + @Parameter(description = "The company id", required = false) @RequestParam(value = "companyId", required = false) Long companyId, + @Parameter(description = "The notification status", required = false) @RequestParam(value = "status", required = false) List statuses); - @Operation(summary = "Api to update notification status", - 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) })) }) + @Operation(summary = "Api to update notification status", 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) })) }) @PutMapping(value = "/{id}", produces = "application/json") - ResponseEntity> updateNotificationStatus(HttpServletRequest request, @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id,@Parameter(description = "The notification status", required = true) @RequestParam(value = "status",required = true) NotificationEnum status); + ResponseEntity> updateNotificationStatus(HttpServletRequest request, + @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id, + @Parameter(description = "The notification status", required = true) @RequestParam(value = "status", required = true) NotificationEnum status); - - @Operation(summary = "Api to delete notification", - 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) })) }) + @Operation(summary = "Api to delete notification", 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) })) }) @DeleteMapping(value = "/{id}", produces = "application/json") - ResponseEntity> deleteNotification(HttpServletRequest request, @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id); + ResponseEntity> deleteNotification(HttpServletRequest request, + @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id); } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java index 7b065b8c..11c61f23 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java @@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; +import static org.hibernate.internal.util.collections.CollectionHelper.listOf; + @RestController @RequestMapping("${openapi.gepafin.base-path:/v1/notification}") public class NotificationApiController implements NotificationApi { @@ -26,41 +28,43 @@ public class NotificationApiController implements NotificationApi { @Autowired private NotificationService notificationService; - public ResponseEntity> sendNotification(HttpServletRequest request, NotificationReq notificationReq, Long userId) { + public ResponseEntity> sendNotification(HttpServletRequest request, NotificationReq notificationReq, Long userId, Long companyId) { - NotificationResponse notificationData = notificationService.sendNotification(userId, notificationReq); + NotificationResponse notificationData = notificationService.sendNotification(userId, notificationReq, companyId); - return ResponseEntity.status(HttpStatus.OK) - .body(new Response<>(notificationData, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_SENT_SUCCESSFULLY))); + return ResponseEntity.status(HttpStatus.OK).body(new Response<>(notificationData, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_SENT_SUCCESSFULLY))); } @Override public ResponseEntity> getNotificationById(HttpServletRequest request, Long id) { - NotificationResponse notificationResponse=notificationService.getNotificationById(request,id); + + NotificationResponse notificationResponse = notificationService.getNotificationById(request, id); return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(notificationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY))); } @Override public ResponseEntity>> getNotificationByUserId(HttpServletRequest request, Long userId, Long companyId, List statuses) { - List notificationResponses=notificationService.getNotificationByUserId(request,userId,companyId,statuses); + + List notificationResponses = notificationService.getNotificationByUserId(request, userId, companyId, statuses); return ResponseEntity.status(HttpStatus.OK) .body(new Response>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY))); } @Override - public ResponseEntity> updateNotificationStatus(HttpServletRequest request, Long id,NotificationEnum notificationEnums) { - NotificationResponse notificationResponse=notificationService.updateNotificationStatus(request,id,notificationEnums); + public ResponseEntity> updateNotificationStatus(HttpServletRequest request, Long id, NotificationEnum notificationEnums) { + + NotificationResponse notificationResponse = notificationService.updateNotificationStatus(request, id, notificationEnums); return ResponseEntity.status(HttpStatus.OK) .body(new Response<>(notificationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_UPDATED_SUCCESSFULLY))); } @Override public ResponseEntity> deleteNotification(HttpServletRequest request, Long id) { - notificationService.deleteNotification(request,id); - return ResponseEntity.status(HttpStatus.OK) - .body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_DELETED_SUCCESSFULLY))); + + notificationService.deleteNotification(request, id); + return ResponseEntity.status(HttpStatus.OK).body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_DELETED_SUCCESSFULLY))); } } \ No newline at end of file diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index f99634bc..1a74fc78 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -22,4 +22,11 @@ appointment.portal.user=UtenzaAPIPortal@621 appointment.portal.password=u13nzaAP1P0rtal appointment.portal.source=GEPAFINPORTAL appointment.portal.context=GEPAFINPORTAL -flagDaFirmare=false \ No newline at end of file +flagDaFirmare=false + +# RabbitMQ properties for STOMP broker relay for Notification +spring.rabbitmq.host=localhost +spring.rabbitmq.port=61613 +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest +spring.rabbitmq.virtual-host=/ \ No newline at end of file diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 11f3d75e..7e78b539 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,6 +1,6 @@ # DataSource Configuration spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_dev_local -spring.datasource.username=root +spring.datasource.username=postgres spring.datasource.password=root spring.datasource.driver-class-name=org.postgresql.Driver @@ -22,9 +22,9 @@ appointment.portal.source=GEPAFINPORTAL appointment.portal.context=GEPAFINPORTAL flagDaFirmare=false -# RabbitMQ properties for STOMP broker relay +# RabbitMQ properties for STOMP broker relay for Notification spring.rabbitmq.host=localhost -spring.rabbitmq.port=5672 +spring.rabbitmq.port=61613 spring.rabbitmq.username=guest spring.rabbitmq.password=guest spring.rabbitmq.virtual-host=/ \ No newline at end of file diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties index 2007e166..e137691f 100644 --- a/src/main/resources/application-production.properties +++ b/src/main/resources/application-production.properties @@ -29,4 +29,11 @@ appointment.portal.user=UtenzaAPIPortal@621 appointment.portal.password=u13nzaAP1P0rtal appointment.portal.source=GEPAFINPORTAL appointment.portal.context=GEPAFINPORTAL -flagDaFirmare=true \ No newline at end of file +flagDaFirmare=true + +# RabbitMQ properties for STOMP broker relay for Notification +spring.rabbitmq.host=localhost +spring.rabbitmq.port=61613 +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest +spring.rabbitmq.virtual-host=/ \ No newline at end of file diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties index 1dbc41cc..0617f3cd 100644 --- a/src/main/resources/application-testing.properties +++ b/src/main/resources/application-testing.properties @@ -11,4 +11,18 @@ default_System_Receiver_Email=test@test.test gepafin_email=test@test.test rinaldo_email=test@test.test carlo_email=test@test.test -default.hub.uuid=p4lk3bcx1RStqTaIVVbXs \ No newline at end of file +default.hub.uuid=p4lk3bcx1RStqTaIVVbXs + +appointment.base.url=https://demo.galileonetwork.it/gateway/rest +appointment.portal.user=UtenzaAPIPortal@621 +appointment.portal.password=u13nzaAP1P0rtal +appointment.portal.source=GEPAFINPORTAL +appointment.portal.context=GEPAFINPORTAL +flagDaFirmare=false + +# RabbitMQ properties for STOMP broker relay for Notification +spring.rabbitmq.host=localhost +spring.rabbitmq.port=61613 +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest +spring.rabbitmq.virtual-host=/ \ No newline at end of file diff --git a/src/main/resources/db/changelog/db.changelog-1.0.0.xml b/src/main/resources/db/changelog/db.changelog-1.0.0.xml index 61ba0949..816716ad 100644 --- a/src/main/resources/db/changelog/db.changelog-1.0.0.xml +++ b/src/main/resources/db/changelog/db.changelog-1.0.0.xml @@ -2030,9 +2030,19 @@ - + + - + + + + + + + + + + diff --git a/src/main/resources/message_en.properties b/src/main/resources/message_en.properties index 966358df..a1a01272 100644 --- a/src/main/resources/message_en.properties +++ b/src/main/resources/message_en.properties @@ -343,3 +343,4 @@ notification.not.found=Notification not found. notification.sent.successfully=Notification sent successfully. notification.deleted.successfully=Notification deleted successfully. notification.updated.successfully=Notification updated successfully. +user.with.company.not.found = User with company not found for user or company. diff --git a/src/main/resources/message_it.properties b/src/main/resources/message_it.properties index da111f9f..03cf99d7 100644 --- a/src/main/resources/message_it.properties +++ b/src/main/resources/message_it.properties @@ -332,4 +332,5 @@ notification.fetched.successfully=Notifica recuperata con successo. notification.not.found=Notifica non trovata. notification.sent.successfully=Notifica inviata con successo. notification.deleted.successfully=Notifica eliminata con successo. -notification.updated.successfully=Notifica aggiornata con successo. \ No newline at end of file +notification.updated.successfully=Notifica aggiornata con successo. +user.with.company.not.found = Utente con azienda non trovato per utente o azienda. \ No newline at end of file From 47aa1d73b9ffc315904e984ded45760b7bcbbb7b Mon Sep 17 00:00:00 2001 From: piyushkag Date: Tue, 24 Dec 2024 16:21:34 +0530 Subject: [PATCH 07/13] Updated Code. --- src/main/resources/application-local.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 7e78b539..e52a9577 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,5 +1,5 @@ # DataSource Configuration -spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_dev_local +spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_local spring.datasource.username=postgres spring.datasource.password=root spring.datasource.driver-class-name=org.postgresql.Driver From 42e1f6a0c5af8c1f55c6e7fdacbd7b9988138153 Mon Sep 17 00:00:00 2001 From: piyushkag Date: Fri, 27 Dec 2024 15:03:07 +0530 Subject: [PATCH 08/13] Updated RabbitMQ config for notification. --- src/main/resources/application-dev.properties | 2 +- src/main/resources/application-production.properties | 2 +- src/main/resources/application-testing.properties | 2 +- src/main/resources/application.properties | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 1a74fc78..2b3482bf 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -25,7 +25,7 @@ appointment.portal.context=GEPAFINPORTAL flagDaFirmare=false # RabbitMQ properties for STOMP broker relay for Notification -spring.rabbitmq.host=localhost +spring.rabbitmq.host=rabitmq.bflows.ai spring.rabbitmq.port=61613 spring.rabbitmq.username=guest spring.rabbitmq.password=guest diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties index e137691f..007831ca 100644 --- a/src/main/resources/application-production.properties +++ b/src/main/resources/application-production.properties @@ -32,7 +32,7 @@ appointment.portal.context=GEPAFINPORTAL flagDaFirmare=true # RabbitMQ properties for STOMP broker relay for Notification -spring.rabbitmq.host=localhost +spring.rabbitmq.host=rabitmq.bflows.ai spring.rabbitmq.port=61613 spring.rabbitmq.username=guest spring.rabbitmq.password=guest diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties index 0617f3cd..e8088376 100644 --- a/src/main/resources/application-testing.properties +++ b/src/main/resources/application-testing.properties @@ -21,7 +21,7 @@ appointment.portal.context=GEPAFINPORTAL flagDaFirmare=false # RabbitMQ properties for STOMP broker relay for Notification -spring.rabbitmq.host=localhost +spring.rabbitmq.host=rabitmq.bflows.ai spring.rabbitmq.port=61613 spring.rabbitmq.username=guest spring.rabbitmq.password=guest diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 60f61aec..c1095613 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,7 +4,7 @@ spring.application.name=tendermanagement spring.servlet.multipart.max-file-size=300MB spring.servlet.multipart.max-request-size=300MB -spring.profiles.active=testing +spring.profiles.active=testing # JPA Configuration From f8099fd4238f36ede2d82d17078c6a34b060560f Mon Sep 17 00:00:00 2001 From: rajesh Date: Fri, 27 Dec 2024 17:31:58 +0530 Subject: [PATCH 09/13] Updated response --- .../dao/ApplicationAmendmentRequestDao.java | 5 ++++- .../gepafin/tendermanagement/dao/ApplicationDao.java | 10 ++++++++++ .../dao/ApplicationEvaluationDao.java | 11 ++++++++++- .../response/ApplicationAmendmentRequestResponse.java | 1 + .../model/response/ApplicationEvaluationResponse.java | 2 ++ .../model/response/ApplicationResponse.java | 4 ++++ 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java index 2937da2c..5cb93052 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationAmendmentRequestDao.java @@ -110,6 +110,8 @@ public class ApplicationAmendmentRequestDao { @Autowired private DocumentRepository documentRepository; + @Autowired + private CompanyService companyService; public ApplicationAmendmentRequestResponse getApplicationDataForAmendment(Long applicationEvaluationId) { log.info("Fetching the application data for the Amendment process {}", applicationEvaluationId); @@ -454,7 +456,8 @@ public class ApplicationAmendmentRequestDao { UserEntity userEntity = userService.validateUser(application.getUserId()); response.setBeneficiaryName(buildBeneficiaryName(userEntity)); - + CompanyEntity company = companyService.validateCompany(application.getCompanyId()); + response.setCompanyName(company.getCompanyName()); Long protocolNumber = entity.getProtocol() != null ? entity.getProtocol().getProtocolNumber() : null; response.setProtocolNumber(protocolNumber); diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java index 45a69384..5353f215 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationDao.java @@ -387,6 +387,16 @@ public class ApplicationDao { responseBean.setStatus(applicationEntity.getStatus()); responseBean.setComments(applicationEntity.getComments()); responseBean.setCompanyId(applicationEntity.getCompanyId()); + Optional assignedApplicationsOptional = + assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(applicationEntity.getId()); + if(assignedApplicationsOptional.isPresent()){ + responseBean.setAssignedUserId(assignedApplicationsOptional.get().getUserId()); + UserEntity user = userService.validateUser(assignedApplicationsOptional.get().getUserId()); + String firstName = user.getFirstName() != null ? user.getFirstName() : ""; + String lastName = user.getLastName() != null ? user.getLastName() : ""; + String userName = String.join(" ", firstName, lastName).trim(); + responseBean.setAssignedUserName(userName); + } CompanyEntity company=companyService.validateCompany(applicationEntity.getCompanyId()); responseBean.setCompanyName(company.getCompanyName()); if(applicationEntity.getProtocol() != null) { diff --git a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java index aad85864..4986dce7 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/ApplicationEvaluationDao.java @@ -558,7 +558,16 @@ public class ApplicationEvaluationDao { response.setAssignedAt(assignedApplications.getAssignedAt()); } response.setEvaluationEndDate(entity.getEndDate()); - + Optional assignedApplicationsOptional = + assignedApplicationsRepository.findByApplicationIdAndIsDeletedFalse(application.getId()); + if(assignedApplicationsOptional.isPresent()){ + response.setAssignedUserId(assignedApplicationsOptional.get().getUserId()); + UserEntity assignedUser = userService.validateUser(assignedApplicationsOptional.get().getUserId()); + String assignedUserFirstName = assignedUser.getFirstName() != null ? assignedUser.getFirstName() : ""; + String assignedUserLastName = assignedUser.getLastName() != null ? assignedUser.getLastName() : ""; + String userName = String.join(" ", assignedUserFirstName, assignedUserLastName).trim(); + response.setAssignedUserName(userName); + } LocalDateTime callEndDate = application.getCall().getEndDate(); response.setCallEndDate(callEndDate); if (application.getCompanyId() != null) { diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java index 01390777..776ad10f 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationAmendmentRequestResponse.java @@ -19,6 +19,7 @@ public class ApplicationAmendmentRequestResponse { private Long protocolNumber; private String callName; private String beneficiaryName; + private String companyName; private List formFields; private List applicationFormFields; private List amendmentDocuments; diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java index b890b327..7da6d25f 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationEvaluationResponse.java @@ -26,6 +26,8 @@ public class ApplicationEvaluationResponse { private LocalDateTime createdDate; private LocalDateTime updatedDate; private String beneficiary; + private Long assignedUserId; + private String assignedUserName; private Long protocolNumber; private String callName; private String motivation; diff --git a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationResponse.java b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationResponse.java index d5df459e..24ad5a34 100644 --- a/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationResponse.java +++ b/src/main/java/net/gepafin/tendermanagement/model/response/ApplicationResponse.java @@ -33,4 +33,8 @@ public class ApplicationResponse{ private Long protocolNumber; + private Long assignedUserId; + + private String assignedUserName; + } \ No newline at end of file From 8074d5d73d6b906053c7fe2d78ceb3e8d12daa7a Mon Sep 17 00:00:00 2001 From: piyushkag Date: Sat, 28 Dec 2024 12:19:39 +0530 Subject: [PATCH 10/13] Added API for getting notifications by compnayId and userId. --- .../tendermanagement/dao/NotificationDao.java | 19 +++++++++++++++++++ .../repositories/NotificationRepository.java | 3 +++ .../service/NotificationService.java | 3 +++ .../service/impl/NotificationServiceImpl.java | 4 ++++ .../web/rest/api/NotificationApi.java | 12 ++++++++++++ .../api/impl/NotificationApiController.java | 10 +++++++--- 6 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java index 5f7d700f..64db69ca 100644 --- a/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java +++ b/src/main/java/net/gepafin/tendermanagement/dao/NotificationDao.java @@ -61,6 +61,9 @@ public class NotificationDao { @Autowired private ApplicationService applicationService; + @Autowired + private UserDao userDao; + public NotificationResponse sendNotification(NotificationReq notificationReq) { // Ensure userId is properly set in notificationReq if not already @@ -249,4 +252,20 @@ public class NotificationDao { notificationEntity.setIsDeleted(true); notificationRepository.save(notificationEntity); } + + public List getNotificationByCompanyIdAndUserId(Long userId, Long companyId) { + + companyDao.validateCompany(companyId); + userDao.validateUser(userId); + + UserWithCompanyEntity userWithCompanyData = userWithCompanyRepository.findByUserIdAndCompanyIdAndIsDeletedFalseForNotification(userId, companyId); + if (userWithCompanyData == null) { + throw new CustomValidationException(Status.BAD_REQUEST, GepafinConstant.USER_MUST_BE_ASSOCIATED_WITH_COMPANY); + } + + List notifications = notificationRepository.findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(userWithCompanyData.getId(), + userWithCompanyData.getUserId()); + return notifications.stream().map(this::convertNotificationEntityToNotificationResponse).toList(); + } + } diff --git a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java index f3c1d037..bce3ba68 100644 --- a/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java +++ b/src/main/java/net/gepafin/tendermanagement/repositories/NotificationRepository.java @@ -1,6 +1,7 @@ package net.gepafin.tendermanagement.repositories; import net.gepafin.tendermanagement.entities.NotificationEntity; +import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; @@ -14,4 +15,6 @@ public interface NotificationRepository extends JpaRepository findByUserIdAndUserWithCompanyIdAndIsDeletedFalseAndStatusIn(Long userId, Long userWithCompanyId, List statuses); List findByUserIdAndIsDeletedFalseAndStatusIn(Long userId, List statuses); + + List findByUserWithCompanyIdAndUserIdAndIsDeletedFalse(Long userWithCompanyId, Long userId); } diff --git a/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java index 4657883d..4d5d3ba6 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java +++ b/src/main/java/net/gepafin/tendermanagement/service/NotificationService.java @@ -17,4 +17,7 @@ public interface NotificationService { public NotificationResponse updateNotificationStatus(HttpServletRequest request, Long id, NotificationEnum status); public void deleteNotification(HttpServletRequest request, Long id); + + public List getNotificationsByCompanyIdAndUserId(Long userId, Long companyId); + } diff --git a/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java index 2a725935..9fa0956a 100644 --- a/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java +++ b/src/main/java/net/gepafin/tendermanagement/service/impl/NotificationServiceImpl.java @@ -55,4 +55,8 @@ public class NotificationServiceImpl implements NotificationService { return; } + @Override + public List getNotificationsByCompanyIdAndUserId(Long userId, Long companyId) { + return notificationDao.getNotificationByCompanyIdAndUserId(userId, companyId); + } } \ No newline at end of file diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java index 739a1516..6f46244b 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/NotificationApi.java @@ -83,6 +83,18 @@ public interface NotificationApi { ResponseEntity> deleteNotification(HttpServletRequest request, @Parameter(description = "The notification id", required = true) @PathVariable(value = "id", required = true) Long id); + @Operation(summary = "API to get notifications by user ID and company ID", 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) })) }) + @GetMapping(value = "/user/{userId}/company/{companyId}/notifications", produces = "application/json") + ResponseEntity>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request, + @Parameter(description = "The user id", required = true) @PathVariable(value = "userId") Long userId, + @Parameter(description = "The company ID", required = true) @PathVariable(value = "companyId") Long companyId); + } diff --git a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java index 11c61f23..586a5f9e 100644 --- a/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java +++ b/src/main/java/net/gepafin/tendermanagement/web/rest/api/impl/NotificationApiController.java @@ -4,7 +4,6 @@ import jakarta.servlet.http.HttpServletRequest; import net.gepafin.tendermanagement.config.Translator; import net.gepafin.tendermanagement.constants.GepafinConstant; import net.gepafin.tendermanagement.enums.NotificationEnum; -import net.gepafin.tendermanagement.enums.NotificationTypeEnum; import net.gepafin.tendermanagement.model.request.NotificationReq; import net.gepafin.tendermanagement.model.response.NotificationResponse; import net.gepafin.tendermanagement.model.util.Response; @@ -19,8 +18,6 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; -import static org.hibernate.internal.util.collections.CollectionHelper.listOf; - @RestController @RequestMapping("${openapi.gepafin.base-path:/v1/notification}") public class NotificationApiController implements NotificationApi { @@ -67,4 +64,11 @@ public class NotificationApiController implements NotificationApi { return ResponseEntity.status(HttpStatus.OK).body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_DELETED_SUCCESSFULLY))); } + @Override + public ResponseEntity>> getNotificationsByUserIdAndCompanyId(HttpServletRequest request,Long userId, Long companyId) { + List notificationResponses = notificationService.getNotificationsByCompanyIdAndUserId(userId, companyId); + return ResponseEntity.status(HttpStatus.OK) + .body(new Response<>(notificationResponses, Status.SUCCESS, Translator.toLocale(GepafinConstant.NOTIFICATION_FETCHED_SUCCESSFULLY))); + } + } \ No newline at end of file From 60cb721a14de3f2c779a2eab674de0bcd55405a4 Mon Sep 17 00:00:00 2001 From: piyushkag Date: Mon, 30 Dec 2024 12:22:43 +0530 Subject: [PATCH 11/13] Resolved RabbitMQ issue and added configuration. --- .../net/gepafin/tendermanagement/config/WebSocketConfig.java | 3 ++- src/main/resources/application-dev.properties | 2 +- src/main/resources/application-local.properties | 4 ++-- src/main/resources/application-production.properties | 2 +- src/main/resources/application-testing.properties | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java index 8aa01986..1b90a882 100644 --- a/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java +++ b/src/main/java/net/gepafin/tendermanagement/config/WebSocketConfig.java @@ -33,6 +33,7 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { - registry.addEndpoint("/wss").setAllowedOrigins("http://localhost:3000").withSockJS(); + registry.addEndpoint("/wss").setAllowedOrigins("http://localhost:3000", "http://127.0.0.1:5500/", "https://bandi-staging.memento.credit/**", "https://bandi.gepafin.it/**") + .withSockJS(); } } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 2b3482bf..e211e883 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -25,7 +25,7 @@ appointment.portal.context=GEPAFINPORTAL flagDaFirmare=false # RabbitMQ properties for STOMP broker relay for Notification -spring.rabbitmq.host=rabitmq.bflows.ai +spring.rabbitmq.host=rabbitmq.bflows.ai spring.rabbitmq.port=61613 spring.rabbitmq.username=guest spring.rabbitmq.password=guest diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index e52a9577..bcf5beab 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,6 +1,6 @@ # DataSource Configuration -spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_local -spring.datasource.username=postgres +spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_dev_local +spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=org.postgresql.Driver diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties index 007831ca..df295088 100644 --- a/src/main/resources/application-production.properties +++ b/src/main/resources/application-production.properties @@ -32,7 +32,7 @@ appointment.portal.context=GEPAFINPORTAL flagDaFirmare=true # RabbitMQ properties for STOMP broker relay for Notification -spring.rabbitmq.host=rabitmq.bflows.ai +spring.rabbitmq.host=rabbitmq.bflows.ai spring.rabbitmq.port=61613 spring.rabbitmq.username=guest spring.rabbitmq.password=guest diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties index e8088376..8ee53329 100644 --- a/src/main/resources/application-testing.properties +++ b/src/main/resources/application-testing.properties @@ -21,7 +21,7 @@ appointment.portal.context=GEPAFINPORTAL flagDaFirmare=false # RabbitMQ properties for STOMP broker relay for Notification -spring.rabbitmq.host=rabitmq.bflows.ai +spring.rabbitmq.host=rabbitmq.bflows.ai spring.rabbitmq.port=61613 spring.rabbitmq.username=guest spring.rabbitmq.password=guest From 4774f9383e143a2114f15d5006f99207d1921865 Mon Sep 17 00:00:00 2001 From: piyushkag Date: Mon, 30 Dec 2024 12:35:30 +0530 Subject: [PATCH 12/13] Added configuration for rabbitMQ connection. --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c1095613..d0af99d3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -67,4 +67,5 @@ default.hub.pdf.banner=https://mementoresources.s3.amazonaws.com/gepafin/staging #feign client config spring.cloud.openfeign.client.config.default.connectTimeout=300000 -spring.cloud.openfeign.client.config.default.readTimeout=300000 \ No newline at end of file +spring.cloud.openfeign.client.config.default.readTimeout=300000 +spring.rabbitmq.connection-timeout=120000 \ No newline at end of file From 83141d009f7baf1e2a8ee24230bb6c84328991c8 Mon Sep 17 00:00:00 2001 From: piyushkag Date: Mon, 30 Dec 2024 13:02:50 +0530 Subject: [PATCH 13/13] Updated code. --- src/main/resources/application-local.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index bcf5beab..e52a9577 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,6 +1,6 @@ # DataSource Configuration -spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_dev_local -spring.datasource.username=root +spring.datasource.url=jdbc:postgresql://localhost:5432/gepafin_local +spring.datasource.username=postgres spring.datasource.password=root spring.datasource.driver-class-name=org.postgresql.Driver