// get information
String tableName = request.getTableName();
Key key = request.getKey();
List<String> attributesToGet = request.getAttributesToGet();
GetItemResult result = new GetItemResult();
// Check to make sure table exists
if (!this.tables.containsKey(tableName)) {
throw new ResourceNotFoundException("The table you're currently trying to access (" + tableName + ") doesn't exists.");
}
// Check to make sure Key is valid
String hashKeyValue = getKeyValue(key.getHashKeyElement());
ItemRangeGroup rangeGroup = this.tables.get(tableName).getItemRangeGroup(hashKeyValue);
if (rangeGroup == null) {
return new GetItemResult();
// throw new ResourceNotFoundException("No item with Hash Key (" + hashKeyValue + ") exists.");
} else {
String rangeKeyValue = getKeyValue(key.getRangeKeyElement());
Map<String, AttributeValue> item = this.tables.get(tableName).getItem(hashKeyValue, rangeKeyValue);
if (item == null) {
return new GetItemResult();
// throw new ResourceNotFoundException("No item with Hash Key (" + hashKeyValue + ") and Range Key )" + rangeKeyValue + ") exists.");
}
if (attributesToGet == null) {
result.setItem(item);
} else {
Map<String, AttributeValue> response = new HashMap<String, AttributeValue>();
for (String att : attributesToGet) {
AttributeValue res = item.get(att);
if (res != null) {
response.put(att, res);
}
}
result.setItem(response);
}
}
return result;
}