diff --git a/managedvms/sparkjava/pom.xml b/managedvms/sparkjava/pom.xml index b9115657517..defb396e9b4 100644 --- a/managedvms/sparkjava/pom.xml +++ b/managedvms/sparkjava/pom.xml @@ -84,9 +84,6 @@ - diff --git a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/Main.java b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/Main.java index d24e0231871..9ca3abdf356 100644 --- a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/Main.java +++ b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/Main.java @@ -22,6 +22,9 @@ public class Main { + /** + * Starts the webapp on localhost:8080. + */ public static void main(String[] args) { port(8080); UserController userController = diff --git a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/ResponseError.java b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/ResponseError.java index c225851dca4..d01e1556453 100644 --- a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/ResponseError.java +++ b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/ResponseError.java @@ -24,7 +24,7 @@ public ResponseError(String message, String... args) { this.message = String.format(message, (Object) args); } - public ResponseError(Exception e) { - this.message = e.getMessage(); + public ResponseError(Exception ex) { + this.message = ex.getMessage(); } } diff --git a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/User.java b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/User.java index 3455f4aac8e..44969b40fbb 100644 --- a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/User.java +++ b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/User.java @@ -24,10 +24,16 @@ public class User { private String name; private String email; + /** + * Construct a user given a name and email. An ID is auto-generated for the user. + */ public User(String name, String email) { this(UUID.randomUUID().toString(), name, email); } + /** + * Construct a user given an ID, name, and email. + */ public User(String id, String name, String email) { this.id = id; this.email = email; diff --git a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserController.java b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserController.java index 75d57caf832..ab44c17f10a 100644 --- a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserController.java +++ b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserController.java @@ -30,6 +30,9 @@ public class UserController { + /** + * Creates a controller that maps requests to gcloud-java functions. + */ public UserController(final UserService userService) { Spark.staticFileLocation("/public"); @@ -48,13 +51,13 @@ public UserController(final UserService userService) { delete("/api/users/:id", (req, res) -> userService.deleteUser(req.params(":id")), json()); after((req, res) -> { - res.type("application/json"); - }); + res.type("application/json"); + }); - exception(IllegalArgumentException.class, (e, req, res) -> { - res.status(400); - res.body(toJson(new ResponseError(e))); - }); + exception(IllegalArgumentException.class, (error, req, res) -> { + res.status(400); + res.body(toJson(new ResponseError(error))); + }); } private static String toJson(Object object) { diff --git a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserService.java b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserService.java index eb183ac4710..21b58ecef1f 100644 --- a/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserService.java +++ b/managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserService.java @@ -38,6 +38,9 @@ public UserService(Datastore datastore) { this.datastore = datastore; } + /** + * Return a list of all users. + */ public List getAllUsers() { Query query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM " + KINDNAME).build(); @@ -51,6 +54,9 @@ public List getAllUsers() { return users; } + /** + * Create a new user and add it to Cloud Datastore. + */ public User createUser(String name, String email) { failIfInvalid(name, email); User user = new User(name, email); @@ -65,6 +71,9 @@ public User createUser(String name, String email) { return user; } + /** + * Delete a user from Cloud Datastore. + */ public String deleteUser(String id) { KeyFactory keyFactory = datastore.newKeyFactory().kind(KINDNAME); Key key = keyFactory.newKey(id); @@ -72,6 +81,9 @@ public String deleteUser(String id) { return "ok"; } + /** + * Updates a user in Cloud Datastore. + */ public User updateUser(String id, String name, String email) { failIfInvalid(name, email); KeyFactory keyFactory = datastore.newKeyFactory().kind(KINDNAME);