use of com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage in project BridgeServer2 by Sage-Bionetworks.
the class DynamoNotificationTopicDao method listTopics.
@Override
public List<NotificationTopic> listTopics(String appId, boolean includeDeleted) {
checkNotNull(appId);
// Consistent reads is set to true, because this is the table's primary key, and having reliable tests is more
// important than saving a small amount of DDB capacity.
DynamoNotificationTopic hashKey = new DynamoNotificationTopic();
hashKey.setAppId(appId);
DynamoDBQueryExpression<DynamoNotificationTopic> query = new DynamoDBQueryExpression<DynamoNotificationTopic>();
query.withConsistentRead(true);
query.withHashKeyValues(hashKey);
if (!includeDeleted) {
query.withQueryFilterEntry("deleted", new Condition().withComparisonOperator(ComparisonOperator.NE).withAttributeValueList(new AttributeValue().withN("1")));
}
QueryResultPage<DynamoNotificationTopic> resultPage = mapper.queryPage(DynamoNotificationTopic.class, query);
List<DynamoNotificationTopic> topicList = resultPage.getResults();
// Load criteria.
topicList.forEach(this::loadCriteria);
return ImmutableList.copyOf(topicList);
}
use of com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage in project BridgeServer2 by Sage-Bionetworks.
the class DynamoOAuthAccessGrantDao method getAccessGrants.
@Override
public ForwardCursorPagedResourceList<OAuthAccessGrant> getAccessGrants(String appId, String vendorId, String offsetKey, int pageSize) {
checkNotNull(appId);
checkArgument(isNotBlank(vendorId));
int pageSizeWithIndicatorRecord = pageSize + 1;
DynamoOAuthAccessGrant grantKey = new DynamoOAuthAccessGrant();
grantKey.setKey(getGrantKey(appId, vendorId));
DynamoDBQueryExpression<DynamoOAuthAccessGrant> query = new DynamoDBQueryExpression<DynamoOAuthAccessGrant>().withHashKeyValues(grantKey).withLimit(pageSizeWithIndicatorRecord);
if (offsetKey != null) {
Condition healthCodeCondition = new Condition().withComparisonOperator(GE).withAttributeValueList(new AttributeValue().withS(offsetKey));
query.withRangeKeyCondition("healthCode", healthCodeCondition);
}
QueryResultPage<DynamoOAuthAccessGrant> page = mapper.queryPage(DynamoOAuthAccessGrant.class, query);
int pageLimit = Math.min(page.getResults().size(), pageSizeWithIndicatorRecord);
List<OAuthAccessGrant> list = Lists.newArrayListWithCapacity(pageLimit);
for (int i = 0; i < pageLimit; i++) {
list.add(page.getResults().get(i));
}
String nextPageOffsetKey = null;
if (list.size() == pageSizeWithIndicatorRecord) {
nextPageOffsetKey = Iterables.getLast(list).getHealthCode();
}
int limit = Math.min(list.size(), pageSize);
return new ForwardCursorPagedResourceList<OAuthAccessGrant>(list.subList(0, limit), nextPageOffsetKey).withRequestParam(PAGE_SIZE, pageSize).withRequestParam(OFFSET_KEY, offsetKey);
}
use of com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage in project BridgeServer2 by Sage-Bionetworks.
the class DynamoHealthDataDao method getRecordsByHealthCodeCreatedOn.
/**
* {@inheritDoc}
*/
@Override
public List<HealthDataRecord> getRecordsByHealthCodeCreatedOn(String healthCode, long createdOnStart, long createdOnEnd) {
// Hash key.
DynamoHealthDataRecord queryRecord = new DynamoHealthDataRecord();
queryRecord.setHealthCode(healthCode);
// Range key.
Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList(new AttributeValue().withN(String.valueOf(createdOnStart)), new AttributeValue().withN(String.valueOf(createdOnEnd)));
// Construct query.
DynamoDBQueryExpression<DynamoHealthDataRecord> expression = new DynamoDBQueryExpression<DynamoHealthDataRecord>().withConsistentRead(false).withHashKeyValues(queryRecord).withRangeKeyCondition("createdOn", rangeKeyCondition).withLimit(BridgeConstants.DUPE_RECORDS_MAX_COUNT);
// Execute query.
QueryResultPage<DynamoHealthDataRecord> resultPage = mapper.queryPage(DynamoHealthDataRecord.class, expression);
List<DynamoHealthDataRecord> recordList = resultPage.getResults();
return ImmutableList.copyOf(recordList);
}
use of com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage in project BridgeServer2 by Sage-Bionetworks.
the class DynamoUploadSchemaDaoTest method getLatestById.
@Test
public void getLatestById() {
// mock DDB mapper
DynamoUploadSchema mapperOutputSchema = new DynamoUploadSchema();
List<DynamoUploadSchema> mapperOutputSchemaList = ImmutableList.of(mapperOutputSchema);
QueryResultPage<DynamoUploadSchema> queryResultPage = new QueryResultPage<>();
queryResultPage.setResults(mapperOutputSchemaList);
ArgumentCaptor<DynamoDBQueryExpression> mapperQueryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
when(mapper.queryPage(eq(DynamoUploadSchema.class), mapperQueryCaptor.capture())).thenReturn(queryResultPage);
// execute
UploadSchema daoOutputSchema = dao.getUploadSchemaLatestRevisionById(TEST_APP_ID, SCHEMA_ID);
// validate query
DynamoDBQueryExpression<DynamoUploadSchema> mapperQuery = mapperQueryCaptor.getValue();
assertFalse(mapperQuery.isScanIndexForward());
assertEquals(mapperQuery.getLimit().intValue(), 1);
assertEquals(mapperQuery.getHashKeyValues().getAppId(), TEST_APP_ID);
assertEquals(mapperQuery.getHashKeyValues().getSchemaId(), SCHEMA_ID);
// Verify DAO output
assertSame(daoOutputSchema, mapperOutputSchema);
}
use of com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage in project BridgeServer2 by Sage-Bionetworks.
the class DynamoUploadSchemaDaoTest method getLatestByIdNoResult.
@Test
public void getLatestByIdNoResult() {
// mock DDB mapper
List<DynamoUploadSchema> mapperOutputSchemaList = ImmutableList.of();
QueryResultPage<DynamoUploadSchema> queryResultPage = new QueryResultPage<>();
queryResultPage.setResults(mapperOutputSchemaList);
when(mapper.queryPage(eq(DynamoUploadSchema.class), any())).thenReturn(queryResultPage);
// execute and validate result is null
UploadSchema daoOutputSchema = dao.getUploadSchemaLatestRevisionById(TEST_APP_ID, SCHEMA_ID);
assertNull(daoOutputSchema);
// query is already validated in getLatestById(). Don't bother checking again.
}
Aggregations