// TODO: test out put item expected and return value @Test public void getItemTest() { AttributeValue hash = createItem(tableName); GetItemRequest request = new GetItemRequest().withTableName(tableName); request.setKey(createItemKey("id", hash)); GetItemResult res = getClient().getItem(request); Assert.assertNotNull(res.getItem()); Assert.assertEquals(res.getItem().get("id"), hash); }
@Override public TranscodingJob get(final String jobId) { final ImmutableMap.Builder<String, AttributeValue> keyBuilder = ImmutableMap.builder(); keyBuilder.put("transcode-job-id", new AttributeValue(jobId)); try { final GetItemResult result = this.dynamoDB.getItem(TABLE_NAME, keyBuilder.build()); return new TranscodingJob( result.getItem().get("transcode-job-id").getS(), Paths.get(result.getItem().get("inputMovie").getS()), Paths.get(result.getItem().get("outputMovie").getS())); } catch (final AmazonServiceException e) { logger.error("AmazonServiceException while getting {}. RID: {}", jobId, e.getRequestId(), e); throw e; } catch (final AmazonClientException e) { logger.error("AmazonClientException while getting {}.", jobId, e); throw e; } }
public GetItemResult unmarshall(JsonUnmarshallerContext context) throws Exception { GetItemResult getItemResult = new GetItemResult(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.currentToken; if (token == null) token = context.nextToken(); if (token == VALUE_NULL) return null; while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("Item", targetDepth)) { context.nextToken(); getItemResult.setItem( new MapUnmarshaller<String, AttributeValue>( StringJsonUnmarshaller.getInstance(), AttributeValueJsonUnmarshaller.getInstance()) .unmarshall(context)); } if (context.testExpression("ConsumedCapacity", targetDepth)) { context.nextToken(); getItemResult.setConsumedCapacity( ConsumedCapacityJsonUnmarshaller.getInstance().unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return getItemResult; }