From 26ab1fb6129e49116273842b36345efc163e970f Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 4 Jan 2024 13:11:13 +0200 Subject: [PATCH] remove old notification --- .../java/eu/eudat/data/old/Notification.java | 174 ----------------- .../data/dao/entities/NotificationDao.java | 13 -- .../dao/entities/NotificationDaoImpl.java | 61 ------ .../managers/DataManagementPlanManager.java | 32 +-- .../eudat/logic/managers/DatasetManager.java | 38 ++-- .../logic/managers/NotificationManager.java | 183 ++++++++---------- .../operations/DatabaseRepository.java | 3 - .../operations/DatabaseRepositoryImpl.java | 12 -- .../notification/NotificationScheduleJob.java | 60 +++--- .../models/data/notiication/Notification.java | 163 ---------------- 10 files changed, 146 insertions(+), 593 deletions(-) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java delete mode 100644 dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDao.java delete mode 100644 dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDaoImpl.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/notiication/Notification.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java deleted file mode 100644 index 35d6f76f4..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Notification.java +++ /dev/null @@ -1,174 +0,0 @@ -package eu.eudat.data.old; - -import eu.eudat.commons.enums.old.notification.ActiveStatus; -import eu.eudat.commons.enums.old.notification.ContactType; -import eu.eudat.commons.enums.old.notification.NotificationType; -import eu.eudat.commons.enums.old.notification.NotifyState; -import eu.eudat.data.UserEntity; -import eu.eudat.data.old.queryableentity.DataEntity; - -import jakarta.persistence.*; -import java.util.Date; -import java.util.List; -import java.util.UUID; - -@Entity -@Table(name = "\"NotificationLegacy\"") -public class Notification implements DataEntity { - - @Id - @GeneratedValue - @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "\"UserId\"") - private UserEntity userId; - - @Enumerated - @Column(name = "\"IsActive\"", nullable = false) - private ActiveStatus isActive; - - @Enumerated - @Column(name = "\"Type\"", nullable = false) - private NotificationType type; - - @Enumerated - @Column(name = "\"ContactTypeHint\"") - private ContactType contactTypeHint; - - @Column(name = "\"ContactHint\"") - private String contactHint; - - @Column(name = "\"Data\"") - private String data; - - @Enumerated - @Column(name = "\"NotifyState\"") - private NotifyState notifyState; - - @Column(name = "\"NotifiedAt\"") - private Date notifiedAt; - - @Column(name = "\"RetryCount\"") - private Integer retryCount; - - @Column(name = "\"CreatedAt\"") - private Date createdAt; - - @Column(name = "\"UpdatedAt\"") - private Date updatedAt; - - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public UserEntity getUserId() { - return userId; - } - - public void setUserId(UserEntity userId) { - this.userId = userId; - } - - public ActiveStatus getIsActive() { - return isActive; - } - - public void setIsActive(ActiveStatus isActive) { - this.isActive = isActive; - } - - public NotificationType getType() { - return type; - } - - public void setType(NotificationType type) { - this.type = type; - } - - public ContactType getContactTypeHint() { - return contactTypeHint; - } - - public void setContactTypeHint(ContactType contactTypeHint) { - this.contactTypeHint = contactTypeHint; - } - - public String getContactHint() { - return contactHint; - } - - public void setContactHint(String contactHint) { - this.contactHint = contactHint; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public NotifyState getNotifyState() { - return notifyState; - } - - public void setNotifyState(NotifyState notifyState) { - this.notifyState = notifyState; - } - - public Date getNotifiedAt() { - return notifiedAt; - } - - public void setNotifiedAt(Date notifiedAt) { - this.notifiedAt = notifiedAt; - } - - public Integer getRetryCount() { - return retryCount; - } - - public void setRetryCount(Integer retryCount) { - this.retryCount = retryCount; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - @Override - public void update(Notification entity) { - } - - @Override - public UUID getKeys() { - return null; - } - - @Override - public Notification buildFromTuple(List tuple, List fields, String base) { - return null; - } - - -} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDao.java deleted file mode 100644 index 9cb0e8fc6..000000000 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDao.java +++ /dev/null @@ -1,13 +0,0 @@ -package eu.eudat.data.dao.entities; - -import eu.eudat.data.dao.DatabaseAccessLayer; -import eu.eudat.data.dao.criteria.NotificationCriteria; -import eu.eudat.data.old.Notification; -import eu.eudat.queryable.QueryableList; - -import java.util.UUID; - -public interface NotificationDao extends DatabaseAccessLayer { - - QueryableList getWithCriteria(NotificationCriteria criteria); -} diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDaoImpl.java deleted file mode 100644 index b10142679..000000000 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/NotificationDaoImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -package eu.eudat.data.dao.entities; - -import eu.eudat.data.dao.DatabaseAccess; -import eu.eudat.data.dao.criteria.NotificationCriteria; -import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.old.Notification; -import eu.eudat.queryable.QueryableList; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import javax.management.InvalidApplicationException; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; - -@Service("NotificationDao") -public class NotificationDaoImpl extends DatabaseAccess implements NotificationDao { - @Autowired - public NotificationDaoImpl(DatabaseService databaseService) { - super(databaseService); - } - - @Override - public QueryableList getWithCriteria(NotificationCriteria criteria) { - QueryableList query = this.getDatabaseService().getQueryable(Notification.class); - if (criteria.getIsActive() != null) - query.where((builder, root) -> builder.equal(root.get("isActive"), criteria.getIsActive())); - if (criteria.getNotifyState() != null) - query.where(((builder, root) -> builder.equal(root.get("notifyState"), criteria.getNotifyState()))); - return query; - } - - @Override - public Notification createOrUpdate(Notification item) { - return this.getDatabaseService().createOrUpdate(item, Notification.class); - } - - @Override - public CompletableFuture createOrUpdateAsync(Notification item) { - return CompletableFuture.supplyAsync(() -> this.getDatabaseService().createOrUpdate(item, Notification.class)); - } - - @Override - public Notification find(UUID id) throws InvalidApplicationException { - return this.getDatabaseService().getQueryable(Notification.class).where(((builder, root) -> builder.equal(root.get("id"), id))).getSingle(); - } - - @Override - public Notification find(UUID id, String hint) { - throw new UnsupportedOperationException(); - } - - @Override - public void delete(Notification item) { - this.getDatabaseService().delete(item); - } - - @Override - public QueryableList asQueryable() { - return this.getDatabaseService().getQueryable(Notification.class); - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index a692646c1..62ba48bca 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -2672,22 +2672,22 @@ public class DataManagementPlanManager { List userDMPS = this.queryFactory.query(DmpUserQuery.class).dmpIds(dmp.getId()).collect(); for (DmpUserEntity userDMP : userDMPS) { if (!userDMP.getUserId().equals(user.getId())) { - Notification notification = new Notification(); - notification.setUserId(user); - notification.setType(notificationType); - notification.setNotifyState(NotifyState.PENDING); - notification.setIsActive(ActiveStatus.ACTIVE); - notification.setData("{" + - "\"userId\": \"" + userDMP.getId() + "\"" + -// ", \"id\": \"" + userDMP.getDmp().getId() + "\"" + //TODO -// ", \"name\": \"" + userDMP.getDmp().getLabel() + "\"" + - ", \"path\": \"" + notificationPaths.get(notificationType) +"\"" + - "}"); - notification.setCreatedAt(new Date()); - notification.setUpdatedAt(notification.getCreatedAt()); - notification.setContactTypeHint(ContactType.EMAIL); - //notification.setContactHint(userDMP.getUser().getEmail()); //TODO - databaseRepository.getNotificationDao().createOrUpdate(notification); +// Notification notification = new Notification(); //TODO +// notification.setUserId(user); +// notification.setType(notificationType); +// notification.setNotifyState(NotifyState.PENDING); +// notification.setIsActive(ActiveStatus.ACTIVE); +// notification.setData("{" + +// "\"userId\": \"" + userDMP.getId() + "\"" + +//// ", \"id\": \"" + userDMP.getDmp().getId() + "\"" + //TODO +//// ", \"name\": \"" + userDMP.getDmp().getLabel() + "\"" + +// ", \"path\": \"" + notificationPaths.get(notificationType) +"\"" + +// "}"); +// notification.setCreatedAt(new Date()); +// notification.setUpdatedAt(notification.getCreatedAt()); +// notification.setContactTypeHint(ContactType.EMAIL); +// //notification.setContactHint(userDMP.getUser().getEmail()); //TODO +// databaseRepository.getNotificationDao().createOrUpdate(notification); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 37119d681..bf4c95568 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -730,25 +730,25 @@ public class DatasetManager { List userDMPS = this.queryFactory.query(DmpUserQuery.class).dmpIds(dmp.getId()).collect(); for (DmpUserEntity userDMP : userDMPS) { if (!userDMP.getUserId().equals(user.getId())) { - Notification notification = new Notification(); - notification.setUserId(user); - notification.setType(notificationType); - notification.setNotifyState(NotifyState.PENDING); - notification.setIsActive(ActiveStatus.ACTIVE); - notification.setData("{" + - "\"userId\": \"" + userDMP.getUserId() + "\"" + - ", \"id\": \"" + descriptionEntity.getId() + "\"" + - ", \"name\": \"" + descriptionEntity.getLabel() + "\"" + - ", \"path\": \"" + notificationPaths.get(notificationType) + "\"" + - "}"); - notification.setCreatedAt(new Date()); - notification.setUpdatedAt(notification.getCreatedAt()); - notification.setContactTypeHint(ContactType.EMAIL); - - UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(userDMP.getUserId()); - query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal)); - notification.setContactHint(query.first().getValue()); - databaseRepository.getNotificationDao().createOrUpdate(notification); +// Notification notification = new Notification(); //TODO +// notification.setUserId(user); +// notification.setType(notificationType); +// notification.setNotifyState(NotifyState.PENDING); +// notification.setIsActive(ActiveStatus.ACTIVE); +// notification.setData("{" + +// "\"userId\": \"" + userDMP.getUserId() + "\"" + +// ", \"id\": \"" + descriptionEntity.getId() + "\"" + +// ", \"name\": \"" + descriptionEntity.getLabel() + "\"" + +// ", \"path\": \"" + notificationPaths.get(notificationType) + "\"" + +// "}"); +// notification.setCreatedAt(new Date()); +// notification.setUpdatedAt(notification.getCreatedAt()); +// notification.setContactTypeHint(ContactType.EMAIL); +// +// UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(userDMP.getUserId()); +// query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal)); +// notification.setContactHint(query.first().getValue()); +// databaseRepository.getNotificationDao().createOrUpdate(notification); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/NotificationManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/NotificationManager.java index ca40c9eb6..b4c414887 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/NotificationManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/NotificationManager.java @@ -1,12 +1,6 @@ package eu.eudat.logic.managers; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.data.old.Notification; -import eu.eudat.data.UserEntity; -import eu.eudat.commons.enums.old.notification.ActiveStatus; -import eu.eudat.commons.enums.old.notification.NotifyState; import eu.eudat.logic.services.ApiContext; -import eu.eudat.query.UserQuery; import gr.cite.tools.data.query.QueryFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,11 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import jakarta.mail.MessagingException; -import jakarta.transaction.Transactional; -import java.io.IOException; -import java.util.*; - @Component public class NotificationManager { private static final Logger logger = LoggerFactory.getLogger(NotificationManager.class); @@ -36,91 +25,91 @@ public class NotificationManager { this.queryFactory = queryFactory; } - @Transactional - public void sendNotification(Notification notification) throws Exception { - if (notification.getNotifyState() == NotifyState.ERROR) { - if (notification.getRetryCount() == null) { - notification.setRetryCount(0); - } - notification.setRetryCount(notification.getRetryCount() + 1); - if (notification.getRetryCount() >= this.environment.getProperty("notification.maxRetries", Integer.class)) { - notification.setIsActive(ActiveStatus.INACTIVE); - notification.setUpdatedAt(new Date()); - return; - } - } - notification.setNotifyState(NotifyState.PROCESSING); - notification.setNotifiedAt(new Date()); - notification.setUpdatedAt(new Date()); - try { - Map data = new ObjectMapper().readValue(notification.getData(), HashMap.class); - UserEntity userInfo = this.queryFactory.query(UserQuery.class).ids(UUID.fromString(data.get("userId"))).first(); - String subjectTemplate = ""; - String contentTemplate = ""; - - switch (notification.getType()) { - case DMP_MODIFIED: - case DATASET_MODIFIED: - subjectTemplate = this.environment.getProperty("notification.modified.subject"); -// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.modified.template")); - break; - case DMP_PUBLISH: - subjectTemplate = this.environment.getProperty("notification.publish.subject"); -// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.publish.template")); - break; - case DMP_FINALISED: - subjectTemplate = this.environment.getProperty("notification.finalised.subject"); -// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.finalised.template")); - break; - case DMP_MODIFIED_FINALISED: - case DATASET_MODIFIED_FINALISED: - subjectTemplate = this.environment.getProperty("notification.modifiedFinalised.subject"); -// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.modified_finalised.template")); - break; - } - - - switch (notification.getContactTypeHint()) { - case EMAIL: - this.sendEmailNotification(notification, userInfo, data, subjectTemplate, contentTemplate); - break; - } - }catch (Exception e) { - notification.setNotifyState(NotifyState.ERROR); - notification.setUpdatedAt(new Date()); - logger.error(e.getMessage(), e); - } - } - - private void sendEmailNotification(Notification notification, UserEntity userInfo, Map data, String subjectTemplate, String contentTemplate) throws IOException { -// SimpleMail simpleMail = new SimpleMail(); -// simpleMail.setFrom(this.environment.getProperty("mail.from")); -// simpleMail.setSubject(makeSubject(data, subjectTemplate)); -// simpleMail.setTo(notification.getContactHint()); -// simpleMail.setContent(makeContent(data, notification, userInfo, contentTemplate)); -// try { -// mailService.sendSimpleMail(simpleMail); -// notification.setNotifyState(NotifyState.SUCCEEDED); -// notification.setUpdatedAt(new Date()); -// } catch (MessagingException e) { -// notification.setNotifyState(NotifyState.ERROR); -// notification.setUpdatedAt(new Date()); -// logger.error(e.getMessage(), e); +// @Transactional +// public void sendNotification(Notification notification) throws Exception { +// if (notification.getNotifyState() == NotifyState.ERROR) { +// if (notification.getRetryCount() == null) { +// notification.setRetryCount(0); // } - } - - private String makeSubject(Map data, String subjectTemplate) { - return subjectTemplate.replace("{name}", data.get("name")); - } - - private String makeContent(Map data, Notification notification, UserEntity userInfo, String template) { - String content = template; - content = content.replace("{recipient}", userInfo.getName()); - for (String key : data.keySet()) { - content = content.replace("{" + key +"}", data.get(key)); - } - content = content.replace("{host}", this.environment.getProperty("dmp.domain")); - content = content.replace("{reasonName}", notification.getUserId().getName()); - return content; - } +// notification.setRetryCount(notification.getRetryCount() + 1); +// if (notification.getRetryCount() >= this.environment.getProperty("notification.maxRetries", Integer.class)) { +// notification.setIsActive(ActiveStatus.INACTIVE); +// notification.setUpdatedAt(new Date()); +// return; +// } +// } +// notification.setNotifyState(NotifyState.PROCESSING); +// notification.setNotifiedAt(new Date()); +// notification.setUpdatedAt(new Date()); +// try { +// Map data = new ObjectMapper().readValue(notification.getData(), HashMap.class); +// UserEntity userInfo = this.queryFactory.query(UserQuery.class).ids(UUID.fromString(data.get("userId"))).first(); +// String subjectTemplate = ""; +// String contentTemplate = ""; +// +// switch (notification.getType()) { +// case DMP_MODIFIED: +// case DATASET_MODIFIED: +// subjectTemplate = this.environment.getProperty("notification.modified.subject"); +//// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.modified.template")); +// break; +// case DMP_PUBLISH: +// subjectTemplate = this.environment.getProperty("notification.publish.subject"); +//// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.publish.template")); +// break; +// case DMP_FINALISED: +// subjectTemplate = this.environment.getProperty("notification.finalised.subject"); +//// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.finalised.template")); +// break; +// case DMP_MODIFIED_FINALISED: +// case DATASET_MODIFIED_FINALISED: +// subjectTemplate = this.environment.getProperty("notification.modifiedFinalised.subject"); +//// contentTemplate = mailService.getMailTemplateContent(this.environment.getProperty("notification.modified_finalised.template")); +// break; +// } +// +// +// switch (notification.getContactTypeHint()) { +// case EMAIL: +// this.sendEmailNotification(notification, userInfo, data, subjectTemplate, contentTemplate); +// break; +// } +// }catch (Exception e) { +// notification.setNotifyState(NotifyState.ERROR); +// notification.setUpdatedAt(new Date()); +// logger.error(e.getMessage(), e); +// } +// } +// +// private void sendEmailNotification(Notification notification, UserEntity userInfo, Map data, String subjectTemplate, String contentTemplate) throws IOException { +//// SimpleMail simpleMail = new SimpleMail(); +//// simpleMail.setFrom(this.environment.getProperty("mail.from")); +//// simpleMail.setSubject(makeSubject(data, subjectTemplate)); +//// simpleMail.setTo(notification.getContactHint()); +//// simpleMail.setContent(makeContent(data, notification, userInfo, contentTemplate)); +//// try { +//// mailService.sendSimpleMail(simpleMail); +//// notification.setNotifyState(NotifyState.SUCCEEDED); +//// notification.setUpdatedAt(new Date()); +//// } catch (MessagingException e) { +//// notification.setNotifyState(NotifyState.ERROR); +//// notification.setUpdatedAt(new Date()); +//// logger.error(e.getMessage(), e); +//// } +// } +// +// private String makeSubject(Map data, String subjectTemplate) { +// return subjectTemplate.replace("{name}", data.get("name")); +// } +// +// private String makeContent(Map data, Notification notification, UserEntity userInfo, String template) { +// String content = template; +// content = content.replace("{recipient}", userInfo.getName()); +// for (String key : data.keySet()) { +// content = content.replace("{" + key +"}", data.get(key)); +// } +// content = content.replace("{host}", this.environment.getProperty("dmp.domain")); +// content = content.replace("{reasonName}", notification.getUserId().getName()); +// return content; +// } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java index b366583b2..fbd6008d8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepository.java @@ -18,9 +18,6 @@ public interface DatabaseRepository { EmailConfirmationDao getLoginConfirmationEmailDao(); - - NotificationDao getNotificationDao(); - FileUploadDao getFileUploadDao(); void detachEntity(T entity); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java index 4f48d5b06..ac8f32eff 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/DatabaseRepositoryImpl.java @@ -22,8 +22,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository { private EmailConfirmationDao loginConfirmationEmailDao; - private NotificationDao notificationDao; - private FileUploadDao fileUploadDao; private EntityManager entityManager; @@ -97,16 +95,6 @@ public class DatabaseRepositoryImpl implements DatabaseRepository { this.loginConfirmationEmailDao = loginConfirmationEmailDao; } - @Override - public NotificationDao getNotificationDao() { - return notificationDao; - } - - @Autowired - public void setNotificationDao(NotificationDao notificationDao) { - this.notificationDao = notificationDao; - } - @Override public FileUploadDao getFileUploadDao() { diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/schedule/notification/NotificationScheduleJob.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/schedule/notification/NotificationScheduleJob.java index b6a6eec69..bd3ce64be 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/schedule/notification/NotificationScheduleJob.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/schedule/notification/NotificationScheduleJob.java @@ -1,22 +1,12 @@ package eu.eudat.logic.utilities.schedule.notification; -import eu.eudat.data.old.Notification; -import eu.eudat.commons.enums.old.notification.ActiveStatus; -import eu.eudat.commons.enums.old.notification.NotifyState; import eu.eudat.logic.managers.NotificationManager; import eu.eudat.logic.services.ApiContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import jakarta.transaction.Transactional; - -import javax.management.InvalidApplicationException; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.CompletableFuture; @Component public class NotificationScheduleJob { @@ -31,29 +21,29 @@ public class NotificationScheduleJob { this.notificationManager = notificationManager; } - @Transactional - @Scheduled(fixedRateString = "${notification.rateInterval}") - public void sendNotifications() throws InvalidApplicationException { - List> futures = new LinkedList<>(); - this.apiContext.getOperationsContext().getDatabaseRepository().getNotificationDao().asQueryable().where(((builder, root) -> - builder.and( - builder.or( - builder.equal(root.get("notifyState"), NotifyState.PENDING), builder.equal(root.get("notifyState"), NotifyState.ERROR)) - , builder.equal(root.get("isActive"), ActiveStatus.ACTIVE)))).toListAsync().thenApplyAsync((notifications) -> { - if (!notifications.isEmpty()) { - notifications.forEach(notification -> { - try { - this.notificationManager.sendNotification(notification); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - }); - } - return notifications; - }).thenApplyAsync((notifications) -> { - notifications.forEach((notification) -> futures.add(this.apiContext.getOperationsContext().getDatabaseRepository().getNotificationDao().createOrUpdateAsync(notification))); - return futures; - }).join(); - - } +// @Transactional //TODO +// @Scheduled(fixedRateString = "${notification.rateInterval}") +// public void sendNotifications() throws InvalidApplicationException { +// List> futures = new LinkedList<>(); +// this.apiContext.getOperationsContext().getDatabaseRepository().getNotificationDao().asQueryable().where(((builder, root) -> +// builder.and( +// builder.or( +// builder.equal(root.get("notifyState"), NotifyState.PENDING), builder.equal(root.get("notifyState"), NotifyState.ERROR)) +// , builder.equal(root.get("isActive"), ActiveStatus.ACTIVE)))).toListAsync().thenApplyAsync((notifications) -> { +// if (!notifications.isEmpty()) { +// notifications.forEach(notification -> { +// try { +// this.notificationManager.sendNotification(notification); +// } catch (Exception e) { +// logger.error(e.getMessage(), e); +// } +// }); +// } +// return notifications; +// }).thenApplyAsync((notifications) -> { +// notifications.forEach((notification) -> futures.add(this.apiContext.getOperationsContext().getDatabaseRepository().getNotificationDao().createOrUpdateAsync(notification))); +// return futures; +// }).join(); +// +// } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/notiication/Notification.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/notiication/Notification.java deleted file mode 100644 index ecb099360..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/notiication/Notification.java +++ /dev/null @@ -1,163 +0,0 @@ -package eu.eudat.models.data.notiication; - -import eu.eudat.commons.enums.old.notification.ActiveStatus; -import eu.eudat.commons.enums.old.notification.ContactType; -import eu.eudat.commons.enums.old.notification.NotificationType; -import eu.eudat.commons.enums.old.notification.NotifyState; -import eu.eudat.model.User; -import eu.eudat.models.DataModel; - -import java.util.Date; -import java.util.UUID; - -public class Notification implements DataModel { - - private UUID id; - private User userId; - private ActiveStatus isActive; - private NotificationType type; - private ContactType contactTypeHint; - private String contactHint; - private String data; - private NotifyState notifyState; - private Date notifiedAt; - private Integer retryCount; - private Date createdAt; - private Date updatedAt; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public User getUserId() { - return userId; - } - - public void setUserId(User userId) { - this.userId = userId; - } - - public ActiveStatus getIsActive() { - return isActive; - } - - public void setIsActive(ActiveStatus isActive) { - this.isActive = isActive; - } - - public NotificationType getType() { - return type; - } - - public void setType(NotificationType type) { - this.type = type; - } - - public ContactType getContactTypeHint() { - return contactTypeHint; - } - - public void setContactTypeHint(ContactType contactTypeHint) { - this.contactTypeHint = contactTypeHint; - } - - public String getContactHint() { - return contactHint; - } - - public void setContactHint(String contactHint) { - this.contactHint = contactHint; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public NotifyState getNotifyState() { - return notifyState; - } - - public void setNotifyState(NotifyState notifyState) { - this.notifyState = notifyState; - } - - public Date getNotifiedAt() { - return notifiedAt; - } - - public void setNotifiedAt(Date notifiedAt) { - this.notifiedAt = notifiedAt; - } - - public Integer getRetryCount() { - return retryCount; - } - - public void setRetryCount(Integer retryCount) { - this.retryCount = retryCount; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - @Override - public Notification fromDataModel(eu.eudat.data.old.Notification entity) { - this.id = entity.getId(); - this.contactHint = entity.getContactHint(); - this.contactTypeHint = entity.getContactTypeHint(); - this.createdAt = entity.getCreatedAt(); - this.data = entity.getData(); - this.isActive = entity.getIsActive(); - this.notifiedAt = entity.getNotifiedAt(); - this.notifyState = entity.getNotifyState(); - this.retryCount = entity.getRetryCount(); - this.type = entity.getType(); - this.updatedAt = entity.getUpdatedAt(); -// this.userId = new UserInfo().fromDataModel(entity.getUserId()); - return this; - } - - @Override - public eu.eudat.data.old.Notification toDataModel() throws Exception { - eu.eudat.data.old.Notification entity = new eu.eudat.data.old.Notification(); - entity.setId(this.id); - entity.setContactHint(this.contactHint); - entity.setContactTypeHint(this.contactTypeHint); - entity.setCreatedAt(this.createdAt); - entity.setData(this.data); - entity.setIsActive(this.isActive); - entity.setNotifiedAt(this.notifiedAt); - entity.setNotifyState(this.notifyState); - entity.setRetryCount(this.retryCount); - entity.setType(this.type); - entity.setUpdatedAt(this.updatedAt); -// entity.setUserId(this.userId.toDataModel()); - return entity; - } - - @Override - public String getHint() { - return null; - } -}