diff --git a/annotation-service/annotation-web/src/main/resources/config/queue.yml b/annotation-service/annotation-web/src/main/resources/config/queue.yml index 903a00663..919162228 100644 --- a/annotation-service/annotation-web/src/main/resources/config/queue.yml +++ b/annotation-service/annotation-web/src/main/resources/config/queue.yml @@ -42,9 +42,10 @@ queue: options: exchange: null tenant-removal-topic: tenant.remove - tenant-touched-topic: tenant.touch + tenant-touch-topic: tenant.touch user-removal-topic: user.remove - user-touched-topic: user.touch + user-touch-topic: user.touch + annotation-entity-touch-topic: annotation.entity.touch rabbitmq: enable: false interval-seconds: 30 diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/audit/AuditableAction.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/audit/AuditableAction.java index 6d65a7a31..14f1c57a6 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/audit/AuditableAction.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/audit/AuditableAction.java @@ -51,4 +51,9 @@ public class AuditableAction { public static final EventId Annotation_Persist = new EventId(24002, "Annotation_Persist"); public static final EventId Annotation_Delete = new EventId(24003, "Annotation_Delete"); + public static final EventId Entity_User_Query = new EventId(25000, "Entity_User_Query"); + public static final EventId Entity_User_Lookup = new EventId(25001, "Entity_User_Lookup"); + public static final EventId Entity_User_Persist = new EventId(25002, "Entity_User_Persist"); + public static final EventId Entity_User_Delete = new EventId(25003, "Entity_User_Delete"); + } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/validation/UuidValidator.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/validation/UuidValidator.java new file mode 100644 index 000000000..909b11611 --- /dev/null +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/validation/UuidValidator.java @@ -0,0 +1,35 @@ +package gr.cite.annotation.common.validation; + +import gr.cite.annotation.convention.ConventionService; +import gr.cite.annotation.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.validation.specification.Specification; +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +public class UuidValidator extends BaseValidator { + + private final MessageSource messageSource; + + protected UuidValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return UUID.class; + } + + @Override + protected List specifications(UUID item) { + return Arrays.asList( + this.spec() + .must(() -> this.isValidGuid(item)) + .failOn("uuid").failWith(messageSource.getMessage("Validation_Required", new Object[]{"uuid"}, LocaleContextHolder.getLocale())) + ); + } +} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/AppRabbitConfigurer.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/AppRabbitConfigurer.java index 15448a5fa..a9390e3b0 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/AppRabbitConfigurer.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/AppRabbitConfigurer.java @@ -33,9 +33,10 @@ public class AppRabbitConfigurer extends RabbitConfigurer { public InboxBindings inboxBindingsCreator() { List bindingItems = new ArrayList<>(); bindingItems.addAll(this.inboxProperties.getTenantRemovalTopic()); - bindingItems.addAll(this.inboxProperties.getTenantTouchedTopic()); + bindingItems.addAll(this.inboxProperties.getTenantTouchTopic()); bindingItems.addAll(this.inboxProperties.getUserRemovalTopic()); - bindingItems.addAll(this.inboxProperties.getUserTouchedTopic()); + bindingItems.addAll(this.inboxProperties.getUserTouchTopic()); + bindingItems.addAll(this.inboxProperties.getAnnotationEntityTouchTopic()); return new InboxBindings(bindingItems); } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxProperties.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxProperties.java index 331216d0a..a2b133711 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxProperties.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxProperties.java @@ -11,39 +11,47 @@ public class InboxProperties { private final List tenantRemovalTopic; - private final List tenantTouchedTopic; + private final List tenantTouchTopic; private final List userRemovalTopic; - private final List userTouchedTopic; + private final List userTouchTopic; + + private final List annotationEntityTouchTopic; public InboxProperties( String exchange, List tenantRemovalTopic, - List tenantTouchedTopic, + List tenantTouchTopic, List userRemovalTopic, - List userTouchedTopic) { + List userTouchTopic, + List annotationEntityTouchTopic) { this.exchange = exchange; this.tenantRemovalTopic = tenantRemovalTopic; - this.tenantTouchedTopic = tenantTouchedTopic; + this.tenantTouchTopic = tenantTouchTopic; this.userRemovalTopic = userRemovalTopic; - this.userTouchedTopic = userTouchedTopic; + this.userTouchTopic = userTouchTopic; + this.annotationEntityTouchTopic = annotationEntityTouchTopic; } public List getTenantRemovalTopic() { return tenantRemovalTopic; } - public List getTenantTouchedTopic() { - return tenantTouchedTopic; + public List getTenantTouchTopic() { + return tenantTouchTopic; } public List getUserRemovalTopic() { return userRemovalTopic; } - public List getUserTouchedTopic() { - return userTouchedTopic; + public List getUserTouchTopic() { + return userTouchTopic; + } + + public List getAnnotationEntityTouchTopic() { + return annotationEntityTouchTopic; } public String getExchange() { diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java index 1be479469..b3822c478 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/InboxRepositoryImpl.java @@ -5,10 +5,11 @@ import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.common.scope.fake.FakeRequestScope; import gr.cite.annotation.data.QueueInboxEntity; import gr.cite.annotation.integrationevent.TrackedEvent; +import gr.cite.annotation.integrationevent.inbox.annotationentitytouch.AnnotationEntityTouchedIntegrationEventHandler; import gr.cite.annotation.integrationevent.inbox.tenantremoval.TenantRemovalIntegrationEventHandler; -import gr.cite.annotation.integrationevent.inbox.tenanttouched.TenantTouchedIntegrationEventHandler; +import gr.cite.annotation.integrationevent.inbox.tenanttouch.TenantTouchedIntegrationEventHandler; import gr.cite.annotation.integrationevent.inbox.userremoval.UserRemovalIntegrationEventHandler; -import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEventHandler; +import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEventHandler; import gr.cite.annotation.query.QueueInboxQuery; import gr.cite.queueinbox.entity.QueueInbox; import gr.cite.queueinbox.entity.QueueInboxStatus; @@ -325,12 +326,14 @@ public class InboxRepositoryImpl implements InboxRepository { logger.debug("Processing message with routing key '{}'", routingKey); if (this.routingKeyMatched(routingKey, this.inboxProperties.getTenantRemovalTopic())) handler = this.applicationContext.getBean(TenantRemovalIntegrationEventHandler.class); - else if (this.routingKeyMatched(routingKey, this.inboxProperties.getTenantTouchedTopic())) + else if (this.routingKeyMatched(routingKey, this.inboxProperties.getTenantTouchTopic())) handler = this.applicationContext.getBean(TenantTouchedIntegrationEventHandler.class); else if (this.routingKeyMatched(routingKey, this.inboxProperties.getUserRemovalTopic())) handler = this.applicationContext.getBean(UserRemovalIntegrationEventHandler.class); - else if (this.routingKeyMatched(routingKey, this.inboxProperties.getUserTouchedTopic())) + else if (this.routingKeyMatched(routingKey, this.inboxProperties.getUserTouchTopic())) handler = this.applicationContext.getBean(UserTouchedIntegrationEventHandler.class); + else if (this.routingKeyMatched(routingKey, this.inboxProperties.getAnnotationEntityTouchTopic())) + handler = this.applicationContext.getBean(AnnotationEntityTouchedIntegrationEventHandler.class); else { logger.error("No handler found for message routing key '{}'. Discarding.", routingKey); handler = null; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEvent.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEvent.java new file mode 100644 index 000000000..1c1e3402c --- /dev/null +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEvent.java @@ -0,0 +1,85 @@ +package gr.cite.annotation.integrationevent.inbox.annotationentitytouch; + +import gr.cite.annotation.common.validation.BaseValidator; +import gr.cite.annotation.common.validation.UuidValidator; +import gr.cite.annotation.convention.ConventionService; +import gr.cite.annotation.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +public class AnnotationEntityTouchedIntegrationEvent { + + private UUID entityId; + + public static final String _entityId = "entityId"; + + private List userIds; + + public static final String _userIds = "userIds"; + + public UUID getEntityId() { + return entityId; + } + + public void setEntityId(UUID entityId) { + this.entityId = entityId; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } + + @Component(AnnotationEntityTouchedIntegrationEvent.AnnotationEntityTouchedIntegrationEventValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class AnnotationEntityTouchedIntegrationEventValidator extends BaseValidator { + + public static final String ValidatorName = "AnnotationEntityTouchedIntegrationEventValidator"; + + private final MessageSource messageSource; + + private final ValidatorFactory validatorFactory; + + protected AnnotationEntityTouchedIntegrationEventValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { + super(conventionService, errors); + this.messageSource = messageSource; + this.validatorFactory = validatorFactory; + } + + @Override + protected Class modelClass() { + return AnnotationEntityTouchedIntegrationEvent.class; + } + + @Override + protected List specifications(AnnotationEntityTouchedIntegrationEvent item) { + return Arrays.asList( + this.spec() + .iff(() -> !this.isNull(item.getEntityId())) + .must(() -> this.isValidGuid(item.getEntityId())) + .failOn(AnnotationEntityTouchedIntegrationEvent._entityId).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationEntityTouchedIntegrationEvent._entityId}, LocaleContextHolder.getLocale())), + this.spec() + .must(() -> !this.isListNullOrEmpty(item.getUserIds())) + .failOn(AnnotationEntityTouchedIntegrationEvent._userIds).failWith(messageSource.getMessage("Validation_Required", new Object[]{AnnotationEntityTouchedIntegrationEvent._userIds}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isListNullOrEmpty(item.getUserIds())) + .on(AnnotationEntityTouchedIntegrationEvent._userIds) + .over(item.getUserIds()) + .using((i) -> this.validatorFactory.validator(UuidValidator.class)) + ); + } + } + +} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandler.java new file mode 100644 index 000000000..4f771def3 --- /dev/null +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandler.java @@ -0,0 +1,7 @@ +package gr.cite.annotation.integrationevent.inbox.annotationentitytouch; + +import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler; + +public interface AnnotationEntityTouchedIntegrationEventHandler extends IntegrationEventHandler { + +} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandlerImpl.java new file mode 100644 index 000000000..034ea668e --- /dev/null +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandlerImpl.java @@ -0,0 +1,149 @@ +package gr.cite.annotation.integrationevent.inbox.annotationentitytouch; + +import gr.cite.annotation.audit.AuditableAction; +import gr.cite.annotation.common.JsonHandlingService; +import gr.cite.annotation.common.enums.IsActive; +import gr.cite.annotation.common.scope.fake.FakeRequestScope; +import gr.cite.annotation.data.EntityUserEntity; +import gr.cite.annotation.integrationevent.inbox.EventProcessingStatus; +import gr.cite.annotation.integrationevent.inbox.InboxPrincipal; +import gr.cite.annotation.integrationevent.inbox.IntegrationEventProperties; +import gr.cite.annotation.query.EntityUserQuery; +import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; +import gr.cite.tools.auditing.AuditService; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.logging.LoggerService; +import gr.cite.tools.validation.ValidatorFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; +import jakarta.persistence.EntityTransaction; +import jakarta.persistence.OptimisticLockException; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.util.AbstractMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class AnnotationEntityTouchedIntegrationEventHandlerImpl implements AnnotationEntityTouchedIntegrationEventHandler { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(AnnotationEntityTouchedIntegrationEventHandlerImpl.class)); + + private final JsonHandlingService jsonHandlingService; + + private final ValidatorFactory validatorFactory; + + private final ApplicationContext applicationContext; + + private final QueryFactory queryFactory; + + public AnnotationEntityTouchedIntegrationEventHandlerImpl(JsonHandlingService jsonHandlingService, ValidatorFactory validatorFactory, ApplicationContext applicationContext, QueryFactory queryFactory) { + this.jsonHandlingService = jsonHandlingService; + this.validatorFactory = validatorFactory; + this.applicationContext = applicationContext; + this.queryFactory = queryFactory; + } + + @Override + public EventProcessingStatus handle(IntegrationEventProperties properties, String message) { + AnnotationEntityTouchedIntegrationEvent event = this.jsonHandlingService.fromJsonSafe(AnnotationEntityTouchedIntegrationEvent.class, message); + if (event == null) + return EventProcessingStatus.Error; + + logger.debug("Handling {}", AnnotationEntityTouchedIntegrationEvent.class.getSimpleName()); + + this.validatorFactory.validator(AnnotationEntityTouchedIntegrationEvent.AnnotationEntityTouchedIntegrationEventValidator.class).validateForce(event); + + EntityManager entityManager = null; + EntityTransaction transaction = null; + try (FakeRequestScope ignored = new FakeRequestScope()) { + try { +// QueryFactory queryFactory = this.applicationContext.getBean(QueryFactory.class); +// TenantScope scope = this.applicationContext.getBean(TenantScope.class); +// if (scope.isMultitenant() && event.getTenant() != null) { +// TenantEntity tenant = queryFactory.query(TenantQuery.class).ids(event.getTenant()).firstAs(new BaseFieldSet().ensure(Tenant._id).ensure(Tenant._code)); +// if (tenant == null) { +// logger.error("missing tenant from event message"); +// return EventProcessingStatus.Error; +// } +// scope.setTenant(event.getTenant(), tenant.getCode()); +// } else if (scope.isMultitenant()) { +// logger.error("missing tenant from event message"); +// return EventProcessingStatus.Error; +// } +// +// ValidationService validator = this.applicationContext.getBean(ValidationService.class); +// validator.validateForce(model); + + CurrentPrincipalResolver currentPrincipalResolver = this.applicationContext.getBean(CurrentPrincipalResolver.class); + currentPrincipalResolver.push(InboxPrincipal.build(properties)); + + EntityManagerFactory entityManagerFactory = this.applicationContext.getBean(EntityManagerFactory.class); + entityManager = entityManagerFactory.createEntityManager(); + + transaction = entityManager.getTransaction(); + transaction.begin(); + + try { + EntityUserQuery entityUserQuery = this.queryFactory.query(EntityUserQuery.class); + List associatedUsersEntities = entityUserQuery + .entityIds(event.getEntityId()) + .isActive(IsActive.Active) + .collect(); + List associatedUsers = associatedUsersEntities.stream() + .map(EntityUserEntity::getUserId) + .toList(); + for (UUID user : event.getUserIds()) { + if (!associatedUsers.contains(user)) { + EntityUserEntity entityUserEntity = new EntityUserEntity(); + entityUserEntity.setId(UUID.randomUUID()); + entityUserEntity.setEntityId(event.getEntityId()); + entityUserEntity.setUserId(user); + entityUserEntity.setCreatedAt(Instant.now()); + entityUserEntity.setUpdatedAt(Instant.now()); + entityUserEntity.setIsActive(IsActive.Active); + + entityManager.persist(entityUserEntity); + } + } + + AuditService auditService = this.applicationContext.getBean(AuditService.class); + + auditService.track(AuditableAction.User_Persist, Map.ofEntries( + new AbstractMap.SimpleEntry("model", event) + )); + + transaction.commit(); + } catch (Exception e) { + transaction.rollback(); + throw e; + } finally { + currentPrincipalResolver.pop(); + } + } catch (OptimisticLockException ex) { + // we get this if/when someone else already modified the notifications. We want to essentially ignore this, and keep working + logger.debug("Concurrency exception getting queue outbox. Skipping: {} ", ex.getMessage()); + if (transaction != null) + transaction.rollback(); + } catch (Exception ex) { + logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); + if (transaction != null) + transaction.rollback(); + } finally { + if (entityManager != null) + entityManager.close(); + } + } catch (Exception ex) { + logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex); + } + return EventProcessingStatus.Success; + } + +} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEvent.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEvent.java similarity index 87% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEvent.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEvent.java index 60824de80..11a47a881 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEvent.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEvent.java @@ -1,4 +1,4 @@ -package gr.cite.annotation.integrationevent.inbox.tenanttouched; +package gr.cite.annotation.integrationevent.inbox.tenanttouch; import gr.cite.annotation.integrationevent.TrackedEvent; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandler.java similarity index 71% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandler.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandler.java index 2e5391235..e0843267a 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandler.java @@ -1,4 +1,4 @@ -package gr.cite.annotation.integrationevent.inbox.tenanttouched; +package gr.cite.annotation.integrationevent.inbox.tenanttouch; import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandlerImpl.java similarity index 98% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandlerImpl.java index d7ba365ec..559874974 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/tenanttouch/TenantTouchedIntegrationEventHandlerImpl.java @@ -1,4 +1,4 @@ -package gr.cite.annotation.integrationevent.inbox.tenanttouched; +package gr.cite.annotation.integrationevent.inbox.tenanttouch; import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; import gr.cite.annotation.audit.AuditableAction; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEvent.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEvent.java similarity index 98% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEvent.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEvent.java index 3b4e9b837..5df47faca 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEvent.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEvent.java @@ -1,4 +1,4 @@ -package gr.cite.annotation.integrationevent.inbox.usertouched; +package gr.cite.annotation.integrationevent.inbox.usertouch; import gr.cite.annotation.common.enums.ContactInfoType; import gr.cite.annotation.common.validation.BaseValidator; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandler.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandler.java similarity index 72% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandler.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandler.java index 42f140ba2..dd36fad10 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandler.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandler.java @@ -1,4 +1,4 @@ -package gr.cite.annotation.integrationevent.inbox.usertouched; +package gr.cite.annotation.integrationevent.inbox.usertouch; import gr.cite.annotation.integrationevent.inbox.IntegrationEventHandler; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java similarity index 98% rename from annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java rename to annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java index d389fde94..60288eb09 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouched/UserTouchedIntegrationEventHandlerImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/integrationevent/inbox/usertouch/UserTouchedIntegrationEventHandlerImpl.java @@ -1,4 +1,4 @@ -package gr.cite.annotation.integrationevent.inbox.usertouched; +package gr.cite.annotation.integrationevent.inbox.usertouch; import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver; import gr.cite.annotation.audit.AuditableAction; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java index da06b8cee..1c184d609 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/persist/UserTouchedIntegrationEventPersist.java @@ -3,7 +3,7 @@ package gr.cite.annotation.model.persist; import gr.cite.annotation.common.validation.BaseValidator; import gr.cite.annotation.convention.ConventionService; import gr.cite.annotation.errorcode.ErrorThesaurusProperties; -import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; +import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent; import gr.cite.tools.validation.specification.Specification; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/EntityUserQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/EntityUserQuery.java new file mode 100644 index 000000000..2c5c36673 --- /dev/null +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/EntityUserQuery.java @@ -0,0 +1,146 @@ +package gr.cite.annotation.query; + +import gr.cite.annotation.authorization.AuthorizationFlags; +import gr.cite.annotation.common.enums.IsActive; +import gr.cite.annotation.data.EntityUserEntity; +import gr.cite.tools.data.query.FieldResolver; +import gr.cite.tools.data.query.QueryBase; +import gr.cite.tools.data.query.QueryContext; +import jakarta.persistence.Tuple; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Predicate; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import java.util.*; + +@Component +@RequestScope +public class EntityUserQuery extends QueryBase { + + private Collection ids, entityIds, userIds; + + private Collection isActives; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + public EntityUserQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } + + public EntityUserQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } + + public EntityUserQuery ids(Collection values) { + this.ids = values; + return this; + } + + public EntityUserQuery entityIds(UUID value) { + this.entityIds = List.of(value); + return this; + } + + public EntityUserQuery entityIds(UUID... value) { + this.entityIds = Arrays.asList(value); + return this; + } + + public EntityUserQuery entityIds(Collection values) { + this.entityIds = values; + return this; + } + + public EntityUserQuery userIds(UUID value) { + this.userIds = List.of(value); + return this; + } + + public EntityUserQuery userIds(UUID... value) { + this.userIds = Arrays.asList(value); + return this; + } + + public EntityUserQuery userIds(Collection values) { + this.userIds = values; + return this; + } + + public EntityUserQuery isActive(IsActive value) { + this.isActives = List.of(value); + return this; + } + + public EntityUserQuery isActive(IsActive... value) { + this.isActives = Arrays.asList(value); + return this; + } + + public EntityUserQuery isActive(Collection values) { + this.isActives = values; + return this; + } + + public EntityUserQuery authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected Boolean isFalseQuery() { + return false; + } + + @Override + protected Class entityClass() { + return EntityUserEntity.class; + } + + @Override + protected Predicate applyFilters(QueryContext queryContext) { + List predicates = new ArrayList<>(); + if (this.ids != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(EntityUserEntity._id)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (this.entityIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(EntityUserEntity._entityId)); + for (UUID item : this.entityIds) + inClause.value(item); + predicates.add(inClause); + } + if (this.userIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(EntityUserEntity._userId)); + for (UUID item : this.userIds) + inClause.value(item); + predicates.add(inClause); + } + if (this.isActives != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(EntityUserEntity._isActive)); + for (IsActive item : this.isActives) + inClause.value(item); + predicates.add(inClause); + } + if (!predicates.isEmpty()) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return null; + } + } + + @Override + protected String fieldNameOf(FieldResolver item) { + return null; + } + + @Override + protected EntityUserEntity convert(Tuple tuple, Set columns) { + return null; + } +} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java index 97de609ba..1e6ac6e4c 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserQuery.java @@ -1,6 +1,5 @@ package gr.cite.annotation.query; -import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.annotation.authorization.AuthorizationFlags; import gr.cite.annotation.authorization.Permission; import gr.cite.annotation.common.enums.IsActive; @@ -8,6 +7,7 @@ import gr.cite.annotation.common.scope.user.UserScope; import gr.cite.annotation.data.UserEntity; import gr.cite.annotation.model.User; import gr.cite.annotation.model.user.PublicUser; +import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryContext; @@ -24,136 +24,151 @@ import java.util.*; @RequestScope public class UserQuery extends QueryBase { - private String like; - private Collection ids; - private Collection isActives; + private String like; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private Collection ids; - private final UserScope userScope; - private final AuthorizationService authService; + private Collection isActives; - public UserQuery( - UserScope userScope, - AuthorizationService authService - ) { - this.userScope = userScope; - this.authService = authService; - } + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - public UserQuery like(String value) { - this.like = value; - return this; - } + private final UserScope userScope; - public UserQuery ids(UUID value) { - this.ids = List.of(value); - return this; - } + private final AuthorizationService authService; - public UserQuery ids(UUID... value) { - this.ids = Arrays.asList(value); - return this; - } + public UserQuery( + UserScope userScope, + AuthorizationService authService + ) { + this.userScope = userScope; + this.authService = authService; + } - public UserQuery ids(Collection values) { - this.ids = values; - return this; - } + public UserQuery like(String value) { + this.like = value; + return this; + } - public UserQuery isActive(IsActive value) { - this.isActives = List.of(value); - return this; - } + public UserQuery ids(UUID value) { + this.ids = List.of(value); + return this; + } - public UserQuery isActive(IsActive... value) { - this.isActives = Arrays.asList(value); - return this; - } + public UserQuery ids(UUID... value) { + this.ids = Arrays.asList(value); + return this; + } - public UserQuery isActive(Collection values) { - this.isActives = values; - return this; - } + public UserQuery ids(Collection values) { + this.ids = values; + return this; + } - public UserQuery authorize(EnumSet values) { - this.authorize = values; - return this; - } + public UserQuery isActive(IsActive value) { + this.isActives = List.of(value); + return this; + } - @Override - protected Class entityClass() { - return UserEntity.class; - } + public UserQuery isActive(IsActive... value) { + this.isActives = Arrays.asList(value); + return this; + } - @Override - protected Boolean isFalseQuery() { - return this.isEmpty(this.ids) || this.isEmpty(this.isActives); - } + public UserQuery isActive(Collection values) { + this.isActives = values; + return this; + } - @Override - protected Predicate applyAuthZ(QueryContext queryContext) { - if (this.authorize.contains(AuthorizationFlags.None)) return null; - if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseUser)) return null; - UUID ownerId = null; - if (this.authorize.contains(AuthorizationFlags.Owner)) ownerId = this.userScope.getUserIdSafe(); + public UserQuery authorize(EnumSet values) { + this.authorize = values; + return this; + } - List predicates = new ArrayList<>(); - if (ownerId != null) { - predicates.add(queryContext.CriteriaBuilder.equal(queryContext.Root.get(User._id), ownerId)); - } - if (predicates.size() > 0) { - Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); - return queryContext.CriteriaBuilder.and(predicatesArray); - } else { - return queryContext.CriteriaBuilder.or(); //Creates a false query - } - } + @Override + protected Class entityClass() { + return UserEntity.class; + } - @Override - protected Predicate applyFilters(QueryContext queryContext) { - List predicates = new ArrayList<>(); - if (this.ids != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)); - for (UUID item : this.ids) inClause.value(item); - predicates.add(inClause); - } - if (this.like != null && !this.like.isEmpty()) { - predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(UserEntity._name), this.like)); - } - if (this.isActives != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._isActive)); - for (IsActive item : this.isActives) inClause.value(item); - predicates.add(inClause); - } - if (predicates.size() > 0) { - Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); - return queryContext.CriteriaBuilder.and(predicatesArray); - } else { - return null; - } - } + @Override + protected Boolean isFalseQuery() { + return this.isEmpty(this.ids) || this.isEmpty(this.isActives); + } - @Override - protected UserEntity convert(Tuple tuple, Set columns) { - UserEntity item = new UserEntity(); - item.setId(QueryBase.convertSafe(tuple, columns, UserEntity._id, UUID.class)); - item.setName(QueryBase.convertSafe(tuple, columns, UserEntity._name, String.class)); - item.setAdditionalInfo(QueryBase.convertSafe(tuple, columns, UserEntity._additionalInfo, String.class)); - item.setCreatedAt(QueryBase.convertSafe(tuple, columns, UserEntity._createdAt, Instant.class)); - item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, UserEntity._updatedAt, Instant.class)); - item.setIsActive(QueryBase.convertSafe(tuple, columns, UserEntity._isActive, IsActive.class)); - return item; - } + @Override + protected Predicate applyAuthZ(QueryContext queryContext) { + if (this.authorize.contains(AuthorizationFlags.None)) + return null; + if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseUser)) + return null; + UUID ownerId = null; + if (this.authorize.contains(AuthorizationFlags.Owner)) + ownerId = this.userScope.getUserIdSafe(); - @Override - protected String fieldNameOf(FieldResolver item) { - if (item.match(User._id) || item.match(PublicUser._id)) return UserEntity._id; - else if (item.match(User._name) || item.match(PublicUser._name)) return UserEntity._name; - else if (item.match(User._createdAt) ) return UserEntity._createdAt; - else if (item.match(User._updatedAt)) return UserEntity._updatedAt; - else if (item.match(User._hash)) return UserEntity._updatedAt; - else if (item.match(User._isActive)) return UserEntity._isActive; - else return null; - } + List predicates = new ArrayList<>(); + if (ownerId != null) { + predicates.add(queryContext.CriteriaBuilder.equal(queryContext.Root.get(User._id), ownerId)); + } + if (!predicates.isEmpty()) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return queryContext.CriteriaBuilder.or(); //Creates a false query + } + } + + @Override + protected Predicate applyFilters(QueryContext queryContext) { + List predicates = new ArrayList<>(); + if (this.ids != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._id)); + for (UUID item : this.ids) + inClause.value(item); + predicates.add(inClause); + } + if (this.like != null && !this.like.isEmpty()) { + predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(UserEntity._name), this.like)); + } + if (this.isActives != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserEntity._isActive)); + for (IsActive item : this.isActives) + inClause.value(item); + predicates.add(inClause); + } + if (!predicates.isEmpty()) { + Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); + return queryContext.CriteriaBuilder.and(predicatesArray); + } else { + return null; + } + } + + @Override + protected UserEntity convert(Tuple tuple, Set columns) { + UserEntity item = new UserEntity(); + item.setId(QueryBase.convertSafe(tuple, columns, UserEntity._id, UUID.class)); + item.setName(QueryBase.convertSafe(tuple, columns, UserEntity._name, String.class)); + item.setAdditionalInfo(QueryBase.convertSafe(tuple, columns, UserEntity._additionalInfo, String.class)); + item.setCreatedAt(QueryBase.convertSafe(tuple, columns, UserEntity._createdAt, Instant.class)); + item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, UserEntity._updatedAt, Instant.class)); + item.setIsActive(QueryBase.convertSafe(tuple, columns, UserEntity._isActive, IsActive.class)); + return item; + } + + @Override + protected String fieldNameOf(FieldResolver item) { + if (item.match(User._id) || item.match(PublicUser._id)) + return UserEntity._id; + else if (item.match(User._name) || item.match(PublicUser._name)) + return UserEntity._name; + else if (item.match(User._createdAt)) + return UserEntity._createdAt; + else if (item.match(User._updatedAt)) + return UserEntity._updatedAt; + else if (item.match(User._hash)) + return UserEntity._updatedAt; + else if (item.match(User._isActive)) + return UserEntity._isActive; + else + return null; + } } diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java index 8d32d3d12..e29fcd36b 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserService.java @@ -1,7 +1,7 @@ package gr.cite.annotation.service.user; import com.fasterxml.jackson.core.JsonProcessingException; -import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; +import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent; import gr.cite.annotation.model.User; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java index 3c8e116a4..6567068b3 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java @@ -10,7 +10,7 @@ import gr.cite.annotation.convention.ConventionService; import gr.cite.annotation.data.UserContactInfoEntity; import gr.cite.annotation.data.UserCredentialEntity; import gr.cite.annotation.data.UserEntity; -import gr.cite.annotation.integrationevent.inbox.usertouched.UserTouchedIntegrationEvent; +import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent; import gr.cite.annotation.model.User; import gr.cite.annotation.model.builder.UserBuilder; import gr.cite.annotation.model.deleter.UserDeleter; diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxIntegrationEvent.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxIntegrationEvent.java index 54d725201..9c2db4fdc 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxIntegrationEvent.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxIntegrationEvent.java @@ -27,6 +27,8 @@ public class OutboxIntegrationEvent extends IntegrationEvent { public static final String DESCRIPTION_TOUCH = "DESCRIPTION_TOUCH"; + public static final String ANNOTATION_ENTITY_TOUCH = "ANNOTATION_ENTITY_TOUCH"; + public static final String WHAT_YOU_KNOW_ABOUT_ME_COMPLETED = "WHAT_YOU_KNOW_ABOUT_ME_COMPLETED"; public static final String GENERATE_FILE = "GENERATE_FILE"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxProperties.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxProperties.java index 8a66f6a26..b9f771aa8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxProperties.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxProperties.java @@ -23,6 +23,8 @@ public class OutboxProperties { private final String descriptionTouchTopic; + private final String annotationEntityTouchTopic; + private final String notifyTopic; private final String forgetMeCompletedTopic; @@ -37,7 +39,10 @@ public class OutboxProperties { String tenantReactivationTopic, String tenantUserInviteTopic, String userRemovalTopic, - String userTouchTopic, String dmpTouchTopic, String descriptionTouchTopic, + String userTouchTopic, + String dmpTouchTopic, + String descriptionTouchTopic, + String annotationEntityTouchTopic, String notifyTopic, String forgetMeCompletedTopic, String whatYouKnowAboutMeCompletedTopic, @@ -52,6 +57,7 @@ public class OutboxProperties { this.userTouchTopic = userTouchTopic; this.dmpTouchTopic = dmpTouchTopic; this.descriptionTouchTopic = descriptionTouchTopic; + this.annotationEntityTouchTopic = annotationEntityTouchTopic; this.notifyTopic = notifyTopic; this.forgetMeCompletedTopic = forgetMeCompletedTopic; this.whatYouKnowAboutMeCompletedTopic = whatYouKnowAboutMeCompletedTopic; @@ -94,6 +100,10 @@ public class OutboxProperties { return descriptionTouchTopic; } + public String getAnnotationEntityTouchTopic() { + return annotationEntityTouchTopic; + } + public String getNotifyTopic() { return notifyTopic; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java index 4ef2cd90b..08f8a8eca 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/OutboxRepositoryImpl.java @@ -415,6 +415,10 @@ public class OutboxRepositoryImpl implements OutboxRepository { routingKey = this.outboxProperties.getDescriptionTouchTopic(); break; } + case OutboxIntegrationEvent.ANNOTATION_ENTITY_TOUCH: { + routingKey = this.outboxProperties.getAnnotationEntityTouchTopic(); + break; + } case OutboxIntegrationEvent.FORGET_ME_COMPLETED: { routingKey = this.outboxProperties.getForgetMeCompletedTopic(); break; diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEvent.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEvent.java new file mode 100644 index 000000000..715d6d7f2 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEvent.java @@ -0,0 +1,30 @@ +package eu.eudat.integrationevent.outbox.annotationentitytouch; + +import eu.eudat.integrationevent.TrackedEvent; + +import java.util.List; +import java.util.UUID; + +public class AnnotationEntityTouchedIntegrationEvent extends TrackedEvent { + + private UUID entityId; + + private List userIds; + + public UUID getEntityId() { + return entityId; + } + + public void setEntityId(UUID entityId) { + this.entityId = entityId; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandler.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandler.java new file mode 100644 index 000000000..856a4922a --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandler.java @@ -0,0 +1,25 @@ +package eu.eudat.integrationevent.outbox.annotationentitytouch; + +import eu.eudat.integrationevent.outbox.dmptouched.DmpTouchedIntegrationEvent; +import eu.eudat.model.persist.DmpPersist; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public interface AnnotationEntityTouchedIntegrationEventHandler { + + void handle(AnnotationEntityTouchedIntegrationEvent event); + + static AnnotationEntityTouchedIntegrationEvent buildEventFromPersistModel(DmpPersist persist) { + AnnotationEntityTouchedIntegrationEvent event = new AnnotationEntityTouchedIntegrationEvent(); + event.setEntityId(persist.getId()); + List users = new ArrayList<>(); + persist.getUsers().forEach(dmpUserPersist -> { + users.add(dmpUserPersist.getUser()); + }); + event.setUserIds(users); + return event; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandlerImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandlerImpl.java new file mode 100644 index 000000000..37a9541e4 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/annotationentitytouch/AnnotationEntityTouchedIntegrationEventHandlerImpl.java @@ -0,0 +1,34 @@ +package eu.eudat.integrationevent.outbox.annotationentitytouch; + +import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent; +import eu.eudat.integrationevent.outbox.OutboxService; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class AnnotationEntityTouchedIntegrationEventHandlerImpl implements AnnotationEntityTouchedIntegrationEventHandler { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(AnnotationEntityTouchedIntegrationEventHandlerImpl.class)); + + private final OutboxService outboxService; + + public AnnotationEntityTouchedIntegrationEventHandlerImpl(OutboxService outboxService) { + this.outboxService = outboxService; + } + + @Override + public void handle(AnnotationEntityTouchedIntegrationEvent event) { + OutboxIntegrationEvent message = new OutboxIntegrationEvent(); + message.setMessageId(UUID.randomUUID()); + message.setType(OutboxIntegrationEvent.ANNOTATION_ENTITY_TOUCH); + message.setEvent(event); + this.outboxService.publish(message); + } + +} diff --git a/dmp-backend/web/src/main/resources/config/queue.yml b/dmp-backend/web/src/main/resources/config/queue.yml index 78ba64a62..54be62ec4 100644 --- a/dmp-backend/web/src/main/resources/config/queue.yml +++ b/dmp-backend/web/src/main/resources/config/queue.yml @@ -35,6 +35,7 @@ queue: user-removal-topic: user.remove dmp-touch-topic: dmp.touch description-touch-topic: description.touch + annotation-entity-touch-topic: annotation.entity.touch what-you-know-about-me-completed-topic: whatyouknowaboutme.completed generate-file-topic: generate.file rabbitmq: