Commit a9fc1321 authored by Aman Verma's avatar Aman Verma
Browse files

Merge branch 'users/amaverma/addNewAPI' into 'master'

[azure] Adding new API to create public schemas in azure

See merge request !117
parents b956b20d 547ce1c2
Pipeline #49492 failed with stages
in 19 seconds
This diff is collapsed.
......@@ -29,15 +29,22 @@
<packaging>jar</packaging>
<properties>
<osdu.corelibazure.version>0.6.1</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.6.9</osdu.oscorecommon.version>
<azure.version>2.1.7</azure.version>
<osdu.corelibazure.version>0.11.0-SNAPSHOT</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.10.0-SNAPSHOT</osdu.oscorecommon.version>
<osdu.os-schema-core.version>0.10.0-SNAPSHOT</osdu.os-schema-core.version>
<mockito.version>1.10.19</mockito.version>
<cucumber.version>5.4.0</cucumber.version>
<nimbus-jose-jwt-azure.version>8.20.2</nimbus-jose-jwt-azure.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>${nimbus-jose-jwt-azure.version}</version>
</dependency>
<!-- Inherit managed dependencies from core-lib-azure -->
<dependency>
<groupId>org.opengroup.osdu</groupId>
......@@ -56,16 +63,6 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......@@ -117,7 +114,6 @@
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-guice</artifactId>
......@@ -147,6 +143,17 @@
<artifactId>jackson-dataformat-cbor</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-starter-active-directory</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot</artifactId>
<version>3.5.0</version>
</dependency>
</dependencies>
......
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.schema.azure.api;
import org.opengroup.osdu.schema.azure.interfaces.ISchemaServiceAzure;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.BadRequestException;
import org.opengroup.osdu.schema.model.SchemaInfo;
import org.opengroup.osdu.schema.model.SchemaRequest;
import org.opengroup.osdu.schema.model.SchemaUpsertResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@RestController
@RequestMapping("/schemas/system")
public class AzureSchemaApi {
@Autowired
ISchemaServiceAzure schemaService;
@PutMapping()
@PreAuthorize("@authorizationFilterSP.hasPermissions()")
public ResponseEntity<SchemaInfo> upsertSystemSchema(@Valid @RequestBody SchemaRequest schemaRequest)
throws ApplicationException, BadRequestException {
SchemaUpsertResponse upsertResp = schemaService.upsertSystemSchema(schemaRequest);
ResponseEntity<SchemaInfo> response = new ResponseEntity<>(upsertResp.getSchemaInfo(), upsertResp.getHttpCode());
return response;
}
}
package org.opengroup.osdu.schema.azure.auth;
import org.opengroup.osdu.schema.azure.interfaces.IAuthorizationServiceForServicePrincipal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Component("authorizationFilterSP")
@RequestScope
public class AuthorizationFilterSP {
@Autowired
private IAuthorizationServiceForServicePrincipal authorizationService;
public boolean hasPermissions() {
return authorizationService.isDomainAdminServiceAccount();
}
}
package org.opengroup.osdu.schema.azure.di;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@Getter
@Setter
@ConfigurationProperties("azure.system")
public class SystemResourceConfig {
private String storageContainerName;
private String cosmosDatabase;
private String sharedTenant;
}
......@@ -21,6 +21,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.definitions.AuthorityDoc;
import org.opengroup.osdu.schema.azure.di.SystemResourceConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
......@@ -31,6 +32,7 @@ import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.model.Authority;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.IAuthorityStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import java.text.MessageFormat;
......@@ -58,6 +60,9 @@ public class AzureAuthorityStore implements IAuthorityStore {
@Autowired
JaxRsDpsLog log;
@Autowired
SystemResourceConfig systemResourceConfig;
/**
* Method to get Authority from Azure store
* @param authorityId
......@@ -69,9 +74,15 @@ public class AzureAuthorityStore implements IAuthorityStore {
public Authority get(String authorityId) throws NotFoundException, ApplicationException {
String id = headers.getPartitionId() + ":" + authorityId;
AuthorityDoc authorityDoc;
AuthorityDoc authorityDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityId, AuthorityDoc.class)
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
authorityDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
authorityDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
return authorityDoc.getAuthority();
}
......@@ -89,7 +100,11 @@ public class AzureAuthorityStore implements IAuthorityStore {
try {
AuthorityDoc authorityDoc = new AuthorityDoc(id, authority);
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, id, authorityDoc);
} else {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityDoc);
}
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.AUTHORITY_EXISTS_ALREADY_REGISTERED);
......
......@@ -20,6 +20,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.definitions.EntityTypeDoc;
import org.opengroup.osdu.schema.azure.di.SystemResourceConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.BadRequestException;
......@@ -27,6 +28,7 @@ import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.model.EntityType;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.IEntityTypeStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import lombok.extern.java.Log;
......@@ -55,6 +57,9 @@ public class AzureEntityTypeStore implements IEntityTypeStore {
@Autowired
JaxRsDpsLog log;
@Autowired
SystemResourceConfig systemResourceConfig;
/**
* Method to get entity type from azure store
* @param entityTypeId
......@@ -66,9 +71,15 @@ public class AzureEntityTypeStore implements IEntityTypeStore {
public EntityType get(String entityTypeId) throws NotFoundException, ApplicationException {
String id = headers.getPartitionId() + ":" + entityTypeId;
EntityTypeDoc entityTypeDoc;
EntityTypeDoc entityTypeDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
entityTypeDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
entityTypeDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
return entityTypeDoc.getEntityType();
}
......@@ -86,7 +97,11 @@ public class AzureEntityTypeStore implements IEntityTypeStore {
try {
EntityTypeDoc entityTypeDoc = new EntityTypeDoc(id, entityType);
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, id, entityTypeDoc);
} else {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeDoc);
}
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.ENTITY_TYPE_EXISTS);
......
......@@ -31,6 +31,7 @@ import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.schema.azure.definitions.FlattenedSchemaInfo;
import org.opengroup.osdu.schema.azure.definitions.SchemaInfoDoc;
import org.opengroup.osdu.schema.azure.di.SystemResourceConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.enums.SchemaScope;
import org.opengroup.osdu.schema.enums.SchemaStatus;
......@@ -80,6 +81,9 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
@Value("${shared.tenant.name:common}")
private String sharedTenant;
@Autowired
SystemResourceConfig systemResourceConfig;
@Autowired
JaxRsDpsLog log;
......@@ -99,7 +103,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
SchemaIdentity schemaIdentity = schemaKindToSchemaIdentity(schemaId);
String partitioningKey = createSchemaInfoPartitionKey(schemaIdentity);
SchemaInfoDoc schemaInfoDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, partitioningKey, SchemaInfoDoc.class)
SchemaInfoDoc schemaInfoDoc = findItemInCosmosStore(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, partitioningKey, SchemaInfoDoc.class)
.orElseThrow(() -> new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT));
return getSchemaInfoObject(schemaInfoDoc.getFlattenedSchemaInfo(), headers.getPartitionId());
......@@ -120,7 +124,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
String partitionKey = createSchemaInfoPartitionKey(schema.getSchemaInfo().getSchemaIdentity());
SchemaInfoDoc schemaInfoDoc = new SchemaInfoDoc(id, partitionKey, flattenedSchemaInfo);
try {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, partitionKey, schemaInfoDoc);
crateItemInCosmos(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, partitionKey, schemaInfoDoc);
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.SCHEMA_ID_EXISTS);
......@@ -150,7 +154,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
String partitionKey = createSchemaInfoPartitionKey(schema.getSchemaInfo().getSchemaIdentity());
SchemaInfoDoc schemaInfoDoc = new SchemaInfoDoc(id, partitionKey, flattenedSchemaInfo);
try {
cosmosStore.upsertItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, partitionKey,schemaInfoDoc);
upsertItemInCosmos(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, partitionKey,schemaInfoDoc);
} catch (Exception ex) {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.SCHEMA_CREATION_FAILED_INVALID_OBJECT);
......@@ -175,13 +179,13 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
String partitionKey = createSchemaInfoPartitionKey(schemaIdentity);
// Check whether SchemaInfo already exists
Boolean exists = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).isPresent();
Boolean exists = findItemInCosmosStore(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).isPresent();
if (!exists) {
return false;
}
// Delete the item.
cosmosStore.deleteItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, headers.getPartitionId());
deleteItemInCosmos(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, headers.getPartitionId());
return true;
}
......@@ -209,7 +213,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
pars.add(new SqlParameter("@entityType", schemaInfo.getSchemaIdentity().getEntityType()));
pars.add(new SqlParameter("@majorVersion", schemaInfo.getSchemaIdentity().getSchemaVersionMajor()));
List<SchemaInfoDoc> schemaInfoList = cosmosStore.queryItems(headers.getPartitionId(), cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class);
List<SchemaInfoDoc> schemaInfoList = queryItemsInCosmos(headers.getPartitionId(), cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class);
TreeMap<Long, String> sortedMap = new TreeMap<>(Collections.reverseOrder());
for (SchemaInfoDoc info : schemaInfoList)
......@@ -244,7 +248,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
SchemaIdentity schemaIdentity = schemaKindToSchemaIdentity(schemaInfo.getSupersededBy().getId());
String partitionKey = createSchemaInfoPartitionKey(schemaIdentity);
if ( !cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, partitionKey, FlattenedSchemaInfo.class).isPresent()) {
if ( !findItemInCosmosStore(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, id, partitionKey, FlattenedSchemaInfo.class).isPresent()) {
log.error(SchemaConstants.INVALID_SUPERSEDEDBY_ID);
throw new BadRequestException(SchemaConstants.INVALID_SUPERSEDEDBY_ID);
}
......@@ -274,7 +278,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
String id = dataPartitionId + ":" + flattenedSchemaInfo.getSupersededBy();
SchemaIdentity schemaIdentity = schemaKindToSchemaIdentity(flattenedSchemaInfo.getSupersededBy());
String partitionKey = createSchemaInfoPartitionKey(schemaIdentity);
SchemaInfoDoc doc = cosmosStore.findItem(dataPartitionId, cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).get();
SchemaInfoDoc doc = findItemInCosmosStore(dataPartitionId, cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).get();
superSededBy = getSchemaIdentity(doc.getFlattenedSchemaInfo());
}
......@@ -352,7 +356,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
query.getParameters().add(new SqlParameter(param, parameterMap.get(param)));
}
List<SchemaInfoDoc> schemaInfoList = cosmosStore.queryItems(tenantId, cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class);
List<SchemaInfoDoc> schemaInfoList = queryItemsInCosmos(tenantId, cosmosDBName,schemaInfoContainer, query, options, SchemaInfoDoc.class);
List<SchemaInfo> schemaList = new LinkedList<>();
for (SchemaInfoDoc info: schemaInfoList)
......@@ -386,7 +390,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
String id = tenant + ":" + schemaId;
String partitionKey = createSchemaInfoPartitionKey(schemaKindToSchemaIdentity(schemaId));
try {
Boolean exists = cosmosStore.findItem(tenant, cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).isPresent();
Boolean exists = findItemInCosmosStore(tenant, cosmosDBName, schemaInfoContainer, id, partitionKey, SchemaInfoDoc.class).isPresent();
if (exists) {
return false;
}
......@@ -468,5 +472,72 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
":"+schemaIdentity.getEntityType()+
":"+schemaIdentity.getSchemaVersionMajor().toString();
}
private <T> Optional<T> findItemInCosmosStore(
String dataPartitionId,
String dataBaseName,
String containerName,
String id,
String partitionKey,
Class<T> clazz) {
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(dataPartitionId)) {
return cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), containerName, id, partitionKey, clazz);
} else {
return cosmosStore.findItem(dataPartitionId, dataBaseName, containerName, id, partitionKey, clazz);
}
}
private <T> void crateItemInCosmos(
String dataPartitionId,
String dataBaseName,
String containerName,
String partitionKey,
T item) {
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(dataPartitionId)) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), containerName, partitionKey, item);
} else {
cosmosStore.createItem(dataPartitionId, dataBaseName, containerName, partitionKey, item);
}
}
private <T> void upsertItemInCosmos(
String dataPartitionId,
String dataBaseName,
String containerName,
String partitionKey,
T item) {
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(dataPartitionId)) {
cosmosStore.upsertItem(systemResourceConfig.getCosmosDatabase(), containerName, partitionKey, item);
} else {
cosmosStore.upsertItem(dataPartitionId, dataBaseName, containerName, partitionKey, item);
}
}
private <T> void deleteItemInCosmos(
String dataPartitionId,
String dataBaseName,
String containerName,
String id,
String partitionKey) {
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(dataPartitionId)) {
cosmosStore.deleteItem(systemResourceConfig.getCosmosDatabase(), containerName, id, partitionKey);
} else {
cosmosStore.deleteItem(dataPartitionId, dataBaseName, containerName, id, partitionKey);
}
}
private <T> List<T> queryItemsInCosmos(
String dataPartitionId,
String cosmosDBName,
String collection,
SqlQuerySpec query,
CosmosQueryRequestOptions options,
Class<T> clazz) {
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(dataPartitionId)) {
return cosmosStore.queryItems(systemResourceConfig.getCosmosDatabase(), collection, query, options, clazz);
} else {
return cosmosStore.queryItems(dataPartitionId, cosmosDBName, collection, query, options, clazz);
}
}
}
......@@ -21,6 +21,7 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.definitions.SourceDoc;
import org.opengroup.osdu.schema.azure.di.SystemResourceConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.BadRequestException;
......@@ -28,6 +29,7 @@ import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.model.Source;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.ISourceStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
/**
......@@ -53,6 +55,9 @@ public class AzureSourceStore implements ISourceStore {
@Autowired
JaxRsDpsLog log;
@Autowired
SystemResourceConfig systemResourceConfig;
/**
* Method to create Source in azure store
* @param sourceId
......@@ -64,8 +69,15 @@ public class AzureSourceStore implements ISourceStore {
public Source get(String sourceId) throws NotFoundException, ApplicationException {
String id = headers.getPartitionId().toString() + ":" + sourceId;
SourceDoc sourceDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, sourceContainer, id, sourceId, SourceDoc.class)
SourceDoc sourceDoc;
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
sourceDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), sourceContainer, id, sourceId, SourceDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
sourceDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, sourceContainer, id, sourceId, SourceDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
return sourceDoc.getSource();
}
......@@ -83,7 +95,11 @@ public class AzureSourceStore implements ISourceStore {
try {
SourceDoc sourceDoc = new SourceDoc(id, source);
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), sourceContainer, id, sourceDoc);
} else {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, sourceContainer, id, sourceDoc);
}
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.SOURCE_EXISTS);
......
......@@ -18,11 +18,13 @@ import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.di.CosmosContainerConfig;
import org.opengroup.osdu.schema.azure.di.SystemResourceConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
/**
......@@ -45,6 +47,9 @@ public class AzureSchemaStore implements ISchemaStore {
@Autowired
JaxRsDpsLog log;
@Autowired
SystemResourceConfig systemResourceConfig;
/**
* Method to get schema from azure Storage given Tenant ProjectInfo
*
......@@ -59,7 +64,12 @@ public class AzureSchemaStore implements ISchemaStore {
public String getSchema(String dataPartitionId, String filePath) throws ApplicationException, NotFoundException {
filePath = dataPartitionId + ":" + filePath + SchemaConstants.JSON_EXTENSION;
try {
String content = blobStore.readFromStorageContainer(dataPartitionId, filePath, config.containerName());
String content = null;
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(dataPartitionId)) {
content = blobStore.readFromStorageContainer(filePath, systemResourceConfig.getStorageContainerName());
} else {
content = blobStore.readFromStorageContainer(dataPartitionId, filePath, config.containerName());
}
if (content != null)
return content;
else
......@@ -84,7 +94,11 @@ public class AzureSchemaStore implements ISchemaStore {
filePath = dataPartitionId + ":" + filePath + SchemaConstants.JSON_EXTENSION;
try {
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
blobStore.writeToStorageContainer(filePath, content, systemResourceConfig.getStorageContainerName());
} else {
blobStore.writeToStorageContainer(dataPartitionId, filePath, content, config.containerName());
}
log.info(SchemaConstants.SCHEMA_CREATED);
return filePath;
} catch (Exception ex) {
......@@ -105,8 +119,12 @@ public class AzureSchemaStore implements ISchemaStore {
try
{
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return blobStore.deleteFromStorageContainer(filePath, systemResourceConfig.getStorageContainerName());
} else {
return blobStore.deleteFromStorageContainer(dataPartitionId, filePath, config.containerName());
}
}
catch (Exception e)
{