Example usage for com.amazonaws.services.dynamodbv2.document Item toJSONPretty

List of usage examples for com.amazonaws.services.dynamodbv2.document Item toJSONPretty

Introduction

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

Prototype

public String toJSONPretty() 

Source Link

Document

Returns this item as a pretty JSON string.

Usage

From source file:com.barryku.karaf.MyServiceImpl.java

License:Apache License

public Response getJobLog(String jobId) {

    DynamoLogger logger = new DynamoLogger(RegionUtils.getRegion("us-west-2"));
    List<Item> items = logger.getLog(jobId);
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    for (Item item : items) {
        sb.append(item.toJSONPretty()).append(",");
    }/*w  w w  .j  a v a 2s.  c  om*/

    return Response.ok().entity(sb.length() > 1 ? sb.substring(0, sb.length() - 1) + "]" : "[]")
            .header("Access-Control-Allow-Origin", "*")
            .header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT").allow("OPTIONS").build();

}

From source file:com.eho.dynamodb.DynamoDBConnection.java

public static PutItemOutcome upload_resource_old(String resource) throws Exception {
    String id;/*from   w  w w  . ja  v a 2s  . c o  m*/
    JSONObject json_resource = new JSONObject(resource);
    //does the resource have a primary key?
    if (json_resource.has(PRIMARY_KEY))//if it does not have a primary key, create one using uuid
        id = json_resource.getString(PRIMARY_KEY);
    else
        id = UUID.randomUUID().toString();

    DynamoDB dynamoDB = new DynamoDB(dynamoDBClient);
    Table table = dynamoDB.getTable(PATIENT_TABLE);

    //lets retreive based on the key. if key invalid (not assigned yet) nullis returned.
    Item retreived_item = table.getItem(PRIMARY_KEY, id);
    if (retreived_item == null)//if null instantiate it
    {
        retreived_item = new Item();
        retreived_item.withPrimaryKey(PRIMARY_KEY, id);
    }

    Integer new_version = retreived_item.getInt("version") + 1;
    retreived_item.withInt("version", new_version);

    Item item_to_upload = Item.fromJSON(retreived_item.toJSONPretty()).withJSON("Document", resource);
    PutItemSpec putItemSpec = new PutItemSpec().withItem(item_to_upload).withReturnValues(ReturnValue.NONE);
    return table.putItem(putItemSpec);
}

From source file:com.eho.dynamodb.DynamoDBConnection.java

private static int create_new_version_numbe_old(Item item) throws Exception {
    JSONObject json_resource = new JSONObject(item.toJSONPretty());
    Iterator<String> itr = json_resource.keys();
    int max_version = Integer.MIN_VALUE;
    while (itr.hasNext()) {
        String nextString = itr.next();

        if (nextString.matches("[0-9]+"))//if a ltter does not exist in the key.this means it is a version of the rseource
        {//from w w  w.jav a  2  s  . com
            int thisValue = Integer.valueOf(nextString);
            if (thisValue > max_version)
                max_version = thisValue;
        }
    }

    if (max_version == Integer.MIN_VALUE)
        return 0;
    else
        return ++max_version;
}