Added integration events and handlers on the main app outbox queue for tenants

This commit is contained in:
Thomas Georgios Giannos 2024-02-01 16:05:21 +02:00
parent bef333ebc9
commit 1fc4e8add5
9 changed files with 193 additions and 22 deletions

View File

@ -2,16 +2,12 @@ package eu.eudat.integrationevent.outbox.notification;
import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent; import eu.eudat.integrationevent.outbox.OutboxIntegrationEvent;
import eu.eudat.integrationevent.outbox.OutboxService; 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.logging.LoggerService;
import gr.cite.tools.validation.ValidatorFactory;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope; import org.springframework.web.context.annotation.RequestScope;
import javax.management.InvalidApplicationException;
import java.util.UUID; import java.util.UUID;
@Component @Component
@ -20,31 +16,20 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(NotifyIntegrationEventHandlerImpl.class)); 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 OutboxService outboxService;
private final ValidatorFactory validatorFactory;
@Autowired @Autowired
public NotifyIntegrationEventHandlerImpl( public NotifyIntegrationEventHandlerImpl(
OutboxService outboxService, OutboxService outboxService) {
QueryFactory queryFactory,
AuditService auditService, ValidatorFactory validatorFactory) {
this.outboxService = outboxService; this.outboxService = outboxService;
this.validatorFactory = validatorFactory;
this.queryFactory = queryFactory;
this.auditService = auditService;
} }
@Override @Override
public void handle(NotifyIntegrationEvent event) throws InvalidApplicationException { public void handle(NotifyIntegrationEvent event) {
OutboxIntegrationEvent message = new OutboxIntegrationEvent(); OutboxIntegrationEvent message = new OutboxIntegrationEvent();
message.setMessageId(UUID.randomUUID()); message.setMessageId(UUID.randomUUID());
message.setType(OutboxIntegrationEvent.NOTIFY); message.setType(OutboxIntegrationEvent.NOTIFY);
message.setEvent(event); message.setEvent(event);
this.outboxService.publish(message); this.outboxService.publish(message);
} }
} }

View File

@ -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<TenantRemovalConsistencyPredicates> {
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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,7 @@
package eu.eudat.integrationevent.outbox.tenanttouched;
public interface TenantTouchedIntegrationEventHandler {
void handle(TenantTouchedIntegrationEvent event);
}

View File

@ -0,0 +1,10 @@
package eu.eudat.integrationevent.outbox.tenanttouched;
public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIntegrationEventHandler {
@Override
public void handle(TenantTouchedIntegrationEvent event) {
}
}