2024-02-12 10:49:37 +01:00
|
|
|
package gr.cite.annotation.integrationevent.inbox.tenantremoval;
|
2024-02-09 17:50:34 +01:00
|
|
|
|
2024-02-12 10:49:37 +01:00
|
|
|
import gr.cite.annotation.audit.AuditableAction;
|
|
|
|
import gr.cite.annotation.common.JsonHandlingService;
|
2024-04-04 15:39:40 +02:00
|
|
|
import gr.cite.annotation.data.TenantEntityManager;
|
2024-02-12 10:49:37 +01:00
|
|
|
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.service.tenant.TenantService;
|
2024-04-04 15:39:40 +02:00
|
|
|
import gr.cite.commons.web.oidc.principal.CurrentPrincipalResolver;
|
2024-04-04 11:21:12 +02:00
|
|
|
import gr.cite.commons.web.oidc.principal.extractor.ClaimExtractorProperties;
|
2024-02-09 17:50:34 +01:00
|
|
|
import gr.cite.tools.auditing.AuditService;
|
|
|
|
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.AbstractMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
@Component
|
|
|
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
|
public class TenantRemovalIntegrationEventHandlerImpl implements TenantRemovalIntegrationEventHandler {
|
|
|
|
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(TenantRemovalIntegrationEventHandlerImpl.class));
|
|
|
|
|
|
|
|
private final JsonHandlingService jsonHandlingService;
|
2024-04-04 15:39:40 +02:00
|
|
|
private final CurrentPrincipalResolver currentPrincipalResolver;
|
|
|
|
private final ClaimExtractorProperties claimExtractorProperties;
|
|
|
|
private final TenantService tenantService;
|
|
|
|
private final AuditService auditService;
|
|
|
|
private final TenantEntityManager tenantEntityManager;
|
|
|
|
private final TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler;
|
|
|
|
public TenantRemovalIntegrationEventHandlerImpl(JsonHandlingService jsonHandlingService, CurrentPrincipalResolver currentPrincipalResolver, ClaimExtractorProperties claimExtractorProperties, TenantService tenantService, AuditService auditService, TenantEntityManager tenantEntityManager, TenantRemovalConsistencyHandler tenantRemovalConsistencyHandler) {
|
2024-02-09 17:50:34 +01:00
|
|
|
this.jsonHandlingService = jsonHandlingService;
|
2024-04-04 15:39:40 +02:00
|
|
|
this.currentPrincipalResolver = currentPrincipalResolver;
|
|
|
|
this.claimExtractorProperties = claimExtractorProperties;
|
|
|
|
this.tenantService = tenantService;
|
|
|
|
this.auditService = auditService;
|
|
|
|
this.tenantEntityManager = tenantEntityManager;
|
|
|
|
this.tenantRemovalConsistencyHandler = tenantRemovalConsistencyHandler;
|
2024-02-09 17:50:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EventProcessingStatus handle(IntegrationEventProperties properties, String message) {
|
|
|
|
TenantRemovalIntegrationEvent event = this.jsonHandlingService.fromJsonSafe(TenantRemovalIntegrationEvent.class, message);
|
|
|
|
if (event == null)
|
|
|
|
return EventProcessingStatus.Error;
|
|
|
|
|
2024-04-04 15:39:40 +02:00
|
|
|
EventProcessingStatus status = EventProcessingStatus.Success;
|
|
|
|
try {
|
2024-02-09 17:50:34 +01:00
|
|
|
|
2024-04-04 15:39:40 +02:00
|
|
|
currentPrincipalResolver.push(InboxPrincipal.build(properties, claimExtractorProperties));
|
2024-02-09 17:50:34 +01:00
|
|
|
|
2024-04-04 15:39:40 +02:00
|
|
|
if (!(tenantRemovalConsistencyHandler.isConsistent(new TenantRemovalConsistencyPredicates(event.getId())))) {
|
|
|
|
status = EventProcessingStatus.Postponed;
|
|
|
|
currentPrincipalResolver.pop();
|
|
|
|
return status;
|
|
|
|
}
|
2024-02-09 17:50:34 +01:00
|
|
|
|
2024-04-04 15:39:40 +02:00
|
|
|
tenantEntityManager.disableTenantFilters();
|
|
|
|
tenantService.deleteAndSave(event.getId());
|
2024-02-09 17:50:34 +01:00
|
|
|
|
|
|
|
|
2024-04-04 15:39:40 +02:00
|
|
|
auditService.track(AuditableAction.Tenant_Delete, Map.ofEntries(
|
|
|
|
new AbstractMap.SimpleEntry<String, Object>("id", event.getId())
|
|
|
|
));
|
|
|
|
//auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
2024-02-09 17:50:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
2024-04-04 15:39:40 +02:00
|
|
|
status = EventProcessingStatus.Error;
|
2024-02-09 17:50:34 +01:00
|
|
|
logger.error("Problem getting list of queue outbox. Skipping: {}", ex.getMessage(), ex);
|
2024-04-04 15:39:40 +02:00
|
|
|
} finally {
|
|
|
|
currentPrincipalResolver.pop();
|
2024-02-09 17:50:34 +01:00
|
|
|
}
|
2024-04-04 15:39:40 +02:00
|
|
|
return status;
|
2024-02-09 17:50:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|