From 50881d059e10a49ef96ceebc9425c51547e331da Mon Sep 17 00:00:00 2001 From: amentis Date: Mon, 15 Apr 2024 18:36:55 +0300 Subject: [PATCH] notification service changes --- .../ExternalFetcherServiceImpl.java | 16 +- .../dmp/overview/dmp-overview.component.html | 4 +- .../UserNotificationPreferenceController.java | 13 +- .../resources/config/notification-devel.yml | 14 +- .../main/resources/config/notification.yml | 2 +- .../src/main/resources/config/queue.yml | 4 +- .../email/body.en.html | 0 .../email/subject.en.txt | 0 .../descriptionfinalised/inapp/body.en.html | 12 + .../inapp/subject.en.txt | 0 .../descriptionmodified/inapp/body.en.html | 298 +---------------- .../inapp/body.en.html | 300 +---------------- .../descrptionfinalised/inapp/body.en.html | 304 ------------------ .../dmpdeposit/inapp/body.en.html | 298 +---------------- .../dmpfinalised/inapp/body.en.html | 298 +---------------- .../inapp/body.en.html | 298 +---------------- .../dmpmodified/inapp/body.en.html | 297 +---------------- .../inapp/body.en.html | 300 +---------------- .../inapp/body.en.html | 300 +---------------- .../UserNotificationPreferenceQuery.java | 12 +- .../InAppNotificationServiceImpl.java | 3 +- .../message/builder/InAppMessageBuilder.java | 2 +- .../message/common/MessageBuilderBase.java | 1 - .../notification/NotificationServiceImpl.java | 20 +- .../NotificationSchedulingServiceImpl.java | 4 +- .../service/notify/InAppNotifier.java | 1 + ...UserNotificationPreferenceServiceImpl.java | 13 +- 27 files changed, 117 insertions(+), 2697 deletions(-) rename notification-service/notification-web/src/main/resources/notification_templates/{descrptionfinalised => descriptionfinalised}/email/body.en.html (100%) rename notification-service/notification-web/src/main/resources/notification_templates/{descrptionfinalised => descriptionfinalised}/email/subject.en.txt (100%) create mode 100644 notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/inapp/body.en.html rename notification-service/notification-web/src/main/resources/notification_templates/{descrptionfinalised => descriptionfinalised}/inapp/subject.en.txt (100%) delete mode 100644 notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/inapp/body.en.html diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java index 0187dcba9..0590553ff 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/externalfetcher/ExternalFetcherServiceImpl.java @@ -117,11 +117,17 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { Map rawData = new HashMap<>(); for (Object object: item.getOptions()) { StaticOptionEntity staticOption = (StaticOptionEntity) object; - if (!this.conventionService.isNullOrEmpty(externalReferenceCriteria.getLike()) && !externalReferenceCriteria.getLike().toUpperCase().contains(staticOption.getValue())) continue; - rawData.put(staticOption.getCode(), staticOption.getValue()); - result.put(staticOption.getCode(), staticOption.getValue()); - result.put(ReferenceEntity.KnownFields.SourceLabel, staticSource.getLabel()); - result.put(ReferenceEntity.KnownFields.Key, staticSource.getKey()); + if (this.conventionService.isNullOrEmpty(externalReferenceCriteria.getLike())){ + rawData.put(staticOption.getCode(), staticOption.getValue()); + result.put(staticOption.getCode(), staticOption.getValue()); + result.put(ReferenceEntity.KnownFields.SourceLabel, staticSource.getLabel()); + result.put(ReferenceEntity.KnownFields.Key, staticSource.getKey()); + }else if (!this.conventionService.isNullOrEmpty(externalReferenceCriteria.getLike()) && externalReferenceCriteria.getLike().toUpperCase().contains(staticOption.getValue().toUpperCase())){ + rawData.put(staticOption.getCode(), staticOption.getValue()); + result.put(staticOption.getCode(), staticOption.getValue()); + result.put(ReferenceEntity.KnownFields.SourceLabel, staticSource.getLabel()); + result.put(ReferenceEntity.KnownFields.Key, staticSource.getKey()); + } } if (!rawData.isEmpty()) externalDataResult.getRawData().add(rawData); diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html index 848a79c14..21266d8f1 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html @@ -195,9 +195,9 @@

{{ 'DMP-OVERVIEW.ACTIONS.EXPORT' | translate }}

- +
-

{{ 'DMP-OVERVIEW.ACTIONS.NEW-VERSION' | translate }}

diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java index d09539f67..54a0e3fb9 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/UserNotificationPreferenceController.java @@ -2,6 +2,7 @@ package gr.cite.notification.web.controllers; import gr.cite.notification.audit.AuditableAction; import gr.cite.notification.authorization.AuthorizationFlags; +import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.TenantConfigurationType; import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.data.UserNotificationPreferenceEntity; @@ -18,6 +19,7 @@ import gr.cite.notification.web.model.QueryResult; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.data.query.Ordering; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; @@ -80,15 +82,16 @@ public class UserNotificationPreferenceController { @GetMapping("user/{userId}/current") @Transactional - public UserNotificationPreference current(@PathVariable UUID userId, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + public List current(@PathVariable UUID userId, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("retrieving" + UserNotificationPreference.class.getSimpleName()).And("userId", userId).And("fields", fieldSet)); this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(fieldSet, userId); - UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(userId); - UserNotificationPreference model = this.builderFactory.builder(UserNotificationPreferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); - if (model == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{userId, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale())); + Ordering ordering = new Ordering(); + ordering.addAscending(UserNotificationPreference._ordinal); + UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(userId).isActives(IsActive.Active); + query.setOrder(ordering); + List model = this.builderFactory.builder(UserNotificationPreferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.collectAs(fieldSet)); this.auditService.track(AuditableAction.User_Notification_Preference_Lookup, Map.ofEntries( new AbstractMap.SimpleEntry("userId", userId), 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 d89f86b2e..c1f5527ea 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 @@ -3,7 +3,7 @@ notification: fields: - key: "{installation-url}" type: "String" - value: "http://localhost:42000" + value: "http://localhost:4200" resolver: global-policies: - #dmpInvitationExternalUser @@ -14,16 +14,16 @@ notification: contacts: [ inapp, email ] - #dpmModified type: 4542262A-22F8-4BAA-9DB6-1C8E70AC1DBB - contacts: [ email ] + contacts: [ inapp, email ] - #dmpFinalised type: 90DB0B46-42DE-BD89-AEBF-6F27EFEB256E - contacts: [ email ] + contacts: [ inapp, email ] - #descriptionModified type: 4FDBFA80-7A71-4A69-B854-67CBB70648F1 - contacts: [ email ] + contacts: [ inapp, email ] - #descriptionFinalised type: 33790bad-94d4-488a-8ee2-7f6295ca18ea - contacts: [ email ] + contacts: [ inapp, email ] - #mergeAcountConfirmation type: BFE68845-CB05-4C5A-A03D-29161A7C9660 contacts: [ email ] @@ -32,10 +32,10 @@ notification: contacts: [ email ] - #dmpDeposit type: 55736F7A-83AB-4190-AF43-9D031A6F9612 - contacts: [ email ] + contacts: [ inapp, email ] - #descriptionTemplateInvitation type: 223BB607-EFA1-4CE7-99EC-4BEABFEF9A8B - contacts: [ email ] + contacts: [ inapp, email ] - #contactSupportType type: 5B1D6C52-88F9-418B-9B8A-6F1F963D9EAD contacts: [ email ] diff --git a/notification-service/notification-web/src/main/resources/config/notification.yml b/notification-service/notification-web/src/main/resources/config/notification.yml index fd0d90609..f9cbdbb05 100644 --- a/notification-service/notification-web/src/main/resources/config/notification.yml +++ b/notification-service/notification-web/src/main/resources/config/notification.yml @@ -2,7 +2,7 @@ notification: task: processor: enable: true - interval-seconds: 3 + interval-seconds: 5 options: retry-threshold: 300 max-retry-delay-seconds: 10800 diff --git a/notification-service/notification-web/src/main/resources/config/queue.yml b/notification-service/notification-web/src/main/resources/config/queue.yml index accbbca49..c1af6b725 100644 --- a/notification-service/notification-web/src/main/resources/config/queue.yml +++ b/notification-service/notification-web/src/main/resources/config/queue.yml @@ -27,7 +27,7 @@ queue: exchange: null rabbitmq: enable: false - interval-seconds: 30 + interval-seconds: 5 options: retry-threashold: 100 retry-delay-step-seconds: 300 @@ -45,7 +45,7 @@ queue: user-touched-topic: user.touch rabbitmq: enable: false - interval-seconds: 30 + interval-seconds: 5 options: retry-threashold: 100 retry-delay-step-seconds: 300 diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/email/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/email/body.en.html similarity index 100% rename from notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/email/body.en.html rename to notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/email/body.en.html diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/email/subject.en.txt b/notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/email/subject.en.txt similarity index 100% rename from notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/email/subject.en.txt rename to notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/email/subject.en.txt diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/inapp/body.en.html new file mode 100644 index 000000000..d4b3099e9 --- /dev/null +++ b/notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/inapp/body.en.html @@ -0,0 +1,12 @@ + + + + + + + +

Dear {recipient},

+

{reasonName} just finalised the Description {name}.

+ Click here to view it. + + \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/inapp/subject.en.txt b/notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/inapp/subject.en.txt similarity index 100% rename from notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/inapp/subject.en.txt rename to notification-service/notification-web/src/main/resources/notification_templates/descriptionfinalised/inapp/subject.en.txt diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descriptionmodified/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/descriptionmodified/inapp/body.en.html index 7025e58bf..efc0f69cc 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/descriptionmodified/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/descriptionmodified/inapp/body.en.html @@ -3,302 +3,10 @@ - Simple Transactional Email - - - - - - - -
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
-

Dear {recipient},

-

{reasonName} just made changes to the Description {name}.

- - - - - - - -
- - - - - - -
Click here to view it.
-
- -
-
- - - - - - -
-
 
+

Dear {recipient},

+

{reasonName} just made changes to the Description {name}.

+ Click here to view it. \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descriptiontemplateinvitation/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/descriptiontemplateinvitation/inapp/body.en.html index 8c2ac8ab7..81edddeac 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/descriptiontemplateinvitation/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/descriptiontemplateinvitation/inapp/body.en.html @@ -3,303 +3,11 @@ - Simple Transactional Email - - - - - - - -
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
-

Dear {recipient},

-

You have been invited to co-develop the Template {templateName}.

-

Click the button to redirect to {templateName}.

- - - - - - - -
- - - - - - -
{templateName}
-
- -
-
- - - - - - -
-
 
+

Dear {recipient},

+

You have been invited to co-develop the Template {templateName}.

+

Click the button to redirect to {templateName}.

+ {templateName} \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/inapp/body.en.html deleted file mode 100644 index f34f75c23..000000000 --- a/notification-service/notification-web/src/main/resources/notification_templates/descrptionfinalised/inapp/body.en.html +++ /dev/null @@ -1,304 +0,0 @@ - - - - - - Simple Transactional Email - - - - - - - - - -
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
-

Dear {recipient},

-

{reasonName} just finalised the Description {name}.

- - - - - - - -
- - - - - - -
Click here to view it.
-
- -
-
- - - - - - -
-
 
- - \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/dmpdeposit/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/dmpdeposit/inapp/body.en.html index c80220834..8b5400605 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/dmpdeposit/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/dmpdeposit/inapp/body.en.html @@ -3,302 +3,10 @@ - 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.
-
- -
-
- - - - - - -
-
 
+

Dear {recipient},

+

{reasonName} just publish the {name}.

+ Click here to view it. \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/dmpfinalised/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/dmpfinalised/inapp/body.en.html index 3e00fce2d..a3ed86e87 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/dmpfinalised/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/dmpfinalised/inapp/body.en.html @@ -3,302 +3,10 @@ - Simple Transactional Email - - - - - - - -
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
-

Dear {recipient},

-

{reasonName} just finalised the Dmp {name}.

- - - - - - - -
- - - - - - -
Click here to view it.
-
- -
-
- - - - - - -
-
 
+

Dear {recipient},

+

{reasonName} just finalised the Dmp {name}.

+ Click here to view it. \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/dmpinvitationexistinguser/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/dmpinvitationexistinguser/inapp/body.en.html index 75a586097..6f79a296a 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/dmpinvitationexistinguser/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/dmpinvitationexistinguser/inapp/body.en.html @@ -4,301 +4,11 @@ Simple Transactional Email - - - - - - - -
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
-

Dear {recipient},

-

{reasonName} just add you to collaborate to Data Management plan {dmpname} with role {dmprole}.

-

Click the button to redirect to {dmpname}.

- - - - - - - -
- - - - - - -
Join
-
-
-
- - - - - - -
-
 
+

Dear {recipient},

+

{reasonName} just add you to collaborate to Data Management plan {dmpname} with role {dmprole}.

+

Click the button to redirect to {dmpname}.

+ Join \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/dmpmodified/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/dmpmodified/inapp/body.en.html index 7a36dccba..1a266243f 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/dmpmodified/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/dmpmodified/inapp/body.en.html @@ -3,302 +3,11 @@ - Simple Transactional Email - - - - - - - +

Dear {recipient},

+

{reasonName} just made changes to the Dmp {name}.

+ Click here to view it.
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
-

Dear {recipient},

-

{reasonName} just made changes to the Dmp {name}.

- - - - - - - -
- - - - - - -
Click here to view it.
-
- -
-
- - - - - - -
-
 
\ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/mergeacountconfirmation/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/mergeacountconfirmation/inapp/body.en.html index bc5bfc087..b0c78080f 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/mergeacountconfirmation/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/mergeacountconfirmation/inapp/body.en.html @@ -3,302 +3,12 @@ - Simple Transactional Email - - - - - - - -
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
- OpenDMP -

User {userName} have sent you a merge Request.

-

Please confirm that you want to merge your {installation-url} account with that account. -
The link will expire in {expiration_time}.

- - - - - - -
- - - - - - -
Confirm Merge Request
-
-
-
- - - - - - -
-
 
+ OpenDMP +

User {userName} have sent you a merge Request.

+

Please confirm that you want to merge your {installation-url} account with that account. +
The link will expire in {expiration_time}.

+ Confirm Merge Request \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/notification_templates/removecredentialconfirmation/inapp/body.en.html b/notification-service/notification-web/src/main/resources/notification_templates/removecredentialconfirmation/inapp/body.en.html index a43224531..24f36119e 100644 --- a/notification-service/notification-web/src/main/resources/notification_templates/removecredentialconfirmation/inapp/body.en.html +++ b/notification-service/notification-web/src/main/resources/notification_templates/removecredentialconfirmation/inapp/body.en.html @@ -3,302 +3,12 @@ - Simple Transactional Email - - - - - - - -
  -
- - - This is preheader text. Some clients will show this text as a preview. - - - - - - - - -
- - - - -
- OpenDMP -

You have made a request to unlink your email account in ARGOS.

-

Please confirm that you want to unlink your {email} account. -
The link will expire in {expiration_time}.

- - - - - - -
- - - - - - -
Confirm Unlink Request
-
-
-
- - - - - - -
-
 
+ OpenDMP +

You have made a request to unlink your email account in ARGOS.

+

Please confirm that you want to unlink your {email} account. +
The link will expire in {expiration_time}.

+ Confirm Unlink Request \ No newline at end of file diff --git a/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java b/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java index e51efad40..addbcfc7b 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/query/UserNotificationPreferenceQuery.java @@ -8,6 +8,7 @@ import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryContext; import jakarta.persistence.Tuple; +import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.Predicate; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; @@ -89,15 +90,20 @@ public class UserNotificationPreferenceQuery extends QueryBase inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserNotificationPreferenceEntity._isActive)); + for (IsActive item : this.isActives) + inClause.value(item); + predicates.add(inClause); } if (this.type != null) { predicates.add(queryContext.Root.get(UserNotificationPreferenceEntity._type).in(this.type)); } if (this.channel != null) { - predicates.add(queryContext.Root.get(UserNotificationPreferenceEntity._channel).in(this.channel)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserNotificationPreferenceEntity._channel)); + for (NotificationContactType item : this.channel) + inClause.value(item); + predicates.add(inClause); } if (!predicates.isEmpty()) { diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java index c42efc474..6b33a2816 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java @@ -1,6 +1,7 @@ package gr.cite.notification.service.inappnotification; import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.notification.authorization.OwnedResource; import gr.cite.notification.authorization.Permission; import gr.cite.notification.common.enums.NotificationInAppTracking; import gr.cite.notification.common.scope.user.UserScope; @@ -92,7 +93,7 @@ public class InAppNotificationServiceImpl implements InAppNotificationService { public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { logger.debug("deleting in-app notification: {}", id); - this.authService.authorizeForce(Permission.DeleteInAppNotification); + this.authService.authorizeAtLeastOneForce(this.userScope.getUserId() != null ? List.of(new OwnedResource(this.userScope.getUserId())) : null, Permission.DeleteInAppNotification); this.deleterFactory.deleter(InAppNotificationDeleter.class).deleteAndSaveByIds(List.of(id)); } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/InAppMessageBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/InAppMessageBuilder.java index 17936dff6..bdc59e025 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/InAppMessageBuilder.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/InAppMessageBuilder.java @@ -70,7 +70,7 @@ public class InAppMessageBuilder extends MessageBuilderBase implements MessageBu } NotificationProperties.Flow options = this.flowMap.get("in-app").getOrDefault(notification.getType(), null); - NotificationTemplate template = notificationTemplateService.lookupOverriddenTemplates(notification.getType(), NotificationTemplateChannel.Email, messageInfo.getLanguage()); + NotificationTemplate template = notificationTemplateService.lookupOverriddenTemplates(notification.getType(), NotificationTemplateChannel.InApp, messageInfo.getLanguage()); if (options == null && template == null) { logger.error("Could not retrieve flow options for notification " + notification.getId() + " of type " + notification.getType()); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/message/common/MessageBuilderBase.java b/notification-service/notification/src/main/java/gr/cite/notification/service/message/common/MessageBuilderBase.java index 7327f02da..380b820b9 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/message/common/MessageBuilderBase.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/message/common/MessageBuilderBase.java @@ -165,7 +165,6 @@ public abstract class MessageBuilderBase { return formatting; } - //TODO: Here check with a language accepted list and fallback to default protected String lookupOrReadLocalizedFile(NotificationProperties.Template.TemplateCache templateCache, String path, String language) { String filename = path.replace("{language}", language); File file = null; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/notification/NotificationServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/notification/NotificationServiceImpl.java index 3bf92b0f9..ff8c91615 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/notification/NotificationServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/notification/NotificationServiceImpl.java @@ -10,13 +10,16 @@ import gr.cite.notification.convention.ConventionService; import gr.cite.notification.data.TenantEntity; import gr.cite.notification.data.TenantEntityManager; import gr.cite.notification.data.NotificationEntity; +import gr.cite.notification.data.UserNotificationPreferenceEntity; import gr.cite.notification.errorcode.ErrorThesaurusProperties; import gr.cite.notification.model.SendNotificationResult; +import gr.cite.notification.model.UserNotificationPreference; import gr.cite.notification.model.builder.NotificationBuilder; import gr.cite.notification.model.Notification; import gr.cite.notification.model.deleter.NotificationDeleter; import gr.cite.notification.model.persist.NotificationPersist; import gr.cite.notification.query.NotificationQuery; +import gr.cite.notification.query.UserNotificationPreferenceQuery; import gr.cite.notification.service.channelResolution.ChannelResolutionService; import gr.cite.notification.service.contact.extractor.ContactExtractorFactory; import gr.cite.notification.service.contact.model.Contact; @@ -25,6 +28,7 @@ import gr.cite.notification.service.message.model.Message; import gr.cite.notification.service.notify.NotifierFactory; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.deleter.DeleterFactory; +import gr.cite.tools.data.query.Ordering; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; @@ -49,6 +53,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; @Service @RequestScope @@ -141,7 +146,9 @@ public class NotificationServiceImpl implements NotificationService { } public SendNotificationResult doNotify(NotificationEntity notification) { - List contactTypes = this.orderContactTypes(notification); + List contactTypes = this.orderContactTypesFromPreferences(notification); + if (this.conventionService.isListNullOrEmpty(contactTypes)) contactTypes = this.orderContactTypes(notification); + for (NotificationContactType contactType: contactTypes) { SendNotificationResult result = this.sendNotification(notification, contactType); if (result.getSuccess()) return result; @@ -149,6 +156,17 @@ public class NotificationServiceImpl implements NotificationService { return null; } + private List orderContactTypesFromPreferences(NotificationEntity notification) { + Ordering ordering = new Ordering(); + ordering.addAscending(UserNotificationPreference._ordinal); + UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(notification.getUserId()).type(notification.getType()).isActives(IsActive.Active); + query.setOrder(ordering); + + List preferences = query.collectAs(new BaseFieldSet().ensure(UserNotificationPreference._channel)); + if (!this.conventionService.isListNullOrEmpty(preferences)) return preferences.stream().map(x -> x.getChannel()).collect(Collectors.toList()); + return null; + } + private List orderContactTypes(NotificationEntity notification) { List contactTypes = this.channelResolutionService.resolve(notification.getType(), notification.getUserId()); if (notification.getContactTypeHint() == null) return contactTypes; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/notificationscheduling/NotificationSchedulingServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/notificationscheduling/NotificationSchedulingServiceImpl.java index b315945e3..53136d40c 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/notificationscheduling/NotificationSchedulingServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/notificationscheduling/NotificationSchedulingServiceImpl.java @@ -141,8 +141,8 @@ public class NotificationSchedulingServiceImpl implements NotificationScheduling } else { tenantScope.setTempTenant(entityManager, null, tenantScope.getDefaultTenantCode()); } - notification = entityManager.merge(notification); - entityManager.persist(notification); +// notification = entityManager.merge(notification); + entityManager.merge(notification); entityManager.flush(); } finally { tenantScope.removeTempTenant(entityManager); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/notify/InAppNotifier.java b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/InAppNotifier.java index e92995be7..96fd88989 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/notify/InAppNotifier.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/InAppNotifier.java @@ -70,6 +70,7 @@ public class InAppNotifier implements Notify{ inApp.setTenantId(tenantScope.getTenant()); entityManager.persist(inApp); + entityManager.flush(); InAppTrackingData trackingData = new InAppTrackingData(inApp.getId()); data = this.jsonHandlingService.toJsonSafe(trackingData); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceServiceImpl.java index 64ddd6d47..10ab5df7f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceServiceImpl.java @@ -1,7 +1,9 @@ package gr.cite.notification.service.userNotificationPreference; import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.notification.authorization.OwnedResource; import gr.cite.notification.authorization.Permission; +import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; import gr.cite.notification.config.notification.NotificationConfig; @@ -66,7 +68,7 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr public List persist(UserNotificationPreferencePersist model, FieldSet fieldSet) { logger.debug(new MapLogEntry("persisting").And("model", model).And("fields", fieldSet)); - this.authService.authorizeForce(Permission.EditUserNotificationPreference); + this.authService.authorizeAtLeastOneForce(model.getUserId() != null ? List.of(new OwnedResource(model.getUserId())) : null, Permission.EditUserNotificationPreference); Map> currentNotificationListPolicies; NotifierListConfigurationDataContainer tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList(); @@ -169,6 +171,7 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr preferences = this.queryFactory .query(UserNotificationPreferenceQuery.class) .type(type) + .isActives(IsActive.Active) .userId(userId).collect(); int ordinal = 0; @@ -176,6 +179,7 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr for (NotificationContactType contactType : contactTypes) { UserNotificationPreferenceEntity preference = preferences.stream().filter(x -> x.getChannel() == contactType).findFirst().orElse(null); + boolean isUpdate = preference != null; if (preference != null) { preference.setOrdinal(ordinal); @@ -186,9 +190,12 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr preference.setOrdinal(ordinal); preference.setChannel(contactType); preference.setCreatedAt(Instant.now()); + preference.setIsActive(IsActive.Active); } - this.entityManager.merge(preference); - this.entityManager.persist(preference); + preference.setUpdatedAt(Instant.now()); + + if(isUpdate) this.entityManager.merge(preference); + else this.entityManager.persist(preference); updatedPreferences.add(preference); ordinal++; }