Example usage for com.amazonaws.services.dynamodbv2.document Table getItem

List of usage examples for com.amazonaws.services.dynamodbv2.document Table getItem

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document Table getItem.

Prototype

@Override
    public Item getItem(String hashKeyName, Object hashKeyValue) 

Source Link

Usage

From source file:io.ignitr.dispatchr.manager.core.data.TopicRepository.java

License:Apache License

/**
 * Saves the metadata about a registered topic.
 *
 * @param topicName name of the topic/*from  ww w.  j a va2  s .c  o  m*/
 * @param topicArn arn of the topic
 * @return an {@link Observable} of {@link Topic} containing the metadata about the topic that was saved
 */
public Observable<Topic> save(String topicName, String topicArn) {
    return Observable.create(subscriber -> {
        Topic metadata = new Topic();
        metadata.setName(topicName);
        metadata.setArn(topicArn);
        metadata.setRegistered(true);

        Table table = dynamoDB.getTable(TOPIC_TABLE_NAME);

        if (table.getItem("name", metadata.getName()) != null) {
            throw new TopicAlreadyRegisteredException(metadata.getName());
        }

        table.putItem(new Item().withPrimaryKey("name", metadata.getName()).withString("arn", metadata.getArn())
                .withLong("register_timestamp", System.currentTimeMillis()));

        subscriber.onNext(metadata);
        subscriber.onCompleted();
    });
}

From source file:io.ignitr.dispatchr.manager.core.data.TopicRepository.java

License:Apache License

/**
 * Deletes the metadata about a registered topic.
 *
 * @param topicName name of the topic//  w w w.j a v a 2  s.  c o  m
 * @param topicArn arn of the topic
 * @return an {@link Observable} of {@link Topic} containing the metadata about the topic that was deleted
 */
public Observable<Topic> delete(String topicName, String topicArn) {
    return Observable.create(subscriber -> {
        Topic metadata = new Topic();
        metadata.setName(topicName);
        metadata.setArn(topicArn);
        metadata.setRegistered(false);

        Table table = dynamoDB.getTable(TOPIC_TABLE_NAME);

        if (table.getItem("name", metadata.getName()) == null) {
            throw new TopicNotFoundException(metadata.getName());
        }

        table.deleteItem("name", metadata.getName());

        subscriber.onNext(metadata);
        subscriber.onCompleted();
    });
}