From 102141aa0dda2704878f13910b5ae92f60dea33b Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Fri, 29 Mar 2024 14:32:47 +0200 Subject: [PATCH] update queues to use smallint enums --- annotation-service/annotation/pom.xml | 6 +-- .../annotation/data/QueueInboxEntity.java | 15 +++---- .../annotation/data/QueueOutboxEntity.java | 12 +++--- .../conventers/QueueInboxStatusConverter.java | 19 +++++++++ .../QueueOutboxNotifyStatusConverter.java | 19 +++++++++ annotation-service/pom.xml | 8 ++-- dmp-backend/core/pom.xml | 4 +- .../db/NamingStrategyProperties.java | 20 +++++++++ .../db/PrefixPhysicalNamingStrategy.java | 30 +++++++++++++ .../java/eu/eudat/data/QueueInboxEntity.java | 14 +++---- .../java/eu/eudat/data/QueueOutboxEntity.java | 12 +++--- .../enums/QueueInboxStatusConverter.java | 19 +++++++++ .../QueueOutboxNotifyStatusConverter.java | 19 +++++++++ .../eudat/model/persist/CloneDmpPersist.java | 4 +- .../model/persist/NewVersionDmpPersist.java | 4 +- dmp-backend/pom.xml | 35 ++++------------ .../web/src/main/resources/config/db.yml | 5 ++- .../updates/00.01.029_addQueueOutbox.sql | 2 +- .../updates/00.01.030_addQueueInbox.sql | 8 ++-- .../updates/00.01.037_add_ntf_QueueInbox.sql | 8 ++-- .../updates/00.01.038_add_ntf_QueueOutbox.sql | 2 +- .../updates/00.01.049_Add_ant_QueueInbox.sql | 8 ++-- .../updates/00.01.050_Add_ant_QueueOutbox.sql | 2 +- .../InAppNotificationController.java | 15 +++---- .../UserNotificationPreferenceController.java | 4 +- .../src/main/resources/config/cache.yml | 3 -- .../src/main/resources/config/db.yml | 7 +++- .../src/main/resources/config/email.yml | 14 +++---- .../src/main/resources/config/idpclaims.yml | 2 + .../src/main/resources/config/permissions.yml | 42 ++++++++----------- .../main/resources/config/security-devel.yml | 6 +++ .../src/main/resources/config/security.yml | 16 +++---- .../src/main/resources/config/server.yml | 12 +++++- notification-service/notification/pom.xml | 4 +- .../notification/data/QueueInboxEntity.java | 15 +++---- .../notification/data/QueueOutboxEntity.java | 14 +++---- .../conventers/QueueInboxStatusConverter.java | 19 +++++++++ .../QueueOutboxNotifyStatusConverter.java | 19 +++++++++ .../java/gr/cite/notification/model/User.java | 2 - .../censorship/InAppNotificationCensor.java | 8 +++- .../model/censorship/UserCensor.java | 3 -- .../UserNotificationPreferenceCensor.java | 8 +++- .../InAppNotificationServiceImpl.java | 8 +++- notification-service/pom.xml | 8 ++-- 44 files changed, 334 insertions(+), 170 deletions(-) create mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueInboxStatusConverter.java create mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueOutboxNotifyStatusConverter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/db/NamingStrategyProperties.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/configurations/db/PrefixPhysicalNamingStrategy.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueInboxStatusConverter.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueOutboxNotifyStatusConverter.java create mode 100644 notification-service/notification-web/src/main/resources/config/security-devel.yml create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueInboxStatusConverter.java create mode 100644 notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueOutboxNotifyStatusConverter.java diff --git a/annotation-service/annotation/pom.xml b/annotation-service/annotation/pom.xml index 5a116402f..aefe1aef0 100644 --- a/annotation-service/annotation/pom.xml +++ b/annotation-service/annotation/pom.xml @@ -62,7 +62,7 @@ gr.cite oidc-authn - 1.0.0 + 2.2.1 gr.cite @@ -72,7 +72,7 @@ gr.cite oidc-authz - 1.0.0 + 2.1.0 gr.cite @@ -82,7 +82,7 @@ gr.cite validation - 3.0.2 + 3.0.3 diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueInboxEntity.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueInboxEntity.java index 3b16254b7..4847bc080 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueInboxEntity.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueInboxEntity.java @@ -2,6 +2,7 @@ package gr.cite.annotation.data; import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.data.conventers.IsActiveConverter; +import gr.cite.annotation.data.conventers.QueueInboxStatusConverter; import gr.cite.annotation.data.types.JsonSQLType; import gr.cite.queueinbox.entity.QueueInbox; import gr.cite.queueinbox.entity.QueueInboxStatus; @@ -21,17 +22,17 @@ public class QueueInboxEntity implements QueueInbox { public static final String _id = "id"; - @Column(name = "\"queue\"", nullable = false, length = 50) + @Column(name = "\"queue\"", nullable = false, length = 200) private String queue; public static final String _queue = "queue"; - @Column(name = "\"exchange\"", nullable = false, length = 50) + @Column(name = "\"exchange\"", nullable = false, length = 200) private String exchange; public static final String _exchange = "exchange"; - @Column(name = "\"route\"", nullable = false, length = 50) + @Column(name = "\"route\"", nullable = false, length = 200) private String route; public static final String _route = "route"; @@ -62,11 +63,11 @@ public class QueueInboxEntity implements QueueInbox { public static final String _tenantId = "tenantId"; - @Column(name = "\"status\"", length = 50, nullable = false) - @Enumerated(EnumType.STRING) + @Column(name = "\"status\"", nullable = false) + @Convert(converter = QueueInboxStatusConverter.class) private QueueInboxStatus status; + public final static String _status = "status"; - public static final String _status = "status"; @Column(name = "\"created_at\"", nullable = false) private Instant createdAt; @@ -79,7 +80,7 @@ public class QueueInboxEntity implements QueueInbox { public static final String _updatedAt = "updatedAt"; - @Column(name = "\"is_active\"", length = 20, nullable = false) + @Column(name = "\"is_active\"", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueOutboxEntity.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueOutboxEntity.java index bef7a6c94..b25ca4edb 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueOutboxEntity.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/QueueOutboxEntity.java @@ -2,6 +2,7 @@ package gr.cite.annotation.data; import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.data.conventers.IsActiveConverter; +import gr.cite.annotation.data.conventers.QueueOutboxNotifyStatusConverter; import gr.cite.queueoutbox.entity.QueueOutbox; import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus; import jakarta.persistence.*; @@ -19,12 +20,12 @@ public class QueueOutboxEntity implements QueueOutbox { public static final String _id = "id"; - @Column(name = "\"exchange\"", nullable = false, length = 50) + @Column(name = "\"exchange\"", nullable = false, length = 200) private String exchange; public static final String _exchange = "exchange"; - @Column(name = "\"route\"", length = 50) + @Column(name = "\"route\"", length = 200) private String route; public static final String _route = "route"; @@ -39,11 +40,10 @@ public class QueueOutboxEntity implements QueueOutbox { public static final String _message = "message"; - @Column(name = "\"notify_status\"", length = 20, nullable = false) - @Enumerated(EnumType.STRING) + @Column(name = "\"notify_status\"", nullable = false) + @Convert(converter = QueueOutboxNotifyStatusConverter.class) private QueueOutboxNotifyStatus notifyStatus; - - public static final String _notifyStatus = "notifyStatus"; + public final static String _notifyStatus = "notifyStatus"; @Column(name = "\"retry_count\"", nullable = false) private Integer retryCount; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueInboxStatusConverter.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueInboxStatusConverter.java new file mode 100644 index 000000000..2089859d8 --- /dev/null +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueInboxStatusConverter.java @@ -0,0 +1,19 @@ +package gr.cite.annotation.data.conventers; + +import gr.cite.queueinbox.entity.QueueInboxStatus; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class QueueInboxStatusConverter implements AttributeConverter { + @Override + public Short convertToDatabaseColumn(QueueInboxStatus value) { + if (value == null) throw new IllegalArgumentException("Value could not be null for: " + this.getClass().getSimpleName()); + return value.getValue(); + } + + @Override + public QueueInboxStatus convertToEntityAttribute(Short dbData) { + return QueueInboxStatus.of(dbData); + } +} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueOutboxNotifyStatusConverter.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueOutboxNotifyStatusConverter.java new file mode 100644 index 000000000..a356181d1 --- /dev/null +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/conventers/QueueOutboxNotifyStatusConverter.java @@ -0,0 +1,19 @@ +package gr.cite.annotation.data.conventers; + +import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class QueueOutboxNotifyStatusConverter implements AttributeConverter { + @Override + public Short convertToDatabaseColumn(QueueOutboxNotifyStatus value) { + if (value == null) throw new IllegalArgumentException("Value could not be null for: " + this.getClass().getSimpleName()); + return value.getValue(); + } + + @Override + public QueueOutboxNotifyStatus convertToEntityAttribute(Short dbData) { + return QueueOutboxNotifyStatus.of(dbData); + } +} diff --git a/annotation-service/pom.xml b/annotation-service/pom.xml index c9662c360..47d35f3bb 100644 --- a/annotation-service/pom.xml +++ b/annotation-service/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.2 + 3.2.1 @@ -136,18 +136,18 @@ gr.cite rabbitmq-core - 2.1.1 + 2.1.2 gr.cite queue-inbox - 1.0.0 + 2.1.1 gr.cite queue-outbox - 1.0.0 + 2.1.1 diff --git a/dmp-backend/core/pom.xml b/dmp-backend/core/pom.xml index 9dcacf260..711c9c8de 100644 --- a/dmp-backend/core/pom.xml +++ b/dmp-backend/core/pom.xml @@ -65,12 +65,12 @@ gr.cite queue-inbox - 1.0.0 + 2.1.1 gr.cite queue-outbox - 1.0.0 + 2.1.1 diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/db/NamingStrategyProperties.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/db/NamingStrategyProperties.java new file mode 100644 index 000000000..d13980dbb --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/configurations/db/NamingStrategyProperties.java @@ -0,0 +1,20 @@ +package eu.eudat.configurations.db; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.bind.ConstructorBinding; + +@ConfigurationProperties(prefix = "naming-strategy") +public class NamingStrategyProperties { + + private final String prefix; + + @ConstructorBinding + public NamingStrategyProperties(String prefix) { + this.prefix = prefix; + } + + public String getPrefix() { + return prefix; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/configurations/db/PrefixPhysicalNamingStrategy.java b/dmp-backend/core/src/main/java/eu/eudat/configurations/db/PrefixPhysicalNamingStrategy.java new file mode 100644 index 000000000..140062448 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/configurations/db/PrefixPhysicalNamingStrategy.java @@ -0,0 +1,30 @@ +package eu.eudat.configurations.db; + +import eu.eudat.convention.ConventionService; +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@EnableConfigurationProperties({NamingStrategyProperties.class}) +public class PrefixPhysicalNamingStrategy extends PhysicalNamingStrategyStandardImpl { + + private final NamingStrategyProperties namingStrategyProperties; + private final ConventionService conventionService; + + public PrefixPhysicalNamingStrategy(NamingStrategyProperties namingStrategyProperties, ConventionService conventionService) { + this.namingStrategyProperties = namingStrategyProperties; + this.conventionService = conventionService; + } + + @Override + public Identifier toPhysicalTableName(Identifier logicalName, JdbcEnvironment context) { + if (conventionService.isNullOrEmpty(namingStrategyProperties.getPrefix())) + return super.toPhysicalTableName(logicalName, context); + Identifier identifier = new Identifier(namingStrategyProperties.getPrefix() + logicalName.getText(), logicalName.isQuoted()); + return super.toPhysicalTableName(identifier, context); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/QueueInboxEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/QueueInboxEntity.java index 43a44bbd6..29d5cb627 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/QueueInboxEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/QueueInboxEntity.java @@ -2,6 +2,7 @@ package eu.eudat.data; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.converters.enums.IsActiveConverter; +import eu.eudat.data.converters.enums.QueueInboxStatusConverter; import eu.eudat.data.types.JsonSQLType; import gr.cite.queueinbox.entity.QueueInbox; import gr.cite.queueinbox.entity.QueueInboxStatus; @@ -19,15 +20,15 @@ public class QueueInboxEntity implements QueueInbox { private UUID id; public final static String _id = "id"; - @Column(name = "\"queue\"", nullable = false, length = 50) + @Column(name = "\"queue\"", nullable = false, length = 200) private String queue; public final static String _queue = "queue"; - @Column(name = "\"exchange\"", nullable = false, length = 50) + @Column(name = "\"exchange\"", nullable = false, length = 200) private String exchange; public final static String _exchange = "exchange"; - @Column(name = "\"route\"", nullable = false, length = 50) + @Column(name = "\"route\"", nullable = false, length = 200) private String route; public final static String _route = "route"; @@ -52,14 +53,13 @@ public class QueueInboxEntity implements QueueInbox { private UUID tenantId; public final static String _tenantId = "tenantId"; - @Column(name = "\"is_active\"", length = 20, nullable = false) + @Column(name = "\"is_active\"", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; public final static String _isActive = "isActive"; - //TODO: as integer - @Column(name = "\"status\"", length = 50, nullable = false) - @Enumerated(EnumType.STRING) + @Column(name = "\"status\"", nullable = false) + @Convert(converter = QueueInboxStatusConverter.class) private QueueInboxStatus status; public final static String _status = "status"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/QueueOutboxEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/QueueOutboxEntity.java index 721d5c94d..daf463a5d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/QueueOutboxEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/QueueOutboxEntity.java @@ -2,6 +2,7 @@ package eu.eudat.data; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.converters.enums.IsActiveConverter; +import eu.eudat.data.converters.enums.QueueOutboxNotifyStatusConverter; import gr.cite.queueoutbox.entity.QueueOutbox; import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus; @@ -17,11 +18,11 @@ public class QueueOutboxEntity implements QueueOutbox { private UUID id; public final static String _id = "id"; - @Column(name = "\"exchange\"", nullable = false, length = 50) + @Column(name = "\"exchange\"", nullable = false, length = 200) private String exchange; public final static String _exchange = "exchange"; - @Column(name = "\"route\"", length = 50) + @Column(name = "\"route\"", length = 200) private String route; public final static String _route = "route"; @@ -33,9 +34,8 @@ public class QueueOutboxEntity implements QueueOutbox { private String message; public final static String _message = "message"; - //TODO: as integer - @Column(name = "\"notify_status\"", length = 20, nullable = false) - @Enumerated(EnumType.STRING) + @Column(name = "\"notify_status\"", nullable = false) + @Convert(converter = QueueOutboxNotifyStatusConverter.class) private QueueOutboxNotifyStatus notifyStatus; public final static String _notifyStatus = "notifyStatus"; @@ -55,7 +55,7 @@ public class QueueOutboxEntity implements QueueOutbox { private UUID tenantId; public final static String _tenantId = "tenantId"; - @Column(name = "\"is_active\"", length = 20, nullable = false) + @Column(name = "\"is_active\"", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; public final static String _isActive = "isActive"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueInboxStatusConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueInboxStatusConverter.java new file mode 100644 index 000000000..387c57ad1 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueInboxStatusConverter.java @@ -0,0 +1,19 @@ +package eu.eudat.data.converters.enums; + +import gr.cite.queueinbox.entity.QueueInboxStatus; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class QueueInboxStatusConverter implements AttributeConverter { + @Override + public Short convertToDatabaseColumn(QueueInboxStatus value) { + if (value == null) throw new IllegalArgumentException("Value could not be null for: " + this.getClass().getSimpleName()); + return value.getValue(); + } + + @Override + public QueueInboxStatus convertToEntityAttribute(Short dbData) { + return QueueInboxStatus.of(dbData); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueOutboxNotifyStatusConverter.java b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueOutboxNotifyStatusConverter.java new file mode 100644 index 000000000..9e822930d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/data/converters/enums/QueueOutboxNotifyStatusConverter.java @@ -0,0 +1,19 @@ +package eu.eudat.data.converters.enums; + +import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class QueueOutboxNotifyStatusConverter implements AttributeConverter { + @Override + public Short convertToDatabaseColumn(QueueOutboxNotifyStatus value) { + if (value == null) throw new IllegalArgumentException("Value could not be null for: " + this.getClass().getSimpleName()); + return value.getValue(); + } + + @Override + public QueueOutboxNotifyStatus convertToEntityAttribute(Short dbData) { + return QueueOutboxNotifyStatus.of(dbData); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java index 2994eac69..cbda577f6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/CloneDmpPersist.java @@ -4,13 +4,13 @@ import eu.eudat.commons.validation.BaseValidator; import gr.cite.tools.validation.specification.Specification; import eu.eudat.convention.ConventionService; import eu.eudat.errorcode.ErrorThesaurusProperties; -import org.apache.commons.compress.utils.Lists; 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.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -29,7 +29,7 @@ public class CloneDmpPersist { public static final String _description = "description"; - private List descriptions = Lists.newArrayList(); + private List descriptions = new ArrayList<>(); public static final String _descriptions = "descriptions"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java index 5adc9b923..15953fd68 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDmpPersist.java @@ -5,13 +5,13 @@ import gr.cite.tools.validation.specification.Specification; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpEntity; import eu.eudat.errorcode.ErrorThesaurusProperties; -import org.apache.commons.compress.utils.Lists; 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.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -33,7 +33,7 @@ public class NewVersionDmpPersist { public static final String _blueprintId = "blueprintId"; - private List descriptions = Lists.newArrayList(); + private List descriptions = new ArrayList<>(); public static final String _descriptions = "descriptions"; diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index f8049f2c1..b3bf79193 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -10,7 +10,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.2 + 3.2.1 @@ -41,7 +41,7 @@ org.json json - 20230227 + 20240303 org.springframework @@ -92,7 +92,7 @@ org.elasticsearch.client elasticsearch-rest-high-level-client - 7.6.0 + 7.17.19 org.hibernate.orm @@ -109,7 +109,7 @@ com.jayway.jsonpath json-path - 2.4.0 + 2.9.0 @@ -153,24 +153,8 @@ 3.5 - - org.apache.poi - poi-ooxml - 4.1.2 - - - - org.apache.poi - poi - 4.1.2 - - - org.apache.xmlgraphics - fop - 2.3 - org.jsoup @@ -190,11 +174,6 @@ 1.0.6 - - fr.opensagres.xdocreport - fr.opensagres.xdocreport.itext.extension - 2.0.4 - commons-io @@ -356,18 +335,18 @@ gr.cite queue-inbox - 1.0.0 + 2.1.1 gr.cite queue-outbox - 1.0.0 + 2.1.1 gr.cite rabbitmq-core - 1.0.0 + 2.1.2 diff --git a/dmp-backend/web/src/main/resources/config/db.yml b/dmp-backend/web/src/main/resources/config/db.yml index 519502f2d..fcc2c426e 100644 --- a/dmp-backend/web/src/main/resources/config/db.yml +++ b/dmp-backend/web/src/main/resources/config/db.yml @@ -16,7 +16,7 @@ spring: dialect: org.hibernate.dialect.PostgreSQLDialect hibernate: naming: - physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + physical-strategy: eu.eudat.configurations.db.PrefixPhysicalNamingStrategy implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy datasource: url: ${DB_URL:} @@ -29,3 +29,6 @@ spring: maximum-pool-size: 10 idle-timeout: 600000 max-lifetime: 1800000 + +naming-strategy: + prefix: \ No newline at end of file diff --git a/dmp-db-scema/updates/00.01.029_addQueueOutbox.sql b/dmp-db-scema/updates/00.01.029_addQueueOutbox.sql index 7a227c7c6..3409653d8 100644 --- a/dmp-db-scema/updates/00.01.029_addQueueOutbox.sql +++ b/dmp-db-scema/updates/00.01.029_addQueueOutbox.sql @@ -10,7 +10,7 @@ BEGIN exchange character varying(200) COLLATE pg_catalog."default" NOT NULL, route character varying(200) COLLATE pg_catalog."default" NOT NULL, message_id uuid NOT NULL, - notify_status character varying(100) COLLATE pg_catalog."default" NOT NULL, + notify_status smallint NOT NULL, retry_count integer NOT NULL, published_at timestamp without time zone, confirmed_at timestamp without time zone, diff --git a/dmp-db-scema/updates/00.01.030_addQueueInbox.sql b/dmp-db-scema/updates/00.01.030_addQueueInbox.sql index 13bdb9a53..e2296b850 100644 --- a/dmp-db-scema/updates/00.01.030_addQueueInbox.sql +++ b/dmp-db-scema/updates/00.01.030_addQueueInbox.sql @@ -7,14 +7,14 @@ BEGIN CREATE TABLE public."QueueInbox" ( id uuid NOT NULL, - queue character varying(50) COLLATE pg_catalog."default" NOT NULL, - exchange character varying(50) COLLATE pg_catalog."default" NOT NULL, - route character varying(50) COLLATE pg_catalog."default" NOT NULL, + queue character varying(200) COLLATE pg_catalog."default" NOT NULL, + exchange character varying(200) COLLATE pg_catalog."default" NOT NULL, + route character varying(200) COLLATE pg_catalog."default" NOT NULL, application_id character varying(100) COLLATE pg_catalog."default" NOT NULL, message_id uuid NOT NULL, message json NOT NULL, retry_count integer, - status character varying(50) COLLATE pg_catalog."default" NOT NULL, + status smallint NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, tenant uuid, diff --git a/dmp-db-scema/updates/00.01.037_add_ntf_QueueInbox.sql b/dmp-db-scema/updates/00.01.037_add_ntf_QueueInbox.sql index ffbf7d7e6..5aa40b82a 100644 --- a/dmp-db-scema/updates/00.01.037_add_ntf_QueueInbox.sql +++ b/dmp-db-scema/updates/00.01.037_add_ntf_QueueInbox.sql @@ -7,14 +7,14 @@ BEGIN CREATE TABLE public."ntf_QueueInbox" ( id uuid NOT NULL, - queue character varying(50) COLLATE pg_catalog."default" NOT NULL, - exchange character varying(50) COLLATE pg_catalog."default" NOT NULL, - route character varying(50) COLLATE pg_catalog."default" NOT NULL, + queue character varying(200) COLLATE pg_catalog."default" NOT NULL, + exchange character varying(200) COLLATE pg_catalog."default" NOT NULL, + route character varying(200) COLLATE pg_catalog."default" NOT NULL, application_id character varying(100) COLLATE pg_catalog."default" NOT NULL, message_id uuid NOT NULL, message json NOT NULL, retry_count integer, - status character varying(50) COLLATE pg_catalog."default" NOT NULL, + status smallint NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, tenant uuid, diff --git a/dmp-db-scema/updates/00.01.038_add_ntf_QueueOutbox.sql b/dmp-db-scema/updates/00.01.038_add_ntf_QueueOutbox.sql index 6720b85e2..53f79fce0 100644 --- a/dmp-db-scema/updates/00.01.038_add_ntf_QueueOutbox.sql +++ b/dmp-db-scema/updates/00.01.038_add_ntf_QueueOutbox.sql @@ -10,7 +10,7 @@ BEGIN exchange character varying(200) COLLATE pg_catalog."default" NOT NULL, route character varying(200) COLLATE pg_catalog."default" NOT NULL, message_id uuid NOT NULL, - notify_status character varying(100) COLLATE pg_catalog."default" NOT NULL, + notify_status smallint NOT NULL, retry_count integer NOT NULL, published_at timestamp without time zone, confirmed_at timestamp without time zone, diff --git a/dmp-db-scema/updates/00.01.049_Add_ant_QueueInbox.sql b/dmp-db-scema/updates/00.01.049_Add_ant_QueueInbox.sql index 48f593f0b..4fd7093bd 100644 --- a/dmp-db-scema/updates/00.01.049_Add_ant_QueueInbox.sql +++ b/dmp-db-scema/updates/00.01.049_Add_ant_QueueInbox.sql @@ -7,14 +7,14 @@ BEGIN CREATE TABLE public."ant_QueueInbox" ( id uuid NOT NULL, - queue character varying(50) COLLATE pg_catalog."default" NOT NULL, - exchange character varying(50) COLLATE pg_catalog."default" NOT NULL, - route character varying(50) COLLATE pg_catalog."default" NOT NULL, + queue character varying(200) COLLATE pg_catalog."default" NOT NULL, + exchange character varying(200) COLLATE pg_catalog."default" NOT NULL, + route character varying(200) COLLATE pg_catalog."default" NOT NULL, application_id character varying(100) COLLATE pg_catalog."default" NOT NULL, message_id uuid NOT NULL, message json NOT NULL, retry_count integer, - status character varying(50) COLLATE pg_catalog."default" NOT NULL, + status smallint NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, tenant uuid, diff --git a/dmp-db-scema/updates/00.01.050_Add_ant_QueueOutbox.sql b/dmp-db-scema/updates/00.01.050_Add_ant_QueueOutbox.sql index a90e251ae..7bcd5e500 100644 --- a/dmp-db-scema/updates/00.01.050_Add_ant_QueueOutbox.sql +++ b/dmp-db-scema/updates/00.01.050_Add_ant_QueueOutbox.sql @@ -10,7 +10,7 @@ BEGIN exchange character varying(200) COLLATE pg_catalog."default" NOT NULL, route character varying(200) COLLATE pg_catalog."default" NOT NULL, message_id uuid NOT NULL, - notify_status character varying(100) COLLATE pg_catalog."default" NOT NULL, + notify_status smallint NOT NULL, retry_count integer NOT NULL, published_at timestamp without time zone, confirmed_at timestamp without time zone, diff --git a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java index 519148da3..4ec5aee6b 100644 --- a/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java +++ b/notification-service/notification-web/src/main/java/gr/cite/notification/web/controllers/InAppNotificationController.java @@ -71,10 +71,10 @@ public class InAppNotificationController { @PostMapping("query") public QueryResult Query(@RequestBody InAppNotificationLookup lookup) throws MyApplicationException, MyForbiddenException, InvalidApplicationException { logger.debug("querying {}", InAppNotification.class.getSimpleName()); - - this.censorFactory.censor(InAppNotificationCensor.class).censor(lookup.getProject()); - UUID userId = this.userScope.getUserId(); + + this.censorFactory.censor(InAppNotificationCensor.class).censor(lookup.getProject(), userId); + if (userId == null) throw new MyForbiddenException(this.errors.getNonPersonPrincipal().getCode(), this.errors.getNonPersonPrincipal().getMessage()); InAppNotificationQuery query = lookup.enrich(this.queryFactory).userId(userId); List data = query.collectAs(lookup.getProject()); @@ -88,12 +88,13 @@ public class InAppNotificationController { @GetMapping("{id}") @Transactional - public InAppNotification Get(@PathVariable UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + public InAppNotification Get(@PathVariable UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { logger.debug(new MapLogEntry("retrieving" + InAppNotification.class.getSimpleName()).And("id", id).And("fields", fieldSet)); - this.censorFactory.censor(InAppNotificationCensor.class).censor(fieldSet); + UUID userId = this.userScope.getUserId(); + this.censorFactory.censor(InAppNotificationCensor.class).censor(fieldSet, userId); - InAppNotificationQuery query = this.queryFactory.query(InAppNotificationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id); + InAppNotificationQuery query = this.queryFactory.query(InAppNotificationQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).userId(userId).ids(id); InAppNotification model = this.builderFactory.builder(InAppNotificationBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Notification.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -142,7 +143,7 @@ public class InAppNotificationController { UUID userId = this.userScope.getUserId(); if (userId == null) throw new MyForbiddenException(this.errors.getNonPersonPrincipal().getCode(), this.errors.getNonPersonPrincipal().getMessage()); - this.censorFactory.censor(InAppNotificationCensor.class).censor(new BaseFieldSet(InAppNotification.Field.ID)); + this.censorFactory.censor(InAppNotificationCensor.class).censor(new BaseFieldSet(InAppNotification.Field.ID), userId); InAppNotificationQuery query = this.queryFactory.query(InAppNotificationQuery.class).isActive(IsActive.Active).trackingState(NotificationInAppTracking.STORED).userId(userId); int count = Math.toIntExact(query.count()); 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 8ff1323fe..d09539f67 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 @@ -66,7 +66,7 @@ public class UserNotificationPreferenceController { public QueryResult query(@RequestBody UserNotificationPreferenceLookup lookup) throws MyApplicationException, MyForbiddenException { logger.debug("querying {}", UserNotificationPreference.class.getSimpleName()); - this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(lookup.getProject()); + this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(lookup.getProject(), null); UserNotificationPreferenceQuery query = lookup.enrich(this.queryFactory); List data = query.collectAs(lookup.getProject()); @@ -83,7 +83,7 @@ public class UserNotificationPreferenceController { public UserNotificationPreference current(@PathVariable UUID userId, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("retrieving" + UserNotificationPreference.class.getSimpleName()).And("userId", userId).And("fields", fieldSet)); - this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(fieldSet); + this.censorFactory.censor(UserNotificationPreferenceCensor.class).censor(fieldSet, userId); UserNotificationPreferenceQuery query = this.queryFactory.query(UserNotificationPreferenceQuery.class).userId(userId); UserNotificationPreference model = this.builderFactory.builder(UserNotificationPreferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); diff --git a/notification-service/notification-web/src/main/resources/config/cache.yml b/notification-service/notification-web/src/main/resources/config/cache.yml index 69541500e..ec7370d42 100644 --- a/notification-service/notification-web/src/main/resources/config/cache.yml +++ b/notification-service/notification-web/src/main/resources/config/cache.yml @@ -39,9 +39,6 @@ cache: enableRecordStats: false expireAfterWriteSeconds: 60 mapCaches: - - names: [ cacheB ] - allowNullValues: true - storeByValue: true apiKey: name: apikey keyPattern: resolve_$keyhash$:v0 diff --git a/notification-service/notification-web/src/main/resources/config/db.yml b/notification-service/notification-web/src/main/resources/config/db.yml index aa3caed0b..0de4aa778 100644 --- a/notification-service/notification-web/src/main/resources/config/db.yml +++ b/notification-service/notification-web/src/main/resources/config/db.yml @@ -1,7 +1,11 @@ spring: jpa: properties: + org: + hibernate: + flushMode: MANUAL hibernate: + globally_quoted_identifiers: true ddl-auto: validate dialect: org.hibernate.dialect.PostgreSQLDialect hibernate: @@ -16,9 +20,10 @@ spring: hikari: connection-timeout: 30000 minimum-idle: 3 - maximum-pool-size: 5 + maximum-pool-size: 10 idle-timeout: 600000 max-lifetime: 1800000 + naming-strategy: prefix: ntf_ diff --git a/notification-service/notification-web/src/main/resources/config/email.yml b/notification-service/notification-web/src/main/resources/config/email.yml index fb7c94ba0..364788161 100644 --- a/notification-service/notification-web/src/main/resources/config/email.yml +++ b/notification-service/notification-web/src/main/resources/config/email.yml @@ -1,14 +1,14 @@ spring: mail: - host: ${MAIL_HOST:} - port: ${MAIL_PORT:} - username: ${MAIL_USERNAME:} - password: ${MAIL_PASSWORD:} + host: ${MAIL_HOST} + port: ${MAIL_PORT} + username: ${MAIL_USERNAME} + password: ${MAIL_PASSWORD} properties: mail: smtp: - auth: ${MAIL_AUTH:} + auth: ${MAIL_AUTH} starttls: - enable: ${MAIL_TLS:} + enable: ${MAIL_TLS} email: - address: ${MAIL_ADDRESS:} \ No newline at end of file + address: ${MAIL_ADDRESS} \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/config/idpclaims.yml b/notification-service/notification-web/src/main/resources/config/idpclaims.yml index 3372e4ca7..97ff4a10e 100644 --- a/notification-service/notification-web/src/main/resources/config/idpclaims.yml +++ b/notification-service/notification-web/src/main/resources/config/idpclaims.yml @@ -37,3 +37,5 @@ idpclient: - type: azp Authorities: - type: authorities + ExternalProviderName: + - type: identity_provider \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/config/permissions.yml b/notification-service/notification-web/src/main/resources/config/permissions.yml index d7247f8d8..a6d600777 100644 --- a/notification-service/notification-web/src/main/resources/config/permissions.yml +++ b/notification-service/notification-web/src/main/resources/config/permissions.yml @@ -5,26 +5,26 @@ permissions: # Tenants BrowseTenant: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false EditTenant: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false DeleteTenant: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false allowAuthenticated: false AllowNoTenant: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false @@ -32,21 +32,19 @@ permissions: # Users BrowseUser: roles: - - ic-sti-superuser - - tenantadmin + - Admin clients: [ ] allowAnonymous: true allowAuthenticated: false EditUser: roles: - - admin - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false DeleteUser: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false @@ -54,20 +52,19 @@ permissions: # UserContactInfo BrowseUserContactInfo: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: true allowAuthenticated: false EditUserContactInfo: roles: - - ic-sti-superuser - - user + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false DeleteUserContactInfo: roles: - - ic-sti-superuser + - Admin claims: [ ] clients: [ ] allowAnonymous: false @@ -94,27 +91,26 @@ permissions: #Tenant Configuration BrowseTenantConfiguration: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false EditTenantConfiguration: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false #User Notification Preference BrowseUserNotificationPreference: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: true allowAuthenticated: false EditUserNotificationPreference: roles: - - ic-sti-superuser - - user + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false @@ -122,26 +118,25 @@ permissions: # ViewPage Permissions ViewNotificationPage: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false ViewNotificationEventRulePage: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false ViewInAppNotificationPage: roles: - - ic-sti-superuser - - tenantadmin + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false ViewNotificationTemplatePage: roles: - - ic-sti-superuser + - Admin clients: [ ] allowAnonymous: false allowAuthenticated: false @@ -170,7 +165,6 @@ permissions: BrowseInAppNotification: roles: - Admin - - User clients: [ ] allowAnonymous: false allowAuthenticated: false diff --git a/notification-service/notification-web/src/main/resources/config/security-devel.yml b/notification-service/notification-web/src/main/resources/config/security-devel.yml new file mode 100644 index 000000000..dbb097b19 --- /dev/null +++ b/notification-service/notification-web/src/main/resources/config/security-devel.yml @@ -0,0 +1,6 @@ +web: + security: + idp: + resource: + jwt: + audiences: [ "dmp_notification" ] \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/config/security.yml b/notification-service/notification-web/src/main/resources/config/security.yml index 3024921aa..8f41034ac 100644 --- a/notification-service/notification-web/src/main/resources/config/security.yml +++ b/notification-service/notification-web/src/main/resources/config/security.yml @@ -2,19 +2,13 @@ web: security: enabled: true authorized-endpoints: [ api ] - allowed-endpoints: [ public, dataset, master-item, test ] + allowed-endpoints: [ public ] idp: api-key: - enabled: true - authorization-header: Authorization - client-id: ${IDP_APIKEY_CLIENT_ID} - client-secret: ${IDP_APIKEY_CLIENT_SECRET} - scope: ${IDP_APIKEY_SCOPE} + enabled: false resource: - token-type: JWT - opaque: - client-id: ${IDP_OPAQUE_CLIENT_ID} - client-secret: ${IDP_OPAQUE_CLIENT_SECRET} + token-type: JWT #| opaque jwt: claims: [ role, x-role ] - issuer-uri: ${IDP_ISSUER_URI:} \ No newline at end of file + issuer-uri: ${IDP_ISSUER_URI} + validIssuer: ${IDP_ISSUER_URI} \ No newline at end of file diff --git a/notification-service/notification-web/src/main/resources/config/server.yml b/notification-service/notification-web/src/main/resources/config/server.yml index bc9a15d9f..9a4a97cbc 100644 --- a/notification-service/notification-web/src/main/resources/config/server.yml +++ b/notification-service/notification-web/src/main/resources/config/server.yml @@ -1,3 +1,13 @@ server: port: ${WEB_PORT} - forward-headers-strategy: NONE \ No newline at end of file + forward-headers-strategy: NONE + tomcat: + threads: + max: 20 + max-connections: 10000 + + spring: + servlet: + multipart: + max-file-size: 10MB + max-request-size: 10MB \ No newline at end of file diff --git a/notification-service/notification/pom.xml b/notification-service/notification/pom.xml index d820e9b6f..da75fb081 100644 --- a/notification-service/notification/pom.xml +++ b/notification-service/notification/pom.xml @@ -63,7 +63,7 @@ gr.cite oidc-authn - 1.0.0 + 2.2.1 gr.cite @@ -73,7 +73,7 @@ gr.cite oidc-authz - 1.0.0 + 2.1.0 gr.cite diff --git a/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java index c59bccb11..97126f92d 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java @@ -2,6 +2,7 @@ package gr.cite.notification.data; import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.data.conventers.IsActiveConverter; +import gr.cite.notification.data.conventers.QueueInboxStatusConverter; import gr.cite.notification.data.types.JsonSQLType; import gr.cite.queueinbox.entity.QueueInbox; import gr.cite.queueinbox.entity.QueueInboxStatus; @@ -21,17 +22,17 @@ public class QueueInboxEntity implements QueueInbox { public static final String _id = "id"; - @Column(name = "\"queue\"", nullable = false, length = 50) + @Column(name = "\"queue\"", nullable = false, length = 200) private String queue; public static final String _queue = "queue"; - @Column(name = "\"exchange\"", nullable = false, length = 50) + @Column(name = "\"exchange\"", nullable = false, length = 200) private String exchange; public static final String _exchange = "exchange"; - @Column(name = "\"route\"", nullable = false, length = 50) + @Column(name = "\"route\"", nullable = false, length = 200) private String route; public static final String _route = "route"; @@ -62,11 +63,11 @@ public class QueueInboxEntity implements QueueInbox { public static final String _tenantId = "tenantId"; - @Column(name = "\"status\"", length = 50, nullable = false) - @Enumerated(EnumType.STRING) + @Column(name = "\"status\"", nullable = false) + @Convert(converter = QueueInboxStatusConverter.class) private QueueInboxStatus status; + public final static String _status = "status"; - public static final String _status = "status"; @Column(name = "\"created_at\"", nullable = false) private Instant createdAt; @@ -79,7 +80,7 @@ public class QueueInboxEntity implements QueueInbox { public static final String _updatedAt = "updatedAt"; - @Column(name = "\"is_active\"", length = 20, nullable = false) + @Column(name = "\"is_active\"", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/data/QueueOutboxEntity.java b/notification-service/notification/src/main/java/gr/cite/notification/data/QueueOutboxEntity.java index e62f2ec4d..232aa169f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/data/QueueOutboxEntity.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/data/QueueOutboxEntity.java @@ -2,6 +2,7 @@ package gr.cite.notification.data; import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.data.conventers.IsActiveConverter; +import gr.cite.notification.data.conventers.QueueOutboxNotifyStatusConverter; import gr.cite.queueoutbox.entity.QueueOutbox; import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus; import jakarta.persistence.*; @@ -19,12 +20,12 @@ public class QueueOutboxEntity implements QueueOutbox { public static final String _id = "id"; - @Column(name = "\"exchange\"", nullable = false, length = 50) + @Column(name = "\"exchange\"", nullable = false, length = 200) private String exchange; public static final String _exchange = "exchange"; - @Column(name = "\"route\"", length = 50) + @Column(name = "\"route\"", length = 200) private String route; public static final String _route = "route"; @@ -39,11 +40,10 @@ public class QueueOutboxEntity implements QueueOutbox { public static final String _message = "message"; - @Column(name = "\"notify_status\"", length = 20, nullable = false) - @Enumerated(EnumType.STRING) + @Column(name = "\"notify_status\"", nullable = false) + @Convert(converter = QueueOutboxNotifyStatusConverter.class) private QueueOutboxNotifyStatus notifyStatus; - - public static final String _notifyStatus = "notifyStatus"; + public final static String _notifyStatus = "notifyStatus"; @Column(name = "\"retry_count\"", nullable = false) private Integer retryCount; @@ -75,7 +75,7 @@ public class QueueOutboxEntity implements QueueOutbox { public static final String _updatedAt = "updatedAt"; - @Column(name = "\"is_active\"", length = 20, nullable = false) + @Column(name = "\"is_active\"", nullable = false) @Convert(converter = IsActiveConverter.class) private IsActive isActive; diff --git a/notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueInboxStatusConverter.java b/notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueInboxStatusConverter.java new file mode 100644 index 000000000..27e108488 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueInboxStatusConverter.java @@ -0,0 +1,19 @@ +package gr.cite.notification.data.conventers; + +import gr.cite.queueinbox.entity.QueueInboxStatus; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class QueueInboxStatusConverter implements AttributeConverter { + @Override + public Short convertToDatabaseColumn(QueueInboxStatus value) { + if (value == null) throw new IllegalArgumentException("Value could not be null for: " + this.getClass().getSimpleName()); + return value.getValue(); + } + + @Override + public QueueInboxStatus convertToEntityAttribute(Short dbData) { + return QueueInboxStatus.of(dbData); + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueOutboxNotifyStatusConverter.java b/notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueOutboxNotifyStatusConverter.java new file mode 100644 index 000000000..e7c5bfb52 --- /dev/null +++ b/notification-service/notification/src/main/java/gr/cite/notification/data/conventers/QueueOutboxNotifyStatusConverter.java @@ -0,0 +1,19 @@ +package gr.cite.notification.data.conventers; + +import gr.cite.queueoutbox.entity.QueueOutboxNotifyStatus; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; + +@Converter +public class QueueOutboxNotifyStatusConverter implements AttributeConverter { + @Override + public Short convertToDatabaseColumn(QueueOutboxNotifyStatus value) { + if (value == null) throw new IllegalArgumentException("Value could not be null for: " + this.getClass().getSimpleName()); + return value.getValue(); + } + + @Override + public QueueOutboxNotifyStatus convertToEntityAttribute(Short dbData) { + return QueueOutboxNotifyStatus.of(dbData); + } +} diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/User.java b/notification-service/notification/src/main/java/gr/cite/notification/model/User.java index 3ea51b87c..7d3596491 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/User.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/User.java @@ -29,8 +29,6 @@ public class User { public static final String _hash = "hash"; private String hash; - public static final String _tenantUsers = "tenantUsers"; - public UUID getId() { return id; } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/InAppNotificationCensor.java b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/InAppNotificationCensor.java index d20a14b4c..20b4ad8cf 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/InAppNotificationCensor.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/InAppNotificationCensor.java @@ -1,6 +1,7 @@ package gr.cite.notification.model.censorship; import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.notification.authorization.OwnedResource; import gr.cite.notification.authorization.Permission; import gr.cite.notification.convention.ConventionService; import gr.cite.tools.fieldset.FieldSet; @@ -12,6 +13,9 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.UUID; + @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class InAppNotificationCensor extends BaseCensor { @@ -24,9 +28,9 @@ public class InAppNotificationCensor extends BaseCensor { this.authService = authService; } - public void censor(FieldSet fields) { + public void censor(FieldSet fields, UUID userId) { logger.debug(new DataLogEntry("censoring fields", fields)); if (this.isEmpty(fields)) return; - this.authService.authorizeForce(Permission.BrowseInAppNotification); + this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseInAppNotification); } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserCensor.java b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserCensor.java index ffe0677b3..11afb5a08 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserCensor.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserCensor.java @@ -43,8 +43,5 @@ public class UserCensor extends BaseCensor { logger.debug(new DataLogEntry("censoring fields", fields)); if (this.isEmpty(fields)) return; this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser); - FieldSet tenantUsersFields = fields.extractPrefixed(this.asIndexerPrefix(User._tenantUsers)); - //FieldSet indicatorAccessesFields = fields.extractPrefixed(this.asIndexerPrefix(User._indicatorAccesses)); - //this.censorFactory.censor(IndicatorAccessCensor.class).censor(indicatorAccessesFields, userId); } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserNotificationPreferenceCensor.java b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserNotificationPreferenceCensor.java index 99f0a7090..13847a527 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserNotificationPreferenceCensor.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/model/censorship/UserNotificationPreferenceCensor.java @@ -1,6 +1,7 @@ package gr.cite.notification.model.censorship; import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.notification.authorization.OwnedResource; import gr.cite.notification.authorization.Permission; import gr.cite.notification.convention.ConventionService; import gr.cite.tools.fieldset.FieldSet; @@ -12,6 +13,9 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.UUID; + @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class UserNotificationPreferenceCensor extends BaseCensor { @@ -24,9 +28,9 @@ public class UserNotificationPreferenceCensor extends BaseCensor { this.authService = authService; } - public void censor(FieldSet fields) { + public void censor(FieldSet fields, UUID userId) { logger.debug(new DataLogEntry("censoring fields", fields)); if (this.isEmpty(fields)) return; - this.authService.authorizeForce(Permission.BrowseUserNotificationPreference); + this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUserNotificationPreference); } } diff --git a/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java index c6c349d6e..1c928e53a 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/service/inappnotification/InAppNotificationServiceImpl.java @@ -3,6 +3,7 @@ package gr.cite.notification.service.inappnotification; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.notification.authorization.Permission; import gr.cite.notification.common.enums.NotificationInAppTracking; +import gr.cite.notification.common.scope.user.UserScope; import gr.cite.notification.data.InAppNotificationEntity; import gr.cite.notification.data.TenantScopedEntityManager; import gr.cite.notification.model.deleter.InAppNotificationDeleter; @@ -36,13 +37,15 @@ public class InAppNotificationServiceImpl implements InAppNotificationService { private final AuthorizationService authService; private final DeleterFactory deleterFactory; + private final UserScope userScope; @Autowired - public InAppNotificationServiceImpl(QueryFactory queryFactory, TenantScopedEntityManager entityManager, AuthorizationService authService, DeleterFactory deleterFactory) { + public InAppNotificationServiceImpl(QueryFactory queryFactory, TenantScopedEntityManager entityManager, AuthorizationService authService, DeleterFactory deleterFactory, UserScope userScope) { this.queryFactory = queryFactory; this.entityManager = entityManager; this.authService = authService; this.deleterFactory = deleterFactory; + this.userScope = userScope; } public void markAsRead(UUID id) { @@ -52,9 +55,10 @@ public class InAppNotificationServiceImpl implements InAppNotificationService { public void markAsRead(List ids) { try { logger.debug(new DataLogEntry("marking as read in-app notifications", ids)); - + UUID userId = this.userScope.getUserId(); List items = this.queryFactory.query(InAppNotificationQuery.class) .ids(ids) + .userId(userId) .collect(); Instant now = Instant.now(); diff --git a/notification-service/pom.xml b/notification-service/pom.xml index a8e1700a0..ea8cdafce 100644 --- a/notification-service/pom.xml +++ b/notification-service/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.2 + 3.2.1 @@ -136,18 +136,18 @@ gr.cite rabbitmq-core - 2.1.1 + 2.1.2 gr.cite queue-inbox - 1.0.0 + 2.1.1 gr.cite queue-outbox - 1.0.0 + 2.1.1