Skip to content

Commit f350e6d

Browse files
committed
Merge pull request #63 from GoogleCloudPlatform/fix-sparkjava-checkstyle
Fix checkstyle issues in SparkJava demo
2 parents 1755d88 + de2b4a5 commit f350e6d

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

managedvms/sparkjava/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@
8484
<configuration>
8585
</configuration>
8686
</plugin>
87-
<!--
88-
The SparkJava demo currently (2016-01-22) fails the Google Style
89-
checks. We can uncomment this block when it is fixed.
9087
<plugin>
9188
<groupId>org.apache.maven.plugins</groupId>
9289
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -101,7 +98,6 @@
10198
<execution><goals><goal>check</goal></goals></execution>
10299
</executions>
103100
</plugin>
104-
-->
105101
</plugins>
106102
</build>
107103
</project>

managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/Main.java

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
public class Main {
2424

25+
/**
26+
* Starts the webapp on localhost:8080.
27+
*/
2528
public static void main(String[] args) {
2629
port(8080);
2730
UserController userController =

managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/ResponseError.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ResponseError(String message, String... args) {
2424
this.message = String.format(message, (Object) args);
2525
}
2626

27-
public ResponseError(Exception e) {
28-
this.message = e.getMessage();
27+
public ResponseError(Exception ex) {
28+
this.message = ex.getMessage();
2929
}
3030
}

managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/User.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ public class User {
2424
private String name;
2525
private String email;
2626

27+
/**
28+
* Construct a user given a name and email. An ID is auto-generated for the user.
29+
*/
2730
public User(String name, String email) {
2831
this(UUID.randomUUID().toString(), name, email);
2932
}
3033

34+
/**
35+
* Construct a user given an ID, name, and email.
36+
*/
3137
public User(String id, String name, String email) {
3238
this.id = id;
3339
this.email = email;

managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserController.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
public class UserController {
3232

33+
/**
34+
* Creates a controller that maps requests to gcloud-java functions.
35+
*/
3336
public UserController(final UserService userService) {
3437
Spark.staticFileLocation("/public");
3538

@@ -48,13 +51,13 @@ public UserController(final UserService userService) {
4851
delete("/api/users/:id", (req, res) -> userService.deleteUser(req.params(":id")), json());
4952

5053
after((req, res) -> {
51-
res.type("application/json");
52-
});
54+
res.type("application/json");
55+
});
5356

54-
exception(IllegalArgumentException.class, (e, req, res) -> {
55-
res.status(400);
56-
res.body(toJson(new ResponseError(e)));
57-
});
57+
exception(IllegalArgumentException.class, (error, req, res) -> {
58+
res.status(400);
59+
res.body(toJson(new ResponseError(error)));
60+
});
5861
}
5962

6063
private static String toJson(Object object) {

managedvms/sparkjava/src/main/java/com/google/appengine/sparkdemo/UserService.java

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public UserService(Datastore datastore) {
3838
this.datastore = datastore;
3939
}
4040

41+
/**
42+
* Return a list of all users.
43+
*/
4144
public List<User> getAllUsers() {
4245
Query<Entity> query =
4346
Query.gqlQueryBuilder(Query.ResultType.ENTITY, "SELECT * FROM " + KINDNAME).build();
@@ -51,6 +54,9 @@ public List<User> getAllUsers() {
5154
return users;
5255
}
5356

57+
/**
58+
* Create a new user and add it to Cloud Datastore.
59+
*/
5460
public User createUser(String name, String email) {
5561
failIfInvalid(name, email);
5662
User user = new User(name, email);
@@ -65,13 +71,19 @@ public User createUser(String name, String email) {
6571
return user;
6672
}
6773

74+
/**
75+
* Delete a user from Cloud Datastore.
76+
*/
6877
public String deleteUser(String id) {
6978
KeyFactory keyFactory = datastore.newKeyFactory().kind(KINDNAME);
7079
Key key = keyFactory.newKey(id);
7180
datastore.delete(key);
7281
return "ok";
7382
}
7483

84+
/**
85+
* Updates a user in Cloud Datastore.
86+
*/
7587
public User updateUser(String id, String name, String email) {
7688
failIfInvalid(name, email);
7789
KeyFactory keyFactory = datastore.newKeyFactory().kind(KINDNAME);

0 commit comments

Comments
 (0)