use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.
the class AttributeValueCoderTest method shouldPassForStringType.
@Test
public void shouldPassForStringType() throws IOException {
AttributeValue expected = AttributeValue.builder().s("test").build();
AttributeValueCoder coder = AttributeValueCoder.of();
ByteArrayOutputStream output = new ByteArrayOutputStream();
coder.encode(expected, output);
ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
AttributeValue actual = coder.decode(in);
Assert.assertEquals(expected, actual);
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.
the class DynamoDBIOIT method buildWriteRequest.
private static KV<String, WriteRequest> buildWriteRequest(TestRow row) {
AttributeValue id = AttributeValue.builder().n(row.id().toString()).build();
AttributeValue name = AttributeValue.builder().s(row.name()).build();
PutRequest req = PutRequest.builder().item(ImmutableMap.of(COL_ID, id, COL_NAME, name)).build();
return KV.of(env.options().getDynamoDBTable(), WriteRequest.builder().putRequest(req).build());
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project cas by apereo.
the class DynamoDbAuditTrailManagerFacilitator method getAuditRecordsSince.
/**
* Gets audit records.
*
* @param localDate the local date
* @return the audit records since
*/
@SuppressWarnings("JavaUtilDate")
public Set<? extends AuditActionContext> getAuditRecordsSince(final LocalDate localDate) {
val time = DateTimeUtils.dateOf(localDate).getTime();
val keys = DynamoDbQueryBuilder.builder().key(ColumnNames.WHEN_ACTION_PERFORMED.getColumnName()).attributeValue(List.of(AttributeValue.builder().s(String.valueOf(time)).build())).operator(ComparisonOperator.GE).build();
return DynamoDbTableUtils.getRecordsByKeys(amazonDynamoDBClient, dynamoDbProperties.getTableName(), List.of(keys), item -> {
val principal = item.get(ColumnNames.PRINCIPAL.getColumnName()).s();
val actionPerformed = item.get(ColumnNames.ACTION_PERFORMED.getColumnName()).s();
val appCode = item.get(ColumnNames.APPLICATION_CODE.getColumnName()).s();
val clientIp = item.get(ColumnNames.CLIENT_IP_ADDRESS.getColumnName()).s();
val serverIp = item.get(ColumnNames.SERVER_IP_ADDRESS.getColumnName()).s();
val resource = item.get(ColumnNames.RESOURCE_OPERATED_UPON.getColumnName()).s();
val userAgent = item.get(ColumnNames.USER_AGENT.getColumnName()).s();
val time1 = Long.parseLong(item.get(ColumnNames.WHEN_ACTION_PERFORMED.getColumnName()).s());
return new AuditActionContext(principal, resource, actionPerformed, appCode, new Date(time1), clientIp, serverIp, userAgent);
}).collect(Collectors.toSet());
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project cas by apereo.
the class DynamoDbTableUtils method getRecordsByKeys.
/**
* Gets records by keys.
*
* @param <T> the type parameter
* @param dynamoDbClient the dynamo db client
* @param tableName the table name
* @param queries the queries
* @param itemMapper the item mapper
* @return the records by keys
*/
public static <T> Stream<T> getRecordsByKeys(final DynamoDbClient dynamoDbClient, final String tableName, final List<DynamoDbQueryBuilder> queries, final Function<Map<String, AttributeValue>, T> itemMapper) {
try {
val scanFilter = queries.stream().map(query -> {
val cond = Condition.builder().comparisonOperator(query.getOperator()).attributeValueList(query.getAttributeValue()).build();
return Pair.of(query.getKey(), cond);
}).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
val scanRequest = ScanRequest.builder().tableName(tableName).scanFilter(scanFilter).build();
LOGGER.debug("Submitting request [{}] to get record with keys [{}]", scanRequest, queries);
val items = dynamoDbClient.scan(scanRequest).items();
return items.stream().map(itemMapper);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
}
return Stream.empty();
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project syndesis-qe by syndesisio.
the class DynamoDbUtils method purgeTable.
public void purgeTable() {
ScanRequest scanRequest = ScanRequest.builder().tableName(tableName).build();
ScanResponse result = dynamoDb.scan(scanRequest);
for (Map<String, AttributeValue> item : result.items()) {
dynamoDb.deleteItem(DeleteItemRequest.builder().tableName(tableName).key(item).build());
}
}
Aggregations