use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse 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.BatchGetItemResponse 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.BatchGetItemResponse 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();
}
use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse in project aws-sdk-java-v2 by aws.
the class BatchGetItemOperationTest method transformResponse_multipleTables_multipleItems_no_unprocessedKeys.
@Test
public void transformResponse_multipleTables_multipleItems_no_unprocessedKeys() {
BatchGetItemResponse fakeResponse = BatchGetItemResponse.builder().build();
BatchGetItemOperation operation = BatchGetItemOperation.create(emptyRequest());
BatchGetResultPage resultsPage = operation.transformResponse(fakeResponse, null);
List<Key> fakeItemResults1 = resultsPage.unprocessedKeysForTable(fakeItemMappedTable);
List<Key> fakeItemResults2 = resultsPage.unprocessedKeysForTable(fakeItemWithSortMappedTable);
assertThat(fakeItemResults1, empty());
assertThat(fakeItemResults2, empty());
}
use of software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse in project aws-sdk-java-v2 by aws.
the class BatchGetItemOperationTest method getServiceCall_usingShortcutForm_makesTheRightCallAndReturnsResponse.
@Test
public void getServiceCall_usingShortcutForm_makesTheRightCallAndReturnsResponse() {
BatchGetItemEnhancedRequest batchGetItemEnhancedRequest = BatchGetItemEnhancedRequest.builder().readBatches(ReadBatch.builder(FakeItem.class).mappedTableResource(fakeItemMappedTable).addGetItem(FAKE_ITEM_KEYS.get(0)).build()).build();
BatchGetItemOperation operation = BatchGetItemOperation.create(batchGetItemEnhancedRequest);
BatchGetItemRequest batchGetItemRequest = BatchGetItemRequest.builder().requestItems(singletonMap("test-table", KeysAndAttributes.builder().keys(singletonList(FAKE_ITEM_MAPS.get(0))).build())).build();
BatchGetItemIterable expectedResponse = mock(BatchGetItemIterable.class);
when(mockDynamoDbClient.batchGetItemPaginator(any(BatchGetItemRequest.class))).thenReturn(expectedResponse);
SdkIterable<BatchGetItemResponse> response = operation.serviceCall(mockDynamoDbClient).apply(batchGetItemRequest);
assertThat(response, sameInstance(expectedResponse));
verify(mockDynamoDbClient).batchGetItemPaginator(batchGetItemRequest);
}
Aggregations