use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoHealthDataEx3DaoTest method getRecordsForAppAndStudy.
@Test
public void getRecordsForAppAndStudy() {
// Mock dependencies.
DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
// Execute.
ForwardCursorPagedResourceList<HealthDataRecordEx3> resultList = dao.getRecordsForAppAndStudy(TestConstants.TEST_APP_ID, STUDY_ID, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, null);
assertEquals(resultList.getItems().size(), 1);
assertSame(resultList.getItems().get(0), record);
assertNull(resultList.getNextPageOffsetKey());
// Validate.
ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
verify(dao).queryHelper(queryCaptor.capture());
DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
assertFalse(query.isConsistentRead());
assertEquals(query.getIndexName(), DynamoHealthDataRecordEx3.APPSTUDYKEY_CREATEDON_INDEX);
assertEquals(query.getHashKeyValues().getAppId(), TestConstants.TEST_APP_ID);
assertEquals(query.getHashKeyValues().getStudyId(), STUDY_ID);
assertEquals(query.getLimit().intValue(), BridgeConstants.API_DEFAULT_PAGE_SIZE + 1);
assertEquals(query.getRangeKeyConditions().size(), 1);
Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
assertEquals(rangeKeyCondition.getComparisonOperator(), ComparisonOperator.BETWEEN.toString());
assertEquals(rangeKeyCondition.getAttributeValueList().size(), 2);
assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START));
assertEquals(rangeKeyCondition.getAttributeValueList().get(1).getN(), String.valueOf(CREATED_ON_END));
}
use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDao method getSurveyGuidForIdentifier.
/**
* {@inheritDoc}
*/
@Override
public String getSurveyGuidForIdentifier(String appId, String surveyId) {
// Hash key.
DynamoSurvey hashKey = new DynamoSurvey();
hashKey.setAppId(appId);
// Range key.
Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(surveyId));
// Construct query.
DynamoDBQueryExpression<DynamoSurvey> expression = new DynamoDBQueryExpression<DynamoSurvey>().withConsistentRead(false).withHashKeyValues(hashKey).withRangeKeyCondition("identifier", rangeKeyCondition).withLimit(1);
// Execute query.
QueryResultPage<DynamoSurvey> resultPage = surveyMapper.queryPage(DynamoSurvey.class, expression);
List<DynamoSurvey> surveyList = resultPage.getResults();
if (surveyList.isEmpty()) {
return null;
}
return surveyList.get(0).getGuid();
}
use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoUploadDao method createCountQuery.
/**
* Create a query for records applying the filter values if they exist.
*/
private DynamoDBQueryExpression<DynamoUpload2> createCountQuery(String appId, DateTime startTime, DateTime endTime) {
Condition rangeKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN.toString()).withAttributeValueList(new AttributeValue().withN(String.valueOf(startTime.getMillis())), new AttributeValue().withN(String.valueOf(endTime.getMillis())));
DynamoUpload2 upload = new DynamoUpload2();
upload.setAppId(appId);
DynamoDBQueryExpression<DynamoUpload2> query = new DynamoDBQueryExpression<>();
query.withIndexName(STUDY_ID_REQUESTED_ON_INDEX);
query.withHashKeyValues(upload);
query.withConsistentRead(false);
query.setScanIndexForward(false);
query.withRangeKeyCondition(REQUESTED_ON, rangeKeyCondition);
return query;
}
Aggregations