From 4ae62076f828e9c79adec867e08c839c8c422e80 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 25 Apr 2024 14:53:07 +0300 Subject: [PATCH] tenant configuration changes --- .../java/eu/eudat/audit/AuditableAction.java | 2 + .../TenantConfigurationController.java | 4 +- .../TenantConfigurationController.java | 134 ++++--- .../UserNotificationPreferenceController.java | 12 +- .../notification/audit/AuditableAction.java | 1 + .../authorization/Permission.java | 1 + .../common/enums/TenantConfigurationType.java | 6 +- .../types/tenant/TenantConfigEntity.java | 35 -- .../tenant/TenantDepositConfigEntity.java | 22 -- .../TenantFileTransformersConfigEntity.java | 21 -- .../types/tenant/TenantSourceEntity.java | 76 ---- ...tUserLocaleConfigurationDataContainer.java | 37 -- ...ltUserLocaleTenantConfigurationEntity.java | 32 ++ ...EmailClientConfigurationDataContainer.java | 87 ----- ...otifierListTenantConfigurationEntity.java} | 9 +- .../types/user/AdditionalInfoEntity.java | 26 -- .../notification/NotificationConfig.java | 4 +- .../data/TenantConfigurationEntity.java | 58 +-- .../NamingStrategyProperties.java | 2 +- .../PrefixPhysicalNamingStrategy.java | 2 +- .../errorcode/ErrorThesaurusProperties.java | 20 + .../cite/notification/event/EventBroker.java | 3 + .../TenantConfigurationTouchedEvent.java | 45 +++ .../model/TenantConfiguration.java | 145 -------- .../model/builder/BaseBuilder.java | 14 + .../builder/TenantConfigurationBuilder.java | 137 ------- .../UserNotificationPreferenceBuilder.java | 2 +- .../tenantconfig/TenantConfigBuilder.java | 60 --- .../tenantconfig/TenantSourceBuilder.java | 62 ---- ...UserLocaleTenantConfigurationBuilder.java} | 37 +- ...tifierListTenantConfigurationBuilder.java} | 35 +- .../TenantConfigurationBuilder.java | 84 +++++ .../censorship/TenantConfigurationCensor.java | 32 -- ...ltUserLocaleTenantConfigurationCensor.java | 38 ++ ...NotifierListTenantConfigurationCensor.java | 38 ++ .../TenantConfigurationCensor.java | 49 +++ .../deleter/TenantConfigurationDeleter.java | 7 +- ...tUserLocaleTenantConfigurationPersist.java | 82 +++++ ...otifierListTenantConfigurationPersist.java | 54 +++ ...TenantConfigurationEmailClientPersist.java | 177 --------- ...enantConfigurationNotifierListPersist.java | 86 ----- .../TenantConfigurationPersist.java | 142 +++++++ ...igurationUserLocaleIntegrationPersist.java | 92 ----- .../model/tenantconfig/TenantConfig.java | 28 -- .../tenantconfig/TenantDepositConfig.java | 17 - .../TenantFileTransformersConfig.java | 17 - .../model/tenantconfig/TenantSource.java | 73 ---- .../DefaultUserLocaleTenantConfiguration.java | 35 ++ .../NotifierListTenantConfiguration.java | 21 ++ .../TenantConfiguration.java | 118 ++++++ .../query/TenantConfigurationQuery.java | 176 ++++++--- .../lookup/TenantConfigurationLookup.java | 59 ++- .../ChannelResolutionServiceImpl.java | 4 +- .../FormattingServiceConfiguration.java | 2 +- .../formatting/FormattingServiceImpl.java | 6 - .../FormattingServiceProperties.java | 2 +- ...ormattingUserprofileCacheCacheService.java | 3 +- .../FormattingUserprofileCacheOptions.java | 2 +- .../message/builder/EmailMessageBuilder.java | 4 +- .../message/builder/InAppMessageBuilder.java | 3 +- .../cache/NotificationTemplateCache.java | 6 +- .../NotificationTemplateCacheOptions.java | 2 +- .../message/common/MessageBuilderBase.java | 2 +- .../MessageBuilderServiceImpl.java | 17 +- .../notification/NotificationServiceImpl.java | 4 +- .../email => service/notify}/EmailConfig.java | 2 +- .../service/notify/EmailNotifier.java | 1 - .../notify}/EmailProperties.java | 2 +- .../TenantConfigurationService.java | 37 +- .../TenantConfigurationServiceImpl.java | 346 ++++++++---------- .../service/user/UserServiceImpl.java | 15 +- .../UserNotificationPreferenceService.java | 5 +- ...UserNotificationPreferenceServiceImpl.java | 12 +- 73 files changed, 1309 insertions(+), 1724 deletions(-) delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantConfigEntity.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantDepositConfigEntity.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantFileTransformersConfigEntity.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantSourceEntity.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleConfigurationDataContainer.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleTenantConfigurationEntity.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/EmailClientConfigurationDataContainer.java rename notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/{NotifierListConfigurationDataContainer.java => NotifierListTenantConfigurationEntity.java} (63%) rename notification-service/notification/src/main/java/gr/cite/notification/{config/db => data/namingstrategy}/NamingStrategyProperties.java (90%) rename notification-service/notification/src/main/java/gr/cite/notification/{config/db => data/namingstrategy}/PrefixPhysicalNamingStrategy.java (96%) create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/event/TenantConfigurationTouchedEvent.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/TenantConfiguration.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/builder/TenantConfigurationBuilder.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantConfigBuilder.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantSourceBuilder.java rename notification-service/notification/src/main/java/gr/cite/notification/model/builder/{tenantconfig/TenantFileTransformersBuilder.java => tenantconfiguration/DefaultUserLocaleTenantConfigurationBuilder.java} (50%) rename notification-service/notification/src/main/java/gr/cite/notification/model/builder/{tenantconfig/TenantDepositConfigBuilder.java => tenantconfiguration/NotifierListTenantConfigurationBuilder.java} (52%) create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/TenantConfigurationBuilder.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/censorship/TenantConfigurationCensor.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/DefaultUserLocaleTenantConfigurationCensor.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/NotifierListTenantConfigurationCensor.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/TenantConfigurationCensor.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/DefaultUserLocaleTenantConfigurationPersist.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/NotifierListTenantConfigurationPersist.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationEmailClientPersist.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationNotifierListPersist.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationPersist.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationUserLocaleIntegrationPersist.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantConfig.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantDepositConfig.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantFileTransformersConfig.java delete mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantSource.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/DefaultUserLocaleTenantConfiguration.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/NotifierListTenantConfiguration.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/TenantConfiguration.java rename notification-service/notification/src/main/java/gr/cite/notification/{config => service}/formatting/FormattingServiceConfiguration.java (84%) rename notification-service/notification/src/main/java/gr/cite/notification/{config => service}/formatting/FormattingServiceProperties.java (95%) rename notification-service/notification/src/main/java/gr/cite/notification/{cache => service/formatting}/FormattingUserprofileCacheCacheService.java (94%) rename notification-service/notification/src/main/java/gr/cite/notification/{config => service}/formatting/FormattingUserprofileCacheOptions.java (87%) rename notification-service/notification/src/main/java/gr/cite/notification/{ => service/message}/cache/NotificationTemplateCache.java (92%) rename notification-service/notification/src/main/java/gr/cite/notification/{config/notification => service/message/cache}/NotificationTemplateCacheOptions.java (85%) rename notification-service/notification/src/main/java/gr/cite/notification/{config/email => service/notify}/EmailConfig.java (84%) rename notification-service/notification/src/main/java/gr/cite/notification/{config/email => service/notify}/EmailProperties.java (88%) diff --git a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java index 447a8da61..0dc55a13b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java +++ b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java @@ -166,6 +166,8 @@ public class AuditableAction { public static final EventId TenantConfiguration_Lookup = new EventId(270001, "TenantConfiguration_Lookup"); public static final EventId TenantConfiguration_Persist = new EventId(270002, "TenantConfiguration_Persist"); public static final EventId TenantConfiguration_Delete = new EventId(270003, "TenantConfiguration_Delete"); + public static final EventId TenantConfiguration_LookupByType = new EventId(270004, "TenantConfiguration_LookupByType"); + } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java index 760d894d4..4f182e086 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/TenantConfigurationController.java @@ -124,7 +124,7 @@ public class TenantConfigurationController { TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, query.firstAs(fieldSet)); - this.auditService.track(AuditableAction.TenantConfiguration_Lookup, Map.ofEntries( + this.auditService.track(AuditableAction.TenantConfiguration_LookupByType, Map.ofEntries( new AbstractMap.SimpleEntry("type", type), new AbstractMap.SimpleEntry("fields", fieldSet) )); @@ -136,7 +136,7 @@ public class TenantConfigurationController { @Transactional @ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model") public TenantConfiguration persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { - logger.debug(new MapLogEntry("persisting" + DescriptionTemplateType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); + logger.debug(new MapLogEntry("persisting" + TenantConfiguration.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet); this.auditService.track(AuditableAction.TenantConfiguration_Persist, Map.ofEntries( diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java index dfa0de411..dc71dca47 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/TenantConfigurationController.java @@ -1,16 +1,18 @@ package gr.cite.notification.web.controllers; +import com.fasterxml.jackson.core.JsonProcessingException; 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.common.scope.tenant.TenantScope; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; import gr.cite.notification.data.TenantConfigurationEntity; -import gr.cite.notification.model.TenantConfiguration; -import gr.cite.notification.model.builder.TenantConfigurationBuilder; -import gr.cite.notification.model.censorship.TenantConfigurationCensor; -import gr.cite.notification.model.persist.NotificationTemplatePersist; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist; +import gr.cite.notification.model.builder.tenantconfiguration.TenantConfigurationBuilder; +import gr.cite.notification.model.censorship.tenantconfiguration.TenantConfigurationCensor; +import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist; +import gr.cite.notification.model.tenantconfiguration.TenantConfiguration; +import gr.cite.notification.model.persist.tenantconfiguration.NotifierListTenantConfigurationPersist; import gr.cite.notification.query.TenantConfigurationQuery; import gr.cite.notification.query.lookup.NotifierListLookup; import gr.cite.notification.query.lookup.TenantConfigurationLookup; @@ -31,46 +33,61 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import javax.management.InvalidApplicationException; -import jakarta.transaction.Transactional; -import jakarta.validation.Valid; + +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.*; @RestController @RequestMapping(path = "api/notification/tenant-configuration") public class TenantConfigurationController { + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationController.class)); private final BuilderFactory builderFactory; - private final AuditService auditService; - private final TenantConfigurationService tenantConfigurationService; - private final CensorFactory censorFactory; - private final QueryFactory queryFactory; - private final MessageSource messageSource; - @Autowired - public TenantConfigurationController(BuilderFactory builderFactory, - AuditService auditService, - TenantConfigurationService tenantConfigurationService, CensorFactory censorFactory, - QueryFactory queryFactory, - MessageSource messageSource) { + private final AuditService auditService; + + private final TenantConfigurationService tenantConfigurationService; + + private final CensorFactory censorFactory; + + private final QueryFactory queryFactory; + + private final MessageSource messageSource; + private final TenantScope tenantScope; + + public TenantConfigurationController( + BuilderFactory builderFactory, + AuditService auditService, + TenantConfigurationService tenantConfigurationService, CensorFactory censorFactory, + QueryFactory queryFactory, + MessageSource messageSource, TenantScope tenantScope) { this.builderFactory = builderFactory; this.auditService = auditService; this.tenantConfigurationService = tenantConfigurationService; this.censorFactory = censorFactory; this.queryFactory = queryFactory; this.messageSource = messageSource; + this.tenantScope = tenantScope; } @PostMapping("query") public QueryResult query(@RequestBody TenantConfigurationLookup lookup) throws MyApplicationException, MyForbiddenException { logger.debug("querying {}", TenantConfiguration.class.getSimpleName()); - this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject()); + this.censorFactory.censor(TenantConfigurationCensor.class).censor(lookup.getProject(), null); + + TenantConfigurationQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); - TenantConfigurationQuery query = lookup.enrich(this.queryFactory); List data = query.collectAs(lookup.getProject()); List models = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); @@ -81,13 +98,12 @@ public class TenantConfigurationController { } @GetMapping("{id}") - @Transactional - public TenantConfiguration get(@PathVariable UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + public TenantConfiguration get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id).And("fields", fieldSet)); - this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet); + this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet, null); - TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).ids(id); + TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id); TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -96,60 +112,41 @@ public class TenantConfigurationController { new AbstractMap.SimpleEntry("id", id), new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return model; } - @PostMapping("persist/email-client") - @Transactional - @ValidationFilterAnnotation(validator = TenantConfigurationEmailClientPersist.TenantConfigurationEmailClientPersistValidator.ValidatorName, argumentName = "model") - public TenantConfiguration persist(@RequestBody TenantConfigurationEmailClientPersist model, FieldSet fieldSet) - { - logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION).And("model", model).And("fields", fieldSet)); + @GetMapping("current-tenant/{type}") + public TenantConfiguration getCurrentTenantType(@PathVariable("type") Short type, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { + logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("type", type).And("fields", fieldSet)); - TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet); + this.censorFactory.censor(TenantConfigurationCensor.class).censor(fieldSet, null); - this.auditService.track(AuditableAction.Tenant_Configuration_Persist, Map.of( - "type", TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION, - "model", model, - "fields", fieldSet - )); - //this._auditService.TrackIdentity(AuditableAction.IdentityTracking_Action); + TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.of(type)); + if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false); + else query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant()); - return persisted; - } + TenantConfiguration model = this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); - @PostMapping("notifier-list/available") - public NotifierListConfigurationDataContainer getAvailableNotifiers(@RequestBody NotifierListLookup tenantNotifierListLookup) - { - logger.debug("querying available notifiers"); - - NotifierListConfigurationDataContainer notifierListData = this.tenantConfigurationService.collectTenantAvailableNotifierList(tenantNotifierListLookup.getNotificationTypes()); - - this.auditService.track(AuditableAction.Tenant_Available_Notifiers_Query, Map.of( - "lookup", tenantNotifierListLookup + this.auditService.track(AuditableAction.TenantConfiguration_LookupByType, Map.ofEntries( + new AbstractMap.SimpleEntry("type", type), + new AbstractMap.SimpleEntry("fields", fieldSet) )); - //this._auditService.TrackIdentity(AuditableAction.IdentityTracking_Action); - return notifierListData; + return model; } - @PostMapping("persist/notifier-list") - @Transactional - @ValidationFilterAnnotation(validator = TenantConfigurationNotifierListPersist.TenantConfigurationNotifierListPersistValidator.ValidatorName, argumentName = "model") - public TenantConfiguration persist(@RequestBody TenantConfigurationNotifierListPersist model, FieldSet fieldSet) - { - logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet)); - + @PostMapping("persist") + @org.springframework.transaction.annotation.Transactional + @ValidationFilterAnnotation(validator = TenantConfigurationPersist.TenantConfigurationPersistValidator.ValidatorName, argumentName = "model") + public TenantConfiguration persist(@RequestBody TenantConfigurationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + logger.debug(new MapLogEntry("persisting" + TenantConfiguration.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); TenantConfiguration persisted = this.tenantConfigurationService.persist(model, fieldSet); - this.auditService.track(AuditableAction.Tenant_Configuration_Persist, Map.of( - "type", TenantConfigurationType.NOTIFIER_LIST, - "model", model, - "fields", fieldSet - )); - //this._auditService.TrackIdentity(AuditableAction.IdentityTracking_Action); + this.auditService.track(AuditableAction.Tenant_Configuration_Persist, Map.ofEntries( + new AbstractMap.SimpleEntry("model", model), + new AbstractMap.SimpleEntry("fields", fieldSet) + )); return persisted; } @@ -157,12 +154,11 @@ public class TenantConfigurationController { @DeleteMapping("{id}") @Transactional public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { - logger.debug(new MapLogEntry("deleting" + TenantConfiguration.class.getSimpleName()).And("id", id)); + logger.debug(new MapLogEntry("retrieving" + TenantConfiguration.class.getSimpleName()).And("id", id)); this.tenantConfigurationService.deleteAndSave(id); this.auditService.track(AuditableAction.Tenant_Configuration_Delete, "id", id); - - //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); } + } 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 54a0e3fb9..249923248 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 @@ -4,9 +4,8 @@ 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.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; import gr.cite.notification.data.UserNotificationPreferenceEntity; -import gr.cite.notification.model.TenantConfiguration; import gr.cite.notification.model.UserNotificationPreference; import gr.cite.notification.model.builder.UserNotificationPreferenceBuilder; import gr.cite.notification.model.censorship.UserNotificationPreferenceCensor; @@ -31,7 +30,6 @@ import gr.cite.tools.validation.ValidationFilterAnnotation; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; -import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.*; import jakarta.transaction.Transactional; @@ -103,11 +101,11 @@ public class UserNotificationPreferenceController { } @PostMapping("notifier-list/available") - public NotifierListConfigurationDataContainer getAvailableNotifiers(@RequestBody NotifierListLookup tenantNotifierListLookup) + public NotifierListTenantConfigurationEntity getAvailableNotifiers(@RequestBody NotifierListLookup tenantNotifierListLookup) { logger.debug("querying available notifiers"); - NotifierListConfigurationDataContainer notifierListData = this.userNotificationPreferenceService.collectUserAvailableNotifierList(tenantNotifierListLookup.getNotificationTypes()); + NotifierListTenantConfigurationEntity notifierListData = this.userNotificationPreferenceService.collectUserAvailableNotifierList(tenantNotifierListLookup.getNotificationTypes()); this.auditService.track(AuditableAction.User_Available_Notifiers_Query, Map.of( "lookup", tenantNotifierListLookup @@ -122,12 +120,12 @@ public class UserNotificationPreferenceController { @ValidationFilterAnnotation(validator = UserNotificationPreferencePersist.UserNotificationPreferencePersistValidator.ValidatorName, argumentName = "model") public List persist(@RequestBody UserNotificationPreferencePersist model, FieldSet fieldSet) { - logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet)); + logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NotifierList).And("model", model).And("fields", fieldSet)); List persisted = this.userNotificationPreferenceService.persist(model, fieldSet); this.auditService.track(AuditableAction.User_Notification_Preference_Persist, Map.of( - "type", TenantConfigurationType.NOTIFIER_LIST, + "type", TenantConfigurationType.NotifierList, "model", model, "fields", fieldSet )); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/audit/AuditableAction.java b/notification-service/notification/src/main/java/gr/cite/notification/audit/AuditableAction.java index 0ad1baed7..f64bd5b9e 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/audit/AuditableAction.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/audit/AuditableAction.java @@ -35,6 +35,7 @@ public class AuditableAction { public static final EventId Tenant_Configuration_Lookup = new EventId(21001, "Tenant_Configuration_Lookup"); public static final EventId Tenant_Configuration_Persist = new EventId(21002, "Tenant_Configuration_Persist"); public static final EventId Tenant_Configuration_Delete = new EventId(21003, "Tenant_Configuration_Delete"); + public static final EventId TenantConfiguration_LookupByType = new EventId(210004, "TenantConfiguration_LookupByType"); public static final EventId User_Notification_Preference_Query = new EventId(22000, "User_Notification_Preference_Query"); public static final EventId User_Notification_Preference_Lookup = new EventId(22001, "User_Notification_Preference_Lookup"); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/authorization/Permission.java b/notification-service/notification/src/main/java/gr/cite/notification/authorization/Permission.java index 59b247dec..4abf5ca0f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/authorization/Permission.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/authorization/Permission.java @@ -24,6 +24,7 @@ public final class Permission { public static final String BrowseTenantConfiguration = "BrowseTenantConfiguration"; public static final String EditTenantConfiguration = "EditTenantConfiguration"; + public static final String DeleteTenantConfiguration = "DeleteTenantConfiguration"; //Notification Preference public static final String BrowseUserNotificationPreference = "BrowseUserNotificationPreference"; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/enums/TenantConfigurationType.java b/notification-service/notification/src/main/java/gr/cite/notification/common/enums/TenantConfigurationType.java index 799a59c7f..0f7b4f739 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/enums/TenantConfigurationType.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/common/enums/TenantConfigurationType.java @@ -6,9 +6,9 @@ import gr.cite.notification.data.conventers.DatabaseEnum; import java.util.Map; public enum TenantConfigurationType implements DatabaseEnum { - EMAIL_CLIENT_CONFIGURATION((short)1), - DEFAULT_USER_LOCALE((short)3), - NOTIFIER_LIST((short)4); + NotifierList((short)0), + DefaultUserLocale((short) 1), + ; private final Short value; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantConfigEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantConfigEntity.java deleted file mode 100644 index 4d5a0a7db..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantConfigEntity.java +++ /dev/null @@ -1,35 +0,0 @@ -package gr.cite.notification.common.types.tenant; - - -import jakarta.xml.bind.annotation.XmlAccessType; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "config") -@XmlAccessorType(XmlAccessType.FIELD) -public class TenantConfigEntity { - - @XmlElement(name = "deposit-configuration") - private TenantDepositConfigEntity deposit; - - @XmlElement(name = "file-transformers-configuration") - private TenantFileTransformersConfigEntity fileTransformers; - - public TenantDepositConfigEntity getDeposit() { - return deposit; - } - - public void setDeposit(TenantDepositConfigEntity deposit) { - this.deposit = deposit; - } - - public TenantFileTransformersConfigEntity getFileTransformers() { - return fileTransformers; - } - - public void setFileTransformers(TenantFileTransformersConfigEntity fileTransformers) { - this.fileTransformers = fileTransformers; - } -} - diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantDepositConfigEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantDepositConfigEntity.java deleted file mode 100644 index f2498eada..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantDepositConfigEntity.java +++ /dev/null @@ -1,22 +0,0 @@ -package gr.cite.notification.common.types.tenant; - -import jakarta.xml.bind.annotation.*; - -import java.util.List; - -@XmlAccessorType(XmlAccessType.FIELD) -public class TenantDepositConfigEntity { - - @XmlElementWrapper(name = "sources") - @XmlElement(name = "source") - private List sources; - - - public List getSources() { - return sources; - } - - public void setSources(List sources) { - this.sources = sources; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantFileTransformersConfigEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantFileTransformersConfigEntity.java deleted file mode 100644 index e661197d7..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantFileTransformersConfigEntity.java +++ /dev/null @@ -1,21 +0,0 @@ -package gr.cite.notification.common.types.tenant; - -import jakarta.xml.bind.annotation.*; - -import java.util.List; - -@XmlAccessorType(XmlAccessType.FIELD) -public class TenantFileTransformersConfigEntity { - - @XmlElementWrapper(name = "sources") - @XmlElement(name = "source") - private List sources; - - public List getSources() { - return sources; - } - - public void setSources(List sources) { - this.sources = sources; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantSourceEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantSourceEntity.java deleted file mode 100644 index 5871f2c0e..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenant/TenantSourceEntity.java +++ /dev/null @@ -1,76 +0,0 @@ -package gr.cite.notification.common.types.tenant; - -import jakarta.xml.bind.annotation.*; - -import java.util.List; - -@XmlAccessorType(XmlAccessType.FIELD) -public class TenantSourceEntity { - - @XmlElement(name = "url") - private String url; - - @XmlElementWrapper(name = "codes") - @XmlElement(name = "code") - private List codes; - - @XmlElement(name = "issuer-url") - private String issuerUrl; - - @XmlElement(name = "client-id") - private String clientId; - - @XmlElement(name = "client-secret") - private String clientSecret; - - @XmlElement(name = "scope") - private String scope; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public List getCodes() { - return codes; - } - - public void setCodes(List codes) { - this.codes = codes; - } - - public String getIssuerUrl() { - return issuerUrl; - } - - public void setIssuerUrl(String issuerUrl) { - this.issuerUrl = issuerUrl; - } - - public String getClientId() { - return clientId; - } - - public void setClientId(String clientId) { - this.clientId = clientId; - } - - public String getClientSecret() { - return clientSecret; - } - - public void setClientSecret(String clientSecret) { - this.clientSecret = clientSecret; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleConfigurationDataContainer.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleConfigurationDataContainer.java deleted file mode 100644 index 2724f54c1..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleConfigurationDataContainer.java +++ /dev/null @@ -1,37 +0,0 @@ -package gr.cite.notification.common.types.tenantconfiguration; - -public class DefaultUserLocaleConfigurationDataContainer { - - public static class Field { - public static final String LANGUAGE = "language"; - public static final String TIME_ZONE = "timeZone"; - public static final String CULTURE = "culture"; - } - private String language; - private String timeZone; - private String culture; - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public String getTimeZone() { - return timeZone; - } - - public void setTimeZone(String timeZone) { - this.timeZone = timeZone; - } - - public String getCulture() { - return culture; - } - - public void setCulture(String culture) { - this.culture = culture; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleTenantConfigurationEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleTenantConfigurationEntity.java new file mode 100644 index 000000000..6e6f29251 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/DefaultUserLocaleTenantConfigurationEntity.java @@ -0,0 +1,32 @@ +package gr.cite.notification.common.types.tenantconfiguration; + +public class DefaultUserLocaleTenantConfigurationEntity { + private String timezone; + private String language; + private String culture; + + public String getTimezone() { + return timezone; + } + + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getCulture() { + return culture; + } + + public void setCulture(String culture) { + this.culture = culture; + } +} + diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/EmailClientConfigurationDataContainer.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/EmailClientConfigurationDataContainer.java deleted file mode 100644 index 71d70a997..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/EmailClientConfigurationDataContainer.java +++ /dev/null @@ -1,87 +0,0 @@ -package gr.cite.notification.common.types.tenantconfiguration; - -public class EmailClientConfigurationDataContainer { - - public static class Field { - public static final String REQUIRE_CREDENTIALS = "requireCredentials"; - public static final String ENABLE_SSL = "enableSSL"; - public static final String CERTIFICATE_PATH = "certificatePath"; - public static final String HOST_SERVER = "hostServer"; - public static final String HOST_PORT_NO = "hostPortNo"; - public static final String EMAIL_ADDRESS = "emailAddress"; - public static final String EMAIL_USER_NAME = "emailUserName"; - public static final String EMAIL_PASSWORD = "emailPassword"; - } - private Boolean requireCredentials; - private Boolean enableSSL; - private String certificatePath; - private String hostServer; - private Integer hostPortNo; - private String emailAddress; - private String emailUserName; - private String emailPassword; - - public Boolean getRequireCredentials() { - return requireCredentials; - } - - public void setRequireCredentials(Boolean requireCredentials) { - this.requireCredentials = requireCredentials; - } - - public Boolean getEnableSSL() { - return enableSSL; - } - - public void setEnableSSL(Boolean enableSSL) { - this.enableSSL = enableSSL; - } - - public String getCertificatePath() { - return certificatePath; - } - - public void setCertificatePath(String certificatePath) { - this.certificatePath = certificatePath; - } - - public String getHostServer() { - return hostServer; - } - - public void setHostServer(String hostServer) { - this.hostServer = hostServer; - } - - public Integer getHostPortNo() { - return hostPortNo; - } - - public void setHostPortNo(Integer hostPortNo) { - this.hostPortNo = hostPortNo; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public String getEmailUserName() { - return emailUserName; - } - - public void setEmailUserName(String emailUserName) { - this.emailUserName = emailUserName; - } - - public String getEmailPassword() { - return emailPassword; - } - - public void setEmailPassword(String emailPassword) { - this.emailPassword = emailPassword; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/NotifierListConfigurationDataContainer.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/NotifierListTenantConfigurationEntity.java similarity index 63% rename from notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/NotifierListConfigurationDataContainer.java rename to notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/NotifierListTenantConfigurationEntity.java index c91a91009..f98090688 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/NotifierListConfigurationDataContainer.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/common/types/tenantconfiguration/NotifierListTenantConfigurationEntity.java @@ -6,17 +6,14 @@ import java.util.List; import java.util.Map; import java.util.UUID; -public class NotifierListConfigurationDataContainer { +public class NotifierListTenantConfigurationEntity { - public static class Field { - public static final String NOTIFIERS = "notifiers"; - } private Map> notifiers; - public NotifierListConfigurationDataContainer() { + public NotifierListTenantConfigurationEntity() { } - public NotifierListConfigurationDataContainer(Map> notifiers) { + public NotifierListTenantConfigurationEntity(Map> notifiers) { this.notifiers = notifiers; } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/types/user/AdditionalInfoEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/common/types/user/AdditionalInfoEntity.java index 1c8c6f4b1..efdc268bd 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/types/user/AdditionalInfoEntity.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/common/types/user/AdditionalInfoEntity.java @@ -3,20 +3,9 @@ package gr.cite.notification.common.types.user; import java.util.UUID; public class AdditionalInfoEntity { - private String avatarUrl; private String timezone; private String culture; private String language; - private String roleOrganization; - private UUID organizationId; - - public String getAvatarUrl() { - return avatarUrl; - } - - public void setAvatarUrl(String avatarUrl) { - this.avatarUrl = avatarUrl; - } public String getTimezone() { return timezone; @@ -42,19 +31,4 @@ public class AdditionalInfoEntity { this.language = language; } - public UUID getOrganizationId() { - return organizationId; - } - - public void setOrganizationId(UUID organizationId) { - this.organizationId = organizationId; - } - - public String getRoleOrganization() { - return roleOrganization; - } - - public void setRoleOrganization(String roleOrganization) { - this.roleOrganization = roleOrganization; - } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/notification/NotificationConfig.java b/notification-service/notification/src/main/java/gr/cite/notification/config/notification/NotificationConfig.java index 5ede51cd9..58d962160 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/notification/NotificationConfig.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/config/notification/NotificationConfig.java @@ -33,13 +33,11 @@ public class NotificationConfig { } private final ApplicationContext applicationContext; private final NotificationProperties properties; - private final QueueListenerProperties queueListenerProperties; @Autowired - public NotificationConfig(ApplicationContext applicationContext, NotificationProperties properties, QueueListenerProperties queueListenerProperties) { + public NotificationConfig(ApplicationContext applicationContext, NotificationProperties properties) { this.applicationContext = applicationContext; this.properties = properties; - this.queueListenerProperties = queueListenerProperties; } @Bean(BeanQualifier.GLOBAL_POLICIES_MAP) diff --git a/notification-service/notification/src/main/java/gr/cite/notification/data/TenantConfigurationEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/data/TenantConfigurationEntity.java index 44c8d6030..9b7b4cbd4 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/data/TenantConfigurationEntity.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/data/TenantConfigurationEntity.java @@ -17,40 +17,29 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity { @Id @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) private UUID id; - - public static final String _id = "id"; + public final static String _id = "id"; @Column(name = "type", nullable = false) @Convert(converter = TenantConfigurationTypeConverter.class) private TenantConfigurationType type; - - public static final String _type = "type"; + public final static String _type = "type"; @Column(name = "value", nullable = false) private String value; - - public static final String _value = "value"; - - @Column(name = "\"tenant\"", columnDefinition = "uuid") - private UUID tenantId; - - public static final String _tenantId = "tenantId"; + public final static String _value = "value"; @Column(name = "created_at", nullable = false) private Instant createdAt; - - public static final String _createdAt = "createdAt"; + public final static String _createdAt = "createdAt"; @Column(name = "updated_at", nullable = false) private Instant updatedAt; - - public static final String _updatedAt = "updatedAt"; + public final static String _updatedAt = "updatedAt"; @Column(name = "is_active", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; - - public static final String _isActive = "isActive"; + public final static String _isActive = "isActive"; public UUID getId() { return id; @@ -60,14 +49,6 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity { this.id = id; } - public TenantConfigurationType getType() { - return type; - } - - public void setType(TenantConfigurationType type) { - this.type = type; - } - public String getValue() { return value; } @@ -76,14 +57,20 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity { this.value = value; } - @Override - public UUID getTenantId() { - return tenantId; + public TenantConfigurationType getType() { + return type; } - @Override - public void setTenantId(UUID tenantId) { - this.tenantId = tenantId; + public void setType(TenantConfigurationType type) { + this.type = type; + } + + public IsActive getIsActive() { + return isActive; + } + + public void setIsActive(IsActive isActive) { + this.isActive = isActive; } public Instant getCreatedAt() { @@ -101,13 +88,4 @@ public class TenantConfigurationEntity extends TenantScopedBaseEntity { public void setUpdatedAt(Instant updatedAt) { this.updatedAt = updatedAt; } - - public IsActive getIsActive() { - return isActive; - } - - public void setIsActive(IsActive isActive) { - this.isActive = isActive; - } - } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/db/NamingStrategyProperties.java b/notification-service/notification/src/main/java/gr/cite/notification/data/namingstrategy/NamingStrategyProperties.java similarity index 90% rename from notification-service/notification/src/main/java/gr/cite/notification/config/db/NamingStrategyProperties.java rename to notification-service/notification/src/main/java/gr/cite/notification/data/namingstrategy/NamingStrategyProperties.java index 60d731cf9..7e68244a9 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/db/NamingStrategyProperties.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/data/namingstrategy/NamingStrategyProperties.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.db; +package gr.cite.notification.data.namingstrategy; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.bind.ConstructorBinding; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/db/PrefixPhysicalNamingStrategy.java b/notification-service/notification/src/main/java/gr/cite/notification/data/namingstrategy/PrefixPhysicalNamingStrategy.java similarity index 96% rename from notification-service/notification/src/main/java/gr/cite/notification/config/db/PrefixPhysicalNamingStrategy.java rename to notification-service/notification/src/main/java/gr/cite/notification/data/namingstrategy/PrefixPhysicalNamingStrategy.java index d058a1fa5..ce04dc72c 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/db/PrefixPhysicalNamingStrategy.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/data/namingstrategy/PrefixPhysicalNamingStrategy.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.db; +package gr.cite.notification.data.namingstrategy; import gr.cite.notification.common.StringUtils; import org.hibernate.boot.model.naming.Identifier; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/errorcode/ErrorThesaurusProperties.java b/notification-service/notification/src/main/java/gr/cite/notification/errorcode/ErrorThesaurusProperties.java index 87fa3ea60..97bf86ead 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/errorcode/ErrorThesaurusProperties.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/errorcode/ErrorThesaurusProperties.java @@ -18,6 +18,10 @@ public class ErrorThesaurusProperties { private ErrorDescription tenantNotAllowed; private ErrorDescription tenantTampering; + private ErrorDescription tenantConfigurationTypeCanNotChange; + + private ErrorDescription multipleTenantConfigurationTypeNotAllowed; + public ErrorDescription getHashConflict() { return hashConflict; } @@ -106,4 +110,20 @@ public class ErrorThesaurusProperties { public void setTenantTampering(ErrorDescription tenantTampering) { this.tenantTampering = tenantTampering; } + + public ErrorDescription getTenantConfigurationTypeCanNotChange() { + return tenantConfigurationTypeCanNotChange; + } + + public void setTenantConfigurationTypeCanNotChange(ErrorDescription tenantConfigurationTypeCanNotChange) { + this.tenantConfigurationTypeCanNotChange = tenantConfigurationTypeCanNotChange; + } + + public ErrorDescription getMultipleTenantConfigurationTypeNotAllowed() { + return multipleTenantConfigurationTypeNotAllowed; + } + + public void setMultipleTenantConfigurationTypeNotAllowed(ErrorDescription multipleTenantConfigurationTypeNotAllowed) { + this.multipleTenantConfigurationTypeNotAllowed = multipleTenantConfigurationTypeNotAllowed; + } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/event/EventBroker.java b/notification-service/notification/src/main/java/gr/cite/notification/event/EventBroker.java index 3bc5a14b8..77f2b316b 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/event/EventBroker.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/event/EventBroker.java @@ -33,5 +33,8 @@ public class EventBroker { public void emit(UserRemovedFromTenantEvent event) { this.applicationEventPublisher.publishEvent(event); } + public void emit(TenantConfigurationTouchedEvent event) { + this.applicationEventPublisher.publishEvent(event); + } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/event/TenantConfigurationTouchedEvent.java b/notification-service/notification/src/main/java/gr/cite/notification/event/TenantConfigurationTouchedEvent.java new file mode 100644 index 000000000..c86e3c5d7 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/event/TenantConfigurationTouchedEvent.java @@ -0,0 +1,45 @@ +package gr.cite.notification.event; + + +import gr.cite.notification.common.enums.TenantConfigurationType; + +import java.util.UUID; + +public class TenantConfigurationTouchedEvent { + public TenantConfigurationTouchedEvent() { + } + + public TenantConfigurationTouchedEvent(UUID tenantId, String tenantCode, TenantConfigurationType type) { + this.tenantId = tenantId; + this.tenantCode = tenantCode; + this.type = type; + } + + private UUID tenantId; + private String tenantCode; + private TenantConfigurationType type; + + public UUID getTenantId() { + return tenantId; + } + + public void setTenantId(UUID tenantId) { + this.tenantId = tenantId; + } + + public TenantConfigurationType getType() { + return type; + } + + public void setType(TenantConfigurationType type) { + this.type = type; + } + + public String getTenantCode() { + return tenantCode; + } + + public void setTenantCode(String tenantCode) { + this.tenantCode = tenantCode; + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/TenantConfiguration.java b/notification-service/notification/src/main/java/gr/cite/notification/model/TenantConfiguration.java deleted file mode 100644 index 2484cd45e..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/TenantConfiguration.java +++ /dev/null @@ -1,145 +0,0 @@ -package gr.cite.notification.model; - -import gr.cite.notification.common.enums.IsActive; -import gr.cite.notification.common.enums.TenantConfigurationType; -import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; - -import java.time.Instant; -import java.util.UUID; - -public class TenantConfiguration { - - private UUID id; - - public static final String _id = "id"; - - private UUID tenantId; - - public static final String _tenantId = "tenantId"; - - private TenantConfigurationType type; - - public static final String _type = "type"; - - private String value; - - public static final String _value = "value"; - - private EmailClientConfigurationDataContainer emailClientData; - - public static final String _emailClientData = "emailClientData"; - - private DefaultUserLocaleConfigurationDataContainer defaultUserLocaleData; - - public static final String _defaultUserLocaleData = "defaultUserLocaleData"; - - private NotifierListConfigurationDataContainer notifierListData; - - public static final String _notifierListData = "notifierListData"; - - private IsActive isActive; - - public static final String _isActive = "isActive"; - - private Instant createdAt; - - public static final String _createdAt = "createdAt"; - - private Instant updatedAt; - - public static final String _updatedAt = "updatedAt"; - - private String hash; - - public static final String _hash = "hash"; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public UUID getTenantId() { - return tenantId; - } - - public void setTenantId(UUID tenantId) { - this.tenantId = tenantId; - } - - public TenantConfigurationType getType() { - return type; - } - - public void setType(TenantConfigurationType type) { - this.type = type; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public EmailClientConfigurationDataContainer getEmailClientData() { - return emailClientData; - } - - public void setEmailClientData(EmailClientConfigurationDataContainer emailClientData) { - this.emailClientData = emailClientData; - } - - public DefaultUserLocaleConfigurationDataContainer getDefaultUserLocaleData() { - return defaultUserLocaleData; - } - - public void setDefaultUserLocaleData(DefaultUserLocaleConfigurationDataContainer defaultUserLocaleData) { - this.defaultUserLocaleData = defaultUserLocaleData; - } - - public NotifierListConfigurationDataContainer getNotifierListData() { - return notifierListData; - } - - public void setNotifierListData(NotifierListConfigurationDataContainer notifierListData) { - this.notifierListData = notifierListData; - } - - public IsActive getIsActive() { - return isActive; - } - - public void setIsActive(IsActive isActive) { - this.isActive = isActive; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - - public Instant getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Instant updatedAt) { - this.updatedAt = updatedAt; - } - - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/BaseBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/BaseBuilder.java index 087df8b45..f062e44e6 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/BaseBuilder.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/BaseBuilder.java @@ -1,12 +1,15 @@ package gr.cite.notification.model.builder; +import gr.cite.notification.common.scope.tenant.TenantScope; import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.data.tenant.TenantScopedBaseEntity; import gr.cite.tools.data.builder.Builder; import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; +import javax.management.InvalidApplicationException; import java.time.Instant; import java.util.*; import java.util.function.Function; @@ -92,4 +95,15 @@ public abstract class BaseBuilder implements Builder { return this.conventionService.asIndexer(names); } + protected boolean getBelongsToCurrentTenant(TenantScopedBaseEntity entity, TenantScope tenantScope){ + if (!tenantScope.isSet()) return true; + try { + if (entity.getTenantId() == null && tenantScope.getTenant() == null) return true; + if (entity.getTenantId() == null || tenantScope.getTenant() == null) return false; + + return entity.getTenantId().equals(tenantScope.getTenant()); + } catch (InvalidApplicationException e) { + return false; + } + } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/TenantConfigurationBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/TenantConfigurationBuilder.java deleted file mode 100644 index ac79649c6..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/TenantConfigurationBuilder.java +++ /dev/null @@ -1,137 +0,0 @@ -package gr.cite.notification.model.builder; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import gr.cite.notification.authorization.AuthorizationFlags; -import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; -import gr.cite.notification.convention.ConventionService; -import gr.cite.notification.data.TenantConfigurationEntity; -import gr.cite.notification.model.TenantConfiguration; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.DataLogEntry; -import gr.cite.tools.logging.LoggerService; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; - -import java.util.*; - -@Component -@RequestScope -public class TenantConfigurationBuilder extends BaseBuilder { - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - private final ObjectMapper mapper; - @Autowired - public TenantConfigurationBuilder(ConventionService conventionService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigurationBuilder.class))); - this.mapper = new ObjectMapper(); - } - - public TenantConfigurationBuilder authorize(EnumSet values){ - this.authorize = values; - return this; - } - @Override - public List build(FieldSet fields, List data) throws MyApplicationException { - this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0),Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size) .orElse(0)); - this.logger.trace(new DataLogEntry("requested fields",fields)); - if(fields == null || data == null || fields.isEmpty()) return new ArrayList<>(); - - List models = new ArrayList<>(); - for(TenantConfigurationEntity d : data){ - TenantConfiguration m = new TenantConfiguration(); - if(fields.hasField(this.asIndexer(TenantConfiguration._id))) m.setId(d.getId()); - if(fields.hasField(this.asIndexer(TenantConfiguration._tenantId))) m.setTenantId(d.getTenantId()); - if(fields.hasField(this.asIndexer(TenantConfiguration._type))) m.setType(d.getType()); - if(fields.hasField(this.asIndexer(TenantConfiguration._value))) m.setValue(d.getValue()); - if(fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData))) { - try { - m.setDefaultUserLocaleData(mapper.readValue(d.getValue(), DefaultUserLocaleConfigurationDataContainer.class)); - - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - } - if (!fields.extractPrefixed(this.asIndexer(TenantConfiguration._defaultUserLocaleData)).isEmpty()) { - try { - DefaultUserLocaleConfigurationDataContainer container = mapper.readValue(d.getValue(), DefaultUserLocaleConfigurationDataContainer.class); - if (container != null) { - m.setDefaultUserLocaleData(new DefaultUserLocaleConfigurationDataContainer()); - if (fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData, DefaultUserLocaleConfigurationDataContainer.Field.LANGUAGE))) - m.getDefaultUserLocaleData().setLanguage(container.getLanguage()); - if (fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData, DefaultUserLocaleConfigurationDataContainer.Field.TIME_ZONE))) - m.getDefaultUserLocaleData().setTimeZone(container.getTimeZone()); - if (fields.hasField(this.asIndexer(TenantConfiguration._defaultUserLocaleData, DefaultUserLocaleConfigurationDataContainer.Field.CULTURE))) - m.getDefaultUserLocaleData().setCulture(container.getCulture()); - } - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - } - if(fields.hasField(this.asIndexer(TenantConfiguration._emailClientData))) { - try { - m.setEmailClientData(mapper.readValue(d.getValue(), EmailClientConfigurationDataContainer.class)); - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - } - if (!fields.extractPrefixed(this.asIndexer(TenantConfiguration._emailClientData)).isEmpty()) { - try { - EmailClientConfigurationDataContainer container = mapper.readValue(d.getValue(), EmailClientConfigurationDataContainer.class); - if (container != null) { - m.setEmailClientData(new EmailClientConfigurationDataContainer()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.ENABLE_SSL))) - m.getEmailClientData().setEnableSSL(container.getEnableSSL()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.REQUIRE_CREDENTIALS))) - m.getEmailClientData().setRequireCredentials(container.getRequireCredentials()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.HOST_SERVER))) - m.getEmailClientData().setHostServer(container.getHostServer()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.HOST_PORT_NO))) - m.getEmailClientData().setHostPortNo(container.getHostPortNo()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.CERTIFICATE_PATH))) - m.getEmailClientData().setCertificatePath(container.getCertificatePath()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.EMAIL_ADDRESS))) - m.getEmailClientData().setEmailAddress(container.getEmailAddress()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.EMAIL_USER_NAME))) - m.getEmailClientData().setEmailUserName(container.getEmailUserName()); - if (fields.hasField(this.asIndexer(TenantConfiguration._emailClientData, EmailClientConfigurationDataContainer.Field.EMAIL_PASSWORD))) - m.getEmailClientData().setEmailPassword(container.getEmailPassword()); - } - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - } - if(fields.hasField(this.asIndexer(TenantConfiguration._notifierListData))) { - try { - m.setNotifierListData(mapper.readValue(d.getValue(), NotifierListConfigurationDataContainer.class)); - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - } - if (!fields.extractPrefixed(this.asIndexer(TenantConfiguration._notifierListData)).isEmpty()) { - try { - NotifierListConfigurationDataContainer container = mapper.readValue(d.getValue(), NotifierListConfigurationDataContainer.class); - if (container != null) { - m.setNotifierListData(new NotifierListConfigurationDataContainer()); - if (fields.hasField(this.asIndexer(TenantConfiguration._notifierListData, NotifierListConfigurationDataContainer.Field.NOTIFIERS))) - m.getNotifierListData().setNotifiers(container.getNotifiers()); - } - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - } - if(fields.hasField(this.asIndexer(TenantConfiguration._isActive))) m.setIsActive(d.getIsActive()); - if(fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt()); - if(fields.hasField(this.asIndexer(TenantConfiguration._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); - if(fields.hasField(this.asIndexer(TenantConfiguration._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); - models.add(m); - } - this.logger.debug("build {} items",Optional.of(models).map(List::size).orElse(0)); - return models; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java index 667ad53d7..b66a9a863 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/UserNotificationPreferenceBuilder.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import gr.cite.notification.authorization.AuthorizationFlags; import gr.cite.notification.convention.ConventionService; import gr.cite.notification.data.UserNotificationPreferenceEntity; -import gr.cite.notification.model.TenantConfiguration; +import gr.cite.notification.model.tenantconfiguration.TenantConfiguration; import gr.cite.notification.model.UserNotificationPreference; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.fieldset.FieldSet; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantConfigBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantConfigBuilder.java deleted file mode 100644 index 57ad4bea8..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantConfigBuilder.java +++ /dev/null @@ -1,60 +0,0 @@ -package gr.cite.notification.model.builder.tenantconfig; - -import gr.cite.notification.authorization.AuthorizationFlags; -import gr.cite.notification.common.types.tenant.TenantConfigEntity; -import gr.cite.notification.convention.ConventionService; -import gr.cite.notification.model.builder.BaseBuilder; -import gr.cite.notification.model.tenantconfig.TenantConfig; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.DataLogEntry; -import gr.cite.tools.logging.LoggerService; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import java.util.*; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class TenantConfigBuilder extends BaseBuilder { - - private final BuilderFactory builderFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public TenantConfigBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigBuilder.class))); - this.builderFactory = builderFactory; - } - - public TenantConfigBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - public List build(FieldSet fields, List data) throws MyApplicationException { - this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); - this.logger.trace(new DataLogEntry("requested fields", fields)); - if (fields == null || data == null || fields.isEmpty()) - return new ArrayList<>(); - - FieldSet depositFields = fields.extractPrefixed(this.asPrefix(TenantConfig._deposit)); - FieldSet fileFields = fields.extractPrefixed(this.asPrefix(TenantConfig._fileTransformers)); - - List models = new ArrayList<>(); - for (TenantConfigEntity d : data) { - TenantConfig m = new TenantConfig(); - if (!depositFields.isEmpty() && d.getDeposit() != null) m.setDeposit(this.builderFactory.builder(TenantDepositConfigBuilder.class).authorize(this.authorize).build(depositFields, d.getDeposit())); - if (!fileFields.isEmpty() && d.getFileTransformers() != null) m.setFileTransformers(this.builderFactory.builder(TenantFileTransformersBuilder.class).authorize(this.authorize).build(fileFields, d.getFileTransformers())); - models.add(m); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantSourceBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantSourceBuilder.java deleted file mode 100644 index 0260ab410..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantSourceBuilder.java +++ /dev/null @@ -1,62 +0,0 @@ -package gr.cite.notification.model.builder.tenantconfig; - -import gr.cite.notification.authorization.AuthorizationFlags; -import gr.cite.notification.common.types.tenant.TenantSourceEntity; -import gr.cite.notification.convention.ConventionService; -import gr.cite.notification.model.builder.BaseBuilder; -import gr.cite.notification.model.tenantconfig.TenantSource; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.DataLogEntry; -import gr.cite.tools.logging.LoggerService; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import java.util.*; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class TenantSourceBuilder extends BaseBuilder { - - private final BuilderFactory builderFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public TenantSourceBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantSourceBuilder.class))); - this.builderFactory = builderFactory; - } - - public TenantSourceBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - public List build(FieldSet fields, List data) throws MyApplicationException { - this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); - this.logger.trace(new DataLogEntry("requested fields", fields)); - if (fields == null || data == null || fields.isEmpty()) - return new ArrayList<>(); - - List models = new ArrayList<>(); - for (TenantSourceEntity d : data) { - TenantSource m = new TenantSource(); - if (fields.hasField(this.asIndexer(TenantSource._url))) m.setUrl(d.getUrl()); - if (fields.hasField(this.asIndexer(TenantSource._codes))) m.setCodes(d.getCodes()); - if (fields.hasField(this.asIndexer(TenantSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl()); - if (fields.hasField(this.asIndexer(TenantSource._clientId))) m.setClientId(d.getClientId()); - if (fields.hasField(this.asIndexer(TenantSource._clientSecret))) m.setClientSecret(d.getClientSecret()); - if (fields.hasField(this.asIndexer(TenantSource._scope))) m.setScope(d.getScope()); - - models.add(m); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantFileTransformersBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/DefaultUserLocaleTenantConfigurationBuilder.java similarity index 50% rename from notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantFileTransformersBuilder.java rename to notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/DefaultUserLocaleTenantConfigurationBuilder.java index 5ea102750..8bd5916c0 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantFileTransformersBuilder.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/DefaultUserLocaleTenantConfigurationBuilder.java @@ -1,11 +1,10 @@ -package gr.cite.notification.model.builder.tenantconfig; +package gr.cite.notification.model.builder.tenantconfiguration; import gr.cite.notification.authorization.AuthorizationFlags; -import gr.cite.notification.common.types.tenant.TenantFileTransformersConfigEntity; +import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity; import gr.cite.notification.convention.ConventionService; import gr.cite.notification.model.builder.BaseBuilder; -import gr.cite.notification.model.tenantconfig.TenantFileTransformersConfig; -import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.notification.model.tenantconfiguration.DefaultUserLocaleTenantConfiguration; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.DataLogEntry; @@ -20,39 +19,33 @@ import java.util.*; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class TenantFileTransformersBuilder extends BaseBuilder { - - private final BuilderFactory builderFactory; +public class DefaultUserLocaleTenantConfigurationBuilder extends BaseBuilder { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public TenantFileTransformersBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantFileTransformersBuilder.class))); - this.builderFactory = builderFactory; + public DefaultUserLocaleTenantConfigurationBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DefaultUserLocaleTenantConfigurationBuilder.class))); } - public TenantFileTransformersBuilder authorize(EnumSet values) { + public DefaultUserLocaleTenantConfigurationBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - public List build(FieldSet fields, List data) throws MyApplicationException { + public List build(FieldSet fields, List data) throws MyApplicationException { this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); this.logger.trace(new DataLogEntry("requested fields", fields)); if (fields == null || data == null || fields.isEmpty()) return new ArrayList<>(); - FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(TenantFileTransformersConfig._sources)); - - List models = new ArrayList<>(); - for (TenantFileTransformersConfigEntity d : data) { - TenantFileTransformersConfig m = new TenantFileTransformersConfig(); - if (!sourcesFields.isEmpty() && d.getSources() != null) { - m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources())); - } - + List models = new ArrayList<>(); + for (DefaultUserLocaleTenantConfigurationEntity d : data) { + DefaultUserLocaleTenantConfiguration m = new DefaultUserLocaleTenantConfiguration(); + if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._culture))) m.setCulture(d.getCulture()); + if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._timezone))) m.setTimezone(d.getTimezone()); + if (fields.hasField(this.asIndexer(DefaultUserLocaleTenantConfiguration._language))) m.setLanguage(d.getLanguage()); models.add(m); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantDepositConfigBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/NotifierListTenantConfigurationBuilder.java similarity index 52% rename from notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantDepositConfigBuilder.java rename to notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/NotifierListTenantConfigurationBuilder.java index ec7c4b901..438a36dd1 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfig/TenantDepositConfigBuilder.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/NotifierListTenantConfigurationBuilder.java @@ -1,11 +1,10 @@ -package gr.cite.notification.model.builder.tenantconfig; +package gr.cite.notification.model.builder.tenantconfiguration; import gr.cite.notification.authorization.AuthorizationFlags; -import gr.cite.notification.common.types.tenant.TenantDepositConfigEntity; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; import gr.cite.notification.convention.ConventionService; import gr.cite.notification.model.builder.BaseBuilder; -import gr.cite.notification.model.tenantconfig.TenantDepositConfig; -import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.notification.model.tenantconfiguration.NotifierListTenantConfiguration; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.DataLogEntry; @@ -20,39 +19,31 @@ import java.util.*; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class TenantDepositConfigBuilder extends BaseBuilder { - - private final BuilderFactory builderFactory; +public class NotifierListTenantConfigurationBuilder extends BaseBuilder { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public TenantDepositConfigBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantDepositConfigBuilder.class))); - this.builderFactory = builderFactory; + public NotifierListTenantConfigurationBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(NotifierListTenantConfigurationBuilder.class))); } - public TenantDepositConfigBuilder authorize(EnumSet values) { + public NotifierListTenantConfigurationBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - public List build(FieldSet fields, List data) throws MyApplicationException { + public List build(FieldSet fields, List data) throws MyApplicationException { this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); this.logger.trace(new DataLogEntry("requested fields", fields)); if (fields == null || data == null || fields.isEmpty()) return new ArrayList<>(); - FieldSet sourcesFields = fields.extractPrefixed(this.asPrefix(TenantDepositConfig._sources)); - - List models = new ArrayList<>(); - for (TenantDepositConfigEntity d : data) { - TenantDepositConfig m = new TenantDepositConfig(); - if (!sourcesFields.isEmpty() && d.getSources() != null) { - m.setSources(this.builderFactory.builder(TenantSourceBuilder.class).authorize(this.authorize).build(sourcesFields, d.getSources())); - } - + List models = new ArrayList<>(); + for (NotifierListTenantConfigurationEntity d : data) { + NotifierListTenantConfiguration m = new NotifierListTenantConfiguration(); + if (fields.hasField(this.asIndexer(NotifierListTenantConfiguration._notifiers))) m.setNotifiers(d.getNotifiers()); models.add(m); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/TenantConfigurationBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/TenantConfigurationBuilder.java new file mode 100644 index 000000000..8022c2c1d --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/builder/tenantconfiguration/TenantConfigurationBuilder.java @@ -0,0 +1,84 @@ +package gr.cite.notification.model.builder.tenantconfiguration; + +import gr.cite.notification.authorization.AuthorizationFlags; +import gr.cite.notification.common.JsonHandlingService; +import gr.cite.notification.common.enums.TenantConfigurationType; +import gr.cite.notification.common.scope.tenant.TenantScope; +import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; +import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.data.TenantConfigurationEntity; +import gr.cite.notification.model.builder.BaseBuilder; +import gr.cite.notification.model.tenantconfiguration.TenantConfiguration; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class TenantConfigurationBuilder extends BaseBuilder { + private final TenantScope tenantScope; + private final JsonHandlingService jsonHandlingService; + + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public TenantConfigurationBuilder( + ConventionService conventionService, + TenantScope tenantScope, JsonHandlingService jsonHandlingService, BuilderFactory builderFactory1) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(TenantConfigurationBuilder.class))); + this.tenantScope = tenantScope; + this.jsonHandlingService = jsonHandlingService; + this.builderFactory = builderFactory1; + } + + public TenantConfigurationBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List data) throws MyApplicationException { + this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0)); + this.logger.trace(new DataLogEntry("requested fields", fields)); + if (fields == null || data == null || fields.isEmpty()) + return new ArrayList<>(); + + FieldSet notifierListFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._notifierList)); + FieldSet defaultUserLocaleFields = fields.extractPrefixed(this.asPrefix(TenantConfiguration._defaultUserLocale)); + + + List models = new ArrayList<>(); + for (TenantConfigurationEntity d : data) { + TenantConfiguration m = new TenantConfiguration(); + if (fields.hasField(this.asIndexer(TenantConfiguration._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(TenantConfiguration._type))) m.setType(d.getType()); + if (!notifierListFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.NotifierList.equals(d.getType())){ + NotifierListTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(NotifierListTenantConfigurationEntity.class, d.getValue()); + m.setNotifierList(this.builderFactory.builder(NotifierListTenantConfigurationBuilder.class).authorize(this.authorize).build(notifierListFields, valueTyped)); + } + if (!defaultUserLocaleFields.isEmpty() && !this.conventionService.isNullOrEmpty(d.getValue()) && TenantConfigurationType.DefaultUserLocale.equals(d.getType())){ + DefaultUserLocaleTenantConfigurationEntity valueTyped = this.jsonHandlingService.fromJsonSafe(DefaultUserLocaleTenantConfigurationEntity.class, d.getValue()); + m.setDefaultUserLocale(this.builderFactory.builder(DefaultUserLocaleTenantConfigurationBuilder.class).authorize(this.authorize).build(defaultUserLocaleFields, valueTyped)); + } + if (fields.hasField(this.asIndexer(TenantConfiguration._createdAt))) m.setCreatedAt(d.getCreatedAt()); + if (fields.hasField(this.asIndexer(TenantConfiguration._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); + if (fields.hasField(this.asIndexer(TenantConfiguration._isActive))) m.setIsActive(d.getIsActive()); + if (fields.hasField(this.asIndexer(TenantConfiguration._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); + if (fields.hasField(this.asIndexer(TenantConfiguration._belongsToCurrentTenant))) m.setBelongsToCurrentTenant(this.getBelongsToCurrentTenant(d, this.tenantScope)); + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/TenantConfigurationCensor.java b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/TenantConfigurationCensor.java deleted file mode 100644 index d3b099193..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/TenantConfigurationCensor.java +++ /dev/null @@ -1,32 +0,0 @@ -package gr.cite.notification.model.censorship; - -import gr.cite.commons.web.authz.service.AuthorizationService; -import gr.cite.notification.authorization.Permission; -import gr.cite.notification.convention.ConventionService; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.DataLogEntry; -import gr.cite.tools.logging.LoggerService; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class TenantConfigurationCensor extends BaseCensor { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationCensor.class)); - private final AuthorizationService authService; - - @Autowired - public TenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService) { - super(conventionService); - this.authService = authService; - } - - public void censor(FieldSet fields) { - logger.debug(new DataLogEntry("censoring fields", fields)); - if (this.isEmpty(fields)) return; - this.authService.authorizeForce(Permission.BrowseTenantConfiguration); - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/DefaultUserLocaleTenantConfigurationCensor.java b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/DefaultUserLocaleTenantConfigurationCensor.java new file mode 100644 index 000000000..56b215ba7 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/DefaultUserLocaleTenantConfigurationCensor.java @@ -0,0 +1,38 @@ +package gr.cite.notification.model.censorship.tenantconfiguration; + +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.notification.authorization.Permission; +import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.model.censorship.BaseCensor; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DefaultUserLocaleTenantConfigurationCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DefaultUserLocaleTenantConfigurationCensor.class)); + + protected final AuthorizationService authService; + + + public DefaultUserLocaleTenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService) { + super(conventionService); + this.authService = authService; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + this.authService.authorize(Permission.BrowseTenantConfiguration); + } + +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/NotifierListTenantConfigurationCensor.java b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/NotifierListTenantConfigurationCensor.java new file mode 100644 index 000000000..9d396fe77 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/NotifierListTenantConfigurationCensor.java @@ -0,0 +1,38 @@ +package gr.cite.notification.model.censorship.tenantconfiguration; + +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.notification.authorization.Permission; +import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.model.censorship.BaseCensor; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class NotifierListTenantConfigurationCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifierListTenantConfigurationCensor.class)); + + protected final AuthorizationService authService; + + + public NotifierListTenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService) { + super(conventionService); + this.authService = authService; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + this.authService.authorize(Permission.BrowseTenantConfiguration); + } + +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/TenantConfigurationCensor.java b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/TenantConfigurationCensor.java new file mode 100644 index 000000000..6dd0515b2 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/tenantconfiguration/TenantConfigurationCensor.java @@ -0,0 +1,49 @@ +package gr.cite.notification.model.censorship.tenantconfiguration; + +import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.notification.authorization.Permission; +import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.model.censorship.BaseCensor; +import gr.cite.tools.data.censor.CensorFactory; +import gr.cite.tools.fieldset.FieldSet; +import gr.cite.tools.logging.DataLogEntry; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import gr.cite.notification.model.tenantconfiguration.TenantConfiguration; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class TenantConfigurationCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationCensor.class)); + + protected final AuthorizationService authService; + + protected final CensorFactory censorFactory; + + + public TenantConfigurationCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) { + super(conventionService); + this.authService = authService; + this.censorFactory = censorFactory; + } + + public void censor(FieldSet fields, UUID userId) { + logger.debug(new DataLogEntry("censoring fields", fields)); + if (fields == null || fields.isEmpty()) + return; + this.authService.authorize(Permission.BrowseTenantConfiguration); + + FieldSet cssColorsFields = fields.extractPrefixed(this.asIndexerPrefix(TenantConfiguration._notifierList)); + this.censorFactory.censor(NotifierListTenantConfigurationCensor.class).censor(cssColorsFields, userId); + + FieldSet defaultUserLocaleFields = fields.extractPrefixed(this.asIndexerPrefix(TenantConfiguration._defaultUserLocale)); + this.censorFactory.censor(DefaultUserLocaleTenantConfigurationCensor.class).censor(defaultUserLocaleFields, userId); + } + +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/deleter/TenantConfigurationDeleter.java b/notification-service/notification/src/main/java/gr/cite/notification/model/deleter/TenantConfigurationDeleter.java index 5db6972e4..36a6c2d26 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/deleter/TenantConfigurationDeleter.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/deleter/TenantConfigurationDeleter.java @@ -29,17 +29,14 @@ public class TenantConfigurationDeleter implements Deleter { private final TenantEntityManager entityManager; protected final QueryFactory queryFactory; - private final DeleterFactory deleterFactory; @Autowired public TenantConfigurationDeleter( TenantEntityManager entityManager, - QueryFactory queryFactory, - DeleterFactory deleterFactory + QueryFactory queryFactory ) { this.entityManager = entityManager; this.queryFactory = queryFactory; - this.deleterFactory = deleterFactory; } public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { @@ -61,7 +58,7 @@ public class TenantConfigurationDeleter implements Deleter { logger.debug("will delete {} items", Optional.ofNullable(datas).map(List::size).orElse(0)); if (datas == null || datas.isEmpty()) return; - List ids = datas.stream().map(TenantConfigurationEntity::getId).distinct().collect(Collectors.toList()); + List ids = datas.stream().map(TenantConfigurationEntity::getId).distinct().toList(); Instant now = Instant.now(); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/DefaultUserLocaleTenantConfigurationPersist.java b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/DefaultUserLocaleTenantConfigurationPersist.java new file mode 100644 index 000000000..52862fe28 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/DefaultUserLocaleTenantConfigurationPersist.java @@ -0,0 +1,82 @@ +package gr.cite.notification.model.persist.tenantconfiguration; + +import gr.cite.notification.common.validation.BaseValidator; +import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.validation.specification.Specification; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; + +public class DefaultUserLocaleTenantConfigurationPersist { + private String timezone; + public static final String _timezone = "timezone"; + private String language; + public static final String _language = "language"; + private String culture; + public static final String _culture = "culture"; + + public String getTimezone() { + return timezone; + } + + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getCulture() { + return culture; + } + + public void setCulture(String culture) { + this.culture = culture; + } + + @Component(DefaultUserLocaleTenantConfigurationPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class DefaultUserLocaleTenantConfigurationPersistValidator extends BaseValidator { + + public static final String ValidatorName = "DefaultUserLocaleTenantConfigurationPersistValidator"; + + private final MessageSource messageSource; + + protected DefaultUserLocaleTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return DefaultUserLocaleTenantConfigurationPersist.class; + } + + @Override + protected List specifications(DefaultUserLocaleTenantConfigurationPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getTimezone())) + .failOn(DefaultUserLocaleTenantConfigurationPersist._timezone).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._timezone}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getLanguage())) + .failOn(DefaultUserLocaleTenantConfigurationPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._language}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isEmpty(item.getCulture())) + .failOn(DefaultUserLocaleTenantConfigurationPersist._culture).failWith(messageSource.getMessage("Validation_Required", new Object[]{DefaultUserLocaleTenantConfigurationPersist._culture}, LocaleContextHolder.getLocale())) + ); + } + } +} + diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/NotifierListTenantConfigurationPersist.java b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/NotifierListTenantConfigurationPersist.java new file mode 100644 index 000000000..81ee82997 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/NotifierListTenantConfigurationPersist.java @@ -0,0 +1,54 @@ +package gr.cite.notification.model.persist.tenantconfiguration; + +import gr.cite.notification.common.enums.NotificationContactType; +import gr.cite.notification.common.validation.BaseValidator; +import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.validation.specification.Specification; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.*; + +public class NotifierListTenantConfigurationPersist { + private Map> notifiers; + public static final String _notifiers = "notifiers"; + public Map> getNotifiers() { + return notifiers; + } + + public void setNotifiers(Map> notifiers) { + this.notifiers = notifiers; + } + + @Component(NotifierListTenantConfigurationPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class NotifierListTenantConfigurationPersistValidator extends BaseValidator { + + public static final String ValidatorName = "NotifierListTenantConfigurationPersistValidator"; + + private final MessageSource messageSource; + + protected NotifierListTenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return NotifierListTenantConfigurationPersist.class; + } + + @Override + protected List specifications(NotifierListTenantConfigurationPersist item) { + return Collections.singletonList( + this.spec() + .must(() -> !this.isNull(item.getNotifiers())) + .failOn(NotifierListTenantConfigurationPersist._notifiers).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotifierListTenantConfigurationPersist._notifiers}, LocaleContextHolder.getLocale())) + ); + } + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationEmailClientPersist.java b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationEmailClientPersist.java deleted file mode 100644 index 7f3063e6d..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationEmailClientPersist.java +++ /dev/null @@ -1,177 +0,0 @@ -package gr.cite.notification.model.persist.tenantconfiguration; - -import gr.cite.notification.common.validation.BaseValidator; -import gr.cite.notification.convention.ConventionService; -import gr.cite.notification.errorcode.ErrorThesaurusProperties; -import gr.cite.tools.validation.specification.Specification; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Scope; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -public class TenantConfigurationEmailClientPersist { - private UUID id; - public static final String _id = "id"; - private Boolean requireCredentials; - public static final String _requireCredentials = "requireCredentials"; - private Boolean enableSSL; - public static final String _enableSSL = "enableSSL"; - private String certificatePath; - public static final String _certificatePath = "certificatePath"; - private String hostServer; - public static final String _hostServer = "hostServer"; - private Integer hostPortNo; - public static final String _hostPortNo = "hostPortNo"; - private String emailAddress; - public static final String _emailAddress = "emailAddress"; - private String emailUserName; - public static final String _emailUserName = "emailUserName"; - private String emailPassword; - public static final String _emailPassword = "emailPassword"; - private String hash; - public static final String _hash = "hash"; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public Boolean getRequireCredentials() { - return requireCredentials; - } - - public void setRequireCredentials(Boolean requireCredentials) { - this.requireCredentials = requireCredentials; - } - - public Boolean getEnableSSL() { - return enableSSL; - } - - public void setEnableSSL(Boolean enableSSL) { - this.enableSSL = enableSSL; - } - - public String getCertificatePath() { - return certificatePath; - } - - public void setCertificatePath(String certificatePath) { - this.certificatePath = certificatePath; - } - - public String getHostServer() { - return hostServer; - } - - public void setHostServer(String hostServer) { - this.hostServer = hostServer; - } - - public Integer getHostPortNo() { - return hostPortNo; - } - - public void setHostPortNo(Integer hostPortNo) { - this.hostPortNo = hostPortNo; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public String getEmailUserName() { - return emailUserName; - } - - public void setEmailUserName(String emailUserName) { - this.emailUserName = emailUserName; - } - - public String getEmailPassword() { - return emailPassword; - } - - public void setEmailPassword(String emailPassword) { - this.emailPassword = emailPassword; - } - - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - - @Component(TenantConfigurationEmailClientPersist.TenantConfigurationEmailClientPersistValidator.ValidatorName) - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public static class TenantConfigurationEmailClientPersistValidator extends BaseValidator { - - public static final String ValidatorName = "TenantConfigurationEmailClientPersistValidator"; - - private final MessageSource messageSource; - - protected TenantConfigurationEmailClientPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { - super(conventionService, errors); - this.messageSource = messageSource; - } - - @Override - protected Class modelClass() { - return TenantConfigurationEmailClientPersist.class; - } - - @Override - protected List specifications(TenantConfigurationEmailClientPersist item) { - return Arrays.asList( - this.spec() - .iff(() -> this.isValidGuid(item.getId())) - .must(() -> this.isValidHash(item.getHash())) - .failOn(TenantConfigurationEmailClientPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hash}, LocaleContextHolder.getLocale())), - this.spec() - .iff(() -> !this.isValidGuid(item.getId())) - .must(() -> !this.isValidHash(item.getHash())) - .failOn(TenantConfigurationEmailClientPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), - - this.spec() - .must(() -> !this.isNull(item.getRequireCredentials())) - .failOn(TenantConfigurationEmailClientPersist._requireCredentials).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._requireCredentials}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getEnableSSL())) - .failOn(TenantConfigurationEmailClientPersist._enableSSL).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._enableSSL}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getCertificatePath())) - .failOn(TenantConfigurationEmailClientPersist._certificatePath).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._certificatePath}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getHostServer())) - .failOn(TenantConfigurationEmailClientPersist._hostServer).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hostServer}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getHostPortNo())) - .failOn(TenantConfigurationEmailClientPersist._hostPortNo).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hostPortNo}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getEmailAddress())) - .failOn(TenantConfigurationEmailClientPersist._emailAddress).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailAddress}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getEmailUserName())) - .failOn(TenantConfigurationEmailClientPersist._emailUserName).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailUserName}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getEmailPassword())) - .failOn(TenantConfigurationEmailClientPersist._emailPassword).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailPassword}, LocaleContextHolder.getLocale())) - - ); - } - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationNotifierListPersist.java b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationNotifierListPersist.java deleted file mode 100644 index 7152ff49b..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationNotifierListPersist.java +++ /dev/null @@ -1,86 +0,0 @@ -package gr.cite.notification.model.persist.tenantconfiguration; - -import gr.cite.notification.common.enums.NotificationContactType; -import gr.cite.notification.common.validation.BaseValidator; -import gr.cite.notification.convention.ConventionService; -import gr.cite.notification.errorcode.ErrorThesaurusProperties; -import gr.cite.tools.validation.specification.Specification; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Scope; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public class TenantConfigurationNotifierListPersist { - private UUID id; - public static final String _id = "id"; - private Map> notifiers; - public static final String _notifiers = "notifiers"; - private String hash; - public static final String _hash = "hash"; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public Map> getNotifiers() { - return notifiers; - } - - public void setNotifiers(Map> notifiers) { - this.notifiers = notifiers; - } - - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - - @Component(TenantConfigurationNotifierListPersist.TenantConfigurationNotifierListPersistValidator.ValidatorName) - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public static class TenantConfigurationNotifierListPersistValidator extends BaseValidator { - - public static final String ValidatorName = "TenantConfigurationNotifierListPersistValidator"; - - private final MessageSource messageSource; - - protected TenantConfigurationNotifierListPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { - super(conventionService, errors); - this.messageSource = messageSource; - } - - @Override - protected Class modelClass() { - return TenantConfigurationNotifierListPersist.class; - } - - @Override - protected List specifications(TenantConfigurationNotifierListPersist item) { - return Arrays.asList( - this.spec() - .iff(() -> this.isValidGuid(item.getId())) - .must(() -> this.isValidHash(item.getHash())) - .failOn(TenantConfigurationNotifierListPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationNotifierListPersist._hash}, LocaleContextHolder.getLocale())), - this.spec() - .iff(() -> !this.isValidGuid(item.getId())) - .must(() -> !this.isValidHash(item.getHash())) - .failOn(TenantConfigurationNotifierListPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getNotifiers())) - .failOn(TenantConfigurationNotifierListPersist._notifiers).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationNotifierListPersist._notifiers}, LocaleContextHolder.getLocale())) - ); - } - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationPersist.java b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationPersist.java new file mode 100644 index 000000000..a40bb0750 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationPersist.java @@ -0,0 +1,142 @@ +package gr.cite.notification.model.persist.tenantconfiguration; + +import gr.cite.notification.common.enums.TenantConfigurationType; +import gr.cite.notification.common.validation.BaseValidator; +import gr.cite.notification.convention.ConventionService; +import gr.cite.notification.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +public class TenantConfigurationPersist { + + private UUID id; + + public static final String _id = "id"; + + private TenantConfigurationType type; + + public static final String _type = "type"; + + private NotifierListTenantConfigurationPersist notifierList; + + public static final String _notifierList = "notifierList"; + + private DefaultUserLocaleTenantConfigurationPersist defaultUserLocale; + + public static final String _defaultUserLocale = "defaultUserLocale"; + + private String hash; + + public static final String _hash = "hash"; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public NotifierListTenantConfigurationPersist getNotifierList() { + return notifierList; + } + + public void setNotifierList(NotifierListTenantConfigurationPersist notifierList) { + this.notifierList = notifierList; + } + + public DefaultUserLocaleTenantConfigurationPersist getDefaultUserLocale() { + return defaultUserLocale; + } + + public void setDefaultUserLocale(DefaultUserLocaleTenantConfigurationPersist defaultUserLocale) { + this.defaultUserLocale = defaultUserLocale; + } + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } + + public TenantConfigurationType getType() { + return type; + } + + public void setType(TenantConfigurationType type) { + this.type = type; + } + + + + @Component(TenantConfigurationPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class TenantConfigurationPersistValidator extends BaseValidator { + + public static final String ValidatorName = "TenantConfigurationPersistValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected TenantConfigurationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return TenantConfigurationPersist.class; + } + + @Override + protected List specifications(TenantConfigurationPersist item) { + return Arrays.asList( + this.spec() + .iff(() -> this.isValidGuid(item.getId())) + .must(() -> this.isValidHash(item.getHash())) + .failOn(TenantConfigurationPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._hash}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isValidGuid(item.getId())) + .must(() -> !this.isValidHash(item.getHash())) + .failOn(TenantConfigurationPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isNull(item.getType())) + .failOn(TenantConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._type}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.DefaultUserLocale.equals(item.getType())) + .must(() -> !this.isNull(item.getDefaultUserLocale())) + .failOn(TenantConfigurationPersist._defaultUserLocale).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._defaultUserLocale}, LocaleContextHolder.getLocale())), + this.spec() + .iff(() -> !this.isNull(item.getType()) && TenantConfigurationType.NotifierList.equals(item.getType())) + .must(() -> !this.isNull(item.getNotifierList())) + .failOn(TenantConfigurationPersist._notifierList).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationPersist._notifierList}, LocaleContextHolder.getLocale())), + + + this.refSpec() + .iff(() -> !this.isNull(item.getDefaultUserLocale()) && TenantConfigurationType.DefaultUserLocale.equals(item.getType())) + .on(TenantConfigurationPersist._defaultUserLocale) + .over(item.getDefaultUserLocale()) + .using(() -> this.validatorFactory.validator(DefaultUserLocaleTenantConfigurationPersist.DefaultUserLocaleTenantConfigurationPersistValidator.class)), + this.refSpec() + .iff(() -> !this.isNull(item.getNotifierList()) && TenantConfigurationType.NotifierList.equals(item.getType())) + .on(TenantConfigurationPersist._notifierList) + .over(item.getNotifierList()) + .using(() -> this.validatorFactory.validator(NotifierListTenantConfigurationPersist.NotifierListTenantConfigurationPersistValidator.class)) + + ); + } + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationUserLocaleIntegrationPersist.java b/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationUserLocaleIntegrationPersist.java deleted file mode 100644 index a6e15c081..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/persist/tenantconfiguration/TenantConfigurationUserLocaleIntegrationPersist.java +++ /dev/null @@ -1,92 +0,0 @@ -package gr.cite.notification.model.persist.tenantconfiguration; - -import gr.cite.notification.common.validation.BaseValidator; -import gr.cite.notification.convention.ConventionService; -import gr.cite.notification.errorcode.ErrorThesaurusProperties; -import gr.cite.tools.validation.specification.Specification; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Scope; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; - -public class TenantConfigurationUserLocaleIntegrationPersist { - private String language; - public static final String _language = "language"; - private String timeZone; - public static final String _timeZone = "timeZone"; - private String culture; - public static final String _culture = "culture"; - - private String hash; - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public String getTimeZone() { - return timeZone; - } - - public void setTimeZone(String timeZone) { - this.timeZone = timeZone; - } - - public String getCulture() { - return culture; - } - - public void setCulture(String culture) { - this.culture = culture; - } - - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - - @Component(TenantConfigurationUserLocaleIntegrationPersist.TenantConfigurationUserLocaleIntegrationPersistValidator.ValidatorName) - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public static class TenantConfigurationUserLocaleIntegrationPersistValidator extends BaseValidator { - - public static final String ValidatorName = "TenantConfigurationUserLocaleIntegrationPersistValidator"; - - private final MessageSource messageSource; - - protected TenantConfigurationUserLocaleIntegrationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { - super(conventionService, errors); - this.messageSource = messageSource; - } - - @Override - protected Class modelClass() { - return TenantConfigurationUserLocaleIntegrationPersist.class; - } - - @Override - protected List specifications(TenantConfigurationUserLocaleIntegrationPersist item) { - return Arrays.asList( - this.spec() - .must(() -> !this.isNull(item.getLanguage())) - .failOn(TenantConfigurationUserLocaleIntegrationPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._language}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getTimeZone())) - .failOn(TenantConfigurationUserLocaleIntegrationPersist._timeZone).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._timeZone}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getCulture())) - .failOn(TenantConfigurationUserLocaleIntegrationPersist._culture).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._culture}, LocaleContextHolder.getLocale())) - - ); - } - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantConfig.java b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantConfig.java deleted file mode 100644 index cd55d9c64..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package gr.cite.notification.model.tenantconfig; - - -public class TenantConfig { - - public static final String _deposit = "deposit"; - private TenantDepositConfig deposit; - - public static final String _fileTransformers = "fileTransformers"; - private TenantFileTransformersConfig fileTransformers; - - public TenantDepositConfig getDeposit() { - return deposit; - } - - public void setDeposit(TenantDepositConfig deposit) { - this.deposit = deposit; - } - - public TenantFileTransformersConfig getFileTransformers() { - return fileTransformers; - } - - public void setFileTransformers(TenantFileTransformersConfig fileTransformers) { - this.fileTransformers = fileTransformers; - } -} - diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantDepositConfig.java b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantDepositConfig.java deleted file mode 100644 index 2a0517b64..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantDepositConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package gr.cite.notification.model.tenantconfig; - -import java.util.List; - -public class TenantDepositConfig { - - public static final String _sources = "sources"; - private List sources; - - public List getSources() { - return sources; - } - - public void setSources(List sources) { - this.sources = sources; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantFileTransformersConfig.java b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantFileTransformersConfig.java deleted file mode 100644 index c7b6c0cc2..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantFileTransformersConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package gr.cite.notification.model.tenantconfig; - -import java.util.List; - -public class TenantFileTransformersConfig { - - public static final String _sources = "sources"; - private List sources; - - public List getSources() { - return sources; - } - - public void setSources(List sources) { - this.sources = sources; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantSource.java b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantSource.java deleted file mode 100644 index 5003b7781..000000000 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfig/TenantSource.java +++ /dev/null @@ -1,73 +0,0 @@ -package gr.cite.notification.model.tenantconfig; - - -import java.util.List; - -public class TenantSource { - - public static final String _url = "url"; - private String url; - - public static final String _codes = "codes"; - private List codes; - - public static final String _issuerUrl = "issuerUrl"; - private String issuerUrl; - - public static final String _clientId = "clientId"; - private String clientId; - - public static final String _clientSecret = "clientSecret"; - private String clientSecret; - - public static final String _scope = "scope"; - private String scope; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public List getCodes() { - return codes; - } - - public void setCodes(List codes) { - this.codes = codes; - } - - public String getIssuerUrl() { - return issuerUrl; - } - - public void setIssuerUrl(String issuerUrl) { - this.issuerUrl = issuerUrl; - } - - public String getClientId() { - return clientId; - } - - public void setClientId(String clientId) { - this.clientId = clientId; - } - - public String getClientSecret() { - return clientSecret; - } - - public void setClientSecret(String clientSecret) { - this.clientSecret = clientSecret; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } -} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/DefaultUserLocaleTenantConfiguration.java b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/DefaultUserLocaleTenantConfiguration.java new file mode 100644 index 000000000..24d068e61 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/DefaultUserLocaleTenantConfiguration.java @@ -0,0 +1,35 @@ +package gr.cite.notification.model.tenantconfiguration; + +public class DefaultUserLocaleTenantConfiguration { + private String timezone; + public static final String _timezone = "timezone"; + private String language; + public static final String _language = "language"; + private String culture; + public static final String _culture = "culture"; + + public String getTimezone() { + return timezone; + } + + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getCulture() { + return culture; + } + + public void setCulture(String culture) { + this.culture = culture; + } +} + diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/NotifierListTenantConfiguration.java b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/NotifierListTenantConfiguration.java new file mode 100644 index 000000000..77a5618ee --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/NotifierListTenantConfiguration.java @@ -0,0 +1,21 @@ +package gr.cite.notification.model.tenantconfiguration; + +import gr.cite.notification.common.enums.NotificationContactType; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public class NotifierListTenantConfiguration { + + private Map> notifiers; + public static final String _notifiers = "notifiers"; + + public Map> getNotifiers() { + return notifiers; + } + + public void setNotifiers(Map> notifiers) { + this.notifiers = notifiers; + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/TenantConfiguration.java b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/TenantConfiguration.java new file mode 100644 index 000000000..c927cc7f1 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/tenantconfiguration/TenantConfiguration.java @@ -0,0 +1,118 @@ +package gr.cite.notification.model.tenantconfiguration; + +import gr.cite.notification.common.enums.IsActive; +import gr.cite.notification.common.enums.TenantConfigurationType; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; + +import java.time.Instant; +import java.util.UUID; + +public class TenantConfiguration { + + private UUID id; + + public static final String _id = "id"; + + private TenantConfigurationType type; + + public static final String _type = "type"; + + private Instant createdAt; + + public static final String _createdAt = "createdAt"; + + private NotifierListTenantConfiguration notifierList; + + public static final String _notifierList = "notifierList"; + + private DefaultUserLocaleTenantConfiguration defaultUserLocale; + + public static final String _defaultUserLocale = "defaultUserLocale"; + + private Instant updatedAt; + + public static final String _updatedAt = "updatedAt"; + + private IsActive isActive; + + public static final String _isActive = "isActive"; + + private String hash; + + public static final String _hash = "hash"; + + private Boolean belongsToCurrentTenant; + public static final String _belongsToCurrentTenant = "belongsToCurrentTenant"; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public Instant getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Instant createdAt) { + this.createdAt = createdAt; + } + + public NotifierListTenantConfiguration getNotifierList() { + return notifierList; + } + + public void setNotifierList(NotifierListTenantConfiguration notifierList) { + this.notifierList = notifierList; + } + + public DefaultUserLocaleTenantConfiguration getDefaultUserLocale() { + return defaultUserLocale; + } + + public void setDefaultUserLocale(DefaultUserLocaleTenantConfiguration defaultUserLocale) { + this.defaultUserLocale = defaultUserLocale; + } + + public Instant getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Instant updatedAt) { + this.updatedAt = updatedAt; + } + + public IsActive getIsActive() { + return isActive; + } + + public void setIsActive(IsActive isActive) { + this.isActive = isActive; + } + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } + + public Boolean getBelongsToCurrentTenant() { + return belongsToCurrentTenant; + } + + public void setBelongsToCurrentTenant(Boolean belongsToCurrentTenant) { + this.belongsToCurrentTenant = belongsToCurrentTenant; + } + + public TenantConfigurationType getType() { + return type; + } + + public void setType(TenantConfigurationType type) { + this.type = type; + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/query/TenantConfigurationQuery.java b/notification-service/notification/src/main/java/gr/cite/notification/query/TenantConfigurationQuery.java index 2420bc696..35f3ce586 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/query/TenantConfigurationQuery.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/query/TenantConfigurationQuery.java @@ -1,13 +1,15 @@ package gr.cite.notification.query; +import gr.cite.notification.authorization.AuthorizationFlags; import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.TenantConfigurationType; import gr.cite.notification.data.TenantConfigurationEntity; -import gr.cite.notification.model.TenantConfiguration; +import gr.cite.notification.model.tenantconfiguration.TenantConfiguration; 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; @@ -20,45 +22,106 @@ import java.util.*; @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class TenantConfigurationQuery extends QueryBase { - private List ids; + private Collection ids; + private Collection tenantIds; + private Boolean tenantIsSet; + private Collection isActives; + private Collection types; + private Collection excludedIds; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - private List isActives; - private List type; + public TenantConfigurationQuery() { + } - public TenantConfigurationQuery ids(UUID... ids) { - this.ids = Arrays.asList(ids); + public TenantConfigurationQuery ids(UUID value) { + this.ids = List.of(value); return this; } - public TenantConfigurationQuery ids(List ids) { - this.ids = ids; + public TenantConfigurationQuery ids(UUID... value) { + this.ids = Arrays.asList(value); return this; } - public TenantConfigurationQuery isActive(IsActive... isActives) { - this.isActives = Arrays.asList(isActives); + public TenantConfigurationQuery ids(Collection values) { + this.ids = values; return this; } - public TenantConfigurationQuery isActive(List isActive) { - this.isActives = isActive; + public TenantConfigurationQuery tenantIds(UUID value) { + this.tenantIds = List.of(value); return this; } - public TenantConfigurationQuery type(TenantConfigurationType... type) { - this.type = Arrays.asList(type); + public TenantConfigurationQuery tenantIds(UUID... value) { + this.tenantIds = Arrays.asList(value); return this; } - public TenantConfigurationQuery type(List type) { - this.type = type; + public TenantConfigurationQuery tenantIds(Collection values) { + this.tenantIds = values; + return this; + } + + public TenantConfigurationQuery tenantIsSet(Boolean values) { + this.tenantIsSet = values; + return this; + } + + public TenantConfigurationQuery isActive(IsActive value) { + this.isActives = List.of(value); + return this; + } + + public TenantConfigurationQuery isActive(IsActive... value) { + this.isActives = Arrays.asList(value); + return this; + } + + public TenantConfigurationQuery isActive(Collection values) { + this.isActives = values; + return this; + } + + public TenantConfigurationQuery types(TenantConfigurationType value) { + this.types = List.of(value); + return this; + } + + public TenantConfigurationQuery types(TenantConfigurationType... value) { + this.types = Arrays.asList(value); + return this; + } + + public TenantConfigurationQuery types(Collection values) { + this.types = values; + return this; + } + + public TenantConfigurationQuery excludedIds(Collection values) { + this.excludedIds = values; + return this; + } + + public TenantConfigurationQuery excludedIds(UUID value) { + this.excludedIds = List.of(value); + return this; + } + + public TenantConfigurationQuery excludedIds(UUID... value) { + this.excludedIds = Arrays.asList(value); + return this; + } + + public TenantConfigurationQuery authorize(EnumSet values) { + this.authorize = values; return this; } @Override protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.isActives); + return this.isEmpty(this.ids) ||this.isEmpty(this.isActives) ||this.isEmpty(this.types) || this.isEmpty(this.tenantIds); } @Override @@ -70,15 +133,41 @@ public class TenantConfigurationQuery extends QueryBase Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); if (this.ids != null) { - predicates.add(queryContext.Root.get(TenantConfigurationEntity._id).in(ids)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._id)); + for (UUID item : this.ids) inClause.value(item); + predicates.add(inClause); + } + + if (this.tenantIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._tenantId)); + for (UUID item : this.tenantIds) inClause.value(item); + predicates.add(inClause); } if (this.isActives != null) { - predicates.add(queryContext.Root.get(TenantConfigurationEntity._isActive).in(isActives)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._isActive)); + for (IsActive item : this.isActives) inClause.value(item); + predicates.add(inClause); } - if (type != null) { - predicates.add(queryContext.Root.get(TenantConfigurationEntity._type).in(type)); + if (this.tenantIsSet != null) { + if (this.tenantIsSet) predicates.add(queryContext.CriteriaBuilder.isNotNull(queryContext.Root.get(TenantConfigurationEntity._tenantId))); + else predicates.add(queryContext.CriteriaBuilder.isNull(queryContext.Root.get(TenantConfigurationEntity._tenantId))); + } + + + + if (this.types != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._type)); + for (TenantConfigurationType item : this.types) inClause.value(item); + predicates.add(inClause); + } + + if (this.excludedIds != null) { + CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(TenantConfigurationEntity._id)); + for (UUID item : this.excludedIds) + notInClause.value(item); + predicates.add(notInClause.not()); } if (!predicates.isEmpty()) { @@ -90,42 +179,31 @@ public class TenantConfigurationQuery extends QueryBase columns) { TenantConfigurationEntity item = new TenantConfigurationEntity(); item.setId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._id, UUID.class)); item.setValue(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._value, String.class)); - item.setType(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._type, TenantConfigurationType.class)); item.setTenantId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._tenantId, UUID.class)); + item.setType(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._type, TenantConfigurationType.class)); item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._createdAt, Instant.class)); item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._updatedAt, Instant.class)); item.setIsActive(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._isActive, IsActive.class)); return item; } -} + + @Override + protected String fieldNameOf(FieldResolver item) { + if (item.match(TenantConfiguration._id)) return TenantConfigurationEntity._id; + else if (item.match(TenantConfiguration._type)) return TenantConfigurationEntity._type; + else if (item.prefix(TenantConfiguration._notifierList)) return TenantConfigurationEntity._value; + else if (item.match(TenantConfiguration._notifierList)) return TenantConfigurationEntity._value; + else if (item.match(TenantConfiguration._createdAt)) return TenantConfigurationEntity._createdAt; + else if (item.match(TenantConfiguration._updatedAt)) return TenantConfigurationEntity._updatedAt; + else if (item.match(TenantConfiguration._isActive)) return TenantConfigurationEntity._isActive; + else if (item.match(TenantConfiguration._belongsToCurrentTenant)) return TenantConfigurationEntity._tenantId; + else if (item.match(TenantConfigurationEntity._tenantId)) return TenantConfigurationEntity._tenantId; + else return null; + } + +} \ No newline at end of file diff --git a/notification-service/notification/src/main/java/gr/cite/notification/query/lookup/TenantConfigurationLookup.java b/notification-service/notification/src/main/java/gr/cite/notification/query/lookup/TenantConfigurationLookup.java index b31ea5f62..af35dd53d 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/query/lookup/TenantConfigurationLookup.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/query/lookup/TenantConfigurationLookup.java @@ -11,16 +11,21 @@ import java.util.List; import java.util.UUID; public class TenantConfigurationLookup extends Lookup { - private List ids; - private List isActives; - private List type; - public List getIsActives() { - return isActives; + private List isActive; + private List types; + private List ids; + private List tenantIds; + private List excludedIds; + private Boolean tenantIsSet; + + + public List getIsActive() { + return isActive; } - public void setIsActives(List isActive) { - this.isActives = isActive; + public void setIsActive(List isActive) { + this.isActive = isActive; } public List getIds() { @@ -31,23 +36,49 @@ public class TenantConfigurationLookup extends Lookup { this.ids = ids; } - public List getType() { - return type; + public List getExcludedIds() { + return excludedIds; } - public void setType(List type) { - this.type = type; + public void setExcludedIds(List excludeIds) { + this.excludedIds = excludeIds; + } + + public List getTypes() { + return types; + } + + public void setTypes(List types) { + this.types = types; + } + + public List getTenantIds() { + return tenantIds; + } + + public void setTenantIds(List tenantIds) { + this.tenantIds = tenantIds; + } + + public Boolean getTenantIsSet() { + return tenantIsSet; + } + + public void setTenantIsSet(Boolean tenantIsSet) { + this.tenantIsSet = tenantIsSet; } public TenantConfigurationQuery enrich(QueryFactory queryFactory) { TenantConfigurationQuery query = queryFactory.query(TenantConfigurationQuery.class); - if (this.isActives != null) query.isActive(this.isActives); + if (this.types != null) query.types(this.types); + if (this.isActive != null) query.isActive(this.isActive); if (this.ids != null) query.ids(this.ids); - if (this.type != null) query.type(this.type); + if (this.excludedIds != null) query.excludedIds(this.excludedIds); + if (this.tenantIds != null) query.tenantIds(this.tenantIds); + if (this.tenantIsSet != null) query.tenantIsSet(this.tenantIsSet); this.enrichCommon(query); return query; } - } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/channelResolution/ChannelResolutionServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/channelResolution/ChannelResolutionServiceImpl.java index 1495a556a..22593c7f3 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/channelResolution/ChannelResolutionServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/channelResolution/ChannelResolutionServiceImpl.java @@ -1,7 +1,7 @@ package gr.cite.notification.service.channelResolution; import gr.cite.notification.common.enums.NotificationContactType; -import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; import gr.cite.notification.config.notification.NotificationConfig; import gr.cite.notification.errorcode.ErrorThesaurusProperties; import gr.cite.notification.model.UserNotificationPreference; @@ -97,7 +97,7 @@ public class ChannelResolutionServiceImpl implements ChannelResolutionService{ } private List lookupOrCollectTenantPolicies(UUID type) { - NotifierListConfigurationDataContainer container = this.tenantConfigurationService.collectTenantNotifierList(); + NotifierListTenantConfigurationEntity container = this.tenantConfigurationService.collectTenantNotifierList(); if (container == null || container.getNotifiers() == null) return null; return container.getNotifiers().get(type); } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingServiceConfiguration.java b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceConfiguration.java similarity index 84% rename from notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingServiceConfiguration.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceConfiguration.java index 2287c3638..8b4530743 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingServiceConfiguration.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceConfiguration.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.formatting; +package gr.cite.notification.service.formatting; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceImpl.java index 4f7cfebe6..22266bdb3 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceImpl.java @@ -1,14 +1,8 @@ package gr.cite.notification.service.formatting; -import gr.cite.notification.cache.FormattingUserprofileCacheCacheService; -import gr.cite.notification.config.formatting.FormattingServiceProperties; import gr.cite.notification.convention.ConventionService; -import gr.cite.notification.data.UserEntity; import gr.cite.notification.locale.LocaleService; -import gr.cite.notification.model.User; -import gr.cite.notification.query.UserQuery; import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.fieldset.BaseFieldSet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingServiceProperties.java b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceProperties.java similarity index 95% rename from notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingServiceProperties.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceProperties.java index 39f517869..48126d18f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingServiceProperties.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingServiceProperties.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.formatting; +package gr.cite.notification.service.formatting; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/cache/FormattingUserprofileCacheCacheService.java b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingUserprofileCacheCacheService.java similarity index 94% rename from notification-service/notification/src/main/java/gr/cite/notification/cache/FormattingUserprofileCacheCacheService.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingUserprofileCacheCacheService.java index b208526a8..d07091aa9 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/cache/FormattingUserprofileCacheCacheService.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingUserprofileCacheCacheService.java @@ -1,7 +1,6 @@ -package gr.cite.notification.cache; +package gr.cite.notification.service.formatting; import gr.cite.notification.event.UserTouchedEvent; -import gr.cite.notification.config.formatting.FormattingUserprofileCacheOptions; import gr.cite.tools.cache.CacheService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingUserprofileCacheOptions.java b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingUserprofileCacheOptions.java similarity index 87% rename from notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingUserprofileCacheOptions.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingUserprofileCacheOptions.java index 9363efbd6..199d98d3d 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/formatting/FormattingUserprofileCacheOptions.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/formatting/FormattingUserprofileCacheOptions.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.formatting; +package gr.cite.notification.service.formatting; import gr.cite.tools.cache.CacheOptions; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/EmailMessageBuilder.java b/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/EmailMessageBuilder.java index ab99f90e0..8cbe09c2f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/EmailMessageBuilder.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/message/builder/EmailMessageBuilder.java @@ -1,6 +1,6 @@ package gr.cite.notification.service.message.builder; -import gr.cite.notification.cache.NotificationTemplateCache; +import gr.cite.notification.service.message.cache.NotificationTemplateCache; import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationTemplateChannel; @@ -19,7 +19,6 @@ import gr.cite.notification.service.message.model.MessageInfo; import gr.cite.notification.service.notificationtemplate.NotificationTemplateService; import gr.cite.tools.cipher.CipherService; import gr.cite.tools.cipher.config.CipherProfileProperties; -import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +26,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; -import java.util.ArrayList; import java.util.Map; import java.util.UUID; 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 bdc59e025..2523731f3 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 @@ -1,9 +1,8 @@ package gr.cite.notification.service.message.builder; -import gr.cite.notification.cache.NotificationTemplateCache; +import gr.cite.notification.service.message.cache.NotificationTemplateCache; import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.enums.InAppNotificationPriority; -import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationTemplateChannel; import gr.cite.notification.common.types.notification.FieldInfo; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/cache/NotificationTemplateCache.java b/notification-service/notification/src/main/java/gr/cite/notification/service/message/cache/NotificationTemplateCache.java similarity index 92% rename from notification-service/notification/src/main/java/gr/cite/notification/cache/NotificationTemplateCache.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/message/cache/NotificationTemplateCache.java index ebd581155..05538492c 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/cache/NotificationTemplateCache.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/message/cache/NotificationTemplateCache.java @@ -1,13 +1,9 @@ -package gr.cite.notification.cache; +package gr.cite.notification.service.message.cache; -import gr.cite.notification.config.notification.NotificationTemplateCacheOptions; -import gr.cite.tools.cache.CacheOptions; import gr.cite.tools.cache.CacheService; import org.springframework.cache.Cache; import org.springframework.stereotype.Component; -import java.util.UUID; - @Component public class NotificationTemplateCache extends CacheService { diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/notification/NotificationTemplateCacheOptions.java b/notification-service/notification/src/main/java/gr/cite/notification/service/message/cache/NotificationTemplateCacheOptions.java similarity index 85% rename from notification-service/notification/src/main/java/gr/cite/notification/config/notification/NotificationTemplateCacheOptions.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/message/cache/NotificationTemplateCacheOptions.java index 279bfe169..eee0d9134 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/notification/NotificationTemplateCacheOptions.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/message/cache/NotificationTemplateCacheOptions.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.notification; +package gr.cite.notification.service.message.cache; import gr.cite.tools.cache.CacheOptions; import org.springframework.boot.context.properties.ConfigurationProperties; 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 380b820b9..32864b6f4 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 @@ -1,6 +1,6 @@ package gr.cite.notification.service.message.common; -import gr.cite.notification.cache.NotificationTemplateCache; +import gr.cite.notification.service.message.cache.NotificationTemplateCache; import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.types.notification.FieldInfo; import gr.cite.notification.config.notification.NotificationProperties; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/message/infobuilder/MessageBuilderServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/message/infobuilder/MessageBuilderServiceImpl.java index e30571d9d..22f2b5062 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/message/infobuilder/MessageBuilderServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/message/infobuilder/MessageBuilderServiceImpl.java @@ -7,7 +7,8 @@ import gr.cite.notification.common.scope.tenant.TenantScope; import gr.cite.notification.common.enums.NotificationDataType; import gr.cite.notification.common.types.notification.FieldInfo; import gr.cite.notification.common.types.notification.NotificationFieldData; -import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; +import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity; +import gr.cite.notification.common.types.user.AdditionalInfoEntity; import gr.cite.notification.config.notification.NotificationConfig; import gr.cite.notification.config.notification.NotificationProperties; import gr.cite.notification.data.NotificationEntity; @@ -87,16 +88,18 @@ public class MessageBuilderServiceImpl implements MessageInfoBuilderService { .isActive(IsActive.Active).first(); } - if (userProfile != null) { -// messageInfo.setLanguage(userProfile.getLanguage()); -// messageInfo.setCulture(userProfile.getCulture()); -// messageInfo.setTimeZone(userProfile.getTimezone()); + AdditionalInfoEntity additionalInfoEntity = userProfile == null ? null : this.jsonHandlingService.fromJsonSafe(AdditionalInfoEntity.class, userProfile.getAdditionalInfo()); + + if (additionalInfoEntity != null) { + messageInfo.setLanguage(additionalInfoEntity.getLanguage()); + messageInfo.setCulture(additionalInfoEntity.getCulture()); + messageInfo.setTimeZone(additionalInfoEntity.getTimezone()); } else { - DefaultUserLocaleConfigurationDataContainer defaultUserLocaleConfiguration = this.tenantConfigurationService.collectTenantUserLocale(); + DefaultUserLocaleTenantConfigurationEntity defaultUserLocaleConfiguration = this.tenantConfigurationService.collectTenantUserLocale(); if (defaultUserLocaleConfiguration != null) { messageInfo.setLanguage(defaultUserLocaleConfiguration.getLanguage()); messageInfo.setCulture(defaultUserLocaleConfiguration.getCulture()); - messageInfo.setTimeZone(defaultUserLocaleConfiguration.getTimeZone()); + messageInfo.setTimeZone(defaultUserLocaleConfiguration.getTimezone()); } } 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 ff8c91615..56503a197 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 @@ -62,7 +62,6 @@ public class NotificationServiceImpl implements NotificationService { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotificationServiceImpl.class)); private final TenantEntityManager entityManager; private final AuthorizationService authService; - private final AuthorizationService authorizationService; private final DeleterFactory deleterFactory; private final BuilderFactory builderFactory; private final ConventionService conventionService; @@ -78,7 +77,7 @@ public class NotificationServiceImpl implements NotificationService { @Autowired public NotificationServiceImpl( TenantEntityManager entityManager, - AuthorizationService authService, AuthorizationService authorizationService, + AuthorizationService authService, DeleterFactory deleterFactory, BuilderFactory builderFactory, ConventionService conventionService, @@ -87,7 +86,6 @@ public class NotificationServiceImpl implements NotificationService { ChannelResolutionService channelResolutionService, MessageBuilderFactory messageBuilderFactory, ContactExtractorFactory contactExtractorFactory, NotifierFactory notifierFactory, ApplicationContext applicationContext, QueryFactory queryFactory) { this.entityManager = entityManager; this.authService = authService; - this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; this.builderFactory = builderFactory; this.conventionService = conventionService; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/email/EmailConfig.java b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailConfig.java similarity index 84% rename from notification-service/notification/src/main/java/gr/cite/notification/config/email/EmailConfig.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailConfig.java index d3d210f40..ccd8a9a0e 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/email/EmailConfig.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailConfig.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.email; +package gr.cite.notification.service.notify; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailNotifier.java b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailNotifier.java index 0030bda27..f56e603fa 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailNotifier.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailNotifier.java @@ -2,7 +2,6 @@ package gr.cite.notification.service.notify; import gr.cite.notification.common.StringUtils; import gr.cite.notification.common.enums.NotificationContactType; -import gr.cite.notification.config.email.EmailProperties; import gr.cite.notification.service.contact.model.Contact; import gr.cite.notification.service.contact.model.EmailContact; import gr.cite.notification.service.message.model.EmailMessage; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/config/email/EmailProperties.java b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailProperties.java similarity index 88% rename from notification-service/notification/src/main/java/gr/cite/notification/config/email/EmailProperties.java rename to notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailProperties.java index 505b2bd96..ac24b2a99 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/config/email/EmailProperties.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/notify/EmailProperties.java @@ -1,4 +1,4 @@ -package gr.cite.notification.config.email; +package gr.cite.notification.service.notify; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationService.java b/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationService.java index eb295e696..119ea7c8e 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationService.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationService.java @@ -1,26 +1,31 @@ package gr.cite.notification.service.tenantconfiguration; -import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; -import gr.cite.notification.model.TenantConfiguration; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationUserLocaleIntegrationPersist; +import com.fasterxml.jackson.core.JsonProcessingException; +import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; +import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist; +import gr.cite.notification.model.tenantconfiguration.TenantConfiguration; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.exception.MyForbiddenException; +import gr.cite.tools.exception.MyNotFoundException; +import gr.cite.tools.exception.MyValidationException; import gr.cite.tools.fieldset.FieldSet; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import javax.management.InvalidApplicationException; -import java.util.Set; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.UUID; public interface TenantConfigurationService { - EmailClientConfigurationDataContainer collectTenantEmailClient(); - DefaultUserLocaleConfigurationDataContainer collectTenantUserLocale(); - NotifierListConfigurationDataContainer collectTenantNotifierList(); - NotifierListConfigurationDataContainer collectTenantAvailableNotifierList(Set notificationTypes); - TenantConfiguration persist(TenantConfigurationEmailClientPersist emailClientPersist, FieldSet fieldSet); - TenantConfiguration persist(TenantConfigurationUserLocaleIntegrationPersist userLocaleIntegrationPersist, FieldSet fieldSet); - TenantConfiguration persist(TenantConfigurationNotifierListPersist notifierListPersist, FieldSet fieldSet); - void deleteAndSave(UUID id) throws InvalidApplicationException; + TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException; + + void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; + + NotifierListTenantConfigurationEntity collectTenantNotifierList(); + DefaultUserLocaleTenantConfigurationEntity collectTenantUserLocale(); } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationServiceImpl.java index 5b2bd8775..a24c757cd 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/tenantconfiguration/TenantConfigurationServiceImpl.java @@ -6,239 +6,217 @@ import gr.cite.notification.authorization.Permission; import gr.cite.notification.common.JsonHandlingService; import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.enums.TenantConfigurationType; -import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.EmailClientConfigurationDataContainer; -import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; +import gr.cite.notification.common.scope.tenant.TenantScope; +import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleTenantConfigurationEntity; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; import gr.cite.notification.convention.ConventionService; import gr.cite.notification.data.TenantConfigurationEntity; +import gr.cite.notification.data.TenantEntity; import gr.cite.notification.data.TenantEntityManager; import gr.cite.notification.errorcode.ErrorThesaurusProperties; -import gr.cite.notification.model.TenantConfiguration; -import gr.cite.notification.model.builder.TenantConfigurationBuilder; +import gr.cite.notification.event.EventBroker; +import gr.cite.notification.event.TenantConfigurationTouchedEvent; +import gr.cite.notification.model.builder.tenantconfiguration.TenantConfigurationBuilder; import gr.cite.notification.model.deleter.TenantConfigurationDeleter; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist; -import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationUserLocaleIntegrationPersist; +import gr.cite.notification.model.persist.tenantconfiguration.DefaultUserLocaleTenantConfigurationPersist; +import gr.cite.notification.model.persist.tenantconfiguration.NotifierListTenantConfigurationPersist; +import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationPersist; +import gr.cite.notification.model.tenantconfiguration.TenantConfiguration; import gr.cite.notification.query.TenantConfigurationQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.deleter.DeleterFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.exception.MyForbiddenException; import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.exception.MyValidationException; import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; +import gr.cite.tools.logging.MapLogEntry; +import org.jetbrains.annotations.NotNull; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; +import org.springframework.stereotype.Service; +import gr.cite.notification.authorization.AuthorizationFlags; +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; import javax.management.InvalidApplicationException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.time.Instant; import java.util.List; -import java.util.Set; import java.util.UUID; -@Component -@RequestScope +@Service public class TenantConfigurationServiceImpl implements TenantConfigurationService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationServiceImpl.class)); - private final ApplicationContext applicationContext; - private final JsonHandlingService jsonHandlingService; - private final AuthorizationService authorizationService; - private final ConventionService conventionService; - private final ErrorThesaurusProperties errors; - private final MessageSource messageSource; - private final BuilderFactory builderFactory; + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantConfigurationServiceImpl.class)); - private final TenantEntityManager dbContext; - private final DeleterFactory deleterFactory; + private final TenantEntityManager entityManager; - @Autowired - public TenantConfigurationServiceImpl(ApplicationContext applicationContext, JsonHandlingService jsonHandlingService, AuthorizationService authorizationService, ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, BuilderFactory builderFactory, TenantEntityManager dbContext, DeleterFactory deleterFactory) { - this.applicationContext = applicationContext; - this.jsonHandlingService = jsonHandlingService; - this.authorizationService = authorizationService; - this.conventionService = conventionService; - this.errors = errors; - this.messageSource = messageSource; - this.builderFactory = builderFactory; - this.dbContext = dbContext; - this.deleterFactory = deleterFactory; - } + private final AuthorizationService authorizationService; - @Override - public EmailClientConfigurationDataContainer collectTenantEmailClient() { - TenantConfigurationQuery query = applicationContext.getBean(TenantConfigurationQuery.class); - String data = query.isActive(IsActive.Active).type(TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION).first().getValue(); - if (data == null) return null; + private final DeleterFactory deleterFactory; - try { - EmailClientConfigurationDataContainer emailClientData = this.jsonHandlingService.fromJson(EmailClientConfigurationDataContainer.class, data); - return emailClientData; - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - return null; - } + private final BuilderFactory builderFactory; - @Override - public DefaultUserLocaleConfigurationDataContainer collectTenantUserLocale() { - TenantConfigurationQuery query = applicationContext.getBean(TenantConfigurationQuery.class); - TenantConfigurationEntity entity = query.isActive(IsActive.Active).type(TenantConfigurationType.DEFAULT_USER_LOCALE).first(); - if(entity == null){ - return null; - } - String data = entity.getValue(); - if (data == null) return null; + private final ConventionService conventionService; - try { - DefaultUserLocaleConfigurationDataContainer userLocaleData = this.jsonHandlingService.fromJson(DefaultUserLocaleConfigurationDataContainer.class, data); - return userLocaleData; - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - return null; - } + private final ErrorThesaurusProperties errors; - @Override - public NotifierListConfigurationDataContainer collectTenantNotifierList() { - TenantConfigurationQuery query = applicationContext.getBean(TenantConfigurationQuery.class); - TenantConfigurationEntity configurationEntity = query.isActive(IsActive.Active).type(TenantConfigurationType.NOTIFIER_LIST).first(); - String data = configurationEntity != null ? configurationEntity.getValue() : null; - if (data == null) return null; + private final MessageSource messageSource; - try { - NotifierListConfigurationDataContainer notifierListData = this.jsonHandlingService.fromJson(NotifierListConfigurationDataContainer.class, data); - return notifierListData; - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - return null; - } + private final JsonHandlingService jsonHandlingService; - @Override - public NotifierListConfigurationDataContainer collectTenantAvailableNotifierList(Set notificationTypes) { - return null; - } + private final QueryFactory queryFactory; + private final EventBroker eventBroker; + private final TenantScope tenantScope; + @Autowired + public TenantConfigurationServiceImpl( + TenantEntityManager entityManager, + AuthorizationService authorizationService, + DeleterFactory deleterFactory, + BuilderFactory builderFactory, + ConventionService conventionService, + ErrorThesaurusProperties errors, + MessageSource messageSource, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, EventBroker eventBroker, TenantScope tenantScope) { + this.entityManager = entityManager; + this.authorizationService = authorizationService; + this.deleterFactory = deleterFactory; + this.builderFactory = builderFactory; + this.conventionService = conventionService; + this.errors = errors; + this.messageSource = messageSource; + this.jsonHandlingService = jsonHandlingService; + this.queryFactory = queryFactory; + this.eventBroker = eventBroker; + this.tenantScope = tenantScope; + } - @Override - public TenantConfiguration persist(TenantConfigurationEmailClientPersist emailClientPersist, FieldSet fieldSet) { - EmailClientConfigurationDataContainer container = new EmailClientConfigurationDataContainer(); - container.setEnableSSL(emailClientPersist.getEnableSSL()); - container.setRequireCredentials(emailClientPersist.getRequireCredentials()); - container.setHostServer(emailClientPersist.getHostServer()); - container.setHostPortNo(emailClientPersist.getHostPortNo()); - container.setCertificatePath(emailClientPersist.getCertificatePath()); - container.setEmailAddress(emailClientPersist.getEmailAddress()); - container.setEmailUserName(emailClientPersist.getEmailUserName()); - container.setEmailPassword(emailClientPersist.getEmailPassword()); - try { - String value = jsonHandlingService.toJson(container); - return this.persist(emailClientPersist.getId(), emailClientPersist.getHash(), TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION, value, fieldSet); - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - return null; - } + public TenantConfiguration persist(TenantConfigurationPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException, InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException { + logger.debug(new MapLogEntry("persisting data TenantConfiguration").And("model", model).And("fields", fields)); - @Override - public TenantConfiguration persist(TenantConfigurationUserLocaleIntegrationPersist userLocaleIntegrationPersist, FieldSet fieldSet) { - this.authorizationService.authorizeForce(Permission.EditTenantConfiguration); + this.authorizationService.authorizeForce(Permission.EditTenantConfiguration); - TenantConfigurationQuery tenantConfigurationQuery = applicationContext.getBean(TenantConfigurationQuery.class); - TenantConfigurationEntity data = tenantConfigurationQuery.isActive(IsActive.Active).type(TenantConfigurationType.DEFAULT_USER_LOCALE).first(); - Boolean isUpdate = data != null; - if (!isUpdate) { + Boolean isUpdate = this.conventionService.isValidGuid(model.getId()); - data = new TenantConfigurationEntity(); - data.setCreatedAt(Instant.now()); - data.setIsActive(IsActive.Active); - data.setType(TenantConfigurationType.DEFAULT_USER_LOCALE); - } - try { - DefaultUserLocaleConfigurationDataContainer container = new DefaultUserLocaleConfigurationDataContainer(); - container.setCulture(userLocaleIntegrationPersist.getCulture()); - container.setTimeZone(userLocaleIntegrationPersist.getTimeZone()); - container.setLanguage(userLocaleIntegrationPersist.getLanguage()); - String value = jsonHandlingService.toJson(container); + TenantConfigurationEntity data; + if (isUpdate) { + data = this.entityManager.find(TenantConfigurationEntity.class, model.getId()); + if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); + if (!data.getType().equals(model.getType())) throw new MyValidationException(this.errors.getTenantConfigurationTypeCanNotChange().getCode(), this.errors.getTenantConfigurationTypeCanNotChange().getMessage()); + } else { + data = new TenantConfigurationEntity(); + data.setId(UUID.randomUUID()); + data.setIsActive(IsActive.Active); + data.setCreatedAt(Instant.now()); + data.setType(model.getType()); + } - data.setValue(value); - data.setUpdatedAt(Instant.now()); - this.dbContext.merge(data); - } catch (InvalidApplicationException | JsonProcessingException e) { - logger.error(e.getMessage(), e); - } + TenantConfigurationQuery tenantConfigurationQuery = this.queryFactory.query(TenantConfigurationQuery.class).excludedIds(data.getId()).isActive(IsActive.Active).types(data.getType()); + if (data.getTenantId() == null) tenantConfigurationQuery.tenantIsSet(false); + else tenantConfigurationQuery.tenantIsSet(true).tenantIds(data.getTenantId()); + if (tenantConfigurationQuery.count() > 0)throw new MyValidationException(this.errors.getMultipleTenantConfigurationTypeNotAllowed().getCode(), this.errors.getMultipleTenantConfigurationTypeNotAllowed().getMessage()); + + switch (data.getType()){ + case NotifierList -> data.setValue(this.jsonHandlingService.toJson(this.buildNotifierListTenantConfigurationEntity(model.getNotifierList()))); + case DefaultUserLocale -> data.setValue(this.jsonHandlingService.toJson(this.buildDefaultUserLocaleTenantConfigurationEntity(model.getDefaultUserLocale()))); + default -> throw new InternalError("unknown type: " + data.getType()); + } + data.setUpdatedAt(Instant.now()); + if (isUpdate) + this.entityManager.merge(data); + else + this.entityManager.persist(data); - //this._eventBroker.EmitTenantConfigurationTouched(this._scope.Tenant, type); + this.entityManager.flush(); - TenantConfiguration persisted = this.builderFactory.builder(TenantConfigurationBuilder.class).build(fieldSet.merge(new BaseFieldSet(TenantConfiguration._id, TenantConfiguration._hash)), data); - return persisted; - } + if (data.getTenantId() != null) { + TenantEntity tenant = this.entityManager.find(TenantEntity.class, data.getTenantId()); + if (tenant == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getTenantId(), TenantEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); + this.eventBroker.emit(new TenantConfigurationTouchedEvent(tenant.getId(), tenant.getCode(), data.getType())); + } else { + this.eventBroker.emit(new TenantConfigurationTouchedEvent(data.getId(), this.tenantScope.getDefaultTenantCode(), data.getType())); + } + + return this.builderFactory.builder(TenantConfigurationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, TenantConfiguration._id), data); + } - @Override - public TenantConfiguration persist(TenantConfigurationNotifierListPersist notifierListPersist, FieldSet fieldSet) { - NotifierListConfigurationDataContainer container = new NotifierListConfigurationDataContainer(); - container.setNotifiers(notifierListPersist.getNotifiers()); - try { - String value = jsonHandlingService.toJson(container); - return this.persist(notifierListPersist.getId(), notifierListPersist.getHash(), TenantConfigurationType.NOTIFIER_LIST, value, fieldSet); - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - return null; - } + private @NotNull DefaultUserLocaleTenantConfigurationEntity buildDefaultUserLocaleTenantConfigurationEntity(DefaultUserLocaleTenantConfigurationPersist persist){ + DefaultUserLocaleTenantConfigurationEntity data = new DefaultUserLocaleTenantConfigurationEntity(); + if (persist == null) return data; + data.setCulture(persist.getCulture()); + data.setLanguage(persist.getLanguage()); + data.setTimezone(persist.getTimezone()); + return data; + } - @Override - public void deleteAndSave(UUID id) throws InvalidApplicationException { - logger.debug("deleting tenant Configuration: {}", id); - this.authorizationService.authorizeForce(Permission.DeleteNotification); - this.deleterFactory.deleter(TenantConfigurationDeleter.class).deleteAndSaveByIds(List.of(id)); - } - - private TenantConfiguration persist(UUID modelId, String modelHash, TenantConfigurationType type, String value, FieldSet fieldSet) { - this.authorizationService.authorizeForce(Permission.EditTenantConfiguration); - - Boolean isUpdate = this.conventionService.isValidGuid(modelId); - - TenantConfigurationQuery tenantConfigurationQuery = applicationContext.getBean(TenantConfigurationQuery.class); - List existingConfigIds = tenantConfigurationQuery.isActive(IsActive.Active).type(type).collectAs(new BaseFieldSet(TenantConfigurationEntity._id)).stream().map(TenantConfigurationEntity::getId).toList(); - TenantConfigurationEntity data = null; - if (isUpdate) { - if (!existingConfigIds.contains(modelId)) throw new MyValidationException(this.errors.getSingleTenantConfigurationPerTypeSupported().getCode(), this.errors.getSingleTenantConfigurationPerTypeSupported().getMessage()); - if (existingConfigIds.size() > 1) throw new MyValidationException(this.errors.getSingleTenantConfigurationPerTypeSupported().getCode(), this.errors.getSingleTenantConfigurationPerTypeSupported().getMessage()); + private @NotNull NotifierListTenantConfigurationEntity buildNotifierListTenantConfigurationEntity(NotifierListTenantConfigurationPersist persist){ + NotifierListTenantConfigurationEntity data = new NotifierListTenantConfigurationEntity(); + if (persist == null) return data; + data.setNotifiers(persist.getNotifiers()); + return data; + } - data = tenantConfigurationQuery.ids(modelId).first(); - if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{modelId, TenantConfigurationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); - if (!modelHash.equals(this.conventionService.hashValue(data.getUpdatedAt()))) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); - if (!data.getType().equals(type)) throw new MyValidationException(this.errors.getIncompatibleTenantConfigurationTypes().getCode(), this.errors.getIncompatibleTenantConfigurationTypes().getMessage()); - } else { - if (!existingConfigIds.isEmpty()) throw new MyValidationException(this.errors.getSingleTenantConfigurationPerTypeSupported().getCode(), this.errors.getSingleTenantConfigurationPerTypeSupported().getMessage()); + public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { + logger.debug("deleting dataset: {}", id); - data = new TenantConfigurationEntity(); - data.setCreatedAt(Instant.now()); - data.setIsActive(IsActive.Active); - data.setType(type); - } + this.authorizationService.authorizeForce(Permission.DeleteTenantConfiguration); - data.setValue(value); - data.setUpdatedAt(Instant.now()); + TenantConfigurationEntity data = this.entityManager.find(TenantConfigurationEntity.class, id); + if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, TenantConfiguration.class.getSimpleName()}, LocaleContextHolder.getLocale())); - try { - this.dbContext.merge(data); - } catch (InvalidApplicationException e) { - logger.error(e.getMessage(), e); - } + this.deleterFactory.deleter(TenantConfigurationDeleter.class).deleteAndSaveByIds(List.of(id)); - //this._eventBroker.EmitTenantConfigurationTouched(this._scope.Tenant, type); + if (data.getTenantId() != null) { + TenantEntity tenant = this.entityManager.find(TenantEntity.class, data.getTenantId()); + if (tenant == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{data.getTenantId(), TenantEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); + this.eventBroker.emit(new TenantConfigurationTouchedEvent(tenant.getId(), tenant.getCode(), data.getType())); + } else { + this.eventBroker.emit(new TenantConfigurationTouchedEvent(data.getId(), this.tenantScope.getDefaultTenantCode(), data.getType())); + } + } - TenantConfiguration persisted = this.builderFactory.builder(TenantConfigurationBuilder.class).build(fieldSet.merge(new BaseFieldSet(TenantConfiguration._id, TenantConfiguration._hash)), data); - return persisted; - //return null; + @Override + public NotifierListTenantConfigurationEntity collectTenantNotifierList() { + TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.NotifierList); + if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false); + else { + try { + query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant()); + } catch (InvalidApplicationException e) { + throw new RuntimeException(e); + } + } + + TenantConfigurationEntity data = query.first(); + if (data == null || this.conventionService.isNullOrEmpty(data.getValue())) return null; + return this.jsonHandlingService.fromJsonSafe(NotifierListTenantConfigurationEntity.class, data.getValue()); + } + + @Override + public DefaultUserLocaleTenantConfigurationEntity collectTenantUserLocale() { + TenantConfigurationQuery query = this.queryFactory.query(TenantConfigurationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).isActive(IsActive.Active).types(TenantConfigurationType.DefaultUserLocale); + if (this.tenantScope.isDefaultTenant()) query.tenantIsSet(false); + else { + try { + query.tenantIsSet(true).tenantIds(this.tenantScope.getTenant()); + } catch (InvalidApplicationException e) { + throw new RuntimeException(e); + } + } + + TenantConfigurationEntity data = query.first(); + if (data == null || this.conventionService.isNullOrEmpty(data.getValue())) return null; + return this.jsonHandlingService.fromJsonSafe(DefaultUserLocaleTenantConfigurationEntity.class, data.getValue()); + } - } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java index ff5006f3f..d8cbce40e 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/user/UserServiceImpl.java @@ -7,6 +7,7 @@ import gr.cite.notification.authorization.Permission; import gr.cite.notification.common.JsonHandlingService; import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.common.scope.tenant.TenantScope; +import gr.cite.notification.common.types.user.AdditionalInfoEntity; import gr.cite.notification.convention.ConventionService; import gr.cite.notification.data.*; import gr.cite.notification.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; @@ -34,6 +35,7 @@ import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; import jakarta.persistence.EntityManager; import jakarta.transaction.Transactional; +import org.jetbrains.annotations.NotNull; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; @@ -100,7 +102,7 @@ public class UserServiceImpl implements UserService { data = new UserEntity(); data.setId(model.getId()); data.setName(model.getName()); - data.setAdditionalInfo(this.jsonHandlingService.toJson(model.getProfile())); + data.setAdditionalInfo(this.jsonHandlingService.toJson(this.buildAdditionalInfoEntity(model.getProfile()))); data.setCreatedAt(Instant.now()); data.setUpdatedAt(Instant.now()); data.setIsActive(IsActive.Active); @@ -109,7 +111,7 @@ public class UserServiceImpl implements UserService { } else { data.setName(model.getName()); - data.setAdditionalInfo(this.jsonHandlingService.toJson(model.getProfile())); + data.setAdditionalInfo(this.jsonHandlingService.toJson(this.buildAdditionalInfoEntity(model.getProfile()))); data.setUpdatedAt(Instant.now()); data.setIsActive(IsActive.Active); @@ -131,6 +133,15 @@ public class UserServiceImpl implements UserService { return this.builderFactory.builder(UserBuilder.class).authorize(EnumSet.of(AuthorizationFlags.None)).build(BaseFieldSet.build(fields, User._id), data); } + private @NotNull AdditionalInfoEntity buildAdditionalInfoEntity(UserTouchedIntegrationEvent.UserProfile persist){ + AdditionalInfoEntity data = new AdditionalInfoEntity(); + if (persist == null) return data; + data.setCulture(persist.getCulture()); + data.setTimezone(persist.getTimezone()); + data.setLanguage(persist.getLanguage()); + return data; + } + @Override public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { logger.debug("deleting User: {}", id); diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceService.java b/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceService.java index 1a6931496..0c0c4969f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceService.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/userNotificationPreference/UserNotificationPreferenceService.java @@ -1,7 +1,6 @@ package gr.cite.notification.service.userNotificationPreference; -import gr.cite.notification.common.enums.NotificationContactType; -import gr.cite.notification.common.types.tenantconfiguration.NotifierListConfigurationDataContainer; +import gr.cite.notification.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; import gr.cite.notification.model.UserNotificationPreference; import gr.cite.notification.model.persist.UserNotificationPreferencePersist; import gr.cite.tools.fieldset.FieldSet; @@ -14,7 +13,7 @@ import java.util.UUID; public interface UserNotificationPreferenceService { List persist(UserNotificationPreferencePersist model, FieldSet fieldSet); - NotifierListConfigurationDataContainer collectUserAvailableNotifierList(Set notificationTypes); + NotifierListTenantConfigurationEntity collectUserAvailableNotifierList(Set notificationTypes); List collectUserNotificationPreferences(UUID id); Map> collectUserNotificationPreferences(List ids); } 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 10ab5df7f..3b14107a5 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 @@ -5,7 +5,7 @@ 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.common.types.tenantconfiguration.NotifierListTenantConfigurationEntity; import gr.cite.notification.config.notification.NotificationConfig; import gr.cite.notification.data.TenantEntityManager; import gr.cite.notification.data.UserNotificationPreferenceEntity; @@ -71,7 +71,7 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr this.authService.authorizeAtLeastOneForce(model.getUserId() != null ? List.of(new OwnedResource(model.getUserId())) : null, Permission.EditUserNotificationPreference); Map> currentNotificationListPolicies; - NotifierListConfigurationDataContainer tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList(); + NotifierListTenantConfigurationEntity tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList(); if (tenantNotifierListPolicies != null) { currentNotificationListPolicies = mergeNotifierPolicies(tenantNotifierListPolicies.getNotifiers(), this.globalPoliciesMap); @@ -91,9 +91,9 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr } @Override - public NotifierListConfigurationDataContainer collectUserAvailableNotifierList(Set notificationTypes) { + public NotifierListTenantConfigurationEntity collectUserAvailableNotifierList(Set notificationTypes) { Map> currentNotificationListPolicies; - NotifierListConfigurationDataContainer tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList(); + NotifierListTenantConfigurationEntity tenantNotifierListPolicies = this.tenantConfigurationService.collectTenantNotifierList(); if (tenantNotifierListPolicies != null) { currentNotificationListPolicies = mergeNotifierPolicies(tenantNotifierListPolicies.getNotifiers(), this.globalPoliciesMap); @@ -105,12 +105,12 @@ public class UserNotificationPreferenceServiceImpl implements UserNotificationPr if (notificationTypes != null && !notificationTypes.isEmpty()) { - return new NotifierListConfigurationDataContainer(currentNotificationListPolicies + return new NotifierListTenantConfigurationEntity(currentNotificationListPolicies .entrySet().stream() .filter(x -> notificationTypes.contains(x.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } - else return new NotifierListConfigurationDataContainer(currentNotificationListPolicies); + else return new NotifierListTenantConfigurationEntity(currentNotificationListPolicies); } @Override