Search in sources :

Example 1 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project camel by apache.

the class AmazonDDBClientMock method batchGetItem.

@SuppressWarnings("unchecked")
@Override
public BatchGetItemResult batchGetItem(BatchGetItemRequest batchGetItemRequest) {
    this.batchGetItemRequest = batchGetItemRequest;
    Map<String, List<Map<String, AttributeValue>>> responseMap = new HashMap<String, List<Map<String, AttributeValue>>>();
    List<Map<String, AttributeValue>> p = new ArrayList<Map<String, AttributeValue>>();
    p.add(getAttributes());
    responseMap.put("DOMAIN1", p);
    Map<String, AttributeValue> keysMap = new HashMap<String, AttributeValue>();
    keysMap.put("1", new AttributeValue("UNPROCESSED_KEY"));
    Map<String, KeysAndAttributes> unprocessedKeys = new HashMap<String, KeysAndAttributes>();
    unprocessedKeys.put("DOMAIN1", new KeysAndAttributes().withKeys(keysMap));
    return new BatchGetItemResult().withResponses(responseMap).withUnprocessedKeys(unprocessedKeys);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) BatchGetItemResult(com.amazonaws.services.dynamodbv2.model.BatchGetItemResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) KeysAndAttributes(com.amazonaws.services.dynamodbv2.model.KeysAndAttributes) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project camel by apache.

the class DeleteItemCommandTest method execute.

@Test
public void execute() {
    Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("1", new AttributeValue("Key_1"));
    exchange.getIn().setHeader(DdbConstants.KEY, key);
    Map<String, ExpectedAttributeValue> updateCondition = new HashMap<String, ExpectedAttributeValue>();
    updateCondition.put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
    exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, updateCondition);
    exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");
    command.execute();
    assertEquals("DOMAIN1", ddbClient.deleteItemRequest.getTableName());
    assertEquals(key, ddbClient.deleteItemRequest.getKey());
    assertEquals(updateCondition, ddbClient.deleteItemRequest.getExpected());
    assertEquals("ALL_OLD", ddbClient.deleteItemRequest.getReturnValues());
    assertEquals(new AttributeValue("attrValue"), exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get("attrName"));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) HashMap(java.util.HashMap) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) Test(org.junit.Test)

Example 3 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method get.

/**
     * Get registered service.
     *
     * @param id the id
     * @return the registered service
     */
public RegisteredService get(final long id) {
    final Map<String, AttributeValue> keys = new HashMap<>();
    keys.put(ColumnNames.ID.getName(), new AttributeValue(String.valueOf(id)));
    return getRegisteredServiceByKeys(keys);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap)

Example 4 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method getRegisteredServiceByKeys.

private RegisteredService getRegisteredServiceByKeys(final Map<String, AttributeValue> keys) {
    final GetItemRequest request = new GetItemRequest().withKey(keys).withTableName(TABLE_NAME);
    LOGGER.debug("Submitting request [{}] to get service with keys [{}]", request, keys);
    final Map<String, AttributeValue> returnItem = amazonDynamoDBClient.getItem(request).getItem();
    if (returnItem != null) {
        final RegisteredService service = deserializeServiceFromBinaryBlob(returnItem);
        LOGGER.debug("Located service [{}]", service);
        return service;
    }
    return null;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest)

Example 5 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method delete.

/**
     * Delete boolean.
     *
     * @param service the service
     * @return the boolean
     */
public boolean delete(final RegisteredService service) {
    final DeleteItemRequest del = new DeleteItemRequest().withTableName(TABLE_NAME).withKey(Collections.singletonMap(ColumnNames.ID.getName(), new AttributeValue(String.valueOf(service.getId()))));
    LOGGER.debug("Submitting delete request [{}] for service [{}]", del, service);
    final DeleteItemResult res = amazonDynamoDBClient.deleteItem(del);
    LOGGER.debug("Delete request came back with result [{}]", res);
    return res != null;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)32 HashMap (java.util.HashMap)23 Test (org.junit.Test)8 Condition (com.amazonaws.services.dynamodbv2.model.Condition)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)4 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)4 Map (java.util.Map)4 ExpectedAttributeValue (com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue)3 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)3 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)3 DynamoDBScanExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)2 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)2 ComparisonOperator (com.amazonaws.services.dynamodbv2.model.ComparisonOperator)2 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)2 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)2 KeysAndAttributes (com.amazonaws.services.dynamodbv2.model.KeysAndAttributes)2