Search in sources :

Example 11 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project openhab1-addons by openhab.

the class DynamoDBPersistenceService method constructTimeCondition.

private Condition constructTimeCondition(FilterCriteria filter) {
    boolean hasBegin = filter.getBeginDate() != null;
    boolean hasEnd = filter.getEndDate() != null;
    final Condition timeCondition;
    if (!hasBegin && !hasEnd) {
        timeCondition = null;
    } else if (!hasBegin && hasEnd) {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.LE).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
    } else if (hasBegin && !hasEnd) {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.GE).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())));
    } else {
        timeCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList(new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getBeginDate())), new AttributeValue().withS(AbstractDynamoDBItem.DATEFORMATTER.format(filter.getEndDate())));
    }
    return timeCondition;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue)

Example 12 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.

the class DeleteItem method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    DeleteItem <table> <name>\n\n" + "Where:\n" + "    table - the table to delete the item from.\n" + "    name  - the item to delete from the table,\n" + "            using the primary key \"Name\"\n\n" + "Example:\n" + "    DeleteItem HelloTable World\n\n" + "**Warning** This program will actually delete the item\n" + "            that you specify!\n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String table_name = args[0];
    String name = args[1];
    System.out.format("Deleting item \"%s\" from %s\n", name, table_name);
    HashMap<String, AttributeValue> key_to_get = new HashMap<String, AttributeValue>();
    key_to_get.put("Name", new AttributeValue(name));
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    try {
        ddb.deleteItem(table_name, key_to_get);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 13 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.

the class PutItem method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    PutItem <table> <name> [field=value ...]\n\n" + "Where:\n" + "    table    - the table to put the item in.\n" + "    name     - a name to add to the table. If the name already\n" + "               exists, its entry will be updated.\n" + "Additional fields can be added by appending them to the end of the\n" + "input.\n\n" + "Example:\n" + "    PutItem Cellists Pau Language=ca Born=1876\n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String table_name = args[0];
    String name = args[1];
    ArrayList<String[]> extra_fields = new ArrayList<String[]>();
    // any additional args (fields to add to database)?
    for (int x = 2; x < args.length; x++) {
        String[] fields = args[x].split("=", 2);
        if (fields.length == 2) {
            extra_fields.add(fields);
        } else {
            System.out.format("Invalid argument: %s\n", args[x]);
            System.out.println(USAGE);
            System.exit(1);
        }
    }
    System.out.format("Adding \"%s\" to \"%s\"", name, table_name);
    if (extra_fields.size() > 0) {
        System.out.println("Additional fields:");
        for (String[] field : extra_fields) {
            System.out.format("  %s: %s\n", field[0], field[1]);
        }
    }
    HashMap<String, AttributeValue> item_values = new HashMap<String, AttributeValue>();
    item_values.put("Name", new AttributeValue(name));
    for (String[] field : extra_fields) {
        item_values.put(field[0], new AttributeValue(field[1]));
    }
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    try {
        ddb.putItem(table_name, item_values);
    } catch (ResourceNotFoundException e) {
        System.err.format("Error: The table \"%s\" can't be found.\n", table_name);
        System.err.println("Be sure that it exists and that you've typed its name correctly!");
        System.exit(1);
    } catch (AmazonServiceException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 14 with AttributeValue

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

the class DynamoDbTicketRegistryFacilitator method buildTableAttributeValuesMapFromTicket.

/**
     * Build table attribute values from ticket map.
     *
     * @param ticket    the ticket
     * @param encTicket the encoded ticket
     * @return the map
     */
public Map<String, AttributeValue> buildTableAttributeValuesMapFromTicket(final Ticket ticket, final Ticket encTicket) {
    final Map<String, AttributeValue> values = new HashMap<>();
    values.put(ColumnNames.ID.getName(), new AttributeValue(encTicket.getId()));
    values.put(ColumnNames.PREFIX.getName(), new AttributeValue(encTicket.getPrefix()));
    values.put(ColumnNames.CREATION_TIME.getName(), new AttributeValue(ticket.getCreationTime().toString()));
    values.put(ColumnNames.COUNT_OF_USES.getName(), new AttributeValue().withN(Integer.toString(ticket.getCountOfUses())));
    values.put(ColumnNames.TIME_TO_LIVE.getName(), new AttributeValue().withN(Long.toString(ticket.getExpirationPolicy().getTimeToLive())));
    values.put(ColumnNames.TIME_TO_IDLE.getName(), new AttributeValue().withN(Long.toString(ticket.getExpirationPolicy().getTimeToIdle())));
    values.put(ColumnNames.ENCODED.getName(), new AttributeValue().withB(ByteBuffer.wrap(SerializationUtils.serialize(encTicket))));
    LOGGER.debug("Created attribute values [{}] based on provided ticket [{}]", values, encTicket.getId());
    return values;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap)

Example 15 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 String id) {
    final Map<String, AttributeValue> keys = new HashMap<>();
    keys.put(ColumnNames.SERVICE_ID.getName(), new AttributeValue(id));
    return getRegisteredServiceByKeys(keys);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap)

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