From 0c1d78e2991ad90ea263f6794daa660b1134f539 Mon Sep 17 00:00:00 2001
From: "Nikhil Singh[MicroSoft]" <nikhilsingh@microsoft.com>
Date: Wed, 28 Jul 2021 11:00:05 +0000
Subject: [PATCH] Usage of Non Request Scope bean for Service Bus Flow

---
 .../notification/di/SubscriptionCacheFactory.java   | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

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 5879641c8..0291e67f4 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()));
     }
 }
-- 
GitLab