Skip to content
Snippets Groups Projects
Commit dbe0b560 authored by harshit aggarwal's avatar harshit aggarwal
Browse files

Replacing CosmosStore for CosmosFacade for accessing cosmosdb

parent b6c21f41
No related branches found
No related tags found
1 merge request!34Replacing CosmosStore for CosmosFacade for accessing cosmosdb
Pipeline #4185 failed
......@@ -78,7 +78,7 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>0.0.9</version>
<version>0.0.10</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
......
......@@ -14,11 +14,8 @@
package org.opengroup.osdu.legal.azure.di;
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosContainer;
import com.azure.security.keyvault.secrets.SecretClient;
import org.opengroup.osdu.azure.KeyVaultFacade;
import org.opengroup.osdu.common.Validators;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
......@@ -95,16 +92,17 @@ public class AzureBootstrapConfig {
}
@Bean
@Named("LEGAL_TAGS_CONTAINER")
CosmosContainer legalTagsContainer(final CosmosClient cosmosClient) {
Validators.checkNotNull(cosmosClient, "Cosmos client cannot be null");
return cosmosClient.getDatabase(cosmosDBName).getContainer(legalCollectionName);
public String cosmosDBName() {
return cosmosDBName;
}
@Bean
@Named("TENANT_INFO_CONTAINER")
CosmosContainer tenantInfoContainer(final CosmosClient cosmosClient) {
Validators.checkNotNull(cosmosClient, "Cosmos client cannot be null");
return cosmosClient.getDatabase(cosmosDBName).getContainer(tenantCollectionName);
public String legalTagsContainer(){
return legalCollectionName;
}
@Bean
public String tenantInfoContainer(){
return tenantCollectionName;
}
}
\ No newline at end of file
......@@ -14,14 +14,12 @@
package org.opengroup.osdu.legal.azure.di;
import javax.inject.Inject;
import javax.inject.Named;
import com.azure.cosmos.CosmosContainer;
import org.opengroup.osdu.azure.CosmosFacade;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collection;
......@@ -30,9 +28,18 @@ import java.util.Map;
@Component
public class TenantFactoryImpl implements ITenantFactory {
@Inject
@Named("TENANT_INFO_CONTAINER")
private CosmosContainer container;
@Autowired
private CosmosStore cosmosStore;
@Autowired
private String tenantInfoContainer;
@Autowired
private String cosmosDBName;
@Autowired
private DpsHeaders headers;
private Map<String, TenantInfo> tenants;
......@@ -64,7 +71,7 @@ public class TenantFactoryImpl implements ITenantFactory {
private void initTenants() {
this.tenants = new HashMap<>();
CosmosFacade.findAllItems(container, TenantInfoDoc.class).forEach(doc -> {
cosmosStore.findAllItems(headers.getPartitionId(), cosmosDBName, tenantInfoContainer, TenantInfoDoc.class).forEach(doc -> {
TenantInfo ti = new TenantInfo();
String tenantName = doc.getId();
ti.setName(tenantName);
......
......@@ -14,13 +14,18 @@
package org.opengroup.osdu.legal.azure.tags.dataaccess;
import com.azure.cosmos.*;
import org.opengroup.osdu.azure.CosmosFacade;
import com.azure.cosmos.FeedOptions;
import com.azure.cosmos.SqlParameter;
import com.azure.cosmos.SqlParameterList;
import com.azure.cosmos.SqlQuerySpec;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.common.Validators;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.legal.ListLegalTagArgs;
import org.opengroup.osdu.core.common.model.legal.LegalTag;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.legal.provider.interfaces.ILegalTagRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
......@@ -30,17 +35,22 @@ import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Named;
@Repository
public class LegalTagRepositoryImpl implements ILegalTagRepository {
private ReentrantLock mutex = new ReentrantLock();
@Inject
@Named("LEGAL_TAGS_CONTAINER")
private CosmosContainer container;
@Autowired
private CosmosStore cosmosStore;
@Autowired
private String legalTagsContainer;
@Autowired
private String cosmosDBName;
@Autowired
private DpsHeaders headers;
@Override
public Long create(LegalTag legalTag) {
......@@ -51,11 +61,11 @@ public class LegalTagRepositoryImpl implements ILegalTagRepository {
LegalTagDoc legalTagDoc = new LegalTagDoc(strId, legalTag);
try {
mutex.lock();
Optional<LegalTagDoc> existingDoc = CosmosFacade.findItem(container, strId, strId, LegalTagDoc.class);
Optional<LegalTagDoc> existingDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, legalTagsContainer, strId, strId, LegalTagDoc.class);
if (existingDoc.isPresent()) {
throw AppException.legalTagAlreadyExistsError(legalTag.getName());
}
CosmosFacade.upsertItem(container, legalTagDoc);
cosmosStore.upsertItem(headers.getPartitionId(), cosmosDBName, legalTagsContainer, legalTagDoc);
} finally {
mutex.unlock();
}
......@@ -70,7 +80,7 @@ public class LegalTagRepositoryImpl implements ILegalTagRepository {
for(long id : ids)
{
String strId = String.valueOf(id);
CosmosFacade.findItem(container, strId, strId, LegalTagDoc.class)
cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, legalTagsContainer, strId, strId, LegalTagDoc.class)
.ifPresent(tagDoc -> output.add(tagDoc.getLegalTag()));
}
}
......@@ -81,11 +91,11 @@ public class LegalTagRepositoryImpl implements ILegalTagRepository {
public Boolean delete(LegalTag legalTag) {
Long id = legalTag.getId();
String strId = String.valueOf(id);
boolean exists = CosmosFacade.findItem(container, strId, strId, LegalTagDoc.class).isPresent();
boolean exists = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, legalTagsContainer, strId, strId, LegalTagDoc.class).isPresent();
if (!exists)
return false;
CosmosFacade.deleteItem(container, strId, strId);
cosmosStore.deleteItem(headers.getPartitionId(), cosmosDBName, legalTagsContainer, strId, strId);
return true;
}
......@@ -96,11 +106,11 @@ public class LegalTagRepositoryImpl implements ILegalTagRepository {
Long id = newLegalTag.getId();
String strId = String.valueOf(id);
boolean exists = CosmosFacade.findItem(container, strId, strId, LegalTagDoc.class).isPresent();
boolean exists = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, legalTagsContainer, strId, strId, LegalTagDoc.class).isPresent();
if (!exists)
throw AppException.legalTagDoesNotExistError(newLegalTag.getName());
CosmosFacade.upsertItem(container, new LegalTagDoc(strId, newLegalTag));
cosmosStore.upsertItem(headers.getPartitionId(), cosmosDBName, legalTagsContainer, new LegalTagDoc(strId, newLegalTag));
return newLegalTag;
}
......@@ -112,7 +122,7 @@ public class LegalTagRepositoryImpl implements ILegalTagRepository {
.setParameters(new SqlParameterList(new SqlParameter("@isValid", args.getIsValid())));
FeedOptions options = new FeedOptions().setEnableCrossPartitionQuery(true);
return CosmosFacade.queryItems(container, query, options, LegalTagDoc.class)
return cosmosStore.queryItems(headers.getPartitionId(), cosmosDBName, legalTagsContainer, query, options, LegalTagDoc.class)
.stream()
.map(LegalTagDoc::getLegalTag)
.collect(Collectors.toList());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment