Added integration events and handlers on the main app outbox queue for tenants
This commit is contained in:
parent
bef333ebc9
commit
1fc4e8add5
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package eu.eudat.integrationevent.outbox.tenanttouched;
|
||||
|
||||
public interface TenantTouchedIntegrationEventHandler {
|
||||
|
||||
void handle(TenantTouchedIntegrationEvent event);
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package eu.eudat.integrationevent.outbox.tenanttouched;
|
||||
|
||||
public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIntegrationEventHandler {
|
||||
|
||||
@Override
|
||||
public void handle(TenantTouchedIntegrationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue