Skip to content
Snippets Groups Projects
Commit b7433920 authored by Chad Leong's avatar Chad Leong
Browse files

Merge branch 'aws-merge-to-release-0.19' into 'release/0.19'

Merge branch 'aws-merge-to-release-0.19' to 'release/0.19'

See merge request !655
parents 49ffbd2e 3f8116f0
No related branches found
No related tags found
2 merge requests!680Merge branch 'aws-integration-eks' into 'master',!655Merge branch 'aws-merge-to-release-0.19' to 'release/0.19'
Pipeline #179771 passed
......@@ -66,7 +66,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.17.0</version>
<version>0.19.1</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -15,6 +15,7 @@
package org.opengroup.osdu.storage.provider.aws;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ComparisonOperator;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelperFactory;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelperV2;
......@@ -121,7 +122,16 @@ public class QueryRepositoryImpl implements IQueryRepository {
QueryPageResult<RecordMetadataDoc> scanPageResults;
try {
scanPageResults = recordMetadataQueryHelper.queryPage(RecordMetadataDoc.class, recordMetadataKey, "Status", "active", numRecords, cursor);
scanPageResults = recordMetadataQueryHelper.queryPage(
RecordMetadataDoc.class,
recordMetadataKey,
"Status",
"active",
"Id",
ComparisonOperator.BEGINS_WITH,
String.format("%s:", this.headers.getPartitionId()),
numRecords,
cursor);
} catch (UnsupportedEncodingException e) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error parsing results",
e.getMessage(), e);
......
......@@ -14,6 +14,7 @@
package org.opengroup.osdu.storage.provider.aws.api;
import com.amazonaws.services.dynamodbv2.model.ComparisonOperator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
......@@ -134,15 +135,85 @@ public class QueryRepositoryTest {
RecordMetadataDoc recordMetadataKey = new RecordMetadataDoc();
recordMetadataKey.setKind(kind);
Mockito.when(queryHelper.queryPage(Mockito.eq(RecordMetadataDoc.class), Mockito.anyObject(), Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.eq(cursor)))
.thenReturn(expectedQueryPageResult);
Mockito.when(queryHelper.queryPage(
Mockito.eq(RecordMetadataDoc.class),
Mockito.anyObject(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.eq(ComparisonOperator.BEGINS_WITH),
Mockito.anyString(),
Mockito.anyInt(),
Mockito.anyString()))
.thenReturn(expectedQueryPageResult);
// Act
DatastoreQueryResult datastoreQueryResult = repo.getAllRecordIdsFromKind(kind, 50, cursor, Optional.empty());
// Assert
Mockito.verify(queryHelper, Mockito.times(1)).queryPage(
Mockito.eq(RecordMetadataDoc.class),
Mockito.anyObject(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.eq(ComparisonOperator.BEGINS_WITH),
Mockito.anyString(),
Mockito.eq(50),
Mockito.eq(cursor)
);
Assert.assertEquals(expectedDatastoreQueryResult, datastoreQueryResult);
}
@Test
public void getAllRecordIdsFromDifferentKind() throws UnsupportedEncodingException {
// Arrange
String kind = "osdu:source:type:1.0.0";
String cursor = "abc123";
String recordId = "tenant:source:type:1.0.0.1212";
List<String> resultsIds = new ArrayList<>();
resultsIds.add(recordId);
DatastoreQueryResult expectedDatastoreQueryResult = new DatastoreQueryResult(cursor, resultsIds);
String user = "test-user";
RecordMetadataDoc expectedRecordMetadataDoc = new RecordMetadataDoc();
expectedRecordMetadataDoc.setId(recordId);
expectedRecordMetadataDoc.setKind(kind);
expectedRecordMetadataDoc.setUser(user);
expectedRecordMetadataDoc.setStatus("active");
List<RecordMetadataDoc> expectedRecordMetadataDocList = new ArrayList<>();
expectedRecordMetadataDocList.add(expectedRecordMetadataDoc);
QueryPageResult<RecordMetadataDoc> expectedQueryPageResult = new QueryPageResult<>(cursor, expectedRecordMetadataDocList);
// Set GSI hash key
RecordMetadataDoc recordMetadataKey = new RecordMetadataDoc();
recordMetadataKey.setKind(kind);
Mockito.when(queryHelper.queryPage(
Mockito.eq(RecordMetadataDoc.class),
Mockito.anyObject(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.eq(ComparisonOperator.BEGINS_WITH),
Mockito.anyString(),
Mockito.anyInt(),
Mockito.anyString()))
.thenReturn(expectedQueryPageResult);
// Act
DatastoreQueryResult datastoreQueryResult = repo.getAllRecordIdsFromKind(kind, 50, cursor, Optional.empty());
// Assert
Mockito.verify(queryHelper, Mockito.times(1)).queryPage(Mockito.eq(RecordMetadataDoc.class), Mockito.anyObject(), Mockito.anyString(),
Mockito.anyString(), Mockito.anyInt(), Mockito.eq(cursor));
Mockito.verify(queryHelper, Mockito.times(1)).queryPage(
Mockito.eq(RecordMetadataDoc.class),
Mockito.anyObject(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.eq(ComparisonOperator.BEGINS_WITH),
Mockito.anyString(),
Mockito.eq(50),
Mockito.eq(cursor)
);
Assert.assertEquals(expectedDatastoreQueryResult, datastoreQueryResult);
}
}
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