Browse Source

Add missing descriptions

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.2-alpha
Pekka Helenius 4 years ago
parent
commit
cbec5eaf48
15 changed files with 146 additions and 8 deletions
  1. +9
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java
  2. +10
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java
  3. +14
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorJsonSerializer.java
  4. +7
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java
  5. +10
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java
  6. +16
    -3
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookEventHandler.java
  7. +13
    -5
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java
  8. +7
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java
  9. +7
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java
  10. +10
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java
  11. +14
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java
  12. +7
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java
  13. +6
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/web/BigDecimalPropertyEditor.java
  14. +9
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/web/BookRestController.java
  15. +7
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/web/HttpServerLogger.java

+ 9
- 0
bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java View File

@ -21,6 +21,15 @@ import com.fjordtek.bookstore.model.BookRepository;
import com.fjordtek.bookstore.model.Category; import com.fjordtek.bookstore.model.Category;
import com.fjordtek.bookstore.model.CategoryRepository; import com.fjordtek.bookstore.model.CategoryRepository;
/**
*
* This is the main Spring Boot application class for the bookstore project.
* <p>
* Initializes and handles initialization of the application.
*
* @author Pekka Helenius
*/
@SpringBootApplication @SpringBootApplication
public class BookstoreApplication extends SpringBootServletInitializer { public class BookstoreApplication extends SpringBootServletInitializer {
private static final Logger commonLogger = LoggerFactory.getLogger(BookstoreApplication.class); private static final Logger commonLogger = LoggerFactory.getLogger(BookstoreApplication.class);


+ 10
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/Author.java View File

@ -19,6 +19,16 @@ import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* This class implements Author entity which forms
* core structure for the corresponding AUTHOR table in a database.
* <p>
* Additionally, Author entity objects are Java objects having
* methods, attributes and other class-related additions within them.
*
* @author Pekka Helenius
*/
@Entity @Entity
public class Author { public class Author {


+ 14
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorJsonSerializer.java View File

@ -8,6 +8,20 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* This class implements Jackson JSON serializer for Author entity class.
* <p>
* When writing a JSON output based on a Author entity object, the processing
* is handled in the way described in this class.
* <p>
* 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<Author> { public class AuthorJsonSerializer extends StdSerializer<Author> {
private static final long serialVersionUID = 5233819344225306443L; private static final long serialVersionUID = 5233819344225306443L;


+ 7
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java View File

@ -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.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource; 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( @RepositoryRestResource(
path = "authors", path = "authors",
itemResourceRel = "authors", itemResourceRel = "authors",


+ 10
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -33,6 +33,16 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fjordtek.bookstore.annotation.CurrentYear; import com.fjordtek.bookstore.annotation.CurrentYear;
/**
* This class implements Book entity which forms
* core structure for the corresponding BOOK table in a database.
* <p>
* Additionally, Book entity objects are Java objects having
* methods, attributes and other class-related additions within them.
*
* @author Pekka Helenius
*/
@Entity @Entity
public class Book { public class Book {


+ 16
- 3
bookstore/src/main/java/com/fjordtek/bookstore/model/BookEventHandler.java View File

@ -7,6 +7,22 @@ import org.springframework.data.rest.core.annotation.HandleAfterCreate;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler; import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* This class is part of Spring framework, having @Component
* annotation.
* <p>
* 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 @Component
@RepositoryEventHandler(Book.class) @RepositoryEventHandler(Book.class)
public class BookEventHandler { public class BookEventHandler {
@ -22,9 +38,6 @@ public class BookEventHandler {
* curl --request POST --header "Content-Type: application/json" --data * curl --request POST --header "Content-Type: application/json" --data
* '{"title":"Bloody Chamber", ...}' http://localhost:8080/api/booklist * '{"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 @HandleAfterCreate
public void handleAfterCreate(Book book) { public void handleAfterCreate(Book book) {


+ 13
- 5
bookstore/src/main/java/com/fjordtek/bookstore/model/BookHash.java View File

@ -19,19 +19,27 @@ import org.hibernate.annotations.Parameter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
/*
/**
* This class implements BookHash entity which forms
* core structure for the corresponding BOOK_HASH table in a database.
* <p>
* Additionally, BookHash entity objects are Java objects having
* methods, attributes and other class-related additions within them.
* <p>
* This entity shares same primary key with the Book entity * This entity shares same primary key with the Book entity
* which is simultaneously a foreign key (unidirectional mapping) * which is simultaneously a foreign key (unidirectional mapping)
* for this one. * for this one.
* For implementation reference, see also:
* https://www.programmersought.com/article/1610322983/
*
* <p>
* This entity generates a table which holds auto-generated * This entity generates a table which holds auto-generated
* random string values associated to each book. * random string values associated to each book.
*
* <p>
* These random string values represent difficult-to-enumerate * These random string values represent difficult-to-enumerate
* unique book IDs used for front-end purposes. Main purpose * unique book IDs used for front-end purposes. Main purpose
* is not to expose real Book entity id value. * is not to expose real Book entity id value.
*
* @see https://www.programmersought.com/article/1610322983/
*
* @author Pekka Helenius
*/ */
@Entity @Entity


+ 7
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/BookHashRepository.java View File

@ -8,6 +8,13 @@ import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource; 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( @RepositoryRestResource(
path = "bookhashes", path = "bookhashes",
itemResourceRel = "bookhashes", itemResourceRel = "bookhashes",


+ 7
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java View File

@ -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.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource; 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( @RepositoryRestResource(
path = "booklist", path = "booklist",
itemResourceRel = "booklist", itemResourceRel = "booklist",


+ 10
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/Category.java View File

@ -16,6 +16,16 @@ import javax.persistence.SequenceGenerator;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* This class implements Category entity which forms
* core structure for the corresponding CATEGORY table in a database.
* <p>
* Additionally, Category entity objects are Java objects having
* methods, attributes and other class-related additions within them.
*
* @author Pekka Helenius
*/
@Entity @Entity
public class Category { public class Category {


+ 14
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryJsonSerializer.java View File

@ -8,6 +8,20 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* This class implements Jackson JSON serializer for Category entity class.
* <p>
* When writing a JSON output based on a Category entity object, the processing
* is handled in the way described in this class.
* <p>
* 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<Category> { public class CategoryJsonSerializer extends StdSerializer<Category> {
private static final long serialVersionUID = 6376700470881235634L; private static final long serialVersionUID = 6376700470881235634L;


+ 7
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java View File

@ -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.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource; 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( @RepositoryRestResource(
path = "categories", path = "categories",
itemResourceRel = "categories", itemResourceRel = "categories",


+ 6
- 0
bookstore/src/main/java/com/fjordtek/bookstore/web/BigDecimalPropertyEditor.java View File

@ -5,6 +5,12 @@ package com.fjordtek.bookstore.web;
import java.beans.PropertyEditorSupport; import java.beans.PropertyEditorSupport;
import java.math.BigDecimal; import java.math.BigDecimal;
/**
* Converts numbers with custom decimal separators to proper BigDecimal format.
*
* @author Pekka Helenius
*/
public class BigDecimalPropertyEditor extends PropertyEditorSupport { public class BigDecimalPropertyEditor extends PropertyEditorSupport {
@Override @Override


+ 9
- 0
bookstore/src/main/java/com/fjordtek/bookstore/web/BookRestController.java View File

@ -20,6 +20,15 @@ import com.fjordtek.bookstore.model.Book;
import com.fjordtek.bookstore.model.BookHashRepository; import com.fjordtek.bookstore.model.BookHashRepository;
import com.fjordtek.bookstore.model.BookRepository; 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 @RestController
@RequestMapping("json") @RequestMapping("json")
public class BookRestController { public class BookRestController {


+ 7
- 0
bookstore/src/main/java/com/fjordtek/bookstore/web/HttpServerLogger.java View File

@ -12,6 +12,13 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
*
* This class implements a custom logger for HTTP requests.
*
* @author Pekka Helenius
*/
public class HttpServerLogger { public class HttpServerLogger {
private static final Logger serverLogger = LoggerFactory.getLogger(HttpServerLogger.class); private static final Logger serverLogger = LoggerFactory.getLogger(HttpServerLogger.class);


Loading…
Cancel
Save