diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactory.java b/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactory.java index 5879641c8219a4dd4af318e5ce8da70ca3d5b0c5..0291e67f48be2d75a689fce3caa0d010ebd116ed 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactory.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/di/SubscriptionCacheFactory.java @@ -19,7 +19,10 @@ package org.opengroup.osdu.notification.di; import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.core.common.cache.MultiTenantCache; import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -27,7 +30,9 @@ import org.springframework.stereotype.Component; @Component public class SubscriptionCacheFactory implements ICache<String, String> { @Autowired - private TenantInfo tenant; + private DpsHeaders headers; + @Autowired + private ITenantFactory tenantFactory; private MultiTenantCache<String> caches; @@ -56,6 +61,10 @@ public class SubscriptionCacheFactory implements ICache<String, String> { } private ICache<String, String> partitionCache() { - return this.caches.get(String.format("%s:subscription", this.tenant.getDataPartitionId())); + TenantInfo tenantInfo = this.tenantFactory.getTenantInfo(this.headers.getPartitionIdWithFallbackToAccountId()); + if (tenantInfo == null) { + throw AppException.createUnauthorized(String.format("could not retrieve tenant info for data partition id: %s", this.headers.getPartitionIdWithFallbackToAccountId())); + } + return this.caches.get(String.format("%s:subscription", tenantInfo.getDataPartitionId())); } }