From 6eb01fbd1c51ef80a132156a6ea1fe9d2d7501a9 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 2 May 2024 12:38:36 +0300 Subject: [PATCH] revert tenant filter disable --- .../org/opencdmp/data/tenant/TenantFilterAspect.java | 11 +++++------ .../opencdmp/data/tenant/TenantScopedBaseEntity.java | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java index 2aee794cc..001440dcd 100644 --- a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java +++ b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantFilterAspect.java @@ -1,13 +1,12 @@ package org.opencdmp.data.tenant; -import org.opencdmp.commons.scope.tenant.TenantScope; import jakarta.persistence.EntityManager; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.hibernate.Session; +import org.opencdmp.commons.scope.tenant.TenantScope; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.stereotype.Component; import javax.management.InvalidApplicationException; @@ -15,7 +14,7 @@ import javax.management.InvalidApplicationException; @Aspect @Component -@ConditionalOnMissingBean(TenantScope.class) +//@ConditionalOnMissingBean(TenantScope.class) public class TenantFilterAspect { private final TenantScope tenantScope; @@ -31,12 +30,12 @@ public class TenantFilterAspect { pointcut = "bean(entityManagerFactory) && execution(* createEntityManager(..))", returning = "retVal") public void getSessionAfter(JoinPoint joinPoint, Object retVal) throws InvalidApplicationException { - if (retVal instanceof EntityManager && tenantScope.isSet()) { + if (retVal instanceof EntityManager && this.tenantScope.isSet()) { Session session = ((EntityManager) retVal).unwrap(Session.class); - if(!tenantScope.isDefaultTenant()) { + if(!this.tenantScope.isDefaultTenant()) { session .enableFilter(TenantScopedBaseEntity.TENANT_FILTER) - .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, tenantScope.getTenant().toString()); + .setParameter(TenantScopedBaseEntity.TENANT_FILTER_TENANT_PARAM, this.tenantScope.getTenant().toString()); } else { session .enableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); diff --git a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java index c416b48d6..89b3b3750 100644 --- a/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java +++ b/backend/core/src/main/java/org/opencdmp/data/tenant/TenantScopedBaseEntity.java @@ -1,6 +1,7 @@ package org.opencdmp.data.tenant; import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; import org.hibernate.annotations.Filter; import org.hibernate.annotations.FilterDef; @@ -18,7 +19,7 @@ import java.util.UUID; @FilterDef(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER) @Filter(name = TenantScopedBaseEntity.DEFAULT_TENANT_FILTER, condition = "(tenant = tenant is null)") @Filter(name = TenantScopedBaseEntity.TENANT_FILTER, condition = "(tenant = (cast(:tenantId as uuid)) or tenant is null)") -//@EntityListeners(TenantListener.class) +@EntityListeners(TenantListener.class) public abstract class TenantScopedBaseEntity implements TenantScoped, Serializable { private static final long serialVersionUID = 1L; public static final String TENANT_FILTER = "tenantFilter";