diff --git a/backend/core/src/main/java/org/opencdmp/commons/notification/NotificationProperties.java b/backend/core/src/main/java/org/opencdmp/commons/notification/NotificationProperties.java index a4e6dc488..c442c755b 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/notification/NotificationProperties.java +++ b/backend/core/src/main/java/org/opencdmp/commons/notification/NotificationProperties.java @@ -11,6 +11,7 @@ public class NotificationProperties { private UUID dmpInvitationExistingUserType; private UUID dmpModifiedType; private UUID dmpFinalisedType; + private UUID descriptionCreatedType; private UUID descriptionModifiedType; private UUID descriptionFinalisedType; private UUID descriptionAnnotationCreated; @@ -55,6 +56,14 @@ public class NotificationProperties { this.dmpFinalisedType = dmpFinalisedType; } + public UUID getDescriptionCreatedType() { + return descriptionCreatedType; + } + + public void setDescriptionCreatedType(UUID descriptionCreatedType) { + this.descriptionCreatedType = descriptionCreatedType; + } + public UUID getDescriptionModifiedType() { return this.descriptionModifiedType; } diff --git a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java index ec1fcb363..c33a11f1f 100644 --- a/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/description/DescriptionServiceImpl.java @@ -260,9 +260,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.persistTags(data.getId(), model.getTags()); - if (isUpdate){ - this.sendNotification(data); - } + this.sendNotification(data, isUpdate); //this.deleteOldFilesAndAddNew(datasetWizardModel, userInfo); //TODO this.eventBroker.emit(new DescriptionTouchedEvent(data.getId())); @@ -313,7 +311,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.entityManager.flush(); - this.sendNotification(data); + this.sendNotification(data, true); this.eventBroker.emit(new DescriptionTouchedEvent(data.getId())); @@ -322,7 +320,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.elasticService.persistDescription(data); } - private void sendNotification(DescriptionEntity description) throws InvalidApplicationException { + private void sendNotification(DescriptionEntity description, Boolean isUpdate) throws InvalidApplicationException { List existingUsers = this.queryFactory.query(DmpUserQuery.class).disableTracking() .dmpIds(description.getDmpId()) .isActives(IsActive.Active) @@ -335,7 +333,7 @@ public class DescriptionServiceImpl implements DescriptionService { if (!dmpUser.getUserId().equals(this.userScope.getUserIdSafe())){ UserEntity user = this.queryFactory.query(UserQuery.class).disableTracking().ids(dmpUser.getUserId()).first(); if (user == null || user.getIsActive().equals(IsActive.Inactive)) throw new MyValidationException(this.errors.getDmpInactiveUser().getCode(), this.errors.getDmpInactiveUser().getMessage()); - this.createDescriptionNotificationEvent(description, user); + this.createDescriptionNotificationEvent(description, user, isUpdate); } } } @@ -384,11 +382,11 @@ public class DescriptionServiceImpl implements DescriptionService { return cleanData; } - private void createDescriptionNotificationEvent(DescriptionEntity description, UserEntity user) throws InvalidApplicationException { + private void createDescriptionNotificationEvent(DescriptionEntity description, UserEntity user, Boolean isUpdate) throws InvalidApplicationException { NotifyIntegrationEvent event = new NotifyIntegrationEvent(); event.setUserId(user.getId()); - this.applyNotificationType(description.getStatus(), event); + this.applyNotificationType(description.getStatus(), event, isUpdate); NotificationFieldData data = new NotificationFieldData(); List fieldInfoList = new ArrayList<>(); fieldInfoList.add(new FieldInfo("{recipient}", DataType.String, user.getName())); @@ -404,18 +402,20 @@ public class DescriptionServiceImpl implements DescriptionService { this.eventHandler.handle(event); } - private void applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event) { - switch (status) { - case Draft: - event.setNotificationType(this.notificationProperties.getDescriptionModifiedType()); - break; - case Finalized: - event.setNotificationType(this.notificationProperties.getDescriptionFinalisedType()); - break; - default: - throw new MyApplicationException("Unsupported Description Status."); + private void applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event, Boolean isUpdate) { + if (!isUpdate) event.setNotificationType(this.notificationProperties.getDescriptionCreatedType()); + else { + switch (status) { + case Draft: + event.setNotificationType(this.notificationProperties.getDescriptionModifiedType()); + break; + case Finalized: + event.setNotificationType(this.notificationProperties.getDescriptionFinalisedType()); + break; + default: + throw new MyApplicationException("Unsupported Description Status."); + } } - return; } @Override @@ -446,7 +446,7 @@ public class DescriptionServiceImpl implements DescriptionService { this.eventBroker.emit(new DescriptionTouchedEvent(data.getId())); this.annotationEntityTouchedIntegrationEventHandler.handleDescription(data.getId()); - if (data.getStatus().equals(DescriptionStatus.Finalized)) this.sendNotification(data); + if (data.getStatus().equals(DescriptionStatus.Finalized)) this.sendNotification(data, true); } return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(BaseFieldSet.build(fields, Description._id), data); } diff --git a/backend/web/src/main/resources/config/notification-devel.yml b/backend/web/src/main/resources/config/notification-devel.yml index 91df5d19b..eeb865325 100644 --- a/backend/web/src/main/resources/config/notification-devel.yml +++ b/backend/web/src/main/resources/config/notification-devel.yml @@ -3,6 +3,7 @@ notification: dmpInvitationExistingUserType: 4904dea2-5079-46d3-83be-3a19c9ab45dc dmpModifiedType: 4542262A-22F8-4BAA-9DB6-1C8E70AC1DBB dmpFinalisedType: 90DB0B46-42DE-BD89-AEBF-6F27EFEB256E + descriptionCreatedType: 8965b1d5-99a6-4acf-9016-c0d0ce341364 descriptionModifiedType: 4FDBFA80-7A71-4A69-B854-67CBB70648F1 descriptionFinalisedType: 33790bad-94d4-488a-8ee2-7f6295ca18ea descriptionAnnotationCreated: db1e99d2-a240-4e75-9bb2-ef25b234c1f0 diff --git a/notification-service/notification-web/src/main/resources/config/notification-devel.yml b/notification-service/notification-web/src/main/resources/config/notification-devel.yml index 11e23d889..5c3907265 100644 --- a/notification-service/notification-web/src/main/resources/config/notification-devel.yml +++ b/notification-service/notification-web/src/main/resources/config/notification-devel.yml @@ -18,6 +18,9 @@ notification: - #planFinalised type: 90DB0B46-42DE-BD89-AEBF-6F27EFEB256E contacts: [ inapp, email ] + - #descriptionCreated + type: 8965b1d5-99a6-4acf-9016-c0d0ce341364 + contacts: [ inapp, email ] - #descriptionModified type: 4FDBFA80-7A71-4A69-B854-67CBB70648F1 contacts: [ inapp, email ] @@ -149,6 +152,31 @@ notification: bcc-mode: 0 allow-attachments: false cipher-fields: [ ] + - #desriptionCreated + key: 8965b1d5-99a6-4acf-9016-c0d0ce341364 + subject-path: classpath:notification_templates/descriptioncreated/email/subject.{language}.txt + subject-field-options: + mandatory: [ ] + optional: [ ] + body-path: classpath:notification_templates/descriptioncreated/email/body.{language}.html + body-field-options: + mandatory: [ "{reasonName}", "{name}", "{installation-url}", "{id}" ] + optional: + - key: "{recipient}" + value: + - key: "{tenant-url-path}" + value: + formatting: + '[{reasonName}]': null + '[{name}]': null + '[{recipient}]': null + '[{tenant-url-path}]': null + cc: [ ] + cc-mode: 0 + bcc: [ ] + bcc-mode: 0 + allow-attachments: false + cipher-fields: [ ] - #desriptionModified key: 4FDBFA80-7A71-4A69-B854-67CBB70648F1 subject-path: classpath:notification_templates/descriptionmodified/email/subject.{language}.txt @@ -431,6 +459,31 @@ notification: '[{tenant-url-path}]': null priority-key: null cipher-fields: [ ] + - #desriptionCreated + key: 8965b1d5-99a6-4acf-9016-c0d0ce341364 + subject-path: classpath:notification_templates/descriptioncreated/inapp/subject.{language}.txt + subject-field-options: + mandatory: [ ] + optional: [ ] + body-path: classpath:notification_templates/descriptioncreated/inapp/body.{language}.html + body-field-options: + mandatory: [ "{reasonName}", "{name}", "{installation-url}", "{id}" ] + optional: + - key: "{recipient}" + value: + - key: "{tenant-url-path}" + value: + formatting: + '[{reasonName}]': null + '[{name}]': null + '[{recipient}]': null + '[{tenant-url-path}]': null + cc: [ ] + cc-mode: 0 + bcc: [ ] + bcc-mode: 0 + allow-attachments: false + cipher-fields: [ ] - #desriptionModified key: 4FDBFA80-7A71-4A69-B854-67CBB70648F1 subject-path: classpath:notification_templates/descriptionmodified/inapp/subject.{language}.txt diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/email/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/email/body.en.html new file mode 100644 index 000000000..f021ad9ea --- /dev/null +++ b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/email/body.en.html @@ -0,0 +1,304 @@ + + + + + + OpenCDMP Notification + + + + + + + + + +
  +
+ + + This is preheader text. Some clients will show this text as a preview. + + + + + + + + +
+ + + + +
+

Dear {recipient},

+

{reasonName} created new Description with name {name}.

+ + + + + + + +
+ + + + + + +
Click here to view it.
+
+ +
+
+ + + + + + +
+
 
+ + \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/email/subject.en.txt b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/email/subject.en.txt new file mode 100644 index 000000000..c680595b0 --- /dev/null +++ b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/email/subject.en.txt @@ -0,0 +1 @@ +OpenCDMP - Description Created \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/inapp/body.en.html new file mode 100644 index 000000000..e28ad9712 --- /dev/null +++ b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/inapp/body.en.html @@ -0,0 +1,12 @@ + + + + + + + +

Dear {recipient},

+

{reasonName} created new Description with name {name}.

+ Click here to view it. + + \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/inapp/subject.en.txt b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/inapp/subject.en.txt new file mode 100644 index 000000000..c680595b0 --- /dev/null +++ b/notification-service/notification-web/src/main/resources/notification_templates/descriptioncreated/inapp/subject.en.txt @@ -0,0 +1 @@ +OpenCDMP - Description Created \ No newline at end of file