50 lines
2.2 KiB
Java
50 lines
2.2 KiB
Java
package org.opencdmp.integrationevent.outbox.userremoval;
|
|
|
|
import org.opencdmp.commons.scope.tenant.TenantScope;
|
|
import org.opencdmp.integrationevent.outbox.OutboxIntegrationEvent;
|
|
import org.opencdmp.integrationevent.outbox.OutboxService;
|
|
import gr.cite.tools.logging.LoggerService;
|
|
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 javax.management.InvalidApplicationException;
|
|
import java.util.UUID;
|
|
|
|
@Component("outboxuserremovalintegrationeventhandler")
|
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public class UserRemovalIntegrationEventHandlerImpl implements UserRemovalIntegrationEventHandler {
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserRemovalIntegrationEventHandlerImpl.class));
|
|
|
|
private final OutboxService outboxService;
|
|
|
|
private final ApplicationContext applicationContext;
|
|
private final TenantScope tenantScope;
|
|
|
|
public UserRemovalIntegrationEventHandlerImpl(OutboxService outboxService, ApplicationContext applicationContext, TenantScope tenantScope) {
|
|
this.outboxService = outboxService;
|
|
this.applicationContext = applicationContext;
|
|
this.tenantScope = tenantScope;
|
|
}
|
|
|
|
@Override
|
|
public void handle(UUID userId) throws InvalidApplicationException {
|
|
UserRemovalConsistencyHandler userRemovalConsistencyHandler = this.applicationContext.getBean(UserRemovalConsistencyHandler.class);
|
|
if (!userRemovalConsistencyHandler.isConsistent(new UserRemovalConsistencyPredicates(userId)))
|
|
return;
|
|
|
|
OutboxIntegrationEvent message = new OutboxIntegrationEvent();
|
|
message.setMessageId(UUID.randomUUID());
|
|
message.setType(OutboxIntegrationEvent.USER_REMOVE);
|
|
if (this.tenantScope.isSet()) message.setTenantId(tenantScope.getTenant());
|
|
UserRemovalIntegrationEvent event = new UserRemovalIntegrationEvent();
|
|
event.setUserId(userId);
|
|
message.setEvent(event);
|
|
|
|
this.outboxService.publish(message);
|
|
}
|
|
}
|