Commit 667522c0 authored by Gokul Nagare's avatar Gokul Nagare Committed by Anuj Gupta
Browse files

ibm partition check added

parent 9c61218a
......@@ -12,7 +12,7 @@
<properties>
<start-class>org.opengroup.osdu.schema.provider.ibm.app.SchemaIBMApplication</start-class>
<os-core-lib-ibm.version>0.3.8-SNAPSHOT</os-core-lib-ibm.version>
<os-core-lib-ibm.version>0.3.23-SNAPSHOT</os-core-lib-ibm.version>
</properties>
......
......@@ -28,6 +28,7 @@ import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.BadRequestException;
import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.exceptions.UnauthorizedException;
import org.opengroup.osdu.schema.impl.schemainfostore.util.IbmDocumentStore;
import org.opengroup.osdu.schema.model.QueryParams;
import org.opengroup.osdu.schema.model.SchemaIdentity;
......@@ -68,6 +69,9 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Inject
private TenantFactory tenantFactory;
@Inject
private TenantInfo tenant;
@Autowired
private ISchemaStore schemaStore;
......@@ -83,6 +87,11 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Override
public boolean isUnique(String schemaId, String tenantId) throws ApplicationException {
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
Set<String> tenantList = new HashSet<>();
tenantList.add(sharedTenant);
tenantList.add(tenantId);
......@@ -120,6 +129,11 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
*/
@Override
public SchemaInfo getSchemaInfo(String schemaId) throws ApplicationException, NotFoundException {
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
if (db.contains(schemaId)) {
SchemaDoc sd = db.find(SchemaDoc.class, schemaId);
return sd.getSchemaInfo();
......@@ -259,7 +273,12 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Override
public List<SchemaInfo> getSchemaInfoList(QueryParams queryParams, String tenantId) throws ApplicationException {
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
long numRecords = LIMIT_SIZE;
if (Long.valueOf(queryParams.getLimit()) != null) {
numRecords = Long.valueOf(queryParams.getLimit());
......
......@@ -21,6 +21,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.annotation.RequestScope;
import org.opengroup.osdu.schema.exceptions.UnauthorizedException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3;
import com.ibm.cloud.objectstorage.services.s3.model.AmazonS3Exception;
import com.ibm.cloud.objectstorage.services.s3.model.ObjectMetadata;
......@@ -43,6 +45,9 @@ public class IBMSchemaStore implements ISchemaStore {
@Inject
private JaxRsDpsLog logger;
@Inject
private TenantInfo tenant;
AmazonS3 s3Client;
......@@ -67,6 +72,12 @@ public class IBMSchemaStore implements ISchemaStore {
// dataPartitionId not used b/c getting from header
String content = null;
try {
tenant.getName();
} catch (Exception e) {
throw new UnauthorizedException("Unauthorized");
}
try {
content = getObjectAsString(schemaId);
} catch (AmazonS3Exception s3Exp) {
......
......@@ -94,6 +94,9 @@ public class IbmSchemaInfoStoreTest {
@Mock
IBMSchemaStore schemaStore;
@Mock
TenantInfo tenant;
@Rule
public ExpectedException expectedException = ExpectedException.none();
......@@ -424,9 +427,11 @@ public class IbmSchemaInfoStoreTest {
List<SchemaDoc> schemaDocsList = new LinkedList<>();
schemaDocsList.add(schemaDoc);
schemaDocsList.add(latestSchemaDoc);
Mockito.when(headers.getPartitionIdWithFallbackToAccountId()).thenReturn(dataPartitionId);
Mockito.when(cloudantFactory.getDatabase(any(),anyString())).thenReturn(db);
Mockito.when(db.query(Mockito.any(),Mockito.any())).thenReturn(queryResult);
Mockito.when(queryResult.getDocs()).thenReturn(schemaDocsList);
Mockito.when(tenant.getName()).thenReturn(dataPartitionId);
assertEquals(2, schemaInfoStore.getSchemaInfoList(
QueryParams.builder().scope("test").status("test").latestVersion(true).limit(100).offset(0).build(),
......
......@@ -15,7 +15,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.ibm.objectstorage.CloudObjectStorageFactory;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
......@@ -36,6 +36,9 @@ public class IBMSchemaStoreTest {
@Mock
DpsHeaders headers;
@Mock
TenantInfo tenant;
@Mock
CloudObjectStorageFactory cosFactory;
......@@ -88,6 +91,7 @@ public class IBMSchemaStoreTest {
Mockito.when(cosFactory.getClient()).thenReturn(s3Client);
Mockito.when(cosFactory.getBucketName(dataPartitionId, BUCKET)).thenReturn(bucketName);
Mockito.when(s3Client.getObjectAsString(bucketName, SCHEMA_ID)).thenReturn(CONTENT);
Mockito.when(tenant.getName()).thenReturn(dataPartitionId);
Assert.assertEquals(CONTENT, schemaStore.getSchema(dataPartitionId, SCHEMA_ID));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment