BAEL-650: Small refactoring

This commit is contained in:
Sunil Gulabani 2017-02-15 18:07:14 +05:30
parent c9bb4b9e37
commit dd01588369
2 changed files with 12 additions and 14 deletions

View File

@ -17,18 +17,16 @@ public class SavePersonHandler implements RequestHandler<PersonRequest, PersonRe
private DynamoDB dynamoDb;
private final String DYNAMODB_TABLE_NAME = "Person";
private final Regions REGION = Regions.US_WEST_2;
private String DYNAMODB_TABLE_NAME = "Person";
private Regions REGION = Regions.US_WEST_2;
public PersonResponse handleRequest(PersonRequest personRequest, Context context) {
context.getLogger().log("personRequest: " + personRequest);
this.initDynamoDbClient();
persistData(personRequest);
PersonResponse personResponse = new PersonResponse();
personResponse.setMessage("Saved Successfully!!!");
context.getLogger().log("personResponse: " + personResponse);
return personResponse;
}
@ -40,12 +38,11 @@ public class SavePersonHandler implements RequestHandler<PersonRequest, PersonRe
.withString("firstName", personRequest.getFirstName())
.withString("lastName", personRequest.getLastName())
.withNumber("age", personRequest.getAge())
.withString("address", personRequest.getAddress())
));
.withString("address", personRequest.getAddress())));
}
private void initDynamoDbClient() {
final AmazonDynamoDBClient client = new AmazonDynamoDBClient();
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.setRegion(Region.getRegion(REGION));
this.dynamoDb = new DynamoDB(client);
}

View File

@ -1,6 +1,7 @@
package com.baeldung.lambda.dynamodb.bean;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class PersonRequest {
private int id;
@ -20,7 +21,7 @@ public class PersonRequest {
}
public String toString() {
final Gson gson = new Gson();
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(this);
}