Adjust checkstyle rules. Make checkstyle fail the build when violations are found. Correct all current checkstyle violations.
This commit is contained in:
		@@ -4,31 +4,31 @@ import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * Layers is an architectural style where software responsibilities are divided among the different
 | 
			
		||||
 * layers of the application.
 | 
			
		||||
 * Layers is an architectural style where software responsibilities are divided among the different layers of the
 | 
			
		||||
 * application.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * This example demonstrates a traditional 3-layer architecture consisting of data access layer,
 | 
			
		||||
 * business layer and presentation layer.
 | 
			
		||||
 * This example demonstrates a traditional 3-layer architecture consisting of data access layer, business layer and
 | 
			
		||||
 * presentation layer.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * The data access layer is formed of Spring Data repositories <code>CakeDao</code>,
 | 
			
		||||
 * <code>CakeToppingDao</code> and <code>CakeLayerDao</code>. The repositories can be used for CRUD
 | 
			
		||||
 * operations on cakes, cake toppings and cake layers respectively.
 | 
			
		||||
 * The data access layer is formed of Spring Data repositories <code>CakeDao</code>, <code>CakeToppingDao</code> and
 | 
			
		||||
 * <code>CakeLayerDao</code>. The repositories can be used for CRUD operations on cakes, cake toppings and cake layers
 | 
			
		||||
 * respectively.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * The business layer is built on top of the data access layer. <code>CakeBakingService</code>
 | 
			
		||||
 * offers methods to retrieve available cake toppings and cake layers and baked cakes. Also the
 | 
			
		||||
 * service is used to create new cakes out of cake toppings and cake layers.
 | 
			
		||||
 * The business layer is built on top of the data access layer. <code>CakeBakingService</code> offers methods to
 | 
			
		||||
 * retrieve available cake toppings and cake layers and baked cakes. Also the service is used to create new cakes out of
 | 
			
		||||
 * cake toppings and cake layers.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * The presentation layer is built on the business layer and in this example it simply lists the
 | 
			
		||||
 * cakes that have been baked.
 | 
			
		||||
 * The presentation layer is built on the business layer and in this example it simply lists the cakes that have been
 | 
			
		||||
 * baked.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * We have applied so called strict layering which means that the layers can only access the classes
 | 
			
		||||
 * directly beneath them. This leads the solution to create an additional set of DTOs (
 | 
			
		||||
 * <code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) to translate
 | 
			
		||||
 * data between layers. In other words, <code>CakeBakingService</code> cannot return entities (
 | 
			
		||||
 * <code>Cake</code>, <code>CakeTopping</code>, <code>CakeLayer</code>) directly since these reside
 | 
			
		||||
 * on data access layer but instead translates these into business layer DTOs (<code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) and returns them instead. This way
 | 
			
		||||
 * the presentation layer does not have any knowledge of other layers than the business layer and
 | 
			
		||||
 * thus is not affected by changes to them.
 | 
			
		||||
 * We have applied so called strict layering which means that the layers can only access the classes directly beneath
 | 
			
		||||
 * them. This leads the solution to create an additional set of DTOs ( <code>CakeInfo</code>,
 | 
			
		||||
 * <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) to translate data between layers. In other words,
 | 
			
		||||
 * <code>CakeBakingService</code> cannot return entities ( <code>Cake</code>, <code>CakeTopping</code>,
 | 
			
		||||
 * <code>CakeLayer</code>) directly since these reside on data access layer but instead translates these into business
 | 
			
		||||
 * layer DTOs (<code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>) and returns them
 | 
			
		||||
 * instead. This way the presentation layer does not have any knowledge of other layers than the business layer and thus
 | 
			
		||||
 * is not affected by changes to them.
 | 
			
		||||
 *
 | 
			
		||||
 * @see Cake
 | 
			
		||||
 * @see CakeTopping
 | 
			
		||||
