Source:
public RingTime getNextRingTime(final String deviceId){ final Map<String, Condition> queryConditions = new HashMap<String, Condition>(); final Condition selectDateCondition = new Condition() .withComparisonOperator(ComparisonOperator.LE.toString()) .withAttributeValueList(new AttributeValue().withN(String.valueOf(DateTime.now().getMillis()))); queryConditions.put(CREATED_AT_ATTRIBUTE_NAME, selectDateCondition); final Condition selectAccountIdCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(deviceId)); queryConditions.put(MORPHEUS_ID_ATTRIBUTE_NAME, selectAccountIdCondition); final Collection<String> targetAttributeSet = new HashSet<String>(); Collections.addAll(targetAttributeSet, MORPHEUS_ID_ATTRIBUTE_NAME, RING_TIME_ATTRIBUTE_NAME, CREATED_AT_ATTRIBUTE_NAME); final QueryRequest queryRequest = new QueryRequest(this.tableName) .withKeyConditions(queryConditions) .withAttributesToGet(targetAttributeSet) .withLimit(1) .withScanIndexForward(false); final QueryResult queryResult = this.dynamoDBClient.query(queryRequest); if(queryResult.getItems() == null){ return RingTime.createEmpty(); } final List<Map<String, AttributeValue>> items = queryResult.getItems(); for(final Map<String, AttributeValue> item:items){ if(!item.keySet().containsAll(targetAttributeSet)){ LOGGER.warn("Missing field in item {}", item); continue; } try { final String ringTimeJSON = item.get(RING_TIME_ATTRIBUTE_NAME).getS(); final ObjectMapper mapper = new ObjectMapper(); final RingTime ringTime = mapper.readValue(ringTimeJSON, RingTime.class); return ringTime; }catch (Exception ex){ LOGGER.error("Get ring time failed for device {}.", deviceId); } } return RingTime.createEmpty(); }

Target:
public RingTime getNextRingTime(final String deviceId){ final Map<String, Condition> queryConditions = new HashMap<String, Condition>(); final Condition selectDateCondition = new Condition() .withComparisonOperator(ComparisonOperator.LE.toString()) .withAttributeValueList(new AttributeValue().withN(String.valueOf(DateTime.now().getMillis()))); queryConditions.put(CREATED_AT_ATTRIBUTE_NAME, selectDateCondition); final Condition selectAccountIdCondition = new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(deviceId)); queryConditions.put(MORPHEUS_ID_ATTRIBUTE_NAME, selectAccountIdCondition); final Collection<String> targetAttributeSet = new HashSet<String>(); Collections.addAll(targetAttributeSet, MORPHEUS_ID_ATTRIBUTE_NAME, RING_TIME_ATTRIBUTE_NAME, CREATED_AT_ATTRIBUTE_NAME); final QueryRequest queryRequest = new QueryRequest(this.tableName) .withKeyConditions(queryConditions) .withAttributesToGet(targetAttributeSet) .withLimit(1) .withScanIndexForward(false); final QueryResult queryResult = this.dynamoDBClient.query(queryRequest); if(queryResult.getItems() == null){ return RingTime.createEmpty(); } final List<Map<String, AttributeValue>> items = queryResult.getItems(); for(final Map<String, AttributeValue> item:items){ final RingTime ringTime = ringTimeFromItemSet(deviceId, targetAttributeSet, item); if(ringTime != null){ return ringTime; } } return RingTime.createEmpty(); }