From aa74f810e5cd9d0ff2f735d115725fc88f348801 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Mon, 17 Feb 2020 12:41:01 +0200 Subject: [PATCH] Add additional Notifications when the DMP/Dataset gets finalised and when the DMP gets public (ref #243 & #244) --- .../notification/NotificationType.java | 14 +- .../managers/DataManagementPlanManager.java | 25 +- .../eudat/logic/managers/DatasetManager.java | 17 +- .../logic/managers/NotificationManager.java | 21 +- .../src/main/resources/application.properties | 8 +- .../main/resources/finalisedNotification.html | 304 ++++++++++++++++++ .../modifiedFinalisedNotification.html | 304 ++++++++++++++++++ .../main/resources/publishNotification.html | 304 ++++++++++++++++++ 8 files changed, 983 insertions(+), 14 deletions(-) create mode 100644 dmp-backend/web/src/main/resources/finalisedNotification.html create mode 100644 dmp-backend/web/src/main/resources/modifiedFinalisedNotification.html create mode 100644 dmp-backend/web/src/main/resources/publishNotification.html diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/enumeration/notification/NotificationType.java b/dmp-backend/data/src/main/java/eu/eudat/data/enumeration/notification/NotificationType.java index 392fe3bd5..5f5ece40d 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/enumeration/notification/NotificationType.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/enumeration/notification/NotificationType.java @@ -2,7 +2,11 @@ package eu.eudat.data.enumeration.notification; public enum NotificationType { DMP_MODIFIED(0), - DATASET_MODIFIED(1); + DATASET_MODIFIED(1), + DMP_PUBLISH(2), + DMP_FINALISED(3), + DMP_MODIFIED_FINALISED(4), + DATASET_MODIFIED_FINALISED(5); private int type; @@ -20,6 +24,14 @@ public enum NotificationType { return DMP_MODIFIED; case 1: return DATASET_MODIFIED; + case 2: + return DMP_PUBLISH; + case 3: + return DMP_FINALISED; + case 4: + return DMP_MODIFIED_FINALISED; + case 5: + return DATASET_MODIFIED_FINALISED; default: throw new RuntimeException("Unsupported Notification Type"); } 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 3da078abd..2f4b377ce 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 @@ -79,11 +79,19 @@ import java.nio.file.Files; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +import java.util.stream.Stream; @Component public class DataManagementPlanManager { private static final Logger logger = LoggerFactory.getLogger(DataManagementPlanManager.class); + private final Map notificationPaths = Stream.of(new Object[][] { + {NotificationType.DMP_MODIFIED, "/plans/edit"}, + {NotificationType.DMP_PUBLISH, "/plans/publicEdit"}, + {NotificationType.DMP_FINALISED, "/plans/edit"}, + {NotificationType.DMP_MODIFIED_FINALISED, "/plans/edit"} + }).collect(Collectors.toMap(data -> (NotificationType) data[0], data -> (String) data[1])); + private ApiContext apiContext; private DatasetManager datasetManager; private UtilitiesService utilitiesService; @@ -575,26 +583,30 @@ public class DataManagementPlanManager { assignUser(newDmp, user); if (setNotification) { - this.sendNotification(newDmp, user); + if (newDmp.getStatus() != DMP.DMPStatus.FINALISED.getValue()) { + this.sendNotification(newDmp, user, NotificationType.DMP_MODIFIED); + } else { + this.sendNotification(newDmp, user, NotificationType.DMP_MODIFIED_FINALISED); + } } return newDmp; } - private void sendNotification(DMP dmp, UserInfo user) { + private void sendNotification(DMP dmp, UserInfo user, NotificationType notificationType) { List userDMPS = databaseRepository.getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList(); for (UserDMP userDMP : userDMPS) { if (!userDMP.getUser().getId().equals(user.getId())) { Notification notification = new Notification(); notification.setUserId(user); - notification.setType(NotificationType.DMP_MODIFIED); + notification.setType(notificationType); notification.setNotifyState(NotifyState.PENDING); notification.setIsActive(ActiveStatus.ACTIVE); notification.setData("{" + "\"userId\": \"" + userDMP.getUser().getId() + "\"" + ", \"id\": \"" + userDMP.getDmp().getId() + "\"" + ", \"name\": \"" + userDMP.getDmp().getLabel() + "\"" + - ", \"path\": \"/plans/edit\"" + + ", \"path\": \"" + notificationPaths.get(notificationType) +"\"" + "}"); notification.setCreatedAt(new Date()); notification.setUpdatedAt(notification.getCreatedAt()); @@ -1174,6 +1186,8 @@ public class DataManagementPlanManager { throw new Exception("DMP is not finalized"); dmp.setPublic(true); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); + UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); + sendNotification(dmp, user, NotificationType.DMP_PUBLISH); } public void makeFinalize(UUID id, Principal principal, DatasetsToBeFinalized datasetsToBeFinalized) throws Exception { @@ -1209,6 +1223,9 @@ public class DataManagementPlanManager { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled)) .update(root -> root.get("status"), Dataset.Status.CANCELED.getValue()); + + UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); + sendNotification(dmp, user, NotificationType.DMP_FINALISED); } } 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 ab1b1d862..f9b72232c 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 @@ -81,6 +81,11 @@ import java.util.zip.ZipInputStream; public class DatasetManager { private static final Logger logger = LoggerFactory.getLogger(DatasetManager.class); + private final Map notificationPaths = Stream.of(new Object[][] { + {NotificationType.DATASET_MODIFIED, "/datasets/edit"}, + {NotificationType.DATASET_MODIFIED_FINALISED, "/datasets/edit"} + }).collect(Collectors.toMap(data -> (NotificationType) data[0], data -> (String) data[1])); + private ApiContext apiContext; private DatabaseRepository databaseRepository; private DatasetRepository datasetRepository; @@ -434,25 +439,29 @@ public class DatasetManager { datasetWizardModel.setId(dataset1.getId()); updateTags(apiContext.getOperationsContext().getDatasetRepository(), datasetWizardModel); if (sendNotification) { - this.sendNotification(dataset1, dataset1.getDmp(), userInfo); + if (dataset1.getStatus() != Dataset.Status.FINALISED.getValue()) { + this.sendNotification(dataset1, dataset1.getDmp(), userInfo, NotificationType.DATASET_MODIFIED); + } else { + this.sendNotification(dataset1, dataset1.getDmp(), userInfo, NotificationType.DATASET_MODIFIED_FINALISED); + } } return dataset1; } - private void sendNotification(Dataset dataset, DMP dmp, UserInfo user) { + private void sendNotification(Dataset dataset, DMP dmp, UserInfo user, NotificationType notificationType) { List userDMPS = databaseRepository.getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList(); for (UserDMP userDMP : userDMPS) { if (!userDMP.getUser().getId().equals(user.getId())) { Notification notification = new Notification(); notification.setUserId(user); - notification.setType(NotificationType.DATASET_MODIFIED); + notification.setType(notificationType); notification.setNotifyState(NotifyState.PENDING); notification.setIsActive(ActiveStatus.ACTIVE); notification.setData("{" + "\"userId\": \"" + userDMP.getUser().getId() + "\"" + ", \"id\": \"" + dataset.getId() + "\"" + ", \"name\": \"" + dataset.getLabel() + "\"" + - ", \"path\": \"/datasets/edit\"" + + ", \"path\": \"" + notificationPaths.get(notificationType) + "\"" + "}"); notification.setCreatedAt(new Date()); notification.setUpdatedAt(notification.getCreatedAt()); 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 a4c8c2e11..1051d20b1 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 @@ -64,9 +64,22 @@ public class NotificationManager { switch (notification.getType()) { case DMP_MODIFIED: case DATASET_MODIFIED: - subjectTemplate = this.environment.getProperty("mail.modified.notification.subject"); + subjectTemplate = this.environment.getProperty("notification.modified.subject"); contentTemplate = mailService.getMailTemplateContent("classpath:modifiedNotification.html"); break; + case DMP_PUBLISH: + subjectTemplate = this.environment.getProperty("notification.publish.subject"); + contentTemplate = mailService.getMailTemplateContent("classpath:publishNotification.html"); + break; + case DMP_FINALISED: + subjectTemplate = this.environment.getProperty("notification.finalised.subject"); + contentTemplate = mailService.getMailTemplateContent("classpath:finalisedNotification.html"); + break; + case DMP_MODIFIED_FINALISED: + case DATASET_MODIFIED_FINALISED: + subjectTemplate = this.environment.getProperty("notification.modifiedFinalised.subject"); + contentTemplate = mailService.getMailTemplateContent("classpath:modifiedFinalisedNotification.html"); + break; } @@ -108,11 +121,11 @@ public class NotificationManager { private String makeContent(Map data, Notification notification, UserInfo userInfo, String template) { String content = template; content = content.replace("{recipient}", userInfo.getName()); - content = content.replace("{id}", data.get("id")); - content = content.replace("{name}", data.get("name")); + 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()); - content = content.replace("{path}", data.get("path")); return content; } } diff --git a/dmp-backend/web/src/main/resources/application.properties b/dmp-backend/web/src/main/resources/application.properties index 6f76429c6..9af18afb3 100644 --- a/dmp-backend/web/src/main/resources/application.properties +++ b/dmp-backend/web/src/main/resources/application.properties @@ -9,7 +9,6 @@ eu.eudat.logic.proxy.allowed.host=https://eestore.paas2.uninett.no ####################GENERIC MAIL CONFIGURATIONS################# mail.subject=Invitation to DMP Plan {dmpname} mail.from=TheApp@dev.cite.gr -mail.modified.notification.subject=[OpenDMP] The {name} has been modified ####################SPRING MAIL CONFIGURATIONS################# spring.mail.default-encoding=UTF-8 @@ -78,7 +77,14 @@ http-logger.delay = 10 database.driver-class-name=org.postgresql.Driver database.lock-fail-interval=120000 +##########################MISC########################################## +#############USER GUIDE######### userguide.path=guide/ +#############NOTIFICATION######### notification.rateInterval=30000 notification.maxRetries=10 +notification.modified.subject=[OpenDMP] The {name} has been modified +notification.publish.subject=[OpenDMP] The {name} has been published +notification.finalised.subject=[OpenDMP] The {name} has been finalised +notification.modifiedFinalised.subject=[OpenDMP] The {name} has been modified and finalised diff --git a/dmp-backend/web/src/main/resources/finalisedNotification.html b/dmp-backend/web/src/main/resources/finalisedNotification.html new file mode 100644 index 000000000..7316beb27 --- /dev/null +++ b/dmp-backend/web/src/main/resources/finalisedNotification.html @@ -0,0 +1,304 @@ + + + + + + Simple Transactional Email + + + + + + + + + +
  +
+ + + This is preheader text. Some clients will show this text as a preview. + + + + + + + + +
+ + + + +
+

Dear {recipient},

+

{reasonName} just finalised the {name}.

+ + + + + + + +
+ + + + + + +
Click here to view it.
+
+ +
+
+ + + + + + +
+
 
+ + \ No newline at end of file diff --git a/dmp-backend/web/src/main/resources/modifiedFinalisedNotification.html b/dmp-backend/web/src/main/resources/modifiedFinalisedNotification.html new file mode 100644 index 000000000..1cfb61e82 --- /dev/null +++ b/dmp-backend/web/src/main/resources/modifiedFinalisedNotification.html @@ -0,0 +1,304 @@ + + + + + + Simple Transactional Email + + + + + + + + + +
  +
+ + + This is preheader text. Some clients will show this text as a preview. + + + + + + + + +
+ + + + +
+

Dear {recipient},

+

{reasonName} just made changes and finalised the {name}.

+ + + + + + + +
+ + + + + + +
Click here to view it.
+
+ +
+
+ + + + + + +
+
 
+ + \ No newline at end of file diff --git a/dmp-backend/web/src/main/resources/publishNotification.html b/dmp-backend/web/src/main/resources/publishNotification.html new file mode 100644 index 000000000..d23a1d6d8 --- /dev/null +++ b/dmp-backend/web/src/main/resources/publishNotification.html @@ -0,0 +1,304 @@ + + + + + + Simple Transactional Email + + + + + + + + + +
  +
+ + + This is preheader text. Some clients will show this text as a preview. + + + + + + + + +
+ + + + +
+

Dear {recipient},

+

{reasonName} just publish the {name}.

+ + + + + + + +
+ + + + + + +
Click here to view it.
+
+ +
+
+ + + + + + +
+
 
+ + \ No newline at end of file