From a56a9075b117572e505e8fa6d54d21c557b2d3be Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Fri, 19 Jan 2024 15:12:33 +0200 Subject: [PATCH] Fixes on notification service and core --- .../java/eu/eudat/data/QueueInboxEntity.java | 3 + .../java/eu/eudat/data/types/JsonSQLType.java | 80 +++++++++++++++++++ .../NotificationIntegrationEventHandler.java | 7 -- ...Event.java => NotifyIntegrationEvent.java} | 21 +++-- .../NotifyIntegrationEventHandler.java | 7 ++ ...=> NotifyIntegrationEventHandlerImpl.java} | 32 +------- .../ContactSupportServiceImpl.java | 18 ++--- .../description/DescriptionServiceImpl.java | 35 ++++---- .../DescriptionTemplateServiceImpl.java | 12 +-- .../eu/eudat/service/dmp/DmpServiceImpl.java | 46 ++++++----- .../eudat/service/user/UserServiceImpl.java | 32 ++++---- .../core/target/maven-archiver/pom.properties | 3 - .../notification-web/.gitignore | 33 ++++++++ .../src/main/resources/config/queue.yml | 2 +- .../target/classes/config/queue.yml | 2 +- .../notification/data/QueueInboxEntity.java | 5 ++ .../notification/data/types/JsonSQLType.java | 80 +++++++++++++++++++ .../integrationevent/AppRabbitConfigurer.java | 1 + .../InboxIntegrationEventConfigurer.java | 25 +++--- .../inbox/notify/NotifyIntegrationEvent.java | 3 + .../NotifyIntegrationEventHandlerImpl.java | 2 +- dmp-backend/notification-service/pom.xml | 2 +- .../web/src/main/resources/config/queue.yml | 2 +- 23 files changed, 323 insertions(+), 130 deletions(-) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/types/JsonSQLType.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEventHandler.java rename dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/{NotificationIntegrationEvent.java => NotifyIntegrationEvent.java} (84%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandler.java rename dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/{NotificationIntegrationEventHandlerImpl.java => NotifyIntegrationEventHandlerImpl.java} (64%) delete mode 100644 dmp-backend/core/target/maven-archiver/pom.properties create mode 100644 dmp-backend/notification-service/notification-web/.gitignore create mode 100644 dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/types/JsonSQLType.java 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 dc2e18d51..43a44bbd6 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,9 +2,11 @@ package eu.eudat.data; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.converters.enums.IsActiveConverter; +import eu.eudat.data.types.JsonSQLType; import gr.cite.queueinbox.entity.QueueInbox; import gr.cite.queueinbox.entity.QueueInboxStatus; import jakarta.persistence.*; +import org.hibernate.annotations.Type; import java.time.Instant; import java.util.UUID; @@ -37,6 +39,7 @@ public class QueueInboxEntity implements QueueInbox { private UUID messageId; public final static String _messageId = "messageId"; + @Type(JsonSQLType.class) @Column(name = "\"message\"", columnDefinition = "json", nullable = false) private String message; public final static String _message = "message"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/types/JsonSQLType.java b/dmp-backend/core/src/main/java/eu/eudat/data/types/JsonSQLType.java new file mode 100644 index 000000000..ae87c56d6 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/data/types/JsonSQLType.java @@ -0,0 +1,80 @@ +package eu.eudat.data.types; + +import org.hibernate.HibernateException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.type.SqlTypes; +import org.hibernate.usertype.UserType; + +import java.io.Serializable; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; + +public class JsonSQLType implements UserType { + + @Override + public int getSqlType() { + return SqlTypes.JSON; + } + + @Override + public Class returnedClass() { + return String.class; + } + + @Override + public boolean equals(String x, String y) { + if (x == null) { + return y == null; + } else { + return x.equals(y); + } + } + + @Override + public int hashCode(String x) { + return x.hashCode(); + } + + @Override + public String nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + String json = rs.getString(position); + return rs.wasNull() ? null : json; + } + + @Override + public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) throws SQLException { + if (value == null) { + st.setNull(index, Types.OTHER); + } else { + st.setObject(index, value, Types.OTHER); + } + } + + @Override + public String deepCopy(String value) throws HibernateException { + return value; + } + + @Override + public boolean isMutable() { + return false; + } + + @Override + public Serializable disassemble(String value) throws HibernateException { + return value; + } + + @Override + public String assemble(Serializable cached, Object owner) throws HibernateException { + return (String) cached; + } + + @Override + public String replace(String original, String target, Object owner) throws HibernateException { + return original; + } + +} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEventHandler.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEventHandler.java deleted file mode 100644 index 656aba6e7..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEventHandler.java +++ /dev/null @@ -1,7 +0,0 @@ -package eu.eudat.integrationevent.outbox.notification; - -import javax.management.InvalidApplicationException; - -public interface NotificationIntegrationEventHandler { - void handle(NotificationIntegrationEvent event) throws InvalidApplicationException; -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEvent.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEvent.java similarity index 84% rename from dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEvent.java rename to dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEvent.java index 2270b4be9..f5e0e7a7f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEvent.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEvent.java @@ -5,16 +5,25 @@ import eu.eudat.integrationevent.TrackedEvent; import java.util.UUID; -public class NotificationIntegrationEvent extends TrackedEvent { +public class NotifyIntegrationEvent extends TrackedEvent { private UUID userId; - private UUID tenant; + + private UUID tenantId; + private UUID notificationType; + private NotificationContactType contactTypeHint; + private String contactHint; + private String data; + private String provenanceRef; + public NotifyIntegrationEvent() { + } + public UUID getUserId() { return userId; } @@ -23,12 +32,12 @@ public class NotificationIntegrationEvent extends TrackedEvent { this.userId = userId; } - public UUID getTenant() { - return tenant; + public UUID getTenantId() { + return tenantId; } - public void setTenant(UUID tenant) { - this.tenant = tenant; + public void setTenantId(UUID tenantId) { + this.tenantId = tenantId; } public UUID getNotificationType() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandler.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandler.java new file mode 100644 index 000000000..a5bb251d9 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandler.java @@ -0,0 +1,7 @@ +package eu.eudat.integrationevent.outbox.notification; + +import javax.management.InvalidApplicationException; + +public interface NotifyIntegrationEventHandler { + void handle(NotifyIntegrationEvent event) throws InvalidApplicationException; +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEventHandlerImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java similarity index 64% rename from dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEventHandlerImpl.java rename to dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java index 935ed86c8..9da92b00e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotificationIntegrationEventHandlerImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java @@ -1,10 +1,6 @@ package eu.eudat.integrationevent.outbox.notification; -import eu.eudat.audit.AuditableAction; import eu.eudat.commons.enums.ContactInfoType; -import eu.eudat.commons.enums.notification.NotificationNotifyState; -import eu.eudat.commons.enums.notification.NotificationTrackingProcess; -import eu.eudat.commons.enums.notification.NotificationTrackingState; import eu.eudat.data.UserContactInfoEntity; import eu.eudat.data.UserEntity; import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent; @@ -24,15 +20,14 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; import javax.management.InvalidApplicationException; -import java.time.Instant; import java.util.List; import java.util.UUID; @Component @RequestScope -public class NotificationIntegrationEventHandlerImpl implements NotificationIntegrationEventHandler { +public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEventHandler { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotificationIntegrationEventHandlerImpl.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifyIntegrationEventHandlerImpl.class)); private final NotificationService notificationService; @@ -45,7 +40,7 @@ public class NotificationIntegrationEventHandlerImpl implements NotificationInte private final ValidatorFactory validatorFactory; @Autowired - public NotificationIntegrationEventHandlerImpl( + public NotifyIntegrationEventHandlerImpl( OutboxService outboxService, NotificationService notificationService, QueryFactory queryFactory, @@ -58,31 +53,12 @@ public class NotificationIntegrationEventHandlerImpl implements NotificationInte } @Override - public void handle(NotificationIntegrationEvent event) throws InvalidApplicationException { + public void handle(NotifyIntegrationEvent event) throws InvalidApplicationException { OutboxIntegrationEvent message = new OutboxIntegrationEvent(); message.setMessageId(UUID.randomUUID()); message.setType(OutboxIntegrationEvent.NOTIFY); message.setEvent(event); this.outboxService.publish(message); -// NotificationPersist persist = new NotificationPersist(); -// persist.setType(event.getNotificationType()); -// persist.setUserId(event.getUserId()); -// persist.setContactHint(event.getContactHint()); -// persist.setContactTypeHint(event.getContactTypeHint()); -// persist.setData(event.getData()); -// persist.setNotifyState(NotificationNotifyState.PENDING); -// persist.setNotifiedWith(event.getContactTypeHint()); -// persist.setRetryCount(0); -// persist.setTrackingState(NotificationTrackingState.UNDEFINED); -// persist.setTrackingProcess(NotificationTrackingProcess.PENDING); -// persist.setTrackingData(null); -// persist.setProvenanceRef(event.getProvenanceRef()); -// persist.setNotifiedAt(Instant.now()); -// validatorFactory.validator(NotificationPersist.NotificationPersistValidator.class).validateForce(persist); -// if (isNotificationConsistent(persist)) { -// notificationService.persist(persist, null); -// auditService.track(AuditableAction.Notification_Persist, "notification_event", event); -// } } private boolean isNotificationConsistent(NotificationPersist notification) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java index 16550be3d..63ca2752f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/contactsupport/ContactSupportServiceImpl.java @@ -8,8 +8,8 @@ import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.notification.*; import eu.eudat.configurations.notification.NotificationProperties; import eu.eudat.data.UserContactInfoEntity; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEvent; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEventHandler; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import eu.eudat.model.UserContactInfo; import eu.eudat.model.persist.ContactSupportPersist; import eu.eudat.model.persist.PublicContactSupportPersist; @@ -41,7 +41,7 @@ public class ContactSupportServiceImpl implements ContactSupportService { private final UserScope userScope; - private final NotificationIntegrationEventHandler notificationIntegrationEventHandler; + private final NotifyIntegrationEventHandler notifyIntegrationEventHandler; private final NotificationProperties notificationProperties; @Autowired @@ -50,13 +50,13 @@ public class ContactSupportServiceImpl implements ContactSupportService { QueryFactory queryFactory, JsonHandlingService jsonHandlingService, UserScope userScope, - NotificationIntegrationEventHandler notificationIntegrationEventHandler, + NotifyIntegrationEventHandler notifyIntegrationEventHandler, NotificationProperties notificationProperties) { this.authorizationService = authorizationService; this.queryFactory = queryFactory; this.jsonHandlingService = jsonHandlingService; this.userScope = userScope; - this.notificationIntegrationEventHandler = notificationIntegrationEventHandler; + this.notifyIntegrationEventHandler = notifyIntegrationEventHandler; this.notificationProperties = notificationProperties; } @@ -65,7 +65,7 @@ public class ContactSupportServiceImpl implements ContactSupportService { logger.debug(new MapLogEntry("send contact email").And("model", model)); this.authorizationService.authorizeForce(Permission.SendContactSupport); - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(this.userScope.getUserId()); query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal)); @@ -86,7 +86,7 @@ public class ContactSupportServiceImpl implements ContactSupportService { data.setFields(fieldInfoList); event.setData(jsonHandlingService.toJsonSafe(data)); - notificationIntegrationEventHandler.handle(event); + notifyIntegrationEventHandler.handle(event); } @Override @@ -94,7 +94,7 @@ public class ContactSupportServiceImpl implements ContactSupportService { logger.debug(new MapLogEntry("public send contact email").And("model", model)); this.authorizationService.authorizeForce(Permission.PublicSendContactSupport); - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); List contactPairs = new ArrayList<>(); contactPairs.add(new ContactPair(ContactInfoType.Email, notificationProperties.getContactSupportEmail())); @@ -112,7 +112,7 @@ public class ContactSupportServiceImpl implements ContactSupportService { data.setFields(fieldInfoList); event.setData(jsonHandlingService.toJsonSafe(data)); - notificationIntegrationEventHandler.handle(event); + notifyIntegrationEventHandler.handle(event); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java index 7d2ddbb87..9e2351c22 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java @@ -1,6 +1,5 @@ package eu.eudat.service.description; -import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.JsonHandlingService; @@ -21,8 +20,8 @@ import eu.eudat.data.*; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.event.DescriptionTouchedEvent; import eu.eudat.event.EventBroker; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEvent; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEventHandler; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import eu.eudat.model.*; import eu.eudat.model.builder.DescriptionBuilder; import eu.eudat.model.deleter.DescriptionDeleter; @@ -100,7 +99,7 @@ public class DescriptionServiceImpl implements DescriptionService { private final XmlHandlingService xmlHandlingService; private final FileTransformerService fileTransformerService; - private final NotificationIntegrationEventHandler eventHandler; + private final NotifyIntegrationEventHandler eventHandler; private final NotificationProperties notificationProperties; @@ -109,18 +108,18 @@ public class DescriptionServiceImpl implements DescriptionService { @Autowired public DescriptionServiceImpl( - EntityManager entityManager, - AuthorizationService authorizationService, - DeleterFactory deleterFactory, - BuilderFactory builderFactory, - ConventionService conventionService, - ErrorThesaurusProperties errors, - MessageSource messageSource, - EventBroker eventBroker, - QueryFactory queryFactory, - JsonHandlingService jsonHandlingService, - UserScope userScope, - XmlHandlingService xmlHandlingService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService) { + EntityManager entityManager, + AuthorizationService authorizationService, + DeleterFactory deleterFactory, + BuilderFactory builderFactory, + ConventionService conventionService, + ErrorThesaurusProperties errors, + MessageSource messageSource, + EventBroker eventBroker, + QueryFactory queryFactory, + JsonHandlingService jsonHandlingService, + UserScope userScope, + XmlHandlingService xmlHandlingService, NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, FileTransformerService fileTransformerService, ElasticService elasticService) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -225,7 +224,7 @@ public class DescriptionServiceImpl implements DescriptionService { } private void createDescriptionNotificationEvent(DescriptionEntity description, UserEntity user, NotificationContactType type) throws InvalidApplicationException { - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); event.setUserId(this.userScope.getUserId()); UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(user.getId()); @@ -250,7 +249,7 @@ public class DescriptionServiceImpl implements DescriptionService { eventHandler.handle(event); } - private NotificationIntegrationEvent applyNotificationType(DescriptionStatus status, NotificationIntegrationEvent event) { + private NotifyIntegrationEvent applyNotificationType(DescriptionStatus status, NotifyIntegrationEvent event) { switch (status) { case Draft: event.setNotificationType(notificationProperties.getDescriptionModifiedType()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index d4905b824..e343d8681 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -19,8 +19,8 @@ import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.UserDescriptionTemplateEntity; import eu.eudat.data.UserEntity; import eu.eudat.errorcode.ErrorThesaurusProperties; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEvent; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEventHandler; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.UserContactInfo; import eu.eudat.model.builder.DescriptionTemplateBuilder; @@ -116,7 +116,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic private final JsonHandlingService jsonHandlingService; - private final NotificationIntegrationEventHandler eventHandler; + private final NotifyIntegrationEventHandler eventHandler; private final NotificationProperties notificationProperties; @@ -137,7 +137,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic ResponseUtilsService responseUtilsService, StorageFileService storageFileService, JsonHandlingService jsonHandlingService, - NotificationIntegrationEventHandler eventHandler, + NotifyIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ValidatorFactory validatorFactory) { this.entityManager = entityManager; @@ -237,8 +237,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic } private void sendDescriptionTemplateInvitationEvent(UserDescriptionTemplateEntity userDescriptionTemplate, NotificationContactType type) throws InvalidApplicationException { - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); - event.setTenant(tenantScope.getTenant()); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); + event.setTenantId(tenantScope.getTenant()); event.setUserId(userScope.getUserIdSafe()); UserEntity user = this.entityManager.find(UserEntity.class, userDescriptionTemplate.getUserId()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index f34e63bcc..089b2ce34 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -22,8 +22,8 @@ import eu.eudat.data.*; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.event.DmpTouchedEvent; import eu.eudat.event.EventBroker; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEvent; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEventHandler; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import eu.eudat.model.Dmp; import eu.eudat.model.DmpUser; import eu.eudat.model.Reference; @@ -112,29 +112,37 @@ public class DmpServiceImpl implements DmpService { private final DescriptionService descriptionService; private final FileTransformerService fileTransformerService; - private final NotificationIntegrationEventHandler eventHandler; + private final NotifyIntegrationEventHandler eventHandler; private final NotificationProperties notificationProperties; private final ActionConfirmationService actionConfirmationService; - private final ValidatorFactory validatorFactory; + private final gr.cite.tools.validation.ValidatorFactory validatorFactory; private final ElasticService elasticService; @Autowired public DmpServiceImpl( - EntityManager entityManager, - AuthorizationService authorizationService, - DeleterFactory deleterFactory, - BuilderFactory builderFactory, - QueryFactory queryFactory, - ConventionService conventionService, - ErrorThesaurusProperties errors, - MessageSource messageSource, - XmlHandlingService xmlHandlingService, - JsonHandlingService jsonHandlingService, - UserScope userScope, EventBroker eventBroker, DescriptionService descriptionService, NotificationIntegrationEventHandler eventHandler, NotificationProperties notificationProperties, ActionConfirmationService actionConfirmationService, FileTransformerService fileTransformerService, ValidatorFactory validatorFactory, ElasticService elasticService) { + EntityManager entityManager, + AuthorizationService authorizationService, + DeleterFactory deleterFactory, + BuilderFactory builderFactory, + QueryFactory queryFactory, + ConventionService conventionService, + ErrorThesaurusProperties errors, + MessageSource messageSource, + XmlHandlingService xmlHandlingService, + JsonHandlingService jsonHandlingService, + UserScope userScope, + EventBroker eventBroker, + DescriptionService descriptionService, + NotifyIntegrationEventHandler eventHandler, + NotificationProperties notificationProperties, + ActionConfirmationService actionConfirmationService, + FileTransformerService fileTransformerService, + ValidatorFactory validatorFactory, + ElasticService elasticService) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -196,7 +204,7 @@ public class DmpServiceImpl implements DmpService { } private void createDmpNotificationEvent(DmpEntity dmp, UserEntity user, NotificationContactType type) throws InvalidApplicationException { - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); event.setUserId(this.userScope.getUserId()); UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(user.getId()); query.setOrder(new Ordering().addAscending(UserContactInfo._ordinal)); @@ -220,7 +228,7 @@ public class DmpServiceImpl implements DmpService { eventHandler.handle(event); } - private NotificationIntegrationEvent applyNotificationType(DmpStatus status, NotificationIntegrationEvent event) { + private NotifyIntegrationEvent applyNotificationType(DmpStatus status, NotifyIntegrationEvent event) { switch (status) { case Draft: event.setNotificationType(notificationProperties.getDmpModifiedType()); @@ -785,7 +793,7 @@ public class DmpServiceImpl implements DmpService { private void createDmpInvitationExistingUserEvent(UserEntity recipient, DmpEntity dmp, DmpUserRole role, String email, NotificationContactType type) throws InvalidApplicationException { - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); event.setUserId(this.userScope.getUserIdSafe()); List contactPairs = new ArrayList<>(); @@ -809,7 +817,7 @@ public class DmpServiceImpl implements DmpService { private void sendDmpInvitationExternalUser(String email, DmpEntity dmp, DmpUserRole role) throws JAXBException, InvalidApplicationException { String token = this.createActionConfirmation(email, dmp, role); - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); event.setUserId(this.userScope.getUserIdSafe()); List contactPairs = new ArrayList<>(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java index 103d4ff9f..df3de7177 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/user/UserServiceImpl.java @@ -23,8 +23,8 @@ import eu.eudat.data.*; import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.event.UserTouchedEvent; import eu.eudat.event.EventBroker; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEvent; -import eu.eudat.integrationevent.outbox.notification.NotificationIntegrationEventHandler; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEvent; +import eu.eudat.integrationevent.outbox.notification.NotifyIntegrationEventHandler; import eu.eudat.model.User; import eu.eudat.model.UserContactInfo; import eu.eudat.model.UserCredential; @@ -99,7 +99,7 @@ public class UserServiceImpl implements UserService { private final KeycloakService keycloakService; private final ActionConfirmationService actionConfirmationService; private final NotificationProperties notificationProperties; - private final NotificationIntegrationEventHandler eventHandler; + private final NotifyIntegrationEventHandler eventHandler; private final ValidatorFactory validatorFactory; @@ -107,17 +107,17 @@ public class UserServiceImpl implements UserService { @Autowired public UserServiceImpl( - EntityManager entityManager, - AuthorizationService authorizationService, - DeleterFactory deleterFactory, - BuilderFactory builderFactory, - ConventionService conventionService, - ErrorThesaurusProperties errors, - MessageSource messageSource, - EventBroker eventBroker, - JsonHandlingService jsonHandlingService, - XmlHandlingService xmlHandlingService, QueryFactory queryFactory, - UserScope userScope, KeycloakService keycloakService, ActionConfirmationService actionConfirmationService, NotificationProperties notificationProperties, NotificationIntegrationEventHandler eventHandler, ValidatorFactory validatorFactory, ElasticService elasticService) { + EntityManager entityManager, + AuthorizationService authorizationService, + DeleterFactory deleterFactory, + BuilderFactory builderFactory, + ConventionService conventionService, + ErrorThesaurusProperties errors, + MessageSource messageSource, + EventBroker eventBroker, + JsonHandlingService jsonHandlingService, + XmlHandlingService xmlHandlingService, QueryFactory queryFactory, + UserScope userScope, KeycloakService keycloakService, ActionConfirmationService actionConfirmationService, NotificationProperties notificationProperties, NotifyIntegrationEventHandler eventHandler, ValidatorFactory validatorFactory, ElasticService elasticService) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -363,7 +363,7 @@ public class UserServiceImpl implements UserService { } private void createMergeNotificationEvent(String token, UserEntity user, String email, NotificationContactType type) throws InvalidApplicationException { - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); event.setUserId(user.getId()); List contactPairs = new ArrayList<>(); contactPairs.add(new ContactPair(ContactInfoType.Email, email)); @@ -393,7 +393,7 @@ public class UserServiceImpl implements UserService { } private void createRemoveCredentialNotificationEvent(String token, UUID userId, NotificationContactType type) throws InvalidApplicationException { - NotificationIntegrationEvent event = new NotificationIntegrationEvent(); + NotifyIntegrationEvent event = new NotifyIntegrationEvent(); event.setUserId(userId); event.setContactTypeHint(type); event.setNotificationType(notificationProperties.getRemoveCredentialConfirmationType()); diff --git a/dmp-backend/core/target/maven-archiver/pom.properties b/dmp-backend/core/target/maven-archiver/pom.properties deleted file mode 100644 index bc6d378ce..000000000 --- a/dmp-backend/core/target/maven-archiver/pom.properties +++ /dev/null @@ -1,3 +0,0 @@ -artifactId=core -groupId=eu.eudat -version=1.0.0-SNAPSHOT diff --git a/dmp-backend/notification-service/notification-web/.gitignore b/dmp-backend/notification-service/notification-web/.gitignore new file mode 100644 index 000000000..5eac309eb --- /dev/null +++ b/dmp-backend/notification-service/notification-web/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ \ No newline at end of file diff --git a/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml b/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml index a61881d7d..6a5cdd471 100644 --- a/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml +++ b/dmp-backend/notification-service/notification-web/src/main/resources/config/queue.yml @@ -9,7 +9,7 @@ spring: queue: rabbitmq: enable: false - app-id: ${THE_API_ID} + app-id: ${QUEUE_APP_ID} durable: null queue: null exchange: null diff --git a/dmp-backend/notification-service/notification-web/target/classes/config/queue.yml b/dmp-backend/notification-service/notification-web/target/classes/config/queue.yml index a61881d7d..6a5cdd471 100644 --- a/dmp-backend/notification-service/notification-web/target/classes/config/queue.yml +++ b/dmp-backend/notification-service/notification-web/target/classes/config/queue.yml @@ -9,7 +9,7 @@ spring: queue: rabbitmq: enable: false - app-id: ${THE_API_ID} + app-id: ${QUEUE_APP_ID} durable: null queue: null exchange: null diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java index 9fee15112..bc30bb257 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/QueueInboxEntity.java @@ -2,10 +2,14 @@ package gr.cite.notification.data; import gr.cite.notification.common.enums.IsActive; import gr.cite.notification.data.conventers.IsActiveConverter; +import gr.cite.notification.data.types.JsonSQLType; import gr.cite.queueinbox.entity.QueueInbox; import gr.cite.queueinbox.entity.QueueInboxStatus; import jakarta.persistence.*; +import org.hibernate.annotations.Type; +import org.hibernate.usertype.UserType; + import java.time.Instant; import java.util.UUID; @@ -37,6 +41,7 @@ public class QueueInboxEntity implements QueueInbox { private UUID messageId; public final static String _messageId = "messageId"; + @Type(JsonSQLType.class) @Column(name = "\"message\"", columnDefinition = "json", nullable = false) private String message; public final static String _message = "message"; diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/types/JsonSQLType.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/types/JsonSQLType.java new file mode 100644 index 000000000..434f8eda1 --- /dev/null +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/data/types/JsonSQLType.java @@ -0,0 +1,80 @@ +package gr.cite.notification.data.types; + +import org.hibernate.HibernateException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.type.SqlTypes; +import org.hibernate.usertype.UserType; + +import java.io.Serializable; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; + +public class JsonSQLType implements UserType { + + @Override + public int getSqlType() { + return SqlTypes.JSON; + } + + @Override + public Class returnedClass() { + return String.class; + } + + @Override + public boolean equals(String x, String y) { + if (x == null) { + return y == null; + } else { + return x.equals(y); + } + } + + @Override + public int hashCode(String x) { + return x.hashCode(); + } + + @Override + public String nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException { + String json = rs.getString(position); + return rs.wasNull() ? null : json; + } + + @Override + public void nullSafeSet(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) throws SQLException { + if (value == null) { + st.setNull(index, Types.OTHER); + } else { + st.setObject(index, value, Types.OTHER); + } + } + + @Override + public String deepCopy(String value) throws HibernateException { + return value; + } + + @Override + public boolean isMutable() { + return false; + } + + @Override + public Serializable disassemble(String value) throws HibernateException { + return value; + } + + @Override + public String assemble(Serializable cached, Object owner) throws HibernateException { + return (String) cached; + } + + @Override + public String replace(String original, String target, Object owner) throws HibernateException { + return original; + } + +} diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java index 753d7db09..a0e003cb9 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/AppRabbitConfigurer.java @@ -48,4 +48,5 @@ public class AppRabbitConfigurer extends RabbitConfigurer { return inboxRepository.create(params) != null; }; } + } diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/InboxIntegrationEventConfigurer.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/InboxIntegrationEventConfigurer.java index ec7abfd6a..998ce70f3 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/InboxIntegrationEventConfigurer.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/InboxIntegrationEventConfigurer.java @@ -4,31 +4,30 @@ import gr.cite.notification.integrationevent.inbox.InboxProperties; import gr.cite.notification.integrationevent.inbox.InboxRepositoryImpl; import gr.cite.queueinbox.InboxConfigurer; import gr.cite.queueinbox.repository.InboxRepository; -import jakarta.persistence.EntityManagerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; -import org.springframework.stereotype.Component; @Configuration @EnableConfigurationProperties({InboxProperties.class}) @ConditionalOnProperty(prefix = "queue.task.listener", name = "enable", matchIfMissing = false) public class InboxIntegrationEventConfigurer extends InboxConfigurer { - private ApplicationContext applicationContext; - private InboxProperties inboxProperties; - public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties) { - this.applicationContext = applicationContext; - this.inboxProperties = inboxProperties; - } + private ApplicationContext applicationContext; - @Bean - public InboxRepository inboxRepositoryCreator() { - return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties); - } + private InboxProperties inboxProperties; + + public InboxIntegrationEventConfigurer(ApplicationContext applicationContext, InboxProperties inboxProperties) { + this.applicationContext = applicationContext; + this.inboxProperties = inboxProperties; + } + + @Bean + public InboxRepository inboxRepositoryCreator() { + return new InboxRepositoryImpl(this.applicationContext, this.inboxProperties); + } } diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEvent.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEvent.java index d04106d74..b07162793 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEvent.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEvent.java @@ -21,6 +21,9 @@ public class NotifyIntegrationEvent extends TrackedEvent { private String provenanceRef; + public NotifyIntegrationEvent() { + } + public UUID getUserId() { return userId; } diff --git a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java index 9b304b7fc..b1cf1ecea 100644 --- a/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java +++ b/dmp-backend/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java @@ -150,7 +150,7 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent } catch (Exception ex) { logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); } - return null; + return EventProcessingStatus.Success; } } diff --git a/dmp-backend/notification-service/pom.xml b/dmp-backend/notification-service/pom.xml index 02ab51031..2aba22d07 100644 --- a/dmp-backend/notification-service/pom.xml +++ b/dmp-backend/notification-service/pom.xml @@ -130,7 +130,7 @@ gr.cite rabbitmq-core - 1.0.0 + 2.1.1 diff --git a/dmp-backend/web/src/main/resources/config/queue.yml b/dmp-backend/web/src/main/resources/config/queue.yml index a9abcd96f..3aa39d16c 100644 --- a/dmp-backend/web/src/main/resources/config/queue.yml +++ b/dmp-backend/web/src/main/resources/config/queue.yml @@ -9,7 +9,7 @@ spring: queue: rabbitmq: enable: false - app-id: ${THE_API_ID} + app-id: ${QUEUE_APP_ID} durable: null queue: null exchange: null