diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java index db26a534c..6885f6418 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/notification/NotifyIntegrationEventHandlerImpl.java @@ -2,16 +2,12 @@ package eu.eudat.integrationevent.outbox.notification; import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent; import eu.eudat.integrationevent.outbox.OutboxService; -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 org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; -import javax.management.InvalidApplicationException; import java.util.UUID; @Component @@ -20,31 +16,20 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifyIntegrationEventHandlerImpl.class)); - private final QueryFactory queryFactory; - - private final AuditService auditService; - private final OutboxService outboxService; - private final ValidatorFactory validatorFactory; - @Autowired public NotifyIntegrationEventHandlerImpl( - OutboxService outboxService, - QueryFactory queryFactory, - AuditService auditService, ValidatorFactory validatorFactory) { + OutboxService outboxService) { this.outboxService = outboxService; - this.validatorFactory = validatorFactory; - this.queryFactory = queryFactory; - this.auditService = auditService; } @Override - 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); + public void handle(NotifyIntegrationEvent event) { + OutboxIntegrationEvent message = new OutboxIntegrationEvent(); + message.setMessageId(UUID.randomUUID()); + message.setType(OutboxIntegrationEvent.NOTIFY); + message.setEvent(event); + this.outboxService.publish(message); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalConsistencyHandler.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalConsistencyHandler.java new file mode 100644 index 000000000..28edb58e7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalConsistencyHandler.java @@ -0,0 +1,26 @@ +package eu.eudat.integrationevent.outbox.tenantremoval; + +import eu.eudat.integrationevent.inbox.ConsistencyHandler; +import eu.eudat.query.TenantQuery; +import gr.cite.tools.data.query.QueryFactory; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class TenantRemovalConsistencyHandler implements ConsistencyHandler { + + private final QueryFactory queryFactory; + + public TenantRemovalConsistencyHandler(QueryFactory queryFactory) { + this.queryFactory = queryFactory; + } + + @Override + public Boolean isConsistent(TenantRemovalConsistencyPredicates consistencyPredicates) { + long count = this.queryFactory.query(TenantQuery.class).ids(consistencyPredicates.getTenantId()).count(); + return count > 0; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalConsistencyPredicates.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalConsistencyPredicates.java new file mode 100644 index 000000000..530fd585e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalConsistencyPredicates.java @@ -0,0 +1,23 @@ +package eu.eudat.integrationevent.outbox.tenantremoval; + +import eu.eudat.integrationevent.inbox.ConsistencyPredicates; + +import java.util.UUID; + +public class TenantRemovalConsistencyPredicates implements ConsistencyPredicates { + + private UUID tenantId; + + public TenantRemovalConsistencyPredicates(UUID tenantId) { + this.tenantId = tenantId; + } + + public UUID getTenantId() { + return tenantId; + } + + public void setTenantId(UUID tenantId) { + this.tenantId = tenantId; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEvent.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEvent.java new file mode 100644 index 000000000..0b4f183a2 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEvent.java @@ -0,0 +1,19 @@ +package eu.eudat.integrationevent.outbox.tenantremoval; + +import eu.eudat.integrationevent.TrackedEvent; + +import java.util.UUID; + +public class TenantRemovalIntegrationEvent extends TrackedEvent { + + private UUID id; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + +} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEventHandler.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEventHandler.java new file mode 100644 index 000000000..171b90af1 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEventHandler.java @@ -0,0 +1,11 @@ +package eu.eudat.integrationevent.outbox.tenantremoval; + +import java.util.UUID; + +public interface TenantRemovalIntegrationEventHandler { + + void handle(TenantRemovalIntegrationEvent event); + + void handle(UUID tenantId); + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEventHandlerImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEventHandlerImpl.java new file mode 100644 index 000000000..59289e081 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenantremoval/TenantRemovalIntegrationEventHandlerImpl.java @@ -0,0 +1,61 @@ +package eu.eudat.integrationevent.outbox.tenantremoval; + +import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent; +import eu.eudat.integrationevent.outbox.OutboxService; +import eu.eudat.integrationevent.outbox.userremoval.UserRemovalConsistencyHandler; +import eu.eudat.integrationevent.outbox.userremoval.UserRemovalConsistencyPredicates; +import gr.cite.tools.logging.LoggerService; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class TenantRemovalIntegrationEventHandlerImpl implements TenantRemovalIntegrationEventHandler { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantRemovalIntegrationEventHandlerImpl.class)); + + private final OutboxService outboxService; + + private final ApplicationContext applicationContext; + + @Autowired + public TenantRemovalIntegrationEventHandlerImpl(OutboxService outboxService, ApplicationContext applicationContext) { + this.outboxService = outboxService; + this.applicationContext = applicationContext; + } + + @Override + public void handle(TenantRemovalIntegrationEvent event) { + TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler = this.applicationContext.getBean(TenantRemovalConsistencyHandler.class); + if (!tenantRemovalConsistencyHandler.isConsistent(new TenantRemovalConsistencyPredicates(event.getId()))) + return; + + OutboxIntegrationEvent message = new OutboxIntegrationEvent(); + message.setMessageId(UUID.randomUUID()); + message.setType(OutboxIntegrationEvent.TENANT_REMOVE); + message.setEvent(event); + this.outboxService.publish(message); + } + + @Override + public void handle(UUID tenantId) { + TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler = this.applicationContext.getBean(TenantRemovalConsistencyHandler.class); + if (!tenantRemovalConsistencyHandler.isConsistent(new TenantRemovalConsistencyPredicates(tenantId))) + return; + + OutboxIntegrationEvent message = new OutboxIntegrationEvent(); + message.setMessageId(UUID.randomUUID()); + message.setType(OutboxIntegrationEvent.TENANT_REMOVE); + TenantRemovalIntegrationEvent event = new TenantRemovalIntegrationEvent(); + event.setId(tenantId); + message.setEvent(event); + this.outboxService.publish(message); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEvent.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEvent.java new file mode 100644 index 000000000..7612dff0d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEvent.java @@ -0,0 +1,29 @@ +package eu.eudat.integrationevent.outbox.tenanttouched; + +import eu.eudat.integrationevent.TrackedEvent; + +import java.util.UUID; + +public class TenantTouchedIntegrationEvent extends TrackedEvent { + + private UUID id; + + private String code; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEventHandler.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEventHandler.java new file mode 100644 index 000000000..579b2e9c7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEventHandler.java @@ -0,0 +1,7 @@ +package eu.eudat.integrationevent.outbox.tenanttouched; + +public interface TenantTouchedIntegrationEventHandler { + + void handle(TenantTouchedIntegrationEvent event); + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java new file mode 100644 index 000000000..b7c2b53f0 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/integrationevent/outbox/tenanttouched/TenantTouchedIntegrationEventHandlerImpl.java @@ -0,0 +1,10 @@ +package eu.eudat.integrationevent.outbox.tenanttouched; + +public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIntegrationEventHandler { + + @Override + public void handle(TenantTouchedIntegrationEvent event) { + + } + +}