@@ -63,8 +63,6 @@ public class App {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Initializes the example data
 | 
			
		||||
   * 
 | 
			
		||||
   * @param cakeBakingService
 | 
			
		||||
   */
 | 
			
		||||
  private static void initializeData(CakeBakingService cakeBakingService) {
 | 
			
		||||
    cakeBakingService.saveNewLayer(new CakeLayerInfo("chocolate", 1200));
 | 
			
		||||
 
 | 
			
		||||
@@ -11,44 +11,31 @@ public interface CakeBakingService {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Bakes new cake according to parameters
 | 
			
		||||
   * 
 | 
			
		||||
   * @param cakeInfo
 | 
			
		||||
   * @throws CakeBakingException
 | 
			
		||||
   */
 | 
			
		||||
  void bakeNewCake(CakeInfo cakeInfo) throws CakeBakingException;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get all cakes
 | 
			
		||||
   * 
 | 
			
		||||
   * @return
 | 
			
		||||
   */
 | 
			
		||||
  List<CakeInfo> getAllCakes();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Store new cake topping
 | 
			
		||||
   * 
 | 
			
		||||
   * @param toppingInfo
 | 
			
		||||
   */
 | 
			
		||||
  void saveNewTopping(CakeToppingInfo toppingInfo);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get available cake toppings
 | 
			
		||||
   * 
 | 
			
		||||
   * @return
 | 
			
		||||
   */
 | 
			
		||||
  List<CakeToppingInfo> getAvailableToppings();
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Add new cake layer
 | 
			
		||||
   * 
 | 
			
		||||
   * @param layerInfo
 | 
			
		||||
   */
 | 
			
		||||
  void saveNewLayer(CakeLayerInfo layerInfo);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get available cake layers
 | 
			
		||||
   * 
 | 
			
		||||
   * @return
 | 
			
		||||
   */
 | 
			
		||||
  List<CakeLayerInfo> getAvailableLayers();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,18 +14,27 @@ public class CakeInfo {
 | 
			
		||||
  public final CakeToppingInfo cakeToppingInfo;
 | 
			
		||||
  public final List<CakeLayerInfo> cakeLayerInfos;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Constructor
 | 
			
		||||
   */
 | 
			
		||||
  public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
 | 
			
		||||
    this.id = Optional.of(id);
 | 
			
		||||
    this.cakeToppingInfo = cakeToppingInfo;
 | 
			
		||||
    this.cakeLayerInfos = cakeLayerInfos;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Constructor
 | 
			
		||||
   */
 | 
			
		||||
  public CakeInfo(CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
 | 
			
		||||
    this.id = Optional.empty();
 | 
			
		||||
    this.cakeToppingInfo = cakeToppingInfo;
 | 
			
		||||
    this.cakeLayerInfos = cakeLayerInfos;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Calculate calories
 | 
			
		||||
   */
 | 
			
		||||
  public int calculateTotalCalories() {
 | 
			
		||||
    int total = cakeToppingInfo != null ? cakeToppingInfo.calories : 0;
 | 
			
		||||
    total += cakeLayerInfos.stream().mapToInt(c -> c.calories).sum();
 | 
			
		||||
 
 | 
			
		||||
@@ -13,12 +13,18 @@ public class CakeLayerInfo {
 | 
			
		||||
  public final String name;
 | 
			
		||||
  public final int calories;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Constructor
 | 
			
		||||
   */
 | 
			
		||||
  public CakeLayerInfo(Long id, String name, int calories) {
 | 
			
		||||
    this.id = Optional.of(id);
 | 
			
		||||
    this.name = name;
 | 
			
		||||
    this.calories = calories;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Constructor
 | 
			
		||||
   */
 | 
			
		||||
  public CakeLayerInfo(String name, int calories) {
 | 
			
		||||
    this.id = Optional.empty();
 | 
			
		||||
    this.name = name;
 | 
			
		||||
 
 | 
			
		||||
@@ -13,12 +13,18 @@ public class CakeToppingInfo {
 | 
			
		||||
  public final String name;
 | 
			
		||||
  public final int calories;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Constructor
 | 
			
		||||
   */
 | 
			
		||||
  public CakeToppingInfo(Long id, String name, int calories) {
 | 
			
		||||
    this.id = Optional.of(id);
 | 
			
		||||
    this.name = name;
 | 
			
		||||
    this.calories = calories;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Constructor
 | 
			
		||||
   */
 | 
			
		||||
  public CakeToppingInfo(String name, int calories) {
 | 
			
		||||
    this.id = Optional.empty();
 | 
			
		||||
    this.name = name;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<persistence version="1.0"
 | 
			
		||||
	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 | 
			
		||||
  xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 | 
			
		||||
 | 
			
		||||
	<persistence-unit name="jpaData" />
 | 
			
		||||
  <persistence-unit name="jpaData" />
 | 
			
		||||
 | 
			
		||||
</persistence>
 | 
			
		||||
@@ -1,42 +1,39 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<beans xmlns="http://www.springframework.org/schema/beans"
 | 
			
		||||
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
 | 
			
		||||
	xmlns:security="http://www.springframework.org/schema/security"
 | 
			
		||||
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
	xmlns:jpa="http://www.springframework.org/schema/data/jpa"
 | 
			
		||||
	xsi:schemaLocation="
 | 
			
		||||
				http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
 | 
			
		||||
				http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
 | 
			
		||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
 | 
			
		||||
  xmlns:context="http://www.springframework.org/schema/context"
 | 
			
		||||
  xmlns:security="http://www.springframework.org/schema/security" xmlns:tx="http://www.springframework.org/schema/tx"
 | 
			
		||||
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
 | 
			
		||||
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
 | 
			
		||||
 | 
			
		||||
	<jpa:repositories base-package="com.iluwatar" />
 | 
			
		||||
  <jpa:repositories base-package="com.iluwatar" />
 | 
			
		||||
 | 
			
		||||
	<tx:annotation-driven transaction-manager="transactionManager" />
 | 
			
		||||
  <tx:annotation-driven transaction-manager="transactionManager" />
 | 
			
		||||
 | 
			
		||||
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
 | 
			
		||||
		<property name="entityManagerFactory" ref="entityManagerFactory" />
 | 
			
		||||
	</bean>
 | 
			
		||||
  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
 | 
			
		||||
    <property name="entityManagerFactory" ref="entityManagerFactory" />
 | 
			
		||||
  </bean>
 | 
			
		||||
 | 
			
		||||
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
 | 
			
		||||
		destroy-method="close">
 | 
			
		||||
		<property name="driverClassName" value="org.h2.Driver" />
 | 
			
		||||
		<property name="url" value="jdbc:h2:~/databases/cake" />
 | 
			
		||||
		<property name="username" value="sa" />
 | 
			
		||||
		<property name="password" value="sa" />
 | 
			
		||||
	</bean>
 | 
			
		||||
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
 | 
			
		||||
    destroy-method="close">
 | 
			
		||||
    <property name="driverClassName" value="org.h2.Driver" />
 | 
			
		||||
    <property name="url" value="jdbc:h2:~/databases/cake" />
 | 
			
		||||
    <property name="username" value="sa" />
 | 
			
		||||
    <property name="password" value="sa" />
 | 
			
		||||
  </bean>
 | 
			
		||||
 | 
			
		||||
	<bean id="entityManagerFactory"
 | 
			
		||||
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
 | 
			
		||||
		<property name="dataSource" ref="dataSource" />
 | 
			
		||||
		<property name="packagesToScan" value="com.iluwatar" />
 | 
			
		||||
		<property name="persistenceProvider">
 | 
			
		||||
			<bean class="org.hibernate.ejb.HibernatePersistence" />
 | 
			
		||||
		</property>
 | 
			
		||||
		<property name="jpaProperties">
 | 
			
		||||
			<map>
 | 
			
		||||
				<entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
 | 
			
		||||
				<entry key="hibernate.hbm2ddl.auto" value="create-drop" />
 | 
			
		||||
				<entry key="hibernate.show_sql" value="false" />
 | 
			
		||||
			</map>
 | 
			
		||||
		</property>
 | 
			
		||||
	</bean>
 | 
			
		||||
  <bean id="entityManagerFactory"
 | 
			
		||||
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
 | 
			
		||||
    <property name="dataSource" ref="dataSource" />
 | 
			
		||||
    <property name="packagesToScan" value="com.iluwatar" />
 | 
			
		||||
    <property name="persistenceProvider">
 | 
			
		||||
      <bean class="org.hibernate.ejb.HibernatePersistence" />
 | 
			
		||||
    </property>
 | 
			
		||||
    <property name="jpaProperties">
 | 
			
		||||
      <map>
 | 
			
		||||
        <entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
 | 
			
		||||
        <entry key="hibernate.hbm2ddl.auto" value="create-drop" />
 | 
			
		||||
        <entry key="hibernate.show_sql" value="false" />
 | 
			
		||||
      </map>
 | 
			
		||||
    </property>
 | 
			
		||||
  </bean>
 | 
			
		||||
</beans>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user