diff --git a/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantFactoryImpl.java b/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantFactoryImpl.java index 6dee229fed1a7d9985b527dc96395b63dc0a4400..bfcc46885710e5333829220b53daf1bda4320c60 100644 --- a/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantFactoryImpl.java +++ b/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantFactoryImpl.java @@ -15,29 +15,28 @@ import java.util.*; @Component @RequestScope public class TenantFactoryImpl implements ITenantFactory { - @Autowired private CosmosDBTenantInfo db; - private TenantInfo tenant; - private Map<String, TenantInfo> tenantsList = new HashMap<>(); - + private Map<String, TenantInfo> tenants; public boolean exists(String tenantName) { - if (this.tenant == null) - initTenants(tenantName); - return this.tenant.getName() == tenantName; + if (this.tenants == null) + initTenants(); + return this.tenants.containsKey(tenantName); } public TenantInfo getTenantInfo(String tenantName) { - if (this.tenant == null) - initTenants(tenantName); - return this.tenant; + if (this.tenants == null) + initTenants(); + return this.tenants.get(tenantName); } public Collection<TenantInfo> listTenantInfo() { - return this.tenantsList.values(); + if (this.tenants == null) + initTenants(); + return this.tenants.values(); } public <V> ICache<String, V> createCache(String tenantName, String host, int port, int expireTimeSeconds, Class<V> classOfV) @@ -47,24 +46,16 @@ public class TenantFactoryImpl implements ITenantFactory { public void flushCache() {} - private void initTenants(String id) { - - Optional<TenantInfoDoc> tenantInfoDoc = db.findById(id); - - if (!tenantInfoDoc.isPresent()) - throw new AppException(HttpStatus.SC_NOT_FOUND, "TenantInfo not found in db", ""); - - this.tenant = new TenantInfo(); - this.tenant.setId(tenantInfoDoc.get().getTenantInfo().getId()); - this.tenant.setName(tenantInfoDoc.get().getTenantInfo().getName()); - this.tenant.setServiceAccount(tenantInfoDoc.get().getTenantInfo().getServiceAccount()); - this.tenant.setProjectId(tenantInfoDoc.get().getTenantInfo().getProjectId()); - this.tenant.setDataPartitionId(tenantInfoDoc.get().getTenantInfo().getDataPartitionId()); - this.tenant.setComplianceRuleSet(tenantInfoDoc.get().getTenantInfo().getComplianceRuleSet()); - this.tenant.setCrmAccountIds(tenantInfoDoc.get().getTenantInfo().getCrmAccountIds()); - - this.tenantsList.putIfAbsent(tenant.getName(), tenant); - + private void initTenants() { + this.tenants = new HashMap<>(); + + db.findAll().forEach(doc -> { + TenantInfo ti = new TenantInfo(); + String tenantName = doc.getId(); + ti.setName(tenantName); + //set serviceprincipalAppId in Azure side instead of ServiceAccount in Gcp + ti.setServiceAccount(doc.getServiceprincipalAppId()); + this.tenants.put(tenantName, ti) ; + }); } - } diff --git a/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantInfoDoc.java b/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantInfoDoc.java index af91db5ee0cd3291c9d915132419bdf995e0c9b5..25439341e0964a7ecdfae1a8e99f68aa7fb9440a 100644 --- a/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantInfoDoc.java +++ b/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantInfoDoc.java @@ -17,8 +17,7 @@ public class TenantInfoDoc { @PartitionKey @Id private String id; - private TenantInfo tenantInfo; - private String domain; + private String serviceprincipalAppId; } interface CosmosDBTenantInfo extends DocumentDbRepository<TenantInfoDoc, String> {} diff --git a/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantInfoFactory.java b/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantInfoFactory.java deleted file mode 100644 index 3e53588e76825af1e4af8b9889fb4478dd05adb5..0000000000000000000000000000000000000000 --- a/indexer-service-azure/src/main/java/org/opendes/indexer/azure/di/TenantInfoFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.opendes.indexer.azure.di; - -import lombok.extern.java.Log; -import org.opengroup.osdu.client.api.DpsHeaders; -import org.opengroup.osdu.client.multitenancy.ITenantFactory; -import org.opengroup.osdu.client.multitenancy.TenantInfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; - -@Log -@Component -@RequestScope -public class TenantInfoFactory extends AbstractFactoryBean<TenantInfo> { - @Autowired - private ITenantFactory tenantFactory; - @Autowired - private DpsHeaders headers; - @Override - protected TenantInfo createInstance() throws Exception { - String id = this.headers.getPartitionIdWithFallbackToAccountId(); - return this.tenantFactory.getTenantInfo(id); - } - @Override - public Class<?> getObjectType() { - return TenantInfo.class; - } -} diff --git a/indexer-service-gcp/src/main/java/org/opendes/indexer/di/TenantInfoFactory.java b/indexer-service-root/src/main/java/org/opendes/indexer/di/TenantInfoFactory.java similarity index 99% rename from indexer-service-gcp/src/main/java/org/opendes/indexer/di/TenantInfoFactory.java rename to indexer-service-root/src/main/java/org/opendes/indexer/di/TenantInfoFactory.java index beab92728b83da53ade1b55c8adbd3e529315652..8b38723cffc7ff7d71f2d45d98cb40db04604bcc 100644 --- a/indexer-service-gcp/src/main/java/org/opendes/indexer/di/TenantInfoFactory.java +++ b/indexer-service-root/src/main/java/org/opendes/indexer/di/TenantInfoFactory.java @@ -1,7 +1,6 @@ package org.opendes.indexer.di; import lombok.extern.java.Log; - import org.opengroup.osdu.client.api.DpsHeaders; import org.opengroup.osdu.client.multitenancy.ITenantFactory; import org.opengroup.osdu.client.multitenancy.TenantInfo;