use of software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes in project formkiq-core by formkiq.
the class ConfigServiceImpl method get.
@Override
public DynamicObject get(final String siteId) {
Collection<Map<String, AttributeValue>> keys = new ArrayList<>();
if (isDefaultSiteId(siteId)) {
keys.add(keysGeneric(null, PREFIX_CONFIG, DEFAULT_SITE_ID));
} else {
keys.add(keysGeneric(null, PREFIX_CONFIG, siteId));
keys.add(keysGeneric(null, PREFIX_CONFIG, DEFAULT_SITE_ID));
}
Map<String, KeysAndAttributes> items = Map.of(this.documentTableName, KeysAndAttributes.builder().keys(keys).build());
BatchGetItemResponse response = this.dynamoDB.batchGetItem(BatchGetItemRequest.builder().requestItems(items).build());
AttributeValueToDynamicObject transform = new AttributeValueToDynamicObject();
Optional<Map<String, AttributeValue>> map = Optional.empty();
List<Map<String, AttributeValue>> list = response.responses().get(this.documentTableName);
if (!list.isEmpty()) {
map = list.stream().filter(s -> s.get(SK).s().equals(siteId)).findFirst();
if (map.isEmpty()) {
map = list.stream().filter(s -> s.get(SK).s().equals(DEFAULT_SITE_ID)).findFirst();
}
}
return !map.isEmpty() ? transform.apply(map.get()) : new DynamicObject(Map.of());
}
use of software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes in project formkiq-core by formkiq.
the class WebhooksServiceImpl method findWebhooks.
@Override
public List<DynamicObject> findWebhooks(final String siteId) {
Map<String, AttributeValue> key = queryKeys(keysGeneric(siteId, PREFIX_WEBHOOKS, null));
String expr = GSI1_PK + " = :pk";
QueryRequest q = QueryRequest.builder().tableName(this.documentTableName).indexName(GSI1).keyConditionExpression(expr).expressionAttributeValues(key).build();
QueryResponse result = this.dynamoDB.query(q);
Collection<? extends Map<String, AttributeValue>> keys = result.items().stream().map(i -> Map.of(PK, i.get(PK), SK, i.get(SK))).collect(Collectors.toList());
List<DynamicObject> retlist = Collections.emptyList();
if (!keys.isEmpty()) {
Map<String, KeysAndAttributes> items = Map.of(this.documentTableName, KeysAndAttributes.builder().keys(keys).build());
BatchGetItemResponse batch = this.dynamoDB.batchGetItem(BatchGetItemRequest.builder().requestItems(items).build());
Map<String, List<Map<String, AttributeValue>>> responses = batch.responses();
List<Map<String, AttributeValue>> list = responses.get(this.documentTableName);
AttributeValueToDynamicObject transform = new AttributeValueToDynamicObject();
retlist = list.stream().map(m -> transform.apply(m)).collect(Collectors.toList());
retlist.forEach(ob -> updateWebhookTimeToLive(ob));
}
return retlist;
}
use of software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes in project aws-sdk-java-v2 by aws.
the class BatchGetItemOperation method addReadRequestsToMap.
private void addReadRequestsToMap(ReadBatch readBatch, Map<String, KeysAndAttributes> readRequestMap) {
KeysAndAttributes newKeysAndAttributes = readBatch.keysAndAttributes();
KeysAndAttributes existingKeysAndAttributes = readRequestMap.get(readBatch.tableName());
if (existingKeysAndAttributes == null) {
readRequestMap.put(readBatch.tableName(), newKeysAndAttributes);
return;
}
KeysAndAttributes mergedKeysAndAttributes = mergeKeysAndAttributes(existingKeysAndAttributes, newKeysAndAttributes);
readRequestMap.put(readBatch.tableName(), mergedKeysAndAttributes);
}
use of software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes in project aws-sdk-java-v2 by aws.
the class DynamoServiceIntegrationTest method testRequestEntityTooLargeErrorHandling.
/**
* Tests that we properly handle error responses for request entities that
* are too large.
*/
// DISABLED because DynamoDB apparently upped their max request size; we
// should be hitting this with a unit test that simulates an appropriate
// SdkServiceException.
// @Test
public void testRequestEntityTooLargeErrorHandling() throws Exception {
Map<String, KeysAndAttributes> items = new HashMap<String, KeysAndAttributes>();
for (int i = 0; i < 1024; i++) {
KeysAndAttributes kaa = KeysAndAttributes.builder().build();
StringBuilder bigString = new StringBuilder();
for (int j = 0; j < 1024; j++) {
bigString.append("a");
}
bigString.append(i);
items.put(bigString.toString(), kaa);
}
BatchGetItemRequest request = BatchGetItemRequest.builder().requestItems(items).build();
try {
dynamo.batchGetItem(request);
} catch (AwsServiceException exception) {
assertNotNull(exception.getMessage());
assertEquals("Request entity too large", exception.awsErrorDetails().errorCode());
assertEquals(413, exception.statusCode());
}
}
use of software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes in project aws-sdk-java-v2 by aws.
the class PaginatorIntegrationTest method batchGetItem_allProcessed_shouldNotHaveNextPage.
@Test
public void batchGetItem_allProcessed_shouldNotHaveNextPage() {
Map<String, KeysAndAttributes> attributes = new HashMap<>();
Map<String, AttributeValue> keys;
KeysAndAttributes keysAndAttributes;
List<Map<String, AttributeValue>> keysList = new ArrayList<>();
for (int i = 0; i < ITEM_COUNT; i++) {
keys = new HashMap<>();
keys.put(HASH_KEY_NAME, AttributeValue.builder().n(String.valueOf(i)).build());
keysList.add(keys);
}
keysAndAttributes = KeysAndAttributes.builder().keys(keysList).build();
attributes.put(TABLE_NAME, keysAndAttributes);
Iterator<BatchGetItemResponse> iterator = dynamo.batchGetItemPaginator(b -> b.requestItems(attributes)).iterator();
assertThat(iterator.next().unprocessedKeys().isEmpty()).isTrue();
assertThat(iterator.hasNext()).isFalse();
}
Aggregations