Skip to content

Commit 02a8173

Browse files
committed
Style fixes and corrections.
1 parent 367e7bd commit 02a8173

File tree

11 files changed

+138
-115
lines changed

11 files changed

+138
-115
lines changed

appengine/guestbook-cloud-datastore/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Then start the [Cloud Datastore Emulator](https://cloud.google.com/datastore/doc
1919
Finally, in a new shell, [set the Datastore Emulator environmental variables](https://cloud.google.com/datastore/docs/tools/datastore-emulator#setting_environment_variables)
2020
and run
2121

22-
mvn clean appengine:devserver
22+
mvn clean appengine:run
2323

2424
## Deploying
2525

2626
Modify `appengine-web.xml` to reflect your app ID and version, then:
2727

28-
mvn clean appengine:update
28+
mvn clean appengine:deploy

appengine/guestbook-cloud-datastore/src/main/java/com/example/guestbook/Greeting.java

+26-20
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
/**
22
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
76
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
7+
* <p>http://www.apache.org/licenses/LICENSE-2.0
98
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
9+
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
1412
* limitations under the License.
1513
*/
1614

@@ -25,14 +23,15 @@
2523
import com.google.cloud.datastore.FullEntity.Builder;
2624
import com.google.cloud.datastore.IncompleteKey;
2725
import com.google.cloud.datastore.Key;
26+
import com.google.common.base.MoreObjects;
27+
2828
import java.util.Date;
2929
import java.util.Objects;
3030

3131
public class Greeting {
3232
private Guestbook book;
3333

3434
public Key key;
35-
3635
public String authorEmail;
3736
public String authorId;
3837
public String content;
@@ -54,11 +53,6 @@ public Greeting(String book, String content, String id, String email) {
5453
authorId = id;
5554
}
5655

57-
/**
58-
* Load greeting from Datastore entity
59-
*
60-
* @param entity
61-
*/
6256
public Greeting(Entity entity) {
6357
key = entity.hasKey() ? entity.key() : null;
6458
authorEmail = entity.contains("authorEmail") ? entity.getString("authorEmail") : null;
@@ -102,16 +96,28 @@ public boolean equals(Object o) {
10296
return false;
10397
}
10498
Greeting greeting = (Greeting) o;
105-
return Objects.equals(key, greeting.key) &&
106-
Objects.equals(authorEmail, greeting.authorEmail) &&
107-
Objects.equals(authorId, greeting.authorId) &&
108-
Objects.equals(content, greeting.content) &&
109-
Objects.equals(date, greeting.date);
99+
return Objects.equals(key, greeting.key)
100+
&& Objects.equals(authorEmail, greeting.authorEmail)
101+
&& Objects.equals(authorId, greeting.authorId)
102+
&& Objects.equals(content, greeting.content)
103+
&& Objects.equals(date, greeting.date);
110104
}
111105

112106
@Override
113107
public int hashCode() {
114108
return Objects.hash(key, authorEmail, authorId, content, date);
115109
}
110+
111+
@Override
112+
public String toString() {
113+
return MoreObjects.toStringHelper(this)
114+
.add("key", key)
115+
.add("authorEmail", authorEmail)
116+
.add("authorId", authorId)
117+
.add("content", content)
118+
.add("date", date)
119+
.add("book", book)
120+
.toString();
121+
}
116122
}
117-
//[END all]
123+
//[END all]
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
/**
22
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
76
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
7+
* <p>http://www.apache.org/licenses/LICENSE-2.0
98
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
9+
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
1412
* limitations under the License.
1513
*/
16-
1714
package com.example.guestbook;
1815

1916
import static com.example.guestbook.Persistence.getDatastore;
@@ -27,20 +24,25 @@
2724
import com.google.cloud.datastore.KeyFactory;
2825
import com.google.cloud.datastore.Query;
2926
import com.google.cloud.datastore.QueryResults;
27+
import com.google.common.base.MoreObjects;
3028
import com.google.common.collect.ImmutableList;
3129
import com.google.common.collect.ImmutableList.Builder;
30+
3231
import java.util.List;
32+
import java.util.Objects;
3333

3434
//[START all]
3535
public class Guestbook {
36-
private static final KeyFactory kf = getKeyFactory(Guestbook.class);
37-
36+
private static final KeyFactory keyFactory = getKeyFactory(Guestbook.class);
3837
private final Key key;
38+
3939
public final String book;
4040

4141
public Guestbook(String book) {
4242
this.book = book == null ? "default" : book;
43-
key = kf.newKey(this.book); // There is a 1:1 mapping between Guestbook names and Guestbook objects
43+
key =
44+
keyFactory.newKey(
45+
this.book); // There is a 1:1 mapping between Guestbook names and Guestbook objects
4446
}
4547

4648
public Key getKey() {
@@ -49,12 +51,13 @@ public Key getKey() {
4951

5052
public List<Greeting> getGreetings() {
5153
// This query requires the index defined in index.yaml to work because of the orderBy on date.
52-
EntityQuery query = Query.entityQueryBuilder()
53-
.kind("Greeting")
54-
.filter(hasAncestor(key))
55-
.orderBy(desc("date"))
56-
.limit(5)
57-
.build();
54+
EntityQuery query =
55+
Query.entityQueryBuilder()
56+
.kind("Greeting")
57+
.filter(hasAncestor(key))
58+
.orderBy(desc("date"))
59+
.limit(5)
60+
.build();
5861

5962
QueryResults<Entity> results = getDatastore().run(query);
6063

@@ -65,5 +68,31 @@ public List<Greeting> getGreetings() {
6568

6669
return resultListBuilder.build();
6770
}
71+
72+
@Override
73+
public boolean equals(Object o) {
74+
if (this == o) {
75+
return true;
76+
}
77+
if (o == null || getClass() != o.getClass()) {
78+
return false;
79+
}
80+
Guestbook guestbook = (Guestbook) o;
81+
return Objects.equals(book, guestbook.book) && Objects.equals(key, guestbook.key);
82+
}
83+
84+
@Override
85+
public int hashCode() {
86+
return Objects.hash(book, key);
87+
}
88+
89+
@Override
90+
public String toString() {
91+
return MoreObjects.toStringHelper(this)
92+
.add("keyFactory", keyFactory)
93+
.add("book", book)
94+
.add("key", key)
95+
.toString();
96+
}
6897
}
69-
//[END all]
98+
//[END all]
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
/**
22
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
76
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
7+
* <p>http://www.apache.org/licenses/LICENSE-2.0
98
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
9+
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
1412
* limitations under the License.
1513
*/
16-
1714
package com.example.guestbook;
1815

1916
import com.google.cloud.datastore.Datastore;
@@ -34,12 +31,12 @@ public static Datastore getDatastore() {
3431
return datastore.get();
3532
}
3633

37-
public static KeyFactory getKeyFactory(Class<?> c) {
38-
return getDatastore().newKeyFactory().kind(c.getSimpleName());
39-
}
40-
4134
public static void setDatastore(Datastore datastore) {
4235
Persistence.datastore.set(datastore);
4336
}
37+
38+
public static KeyFactory getKeyFactory(Class<?> c) {
39+
return getDatastore().newKeyFactory().kind(c.getSimpleName());
40+
}
4441
}
4542
//[END all]

appengine/guestbook-cloud-datastore/src/main/java/com/example/guestbook/SignGuestbookServlet.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
/**
22
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5+
* except in compliance with the License. You may obtain a copy of the License at
76
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
7+
* <p>http://www.apache.org/licenses/LICENSE-2.0
98
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
9+
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
1412
* limitations under the License.
1513
*/
1614

@@ -20,6 +18,7 @@
2018
import com.google.appengine.api.users.User;
2119
import com.google.appengine.api.users.UserService;
2220
import com.google.appengine.api.users.UserServiceFactory;
21+
2322
import java.io.IOException;
2423
import javax.servlet.http.HttpServlet;
2524
import javax.servlet.http.HttpServletRequest;
@@ -29,12 +28,11 @@
2928
public class SignGuestbookServlet extends HttpServlet {
3029
// Process the HTTP POST of the form
3130
@Override
32-
public void doPost(HttpServletRequest req, HttpServletResponse resp)
33-
throws IOException {
31+
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
3432
Greeting greeting;
3533

3634
UserService userService = UserServiceFactory.getUserService();
37-
User user = userService.getCurrentUser(); // Find out who the user is.
35+
User user = userService.getCurrentUser(); // Find out who the user is.
3836

3937
String guestbookName = req.getParameter("guestbookName");
4038
String content = req.getParameter("content");
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
3-
<application>your-app-id-here</application>
4-
<version>your-app-version-here</version>
5-
<threadsafe>true</threadsafe>
6-
7-
<system-properties>
8-
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
9-
</system-properties>
3+
<threadsafe>true</threadsafe>
4+
5+
<system-properties>
6+
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
7+
</system-properties>
108
</appengine-web-app>

appengine/guestbook-cloud-datastore/src/main/webapp/WEB-INF/index.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ indexes:
44
ancestor: yes
55
properties:
66
- name: date
7-
direction: desc
7+
direction: desc

appengine/guestbook-cloud-datastore/src/main/webapp/WEB-INF/logging.properties

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
99
# </system-properties>
1010
#
11-
1211
# Set the default logging level for all loggers to WARNING
13-
.level = WARNING
12+
.level=WARNING
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
3+
xmlns="http://java.sun.com/xml/ns/javaee"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
55

6-
<!-- [START standard_mappings] -->
7-
<servlet>
8-
<servlet-name>sign</servlet-name>
9-
<servlet-class>com.example.guestbook.SignGuestbookServlet</servlet-class>
10-
<load-on-startup>1</load-on-startup>
11-
</servlet>
6+
<!-- [START standard_mappings] -->
7+
<servlet>
8+
<servlet-name>sign</servlet-name>
9+
<servlet-class>com.example.guestbook.SignGuestbookServlet</servlet-class>
10+
<load-on-startup>1</load-on-startup>
11+
</servlet>
1212

13-
<servlet-mapping>
14-
<servlet-name>sign</servlet-name>
15-
<url-pattern>/sign</url-pattern>
16-
</servlet-mapping>
13+
<servlet-mapping>
14+
<servlet-name>sign</servlet-name>
15+
<url-pattern>/sign</url-pattern>
16+
</servlet-mapping>
1717

18-
<welcome-file-list>
19-
<welcome-file>guestbook.jsp</welcome-file>
20-
</welcome-file-list>
21-
<!-- [END standard_mappings] -->
18+
<welcome-file-list>
19+
<welcome-file>guestbook.jsp</welcome-file>
20+
</welcome-file-list>
21+
<!-- [END standard_mappings] -->
2222
</web-app>

0 commit comments

Comments
 (0)