Search in sources :

Example 16 with QueryResultPage

use of com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage 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();
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)

Aggregations

DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)10 Condition (com.amazonaws.services.dynamodbv2.model.Condition)8 Test (org.testng.annotations.Test)8 QueryResultPage (com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage)7 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)7 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)5 ScheduledActivity (org.sagebionetworks.bridge.models.schedules.ScheduledActivity)4 PaginatedQueryList (com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SmsMessage (org.sagebionetworks.bridge.models.sms.SmsMessage)2 UploadSchema (org.sagebionetworks.bridge.models.upload.UploadSchema)2 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)1 Item (com.amazonaws.services.dynamodbv2.document.Item)1 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)1 RangeKeyCondition (com.amazonaws.services.dynamodbv2.document.RangeKeyCondition)1 QueryRequest (com.amazonaws.services.dynamodbv2.model.QueryRequest)1 QueryResult (com.amazonaws.services.dynamodbv2.model.QueryResult)1 DateTime (org.joda.time.DateTime)1