From 05980676088f0a3015944b1127abb937e39e2b2f Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 16 Apr 2024 15:35:44 +0300 Subject: [PATCH] tenant scope fix --- .../common/scope/tenant/TenantScope.java | 22 +++++++++++++++---- .../common/scope/tenant/TenantScope.java | 22 +++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java index 3c0ac7095..e42eaebcf 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java @@ -11,8 +11,6 @@ import javax.management.InvalidApplicationException; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; -@Component -@RequestScope public class TenantScope { public static final String TenantReplaceParameter = "::TenantCode::"; private final MultitenancyProperties multitenancy; @@ -66,7 +64,14 @@ public class TenantScope { this.tenant.set(tenant); this.tenantCode.set(tenantCode); - if (this.tenant.get() != null && !this.isDefaultTenant()) { + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.tenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class) @@ -83,7 +88,16 @@ public class TenantScope { public void removeTempTenant(EntityManager entityManager) { this.tenant.set(this.initialTenant.get()); this.tenantCode.set(this.initialTenantCode.get()); - if (this.initialTenant.get() != null && !this.isDefaultTenant()) { + + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.initialTenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class) diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java b/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java index 473fa321a..0a27d4cc6 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java @@ -11,8 +11,6 @@ import javax.management.InvalidApplicationException; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; -@Component -@RequestScope public class TenantScope { public static final String TenantReplaceParameter = "::TenantCode::"; private final MultitenancyProperties multitenancy; @@ -66,7 +64,14 @@ public class TenantScope { this.tenant.set(tenant); this.tenantCode.set(tenantCode); - if (this.tenant.get() != null && !this.isDefaultTenant()) { + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.tenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class) @@ -83,7 +88,16 @@ public class TenantScope { public void removeTempTenant(EntityManager entityManager) { this.tenant.set(this.initialTenant.get()); this.tenantCode.set(this.initialTenantCode.get()); - if (this.initialTenant.get() != null && !this.isDefaultTenant()) { + + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.initialTenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class)