diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java b/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java index 1cdab98..f912da8 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java @@ -21,6 +21,15 @@ import com.fjordtek.bookstore.model.BookRepository; import com.fjordtek.bookstore.model.Category; import com.fjordtek.bookstore.model.CategoryRepository; +/** +* +* This is the main Spring Boot application class for the bookstore project. +*

+* Initializes and handles initialization of the application. +* +* @author Pekka Helenius +*/ + @SpringBootApplication public class BookstoreApplication extends SpringBootServletInitializer { private static final Logger commonLogger = LoggerFactory.getLogger(BookstoreApplication.class); diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java index da371e6..89c29bd 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java @@ -19,6 +19,16 @@ import javax.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonIgnore; +/** + * This class implements Author entity which forms + * core structure for the corresponding AUTHOR table in a database. + *

+ * Additionally, Author entity objects are Java objects having + * methods, attributes and other class-related additions within them. + * + * @author Pekka Helenius + */ + @Entity public class Author { diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorJsonSerializer.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorJsonSerializer.java index 399a267..f6b7d75 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorJsonSerializer.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorJsonSerializer.java @@ -8,6 +8,20 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; +/** + * This class implements Jackson JSON serializer for Author entity class. + *

+ * When writing a JSON output based on a Author entity object, the processing + * is handled in the way described in this class. + *

+ * Unless specifically instructed, customization defined in this class + * does not affect native Spring REST API JSON outputs generated + * by a controller having either @BasePathAwareController + * or @RepositoryRestController annotation. + * + * @author Pekka Helenius + */ + public class AuthorJsonSerializer extends StdSerializer { private static final long serialVersionUID = 5233819344225306443L; diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java index b6163ca..17a3af8 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java @@ -9,6 +9,13 @@ import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; +/** + * This interface extends CrudRepository interface, implementing + * custom methods for a repository containing Author entities. + * + * @author Pekka Helenius + */ + @RepositoryRestResource( path = "authors", itemResourceRel = "authors", diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java index dea04c3..010433f 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java @@ -33,6 +33,16 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fjordtek.bookstore.annotation.CurrentYear; +/** + * This class implements Book entity which forms + * core structure for the corresponding BOOK table in a database. + *

+ * Additionally, Book entity objects are Java objects having + * methods, attributes and other class-related additions within them. + * + * @author Pekka Helenius + */ + @Entity public class Book { diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookEventHandler.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookEventHandler.java index 6feba42..bcdeaff 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookEventHandler.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookEventHandler.java @@ -7,6 +7,22 @@ import org.springframework.data.rest.core.annotation.HandleAfterCreate; import org.springframework.data.rest.core.annotation.RepositoryEventHandler; import org.springframework.stereotype.Component; +/** + * This class is part of Spring framework, having @Component + * annotation. + *

+ * The class implements @RepositoryEventHandler annotation + * for Book class which instructs Spring to use custom method + * implementations for events annotated with specific event + * handlers in the class. + * + * @see https://docs.spring.io/spring-data/rest/docs/current/reference/html/#events + * @see https://stackoverflow.com/questions/49504103/override-spring-data-rest-post-method + * @see https://www.baeldung.com/spring-data-rest-events + * + * @author Pekka Helenius + */ + @Component @RepositoryEventHandler(Book.class) public class BookEventHandler { @@ -22,9 +38,6 @@ public class BookEventHandler { * curl --request POST --header "Content-Type: application/json" --data * '{"title":"Bloody Chamber", ...}' http://localhost:8080/api/booklist * - * Ref: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#events - * https://stackoverflow.com/questions/49504103/override-spring-data-rest-post-method - * https://www.baeldung.com/spring-data-rest-events */ @HandleAfterCreate public void handleAfterCreate(Book book) { diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java index 4fc222c..6e6bec1 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java @@ -19,19 +19,27 @@ import org.hibernate.annotations.Parameter; import com.fasterxml.jackson.annotation.JsonIgnore; -/* +/** + * This class implements BookHash entity which forms + * core structure for the corresponding BOOK_HASH table in a database. + *

+ * Additionally, BookHash entity objects are Java objects having + * methods, attributes and other class-related additions within them. + *

* This entity shares same primary key with the Book entity * which is simultaneously a foreign key (unidirectional mapping) * for this one. - * For implementation reference, see also: - * https://www.programmersought.com/article/1610322983/ - * + *

* This entity generates a table which holds auto-generated * random string values associated to each book. - * + *

* These random string values represent difficult-to-enumerate * unique book IDs used for front-end purposes. Main purpose * is not to expose real Book entity id value. + * + * @see https://www.programmersought.com/article/1610322983/ + * + * @author Pekka Helenius */ @Entity diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java index 1f552e7..301df54 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java @@ -8,6 +8,13 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; +/** + * This interface extends CrudRepository interface, implementing + * custom methods for a repository containing BookHash entities. + * + * @author Pekka Helenius + */ + @RepositoryRestResource( path = "bookhashes", itemResourceRel = "bookhashes", diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java index 145c8b1..f93df03 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java @@ -12,6 +12,13 @@ import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; +/** + * This interface extends CrudRepository interface, implementing + * custom methods for a repository containing Book entities. + * + * @author Pekka Helenius + */ + @RepositoryRestResource( path = "booklist", itemResourceRel = "booklist", diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java index b3ab1d9..b948867 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java @@ -16,6 +16,16 @@ import javax.persistence.SequenceGenerator; import com.fasterxml.jackson.annotation.JsonIgnore; +/** + * This class implements Category entity which forms + * core structure for the corresponding CATEGORY table in a database. + *

+ * Additionally, Category entity objects are Java objects having + * methods, attributes and other class-related additions within them. + * + * @author Pekka Helenius + */ + @Entity public class Category { diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java index d7c71c0..f6faf5a 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java @@ -8,6 +8,20 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; +/** + * This class implements Jackson JSON serializer for Category entity class. + *

+ * When writing a JSON output based on a Category entity object, the processing + * is handled in the way described in this class. + *

+ * Unless specifically instructed, customization defined in this class + * does not affect native Spring REST API JSON outputs generated + * by a controller having either @BasePathAwareController + * or @RepositoryRestController annotation. + * + * @author Pekka Helenius + */ + public class CategoryJsonSerializer extends StdSerializer { private static final long serialVersionUID = 6376700470881235634L; diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java index 21037bc..0f41411 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java @@ -9,6 +9,13 @@ import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; +/** + * This interface extends CrudRepository interface, implementing + * custom methods for a repository containing Category entities. + * + * @author Pekka Helenius + */ + @RepositoryRestResource( path = "categories", itemResourceRel = "categories", diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/web/BigDecimalPropertyEditor.java b/bookstore/src/main/java/com/fjordtek/bookstore/web/BigDecimalPropertyEditor.java index 7f7a7b4..0f2b47d 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BigDecimalPropertyEditor.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BigDecimalPropertyEditor.java @@ -5,6 +5,12 @@ package com.fjordtek.bookstore.web; import java.beans.PropertyEditorSupport; import java.math.BigDecimal; +/** + * Converts numbers with custom decimal separators to proper BigDecimal format. + * + * @author Pekka Helenius + */ + public class BigDecimalPropertyEditor extends PropertyEditorSupport { @Override diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookRestController.java b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookRestController.java index 43a7778..826041e 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookRestController.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookRestController.java @@ -20,6 +20,15 @@ import com.fjordtek.bookstore.model.Book; import com.fjordtek.bookstore.model.BookHashRepository; import com.fjordtek.bookstore.model.BookRepository; +/** +* +* This class implements a custom JSON-related controller for the bookstore, +* handling requests to a predetermined end points only, using a special prefix +* value in its hard-coded @RequestMapping annotation. +* +* @author Pekka Helenius +*/ + @RestController @RequestMapping("json") public class BookRestController { diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/web/HttpServerLogger.java b/bookstore/src/main/java/com/fjordtek/bookstore/web/HttpServerLogger.java index af01882..07b4e1b 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/HttpServerLogger.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/HttpServerLogger.java @@ -12,6 +12,13 @@ import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** +* +* This class implements a custom logger for HTTP requests. +* +* @author Pekka Helenius +*/ + public class HttpServerLogger { private static final Logger serverLogger = LoggerFactory.getLogger(HttpServerLogger.class);