Skip to content
Snippets Groups Projects
Commit d8041d1a authored by Aman Verma's avatar Aman Verma
Browse files

storing the compact schema in schemaInfoStore

parent 910d0b26
No related branches found
No related tags found
1 merge request!18storing the compact schema in schemaInfoStore
Pipeline #6404 passed
......@@ -38,4 +38,5 @@ public class FlattenedSchemaInfo {
private Long patchVersion;
private String scope;
private String status;
private String schema;
}
......@@ -20,6 +20,7 @@ import java.util.Map.Entry;
import java.util.stream.Collectors;
import com.azure.cosmos.*;
import com.google.gson.Gson;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -28,7 +29,6 @@ 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.impl.schemastore.AzureSchemaStore;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.enums.SchemaScope;
import org.opengroup.osdu.schema.enums.SchemaStatus;
......@@ -71,10 +71,6 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
@Autowired
JaxRsDpsLog log;
@Autowired
AzureSchemaStore schemaStore;
/**
* Method to get schemaInfo from azure store
*
......@@ -105,7 +101,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
@Override
public SchemaInfo createSchemaInfo(SchemaRequest schema) throws ApplicationException, BadRequestException {
String id = headers.getPartitionId() + ":" + schema.getSchemaInfo().getSchemaIdentity().getId();
FlattenedSchemaInfo flattenedSchemaInfo = populateSchemaInfo(schema.getSchemaInfo());
FlattenedSchemaInfo flattenedSchemaInfo = populateSchemaInfo(schema);
SchemaInfoDoc schemaInfoDoc = new SchemaInfoDoc(id, headers.getPartitionId(), flattenedSchemaInfo);
try {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, schemaInfoDoc);
......@@ -134,7 +130,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
@Override
public SchemaInfo updateSchemaInfo(SchemaRequest schema) throws ApplicationException, BadRequestException {
String id = headers.getPartitionId() + ":" + schema.getSchemaInfo().getSchemaIdentity().getId();
FlattenedSchemaInfo flattenedSchemaInfo = populateSchemaInfo(schema.getSchemaInfo());
FlattenedSchemaInfo flattenedSchemaInfo = populateSchemaInfo(schema);
SchemaInfoDoc schemaInfoDoc = new SchemaInfoDoc(id, headers.getPartitionId(), flattenedSchemaInfo);
try {
cosmosStore.upsertItem(headers.getPartitionId(), cosmosDBName, schemaInfoContainer, schemaInfoDoc);
......@@ -191,17 +187,12 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
TreeMap<Long, String> sortedMap = new TreeMap<>(Collections.reverseOrder());
for (SchemaInfoDoc info : schemaInfoList)
{
sortedMap.put(info.getFlattenedSchemaInfo().getMinorVersion(), info.getFlattenedSchemaInfo().getId());
sortedMap.put(info.getFlattenedSchemaInfo().getMinorVersion(), info.getFlattenedSchemaInfo().getSchema());
}
if (sortedMap.size() != 0) {
Entry<Long, String> entry = sortedMap.firstEntry();
String schemaId = entry.getValue();
try {
return schemaStore.getSchema(headers.getPartitionId(), schemaId);
} catch (NotFoundException e) {
return new String();
}
return entry.getValue();
}
return new String();
}
......@@ -212,8 +203,9 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
* @param schema
* @return
*/
private FlattenedSchemaInfo populateSchemaInfo(SchemaInfo schemaInfo)
private FlattenedSchemaInfo populateSchemaInfo(SchemaRequest schemaRequest)
throws BadRequestException {
SchemaInfo schemaInfo = schemaRequest.getSchemaInfo();
// check for super-seeding schemas
String supersededById = "";
if (schemaInfo.getSupersededBy() != null) {
......@@ -227,6 +219,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
supersededById = schemaInfo.getSupersededBy().getId();
}
Gson gson = new Gson();
return FlattenedSchemaInfo.builder().id(schemaInfo.getSchemaIdentity().getId())
.supersededBy(supersededById)
.dateCreated(new Date())
......@@ -239,6 +232,7 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
.patchVersion(schemaInfo.getSchemaIdentity().getSchemaVersionPatch())
.scope(schemaInfo.getScope().name())
.status(schemaInfo.getStatus().name())
.schema(gson.toJson(schemaRequest.getSchema()))
.build();
}
......
......@@ -14,13 +14,11 @@
package org.opengroup.osdu.schema.provider.azure.impl.schemainfostore;
import com.azure.cosmos.*;
import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
......@@ -34,7 +32,6 @@ 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.impl.schemainfostore.AzureSchemaInfoStore;
import org.opengroup.osdu.schema.azure.impl.schemastore.AzureSchemaStore;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.enums.SchemaScope;
import org.opengroup.osdu.schema.enums.SchemaStatus;
......@@ -81,9 +78,6 @@ public class AzureSchemaInfoStoreTest {
@Mock
DpsHeaders headers;
@Mock
AzureSchemaStore schemaStore;
@Mock
FlattenedSchemaInfo flattenedSchemaInfo;
......@@ -126,7 +120,6 @@ public class AzureSchemaInfoStoreTest {
.when(cosmosStore)
.queryItems(eq(dataPartitionId), any(), any(), any(), any(), any());
Mockito.when(schemaStore.getSchema(dataPartitionId, schemaId)).thenReturn(CONTENT);
assertEquals(CONTENT, schemaInfoStore.getLatestMinorVerSchema(getMockSchemaInfo()));
}
......@@ -512,6 +505,7 @@ public class AzureSchemaInfoStoreTest {
.patchVersion(1L)
.scope(SchemaScope.SHARED.toString())
.status(SchemaStatus.PUBLISHED.toString())
.schema(CONTENT)
.build();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment