Skip to content

Commit

Permalink
Fix remaining checkstyle errors in getting-started-java. (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzlier-gcp committed May 23, 2018
1 parent aa1e786 commit 32cbaab
Show file tree
Hide file tree
Showing 57 changed files with 437 additions and 350 deletions.
@@ -1,14 +1,14 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
@@ -1,15 +1,15 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
.level = INFO
Expand Up @@ -50,15 +50,15 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws Serv
IOException {
BookDao dao = (BookDao) this.getServletContext().getAttribute("dao");
try {
// [START bookBuilder]
// [START bookBuilder]
Book book = new Book.Builder()
.author(req.getParameter("author"))
.description(req.getParameter("description"))
.id(Long.decode(req.getParameter("id")))
.publishedDate(req.getParameter("publishedDate"))
.title(req.getParameter("title"))
.build();
// [END bookBuilder]
// [END bookBuilder]
dao.updateBook(book);
resp.sendRedirect("/read?id=" + req.getParameter("id"));
} catch (Exception e) {
Expand Down
Expand Up @@ -46,17 +46,19 @@ public DatastoreDao() {
datastore = DatastoreServiceFactory.getDatastoreService(); // Authorized Datastore service
}
// [END constructor]

// [START entityToBook]
public Book entityToBook(Entity entity) {
return new Book.Builder() // Convert to Book form
.author((String)entity.getProperty(Book.AUTHOR))
.description((String)entity.getProperty(Book.DESCRIPTION))
.author((String) entity.getProperty(Book.AUTHOR))
.description((String) entity.getProperty(Book.DESCRIPTION))
.id(entity.getKey().getId())
.publishedDate((String)entity.getProperty(Book.PUBLISHED_DATE))
.title((String)entity.getProperty(Book.TITLE))
.publishedDate((String) entity.getProperty(Book.PUBLISHED_DATE))
.title((String) entity.getProperty(Book.TITLE))
.build();
}
// [END entityToBook]

// [START create]
@Override
public Long createBook(Book book) {
Expand All @@ -70,6 +72,7 @@ public Long createBook(Book book) {
return bookKey.getId(); // The ID of the Key
}
// [END create]

// [START read]
@Override
public Book readBook(Long bookId) {
Expand All @@ -81,6 +84,7 @@ public Book readBook(Long bookId) {
}
}
// [END read]

// [START update]
@Override
public void updateBook(Book book) {
Expand All @@ -94,13 +98,15 @@ public void updateBook(Book book) {
datastore.put(entity); // Update the Entity
}
// [END update]

// [START delete]
@Override
public void deleteBook(Long bookId) {
Key key = KeyFactory.createKey(BOOK_KIND, bookId); // Create the Key
datastore.delete(key); // Delete the Entity
}
// [END delete]

// [START entitiesToBooks]
public List<Book> entitiesToBooks(Iterator<Entity> results) {
List<Book> resultBooks = new ArrayList<>();
Expand All @@ -110,6 +116,7 @@ public List<Book> entitiesToBooks(Iterator<Entity> results) {
return resultBooks;
}
// [END entitiesToBooks]

// [START listbooks]
@Override
public Result<Book> listBooks(String startCursorString) {
Expand Down
Expand Up @@ -17,7 +17,7 @@

// [START example]
public class Book {
// [START book]
// [START book]
private String title;
private String author;
private String createdBy;
Expand All @@ -26,8 +26,8 @@ public class Book {
private String description;
private Long id;
private String imageUrl;
// [END book]
// [START keys]
// [END book]
// [START keys]
public static final String AUTHOR = "author";
public static final String CREATED_BY = "createdBy";
public static final String CREATED_BY_ID = "createdById";
Expand All @@ -36,8 +36,9 @@ public class Book {
public static final String PUBLISHED_DATE = "publishedDate";
public static final String TITLE = "title";
public static final String IMAGE_URL = "imageUrl";
// [END keys]
// [START constructor]
// [END keys]

// [START constructor]
// We use a Builder pattern here to simplify and standardize construction of Book objects.
private Book(Builder builder) {
this.title = builder.title;
Expand All @@ -49,8 +50,9 @@ private Book(Builder builder) {
this.id = builder.id;
this.imageUrl = builder.imageUrl;
}
// [END constructor]
// [START builder]
// [END constructor]

// [START builder]
public static class Builder {
private String title;
private String author;
Expand Down Expand Up @@ -169,12 +171,13 @@ public String getImageUrl() {
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
// [END builder]

// [END builder]
@Override
public String toString() {
return
"Title: " + title + ", Author: " + author + ", Published date: " + publishedDate
+ ", Added by: " + createdBy;
+ ", Added by: " + createdBy;
}
}
// [END example]
Expand Up @@ -29,11 +29,6 @@
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.IOException;
import java.math.BigInteger;
import java.security.SecureRandom;
Expand All @@ -53,6 +48,11 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

// [START init]
public class DatastoreSessionFilter implements Filter {

Expand All @@ -75,7 +75,7 @@ public void init(FilterConfig config) throws ServletException {
datastore.delete(stateEntity.getKey());
}
}
// [END init]
// [END init]

@Override
public void doFilter(ServletRequest servletReq, ServletResponse servletResp, FilterChain chain)
Expand Down
Expand Up @@ -27,14 +27,16 @@
import com.google.cloud.datastore.QueryResults;
import com.google.cloud.datastore.StructuredQuery;

import java.util.Iterator;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -45,9 +47,6 @@
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.Iterator;
import java.util.List;

@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class UserJourneyTestIT {
Expand Down
Expand Up @@ -18,22 +18,23 @@
import com.example.getstarted.daos.BookDao;
import com.example.getstarted.objects.Book;
import com.example.getstarted.util.CloudStorageHelper;

import com.google.common.base.Strings;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;

// [START example]
@SuppressWarnings("serial")
public class CreateBookServlet extends HttpServlet {
Expand Down
Expand Up @@ -18,22 +18,23 @@
import com.example.getstarted.daos.BookDao;
import com.example.getstarted.objects.Book;
import com.example.getstarted.util.CloudStorageHelper;

import com.google.common.base.Strings;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;

// [START example]
@SuppressWarnings("serial")
public class UpdateBookServlet extends HttpServlet {
Expand Down
Expand Up @@ -17,7 +17,7 @@

// [START example]
public class Book {
// [START book]
// [START book]
private String title;
private String author;
private String createdBy;
Expand All @@ -26,8 +26,8 @@ public class Book {
private String description;
private Long id;
private String imageUrl;
// [END book]
// [START keys]
// [END book]
// [START keys]
public static final String AUTHOR = "author";
public static final String CREATED_BY = "createdBy";
public static final String CREATED_BY_ID = "createdById";
Expand All @@ -36,8 +36,9 @@ public class Book {
public static final String PUBLISHED_DATE = "publishedDate";
public static final String TITLE = "title";
public static final String IMAGE_URL = "imageUrl";
// [END keys]
// [START constructor]
// [END keys]

// [START constructor]
// We use a Builder pattern here to simplify and standardize construction of Book objects.
private Book(Builder builder) {
this.title = builder.title;
Expand All @@ -49,8 +50,9 @@ private Book(Builder builder) {
this.id = builder.id;
this.imageUrl = builder.imageUrl;
}
// [END constructor]
// [START builder]
// [END constructor]

// [START builder]
public static class Builder {
private String title;
private String author;
Expand Down Expand Up @@ -169,7 +171,8 @@ public String getImageUrl() {
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
// [END builder]

// [END builder]
@Override
public String toString() {
return
Expand Down

0 comments on commit 32cbaab

Please sign in to comment.