use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project cas by apereo.
the class DynamoDbServiceRegistryFacilitator method buildTableAttributeValuesMapFromService.
/**
* Build table attribute values from map.
*
* @param service the service
* @return the map
*/
public Map<String, AttributeValue> buildTableAttributeValuesMapFromService(final RegisteredService service) {
final Map<String, AttributeValue> values = new HashMap<>();
values.put(ColumnNames.ID.getName(), new AttributeValue(String.valueOf(service.getId())));
values.put(ColumnNames.NAME.getName(), new AttributeValue(service.getName()));
values.put(ColumnNames.DESCRIPTION.getName(), new AttributeValue(service.getDescription()));
values.put(ColumnNames.SERVICE_ID.getName(), new AttributeValue(service.getServiceId()));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonSerializer.to(out, service);
values.put(ColumnNames.ENCODED.getName(), new AttributeValue().withB(ByteBuffer.wrap(out.toByteArray())));
LOGGER.debug("Created attribute values [{}] based on provided service [{}]", values, service);
return values;
}
use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project cas by apereo.
the class DynamoDbTicketRegistryFacilitator method get.
/**
* Get ticket.
*
* @param ticketId the ticket id
* @return the ticket
*/
public Ticket get(final String ticketId) {
final TicketDefinition metadata = this.ticketCatalog.find(ticketId);
if (metadata != null) {
final Map<String, AttributeValue> keys = new HashMap<>();
keys.put(ColumnNames.ID.getName(), new AttributeValue(ticketId));
final GetItemRequest request = new GetItemRequest().withKey(keys).withTableName(metadata.getProperties().getStorageName());
LOGGER.debug("Submitting request [{}] to get ticket item [{}]", request, ticketId);
final Map<String, AttributeValue> returnItem = amazonDynamoDBClient.getItem(request).getItem();
if (returnItem != null) {
final Ticket ticket = deserializeTicket(returnItem);
LOGGER.debug("Located ticket [{}]", ticket);
return ticket;
}
} else {
LOGGER.warn("No ticket definition could be found in the catalog to match [{}]", ticketId);
}
return null;
}
use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project cas by apereo.
the class DynamoDbTicketRegistryFacilitator method delete.
/**
* Delete.
*
* @param ticketId the ticket id
* @return the boolean
*/
public boolean delete(final String ticketId) {
final TicketDefinition metadata = this.ticketCatalog.find(ticketId);
if (metadata != null) {
final DeleteItemRequest del = new DeleteItemRequest().withTableName(metadata.getProperties().getStorageName()).withKey(Collections.singletonMap(ColumnNames.ID.getName(), new AttributeValue(ticketId)));
LOGGER.debug("Submitting delete request [{}] for ticket [{}]", del, ticketId);
final DeleteItemResult res = amazonDynamoDBClient.deleteItem(del);
LOGGER.debug("Delete request came back with result [{}]", res);
return res != null;
}
return false;
}
use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project archaius by Netflix.
the class DynamoDbConfigurationSource method loadPropertiesFromTable.
@Override
protected synchronized Map<String, Object> loadPropertiesFromTable(String table) {
Map<String, Object> propertyMap = new HashMap<String, Object>();
Map<String, AttributeValue> lastKeysEvaluated = null;
do {
ScanRequest scanRequest = new ScanRequest().withTableName(table).withExclusiveStartKey(lastKeysEvaluated);
ScanResult result = dbScanWithThroughputBackOff(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
propertyMap.put(item.get(keyAttributeName.get()).getS(), item.get(valueAttributeName.get()).getS());
}
lastKeysEvaluated = result.getLastEvaluatedKey();
} while (lastKeysEvaluated != null);
return propertyMap;
}
use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project archaius by Netflix.
the class DynamoDbDeploymentContextTableCache method loadPropertiesFromTable.
/**
* Scan the table in dynamo and create a map with the results. In this case the map has a complex type as the value,
* so that Deployment Context is taken into account.
*
* @param table
* @return
*/
@Override
protected Map<String, PropertyWithDeploymentContext> loadPropertiesFromTable(String table) {
Map<String, PropertyWithDeploymentContext> propertyMap = new HashMap<String, PropertyWithDeploymentContext>();
Map<String, AttributeValue> lastKeysEvaluated = null;
do {
ScanRequest scanRequest = new ScanRequest().withTableName(table).withExclusiveStartKey(lastKeysEvaluated);
ScanResult result = dbScanWithThroughputBackOff(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
String keyVal = item.get(keyAttributeName.get()).getS();
//Need to deal with the fact that these attributes might not exist
DeploymentContext.ContextKey contextKey = item.containsKey(contextKeyAttributeName.get()) ? DeploymentContext.ContextKey.valueOf(item.get(contextKeyAttributeName.get()).getS()) : null;
String contextVal = item.containsKey(contextValueAttributeName.get()) ? item.get(contextValueAttributeName.get()).getS() : null;
String key = keyVal + ";" + contextKey + ";" + contextVal;
propertyMap.put(key, new PropertyWithDeploymentContext(contextKey, contextVal, keyVal, item.get(valueAttributeName.get()).getS()));
}
lastKeysEvaluated = result.getLastEvaluatedKey();
} while (lastKeysEvaluated != null);
return propertyMap;
}
Aggregations