From 09ed33a5fc01209b4190c74f405b2b1e523b739c Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Fri, 16 Oct 2015 09:33:06 +0200 Subject: [PATCH] #96 Reformat code with EditorConfig --- .editorconfig | 9 + pom.xml | 747 +++++++++--------- .../samples/petclinic/model/BaseEntity.java | 7 +- .../samples/petclinic/model/NamedEntity.java | 7 +- .../samples/petclinic/model/Owner.java | 24 +- .../samples/petclinic/model/Pet.java | 21 +- .../samples/petclinic/model/PetType.java | 2 +- .../samples/petclinic/model/Vet.java | 11 +- .../samples/petclinic/model/package-info.java | 3 - .../petclinic/repository/OwnerRepository.java | 5 +- .../petclinic/repository/PetRepository.java | 3 +- .../jdbc/JdbcOwnerRepositoryImpl.java | 32 +- .../petclinic/repository/jdbc/JdbcPet.java | 11 +- .../jdbc/JdbcPetRepositoryImpl.java | 34 +- .../jdbc/JdbcPetVisitExtractor.java | 4 +- .../jdbc/JdbcVetRepositoryImpl.java | 24 +- .../jdbc/JdbcVisitRepositoryImpl.java | 18 +- .../repository/jdbc/package-info.java | 3 - .../jpa/JpaOwnerRepositoryImpl.java | 13 +- .../repository/jpa/JpaPetRepositoryImpl.java | 11 +- .../jpa/JpaVisitRepositoryImpl.java | 11 +- .../repository/jpa/package-info.java | 3 - .../SpringDataOwnerRepository.java | 16 +- .../petclinic/util/CallMonitoringAspect.java | 21 +- .../samples/petclinic/util/EntityUtils.java | 5 +- .../petclinic/web/CrashController.java | 2 +- .../petclinic/web/OwnerController.java | 14 +- .../samples/petclinic/web/PetValidator.java | 6 +- .../samples/petclinic/web/VetController.java | 12 +- .../petclinic/web/VisitController.java | 19 +- .../samples/petclinic/web/package-info.java | 3 - src/main/java/test.html | 76 +- src/main/resources/logback.xml | 4 +- src/main/resources/spring/business-config.xml | 36 +- .../resources/spring/datasource-config.xml | 8 +- src/main/resources/spring/mvc-core-config.xml | 14 +- src/main/resources/spring/mvc-view-config.xml | 32 +- src/main/resources/spring/tools-config.xml | 6 +- src/main/webapp/WEB-INF/jsp/exception.jsp | 2 +- .../WEB-INF/jsp/fragments/bodyHeader.jsp | 2 +- .../WEB-INF/jsp/fragments/staticFiles.jsp | 6 +- .../jsp/owners/createOrUpdateOwnerForm.jsp | 2 +- .../webapp/WEB-INF/jsp/owners/findOwners.jsp | 2 +- .../WEB-INF/jsp/owners/ownerDetails.jsp | 38 +- .../webapp/WEB-INF/jsp/owners/ownersList.jsp | 10 +- .../jsp/pets/createOrUpdatePetForm.jsp | 4 +- .../jsp/pets/createOrUpdateVisitForm.jsp | 12 +- src/main/webapp/WEB-INF/jsp/vets/vetList.jsp | 7 +- src/main/webapp/WEB-INF/jsp/welcome.jsp | 2 +- src/main/webapp/WEB-INF/web.xml | 86 +- .../petclinic/model/ValidatorTests.java | 28 +- .../service/AbstractClinicServiceTests.java | 172 ++-- .../service/ClinicServiceJdbcTests.java | 4 +- .../service/ClinicServiceJpaTests.java | 7 +- .../ClinicServiceSpringDataJpaTests.java | 8 +- .../petclinic/web/VetControllerTests.java | 8 +- 56 files changed, 838 insertions(+), 839 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..de9af4689b5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# top-most EditorConfig file +root = true + +[*.{java,xml}] +charset = utf-8 +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/pom.xml b/pom.xml index 504e97c359f..d4c16ce5bd1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,406 +1,407 @@ - - 4.0.0 - org.springframework.samples - spring-petclinic - 1.0.0-SNAPSHOT + + 4.0.0 + org.springframework.samples + spring-petclinic + 1.0.0-SNAPSHOT - petclinic - war + petclinic + war - + - - 1.7 - UTF-8 - UTF-8 + + 1.7 + UTF-8 + UTF-8 - - 1.1.3.RELEASE - 1.1.0.RELEASE + + 1.1.3.RELEASE + 1.1.0.RELEASE - - 7.0.59 + + 7.0.59 - - 2.2.0 - - - 1.3 - 1.1.1 - 3.2.0.GA + + 2.2.0 - - 5.1.36 + + 1.3 + 1.1.1 + 3.2.0.GA - - 2.3.0 - 1.10.3 - 2.0.3-1 - 1.0.1 + + 5.1.36 - 2.7 + + 2.3.0 + 1.10.3 + 2.0.3-1 + 1.0.1 - + 2.7 - - - - - io.spring.platform - platform-bom - ${spring-io-platform.version} - pom - import - - - + - - - org.jadira.usertype - usertype.core - ${jadira-usertype-core.version} - - - org.apache.tomcat - tomcat-servlet-api - ${tomcat.version} - provided - - - javax.servlet.jsp - javax.servlet.jsp-api - provided - - - org.apache.tomcat - tomcat-jasper-el - ${tomcat.version} - provided - + + + + + io.spring.platform + platform-bom + ${spring-io-platform.version} + pom + import + + + + - javax.servlet.jsp.jstl - javax.servlet.jsp.jstl-api + org.jadira.usertype + usertype.core + ${jadira-usertype-core.version} - - org.apache.taglibs - taglibs-standard-jstlel - - - + + org.apache.tomcat + tomcat-servlet-api + ${tomcat.version} + provided + + + javax.servlet.jsp + javax.servlet.jsp-api + provided + + + org.apache.tomcat + tomcat-jasper-el + ${tomcat.version} + provided + + + + javax.servlet.jsp.jstl + javax.servlet.jsp.jstl-api + + + org.apache.taglibs + taglibs-standard-jstlel + + + com.jayway.jsonpath json-path test - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-data-jpa - + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-data-jpa + - - org.springframework.data - spring-data-jdbc-core - ${spring-data-jdbc.version} - - - org.springframework - * - - - - + + org.springframework.data + spring-data-jdbc-core + ${spring-data-jdbc.version} + + + org.springframework + * + + + + - - org.springframework - spring-jdbc - - - org.springframework - spring-webmvc - - - - org.springframework - spring-context-support - - - org.springframework - spring-oxm - + + org.springframework + spring-jdbc + + + org.springframework + spring-webmvc + + + + org.springframework + spring-context-support + + + org.springframework + spring-oxm + - - org.aspectj - aspectjrt - - - org.aspectj - aspectjweaver - runtime - - - - - org.apache.tomcat - tomcat-jdbc - runtime - + + org.apache.tomcat + tomcat-jdbc + runtime + + + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + runtime + + + + + joda-time + joda-time + + + joda-time + joda-time-hibernate + ${jodatime-hibernate.version} + + + joda-time + joda-time-jsptags + ${jodatime-jsptags.version} + - - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - runtime - - - - - joda-time - joda-time - - - joda-time - joda-time-hibernate - ${jodatime-hibernate.version} - - - joda-time - joda-time-jsptags - ${jodatime-jsptags.version} - + + + org.hsqldb + hsqldb + runtime + - - - org.hsqldb - hsqldb - runtime - + + - - + + + org.hibernate + hibernate-entitymanager + + + org.hibernate + hibernate-validator + - - - org.hibernate - hibernate-entitymanager - - - org.hibernate - hibernate-validator - - - - org.hibernate - hibernate-ehcache - - - net.sf.ehcache - ehcache-core - - - commons-logging - commons-logging - - - - - - org.webjars - bootstrap - ${webjars-bootstrap.version} - - - org.webjars - jquery-ui - ${webjars-jquery-ui.version} - - - org.webjars - jquery - ${webjars-jquery.version} - - - - - org.springframework - spring-test - test - - - junit - junit - test - - - org.assertj - assertj-core - ${assertj.version} - test - + + org.hibernate + hibernate-ehcache + + + net.sf.ehcache + ehcache-core + + + commons-logging + commons-logging + + + + + + org.webjars + bootstrap + ${webjars-bootstrap.version} + + + org.webjars + jquery-ui + ${webjars-jquery-ui.version} + + + org.webjars + jquery + ${webjars-jquery.version} + + + + + org.springframework + spring-test + test + + + junit + junit + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + com.github.dandelion + datatables-jsp + ${dandelion.version} + + + com.github.dandelion + datatables-export-itext + ${dandelion.version} + + + + com.googlecode.json-simple + json-simple + + - - - com.github.dandelion - datatables-jsp - ${dandelion.version} - - - com.github.dandelion - datatables-export-itext - ${dandelion.version} - - - - com.googlecode.json-simple - json-simple - - + + + install + + + + ${project.basedir}/src/test/java + + + ${project.basedir}/src/test/resources + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + + + + true + ${java.version} + ${java.version} + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.13 + + + **/*Tests.java + + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + petclinic + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.9 + + true + true + 2.0 + + **/*.* + + + + org.springframework.ide.eclipse.core.springbuilder + + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.jdt.core.javanature + org.springframework.ide.eclipse.core.springnature + org.eclipse.m2e.core.maven2Nature + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4 + + + jar-with-dependencies + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + tomcat-development-server + 9966 + /petclinic + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + + + + + clean + check + + + + + + + + - - - install - - - - ${project.basedir}/src/test/java - - - ${project.basedir}/src/test/resources - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.0 - - - - - true - ${java.version} - ${java.version} - true - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.13 - - - **/*Tests.java - - - - - org.apache.maven.plugins - maven-war-plugin - 2.3 - - petclinic - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.9 - - true - true - 2.0 - - **/*.* - - - - org.springframework.ide.eclipse.core.springbuilder - - - org.eclipse.m2e.core.maven2Builder - - - - org.eclipse.jdt.core.javanature - org.springframework.ide.eclipse.core.springnature - org.eclipse.m2e.core.maven2Nature - - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.4 - - - jar-with-dependencies - - - - - org.apache.tomcat.maven - tomcat7-maven-plugin - 2.2 - - tomcat-development-server - 9966 - /petclinic - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - - - - - clean - check - - - - - - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - html - - - - - - + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + html + + + + + + - demopetclinic + demopetclinic diff --git a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java index 8dfbfe90b43..55b470e1e3e 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java @@ -32,15 +32,14 @@ public class BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) protected Integer id; + public Integer getId() { + return id; + } public void setId(Integer id) { this.id = id; } - public Integer getId() { - return id; - } - public boolean isNew() { return (this.id == null); } diff --git a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java index cb36a6267a8..d66c97ae748 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java @@ -32,15 +32,14 @@ public class NamedEntity extends BaseEntity { @Column(name = "name") private String name; + public String getName() { + return this.name; + } public void setName(String name) { this.name = name; } - public String getName() { - return this.name; - } - @Override public String toString() { return this.getName(); diff --git a/src/main/java/org/springframework/samples/petclinic/model/Owner.java b/src/main/java/org/springframework/samples/petclinic/model/Owner.java index ca7c97ec271..d0158d907a4 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Owner.java @@ -85,10 +85,6 @@ public void setTelephone(String telephone) { this.telephone = telephone; } - protected void setPetsInternal(Set pets) { - this.pets = pets; - } - protected Set getPetsInternal() { if (this.pets == null) { this.pets = new HashSet<>(); @@ -96,6 +92,10 @@ protected Set getPetsInternal() { return this.pets; } + protected void setPetsInternal(Set pets) { + this.pets = pets; + } + public List getPets() { List sortedPets = new ArrayList<>(getPetsInternal()); PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true)); @@ -141,13 +141,13 @@ public Pet getPet(String name, boolean ignoreNew) { public String toString() { return new ToStringCreator(this) - .append("id", this.getId()) - .append("new", this.isNew()) - .append("lastName", this.getLastName()) - .append("firstName", this.getFirstName()) - .append("address", this.address) - .append("city", this.city) - .append("telephone", this.telephone) - .toString(); + .append("id", this.getId()) + .append("new", this.isNew()) + .append("lastName", this.getLastName()) + .append("firstName", this.getFirstName()) + .append("address", this.address) + .append("city", this.city) + .append("telephone", this.telephone) + .toString(); } } diff --git a/src/main/java/org/springframework/samples/petclinic/model/Pet.java b/src/main/java/org/springframework/samples/petclinic/model/Pet.java index 536fe07e694..09eeb769e2b 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Pet.java @@ -63,33 +63,28 @@ public class Pet extends NamedEntity { @OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER) private Set visits; - - public void setBirthDate(DateTime birthDate) { - this.birthDate = birthDate; - } - public DateTime getBirthDate() { return this.birthDate; } - public void setType(PetType type) { - this.type = type; + public void setBirthDate(DateTime birthDate) { + this.birthDate = birthDate; } public PetType getType() { return this.type; } - protected void setOwner(Owner owner) { - this.owner = owner; + public void setType(PetType type) { + this.type = type; } public Owner getOwner() { return this.owner; } - protected void setVisitsInternal(Set visits) { - this.visits = visits; + protected void setOwner(Owner owner) { + this.owner = owner; } protected Set getVisitsInternal() { @@ -99,6 +94,10 @@ protected Set getVisitsInternal() { return this.visits; } + protected void setVisitsInternal(Set visits) { + this.visits = visits; + } + public List getVisits() { List sortedVisits = new ArrayList<>(getVisitsInternal()); PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false)); diff --git a/src/main/java/org/springframework/samples/petclinic/model/PetType.java b/src/main/java/org/springframework/samples/petclinic/model/PetType.java index 99adf75917e..f60a5cd27a2 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/PetType.java +++ b/src/main/java/org/springframework/samples/petclinic/model/PetType.java @@ -20,7 +20,7 @@ /** * @author Juergen Hoeller - * Can be Cat, Dog, Hamster... + * Can be Cat, Dog, Hamster... */ @Entity @Table(name = "types") diff --git a/src/main/java/org/springframework/samples/petclinic/model/Vet.java b/src/main/java/org/springframework/samples/petclinic/model/Vet.java index 61c51878632..d93e14c4665 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Vet.java @@ -46,14 +46,9 @@ public class Vet extends Person { @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), - inverseJoinColumns = @JoinColumn(name = "specialty_id")) + inverseJoinColumns = @JoinColumn(name = "specialty_id")) private Set specialties; - - protected void setSpecialtiesInternal(Set specialties) { - this.specialties = specialties; - } - protected Set getSpecialtiesInternal() { if (this.specialties == null) { this.specialties = new HashSet<>(); @@ -61,6 +56,10 @@ protected Set getSpecialtiesInternal() { return this.specialties; } + protected void setSpecialtiesInternal(Set specialties) { + this.specialties = specialties; + } + @XmlElement public List getSpecialties() { List sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); diff --git a/src/main/java/org/springframework/samples/petclinic/model/package-info.java b/src/main/java/org/springframework/samples/petclinic/model/package-info.java index 2723dc9aba4..2730958db9e 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/package-info.java +++ b/src/main/java/org/springframework/samples/petclinic/model/package-info.java @@ -1,8 +1,5 @@ - /** - * * The classes in this package represent PetClinic's business layer. - * */ package org.springframework.samples.petclinic.model; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java index 1318337066d..a273a1f7f2d 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java @@ -53,7 +53,7 @@ public interface OwnerRepository { * * @param lastName Value to search for * @return a Collection of matching Owners (or an empty Collection if none - * found) + * found) */ Collection findByLastName(String lastName) throws DataAccessException; @@ -62,8 +62,7 @@ public interface OwnerRepository { * * @param id the id to search for * @return the Owner if found - * @throws org.springframework.dao.DataRetrievalFailureException - * if not found + * @throws org.springframework.dao.DataRetrievalFailureException if not found */ Owner findById(int id) throws DataAccessException; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java index 693b2e5e91e..1770e855503 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java @@ -45,8 +45,7 @@ public interface PetRepository { * * @param id the id to search for * @return the Pet if found - * @throws org.springframework.dao.DataRetrievalFailureException - * if not found + * @throws org.springframework.dao.DataRetrievalFailureException if not found */ Pet findById(int id) throws DataAccessException; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 7103dc4708d..45de1aee009 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -59,8 +59,8 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.insertOwner = new SimpleJdbcInsert(dataSource) - .withTableName("owners") - .usingGeneratedKeyColumns("id"); + .withTableName("owners") + .usingGeneratedKeyColumns("id"); this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); @@ -77,9 +77,9 @@ public Collection findByLastName(String lastName) throws DataAccessExcept Map params = new HashMap<>(); params.put("lastName", lastName + "%"); List owners = this.namedParameterJdbcTemplate.query( - "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName", - params, - BeanPropertyRowMapper.newInstance(Owner.class) + "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName", + params, + BeanPropertyRowMapper.newInstance(Owner.class) ); loadOwnersPetsAndVisits(owners); return owners; @@ -96,9 +96,9 @@ public Owner findById(int id) throws DataAccessException { Map params = new HashMap<>(); params.put("id", id); owner = this.namedParameterJdbcTemplate.queryForObject( - "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id", - params, - BeanPropertyRowMapper.newInstance(Owner.class) + "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id", + params, + BeanPropertyRowMapper.newInstance(Owner.class) ); } catch (EmptyResultDataAccessException ex) { throw new ObjectRetrievalFailureException(Owner.class, id); @@ -111,9 +111,9 @@ public void loadPetsAndVisits(final Owner owner) { Map params = new HashMap<>(); params.put("id", owner.getId()); final List pets = this.namedParameterJdbcTemplate.query( - "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", - params, - new JdbcPetVisitExtractor() + "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", + params, + new JdbcPetVisitExtractor() ); Collection petTypes = getPetTypes(); for (JdbcPet pet : pets) { @@ -130,16 +130,16 @@ public void save(Owner owner) throws DataAccessException { owner.setId(newKey.intValue()); } else { this.namedParameterJdbcTemplate.update( - "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " + - "city=:city, telephone=:telephone WHERE id=:id", - parameterSource); + "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " + + "city=:city, telephone=:telephone WHERE id=:id", + parameterSource); } } public Collection getPetTypes() throws DataAccessException { return this.namedParameterJdbcTemplate.query( - "SELECT id, name FROM types ORDER BY name", new HashMap(), - BeanPropertyRowMapper.newInstance(PetType.class)); + "SELECT id, name FROM types ORDER BY name", new HashMap(), + BeanPropertyRowMapper.newInstance(PetType.class)); } /** diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java index 39ba53b83a8..4c266b93172 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPet.java @@ -29,21 +29,20 @@ class JdbcPet extends Pet { private int ownerId; + public int getTypeId() { + return this.typeId; + } public void setTypeId(int typeId) { this.typeId = typeId; } - public int getTypeId() { - return this.typeId; + public int getOwnerId() { + return this.ownerId; } public void setOwnerId(int ownerId) { this.ownerId = ownerId; } - public int getOwnerId() { - return this.ownerId; - } - } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java index e3c02fc93fd..885c2bc2ff2 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java @@ -64,8 +64,8 @@ public JdbcPetRepositoryImpl(DataSource dataSource, OwnerRepository ownerReposit this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); this.insertPet = new SimpleJdbcInsert(dataSource) - .withTableName("pets") - .usingGeneratedKeyColumns("id"); + .withTableName("pets") + .usingGeneratedKeyColumns("id"); this.ownerRepository = ownerRepository; this.visitRepository = visitRepository; @@ -75,9 +75,9 @@ public JdbcPetRepositoryImpl(DataSource dataSource, OwnerRepository ownerReposit public List findPetTypes() throws DataAccessException { Map params = new HashMap<>(); return this.namedParameterJdbcTemplate.query( - "SELECT id, name FROM types ORDER BY name", - params, - BeanPropertyRowMapper.newInstance(PetType.class)); + "SELECT id, name FROM types ORDER BY name", + params, + BeanPropertyRowMapper.newInstance(PetType.class)); } @Override @@ -87,9 +87,9 @@ public Pet findById(int id) throws DataAccessException { Map params = new HashMap<>(); params.put("id", id); pet = this.namedParameterJdbcTemplate.queryForObject( - "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id", - params, - new JdbcPetRowMapper()); + "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id", + params, + new JdbcPetRowMapper()); } catch (EmptyResultDataAccessException ex) { throw new ObjectRetrievalFailureException(Pet.class, id); } @@ -108,13 +108,13 @@ public Pet findById(int id) throws DataAccessException { public void save(Pet pet) throws DataAccessException { if (pet.isNew()) { Number newKey = this.insertPet.executeAndReturnKey( - createPetParameterSource(pet)); + createPetParameterSource(pet)); pet.setId(newKey.intValue()); } else { this.namedParameterJdbcTemplate.update( - "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " + - "owner_id=:owner_id WHERE id=:id", - createPetParameterSource(pet)); + "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " + + "owner_id=:owner_id WHERE id=:id", + createPetParameterSource(pet)); } } @@ -123,11 +123,11 @@ public void save(Pet pet) throws DataAccessException { */ private MapSqlParameterSource createPetParameterSource(Pet pet) { return new MapSqlParameterSource() - .addValue("id", pet.getId()) - .addValue("name", pet.getName()) - .addValue("birth_date", pet.getBirthDate().toDate()) - .addValue("type_id", pet.getType().getId()) - .addValue("owner_id", pet.getOwner().getId()); + .addValue("id", pet.getId()) + .addValue("name", pet.getName()) + .addValue("birth_date", pet.getBirthDate().toDate()) + .addValue("type_id", pet.getType().getId()) + .addValue("owner_id", pet.getOwner().getId()); } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java index c40786d937e..6a4ba62c3e4 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java @@ -27,7 +27,7 @@ * {@link OneToManyResultSetExtractor} of Spring Data Core JDBC Extensions. */ public class JdbcPetVisitExtractor extends - OneToManyResultSetExtractor { + OneToManyResultSetExtractor { public JdbcPetVisitExtractor() { super(new JdbcPetRowMapper(), new JdbcVisitRowMapper()); @@ -51,4 +51,4 @@ protected Integer mapForeignKey(ResultSet rs) throws SQLException { protected void addChild(JdbcPet root, Visit child) { root.addVisit(child); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java index 79db917f9c6..0231275c1ca 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java @@ -60,25 +60,25 @@ public Collection findAll() throws DataAccessException { List vets = new ArrayList<>(); // Retrieve the list of all vets. vets.addAll(this.jdbcTemplate.query( - "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name", - BeanPropertyRowMapper.newInstance(Vet.class))); + "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name", + BeanPropertyRowMapper.newInstance(Vet.class))); // Retrieve the list of all possible specialties. final List specialties = this.jdbcTemplate.query( - "SELECT id, name FROM specialties", - BeanPropertyRowMapper.newInstance(Specialty.class)); + "SELECT id, name FROM specialties", + BeanPropertyRowMapper.newInstance(Specialty.class)); // Build each vet's list of specialties. for (Vet vet : vets) { final List vetSpecialtiesIds = this.jdbcTemplate.query( - "SELECT specialty_id FROM vet_specialties WHERE vet_id=?", - new BeanPropertyRowMapper() { - @Override - public Integer mapRow(ResultSet rs, int row) throws SQLException { - return rs.getInt(1); - } - }, - vet.getId()); + "SELECT specialty_id FROM vet_specialties WHERE vet_id=?", + new BeanPropertyRowMapper() { + @Override + public Integer mapRow(ResultSet rs, int row) throws SQLException { + return rs.getInt(1); + } + }, + vet.getId()); for (int specialtyId : vetSpecialtiesIds) { Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId); vet.addSpecialty(specialty); diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java index a923b7652bd..330ca1a4c8e 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java @@ -50,8 +50,8 @@ public JdbcVisitRepositoryImpl(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); this.insertVisit = new SimpleJdbcInsert(dataSource) - .withTableName("visits") - .usingGeneratedKeyColumns("id"); + .withTableName("visits") + .usingGeneratedKeyColumns("id"); } @@ -59,7 +59,7 @@ public JdbcVisitRepositoryImpl(DataSource dataSource) { public void save(Visit visit) throws DataAccessException { if (visit.isNew()) { Number newKey = this.insertVisit.executeAndReturnKey( - createVisitParameterSource(visit)); + createVisitParameterSource(visit)); visit.setId(newKey.intValue()); } else { throw new UnsupportedOperationException("Visit update not supported"); @@ -72,17 +72,17 @@ public void save(Visit visit) throws DataAccessException { */ private MapSqlParameterSource createVisitParameterSource(Visit visit) { return new MapSqlParameterSource() - .addValue("id", visit.getId()) - .addValue("visit_date", visit.getDate().toDate()) - .addValue("description", visit.getDescription()) - .addValue("pet_id", visit.getPet().getId()); + .addValue("id", visit.getId()) + .addValue("visit_date", visit.getDate().toDate()) + .addValue("description", visit.getDescription()) + .addValue("pet_id", visit.getPet().getId()); } @Override public List findByPetId(Integer petId) { return this.jdbcTemplate.query( - "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?", - new JdbcVisitRowMapper(), petId); + "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?", + new JdbcVisitRowMapper(), petId); } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java index edd0bf8556d..376da279fd4 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/package-info.java @@ -1,9 +1,6 @@ - /** - * * The classes in this package represent the JDBC implementation * of PetClinic's persistence layer. - * */ package org.springframework.samples.petclinic.repository.jdbc; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java index c7398df5ba5..3972dd349b6 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java @@ -43,7 +43,7 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository { /** - * Important: in the current version of this method, we load Owners with all their Pets and Visits while + * Important: in the current version of this method, we load Owners with all their Pets and Visits while * we do not need Visits at all and we only need one property from the Pet objects (the 'name' property). * There are some ways to improve it such as: * - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass) @@ -70,12 +70,11 @@ public Owner findById(int id) { @Override public void save(Owner owner) { - if (owner.getId() == null) { - this.em.persist(owner); - } - else { - this.em.merge(owner); - } + if (owner.getId() == null) { + this.em.persist(owner); + } else { + this.em.merge(owner); + } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java index 84d564da454..227140d96c1 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java @@ -53,12 +53,11 @@ public Pet findById(int id) { @Override public void save(Pet pet) { - if (pet.getId() == null) { - this.em.persist(pet); - } - else { - this.em.merge(pet); - } + if (pet.getId() == null) { + this.em.persist(pet); + } else { + this.em.merge(pet); + } } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java index 3415def96e1..5d1d42a07c3 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java @@ -45,12 +45,11 @@ public class JpaVisitRepositoryImpl implements VisitRepository { @Override public void save(Visit visit) { - if (visit.getId() == null) { - this.em.persist(visit); - } - else { - this.em.merge(visit); - } + if (visit.getId() == null) { + this.em.persist(visit); + } else { + this.em.merge(visit); + } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java index 13c8552edad..087dc15b663 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/package-info.java @@ -1,9 +1,6 @@ - /** - * * The classes in this package represent the JPA implementation * of PetClinic's persistence layer. - * */ package org.springframework.samples.petclinic.repository.jpa; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java index ca1f709f6f0..24c573eb7d4 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepository.java @@ -30,12 +30,12 @@ * @since 15.1.2013 */ public interface SpringDataOwnerRepository extends OwnerRepository, Repository { - - @Override - @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%") - public Collection findByLastName(@Param("lastName") String lastName); - - @Override - @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id") - public Owner findById(@Param("id") int id); + + @Override + @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%") + public Collection findByLastName(@Param("lastName") String lastName); + + @Override + @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id") + public Owner findById(@Param("id") int id); } diff --git a/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java b/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java index 494d6503eba..fddf17dfae2 100644 --- a/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java +++ b/src/main/java/org/springframework/samples/petclinic/util/CallMonitoringAspect.java @@ -26,8 +26,8 @@ /** * Simple aspect that monitors call count and call invocation time. It uses JMX annotations and therefore can be * monitored using any JMX console such as the jConsole - * - * This is only useful if you use JPA or JDBC. Spring-data-jpa doesn't have any correctly annotated classes to join on + *

+ * This is only useful if you use JPA or JDBC. Spring-data-jpa doesn't have any correctly annotated classes to join on * * @author Rob Harrop * @author Juergen Hoeller @@ -44,15 +44,14 @@ public class CallMonitoringAspect { private long accumulatedCallTime = 0; - @ManagedAttribute - public void setEnabled(boolean enabled) { - this.enabled = enabled; + public boolean isEnabled() { + return enabled; } @ManagedAttribute - public boolean isEnabled() { - return enabled; + public void setEnabled(boolean enabled) { + this.enabled = enabled; } @ManagedOperation @@ -68,10 +67,10 @@ public int getCallCount() { @ManagedAttribute public long getCallTime() { - if (this.callCount > 0) - return this.accumulatedCallTime / this.callCount; - else - return 0; + if (this.callCount > 0) + return this.accumulatedCallTime / this.callCount; + else + return 0; } diff --git a/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java b/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java index 41486a5a76d..eee39069453 100644 --- a/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java +++ b/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java @@ -39,11 +39,10 @@ public abstract class EntityUtils { * @param entityClass the entity class to look up * @param entityId the entity id to look up * @return the found entity - * @throws ObjectRetrievalFailureException - * if the entity was not found + * @throws ObjectRetrievalFailureException if the entity was not found */ public static T getById(Collection entities, Class entityClass, int entityId) - throws ObjectRetrievalFailureException { + throws ObjectRetrievalFailureException { for (T entity : entities) { if (entity.getId() == entityId && entityClass.isInstance(entity)) { return entity; diff --git a/src/main/java/org/springframework/samples/petclinic/web/CrashController.java b/src/main/java/org/springframework/samples/petclinic/web/CrashController.java index e413f3f3b8c..29c55c1c03a 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/CrashController.java +++ b/src/main/java/org/springframework/samples/petclinic/web/CrashController.java @@ -33,7 +33,7 @@ public class CrashController { @RequestMapping(value = "/oups", method = RequestMethod.GET) public String triggerException() { throw new RuntimeException("Expected: controller used to showcase what " + - "happens when an exception is thrown"); + "happens when an exception is thrown"); } diff --git a/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java index 9f2ffb05cb7..4b54e0f9b26 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java @@ -96,19 +96,17 @@ public String processFindForm(Owner owner, BindingResult result, Map model) { - // Here we are returning an object of type 'Vets' rather than a collection of Vet objects + // Here we are returning an object of type 'Vets' rather than a collection of Vet objects // so it is simpler for Object-Xml mapping Vets vets = new Vets(); vets.getVetList().addAll(this.clinicService.findVets()); model.put("vets", vets); return "vets/vetList"; } - + @RequestMapping("/vets.json") - public @ResponseBody Vets showResourcesVetList() { - // Here we are returning an object of type 'Vets' rather than a collection of Vet objects + public + @ResponseBody + Vets showResourcesVetList() { + // Here we are returning an object of type 'Vets' rather than a collection of Vet objects // so it is simpler for JSon/Object mapping Vets vets = new Vets(); vets.getVetList().addAll(this.clinicService.findVets()); diff --git a/src/main/java/org/springframework/samples/petclinic/web/VisitController.java b/src/main/java/org/springframework/samples/petclinic/web/VisitController.java index f3f6f3ffb54..144eba2d9d0 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/VisitController.java +++ b/src/main/java/org/springframework/samples/petclinic/web/VisitController.java @@ -53,13 +53,14 @@ public VisitController(ClinicService clinicService) { public void setAllowedFields(WebDataBinder dataBinder) { dataBinder.setDisallowedFields("id"); } - + /** - * Called before each and every @RequestMapping annotated method. - * 2 goals: - * - Make sure we always have fresh data - * - Since we do not use the session scope, make sure that Pet object always has an id - * (Even though id is not part of the form fields) + * Called before each and every @RequestMapping annotated method. + * 2 goals: + * - Make sure we always have fresh data + * - Since we do not use the session scope, make sure that Pet object always has an id + * (Even though id is not part of the form fields) + * * @param petId * @return Pet */ @@ -67,17 +68,17 @@ public void setAllowedFields(WebDataBinder dataBinder) { public Visit loadPetWithVisit(@PathVariable("petId") int petId) { Pet pet = this.clinicService.findPetById(petId); Visit visit = new Visit(); - pet.addVisit(visit); + pet.addVisit(visit); return visit; } - // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called + // Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called @RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET) public String initNewVisitForm(@PathVariable("petId") int petId, Map model) { return "pets/createOrUpdateVisitForm"; } - // Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called + // Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called @RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST) public String processNewVisitForm(@Valid Visit visit, BindingResult result) { if (result.hasErrors()) { diff --git a/src/main/java/org/springframework/samples/petclinic/web/package-info.java b/src/main/java/org/springframework/samples/petclinic/web/package-info.java index c909ccf7f04..ca189f19a84 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/package-info.java +++ b/src/main/java/org/springframework/samples/petclinic/web/package-info.java @@ -1,8 +1,5 @@ - /** - * * The classes in this package represent PetClinic's web presentation layer. - * */ package org.springframework.samples.petclinic.web; diff --git a/src/main/java/test.html b/src/main/java/test.html index 9a7a99675f4..8c5cb2cf3e7 100644 --- a/src/main/java/test.html +++ b/src/main/java/test.html @@ -1,39 +1,53 @@ - +

Organisation

Speakers

- - - - - - - - + + + + + + + +
- Sergiu Bodiu -

Sergiu Bodiu

-

Java Consultant at Bank of America

- Seasoned consultant experienced in large-scale e-commerce projects, passionate about providing innovative technology solutions to solve complex business problems, have extensive knowledge and experience delivering enterprise wide applications. He is skilled in software design, data modeling, stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, test and maintain software product components with strong focus on design elegance and software reuse. -
- Sergiu Bodiu -

Sergiu Bodiu

-

Java Consultant at Bank of America

- Seasoned consultant experienced in large-scale e-commerce projects, passionate about providing innovative technology solutions to solve complex business problems, have extensive knowledge and experience delivering enterprise wide applications. He is skilled in software design, data modeling, stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, test and maintain software product components with strong focus on design elegance and software reuse. -
+ Sergiu Bodiu + +

Sergiu Bodiu

+ +

Java Consultant at Bank of America

+ Seasoned consultant experienced in large-scale e-commerce projects, passionate about + providing innovative technology solutions to solve complex business problems, have extensive knowledge and + experience delivering enterprise wide applications. He is skilled in software design, data modeling, + stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, + test and maintain software product components with strong focus on design elegance and software reuse. +
+ Sergiu Bodiu + +

Sergiu Bodiu

+ +

Java Consultant at Bank of America

+ Seasoned consultant experienced in large-scale e-commerce projects, passionate about + providing innovative technology solutions to solve complex business problems, have extensive knowledge and + experience delivering enterprise wide applications. He is skilled in software design, data modeling, + stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, + test and maintain software product components with strong focus on design elegance and software reuse. +
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 830ef37debf..ba2b5146390 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -16,9 +16,9 @@ - + - + diff --git a/src/main/resources/spring/business-config.xml b/src/main/resources/spring/business-config.xml index 99cf4c1d309..a029c45ab15 100644 --- a/src/main/resources/spring/business-config.xml +++ b/src/main/resources/spring/business-config.xml @@ -2,36 +2,36 @@ - - + + base-package="org.springframework.samples.petclinic.service"/> - - - - - - + + + + + + @@ -93,4 +93,4 @@ - \ No newline at end of file + diff --git a/src/main/resources/spring/datasource-config.xml b/src/main/resources/spring/datasource-config.xml index f74129963b5..aa705de14d7 100644 --- a/src/main/resources/spring/datasource-config.xml +++ b/src/main/resources/spring/datasource-config.xml @@ -2,11 +2,11 @@ - - + - \ No newline at end of file + diff --git a/src/main/resources/spring/mvc-core-config.xml b/src/main/resources/spring/mvc-core-config.xml index eab2062dc33..641ea44087b 100644 --- a/src/main/resources/spring/mvc-core-config.xml +++ b/src/main/resources/spring/mvc-core-config.xml @@ -2,11 +2,11 @@ - + base-package="org.springframework.samples.petclinic.web"/> @@ -31,11 +31,11 @@ - + - - + @@ -53,7 +53,7 @@ p:basename="messages/messages"/> diff --git a/src/main/resources/spring/mvc-view-config.xml b/src/main/resources/spring/mvc-view-config.xml index 309707cf152..9ba6723c520 100644 --- a/src/main/resources/spring/mvc-view-config.xml +++ b/src/main/resources/spring/mvc-view-config.xml @@ -2,9 +2,9 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/src/main/resources/spring/tools-config.xml b/src/main/resources/spring/tools-config.xml index 1be7e3b6c75..61db5e57dbd 100644 --- a/src/main/resources/spring/tools-config.xml +++ b/src/main/resources/spring/tools-config.xml @@ -2,11 +2,11 @@ - <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> diff --git a/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp b/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp index 207a5b72710..3cb66aa2559 100644 --- a/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp +++ b/src/main/webapp/WEB-INF/jsp/fragments/bodyHeader.jsp @@ -14,7 +14,7 @@
  • "> Veterinarians
  • " - title="trigger a RuntimeException to see how it is handled"> Error
  • diff --git a/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp b/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp index f1eea21e63d..add28329ff2 100644 --- a/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp +++ b/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp @@ -18,13 +18,13 @@ PetClinic :: a Spring Framework demonstration - + - + - + diff --git a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp index a3cc2ade96a..0086220ce94 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> diff --git a/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp b/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp index 91d2ebabccb..662ac7ffded 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> diff --git a/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp b/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp index 4ace4ba2383..e4a970a2c7a 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> @@ -33,17 +33,17 @@ Telephone - - - + + + Edit Owner - + - Add New Pet + Add New Pet @@ -77,21 +77,21 @@ - - - - - - Edit Pet - - - - - - Add Visit + + + + + Edit Pet - + + + + + + Add Visit + + diff --git a/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp b/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp index 5e8eaaaaa90..68e4b0666ee 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> @@ -14,8 +14,8 @@

    Owners

    - - @@ -34,9 +34,9 @@ - + - +
    diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp index a3d144135df..387959b5d10 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdatePetForm.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> @@ -13,7 +13,7 @@
    diff --git a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp index 501a0d48e75..a5eb87fcd87 100644 --- a/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/pets/createOrUpdateVisitForm.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> @@ -16,7 +16,7 @@
    @@ -42,10 +42,10 @@ - - - - + + + +
    diff --git a/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp b/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp index 040679c282d..d2794718d80 100644 --- a/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp +++ b/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> @@ -16,7 +16,8 @@

    Veterinarians

    - + @@ -27,7 +28,7 @@ none - +
    diff --git a/src/main/webapp/WEB-INF/jsp/welcome.jsp b/src/main/webapp/WEB-INF/jsp/welcome.jsp index f33b84e5543..4bd4f767f85 100644 --- a/src/main/webapp/WEB-INF/jsp/welcome.jsp +++ b/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -1,4 +1,4 @@ - + <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index e699ca92d8e..ea965de257a 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,33 +1,33 @@ - Spring PetClinic Spring PetClinic sample application - - + + spring.profiles.active jpa - - + + - - - + + + + + - encodingFilter - org.springframework.web.filter.CharacterEncodingFilter - - encoding - UTF-8 - - - forceEncoding - true - - - - - encodingFilter - /* - - + encodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + forceEncoding + true + + + + + encodingFilter + /* + + dandelionFilter @@ -100,19 +100,19 @@ /* - - + + datatables com.github.dandelion.datatables.core.web.filter.DatatablesFilter - - + + datatables /* - - + + - \ No newline at end of file + diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java index f8582b5d9fb..b836d0cc2bd 100644 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java @@ -13,24 +13,22 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; /** - * * @author Michael Isvy - * Simple test to make sure that Bean Validation is working - * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) - * + * Simple test to make sure that Bean Validation is working + * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) */ public class ValidatorTests { - - private Validator createValidator() { - LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); - localValidatorFactoryBean.afterPropertiesSet(); - return localValidatorFactoryBean; - } - - @Test + + private Validator createValidator() { + LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); + localValidatorFactoryBean.afterPropertiesSet(); + return localValidatorFactoryBean; + } + + @Test public void shouldNotValidateWhenFirstNameEmpty() { - LocaleContextHolder.setLocale(Locale.ENGLISH); + LocaleContextHolder.setLocale(Locale.ENGLISH); Person person = new Person(); person.setFirstName(""); person.setLastName("smith"); @@ -39,9 +37,9 @@ public void shouldNotValidateWhenFirstNameEmpty() { Set> constraintViolations = validator.validate(person); assertThat(constraintViolations.size()).isEqualTo(1); - ConstraintViolation violation = constraintViolations.iterator().next(); + ConstraintViolation violation = constraintViolations.iterator().next(); assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); assertThat(violation.getMessage()).isEqualTo("may not be empty"); } - + } diff --git a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java index 473acdc6e07..0dd87379b8d 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java @@ -69,8 +69,8 @@ public void shouldFindSingleOwnerWithPet() { Owner owner = this.clinicService.findOwnerById(1); assertThat(owner.getLastName()).startsWith("Franklin"); assertThat(owner.getPets().size()).isEqualTo(1); - assertThat(owner.getPets().get(0).getType()).isNotNull(); - assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat"); + assertThat(owner.getPets().get(0).getType()).isNotNull(); + assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat"); } @Test @@ -78,7 +78,7 @@ public void shouldFindSingleOwnerWithPet() { public void shouldInsertOwner() { Collection owners = this.clinicService.findOwnerByLastName("Schultz"); int found = owners.size(); - + Owner owner = new Owner(); owner.setFirstName("Sam"); owner.setLastName("Schultz"); @@ -94,11 +94,11 @@ public void shouldInsertOwner() { @Test @Transactional - public void shouldUpdateOwner() { + public void shouldUpdateOwner() { Owner owner = this.clinicService.findOwnerById(1); String oldLastName = owner.getLastName(); String newLastName = oldLastName + "X"; - + owner.setLastName(newLastName); this.clinicService.saveOwner(owner); @@ -107,87 +107,87 @@ public void shouldUpdateOwner() { assertThat(owner.getLastName()).isEqualTo(newLastName); } - @Test - public void shouldFindPetWithCorrectId() { - Pet pet7 = this.clinicService.findPetById(7); - assertThat(pet7.getName()).startsWith("Samantha"); - assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean"); - - } - - @Test - public void shouldFindAllPetTypes() { - Collection petTypes = this.clinicService.findPetTypes(); - - PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); - assertThat(petType1.getName()).isEqualTo("cat"); - PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); - assertThat(petType4.getName()).isEqualTo("snake"); - } - - @Test - @Transactional - public void shouldInsertPetIntoDatabaseAndGenerateId() { - Owner owner6 = this.clinicService.findOwnerById(6); - int found = owner6.getPets().size(); - - Pet pet = new Pet(); - pet.setName("bowser"); - Collection types = this.clinicService.findPetTypes(); - pet.setType(EntityUtils.getById(types, PetType.class, 2)); - pet.setBirthDate(new DateTime()); - owner6.addPet(pet); - assertThat(owner6.getPets().size()).isEqualTo(found + 1); - - this.clinicService.savePet(pet); - this.clinicService.saveOwner(owner6); - - owner6 = this.clinicService.findOwnerById(6); - assertThat(owner6.getPets().size()).isEqualTo(found + 1); - // checks that id has been generated - assertThat(pet.getId()).isNotNull(); - } - - @Test - @Transactional - public void shouldUpdatePetName() throws Exception { - Pet pet7 = this.clinicService.findPetById(7); - String oldName = pet7.getName(); - - String newName = oldName + "X"; - pet7.setName(newName); - this.clinicService.savePet(pet7); - - pet7 = this.clinicService.findPetById(7); - assertThat(pet7.getName()).isEqualTo(newName); - } - - @Test - public void shouldFindVets() { - Collection vets = this.clinicService.findVets(); - - Vet vet = EntityUtils.getById(vets, Vet.class, 3); - assertThat(vet.getLastName()).isEqualTo("Douglas"); - assertThat(vet.getNrOfSpecialties()).isEqualTo(2); - assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry"); - assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery"); - } - - @Test - @Transactional - public void shouldAddNewVisitForPet() { - Pet pet7 = this.clinicService.findPetById(7); - int found = pet7.getVisits().size(); - Visit visit = new Visit(); - pet7.addVisit(visit); - visit.setDescription("test"); - this.clinicService.saveVisit(visit); - this.clinicService.savePet(pet7); - - pet7 = this.clinicService.findPetById(7); - assertThat(pet7.getVisits().size()).isEqualTo(found + 1); - assertThat(visit.getId()).isNotNull(); - } + @Test + public void shouldFindPetWithCorrectId() { + Pet pet7 = this.clinicService.findPetById(7); + assertThat(pet7.getName()).startsWith("Samantha"); + assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean"); + + } + + @Test + public void shouldFindAllPetTypes() { + Collection petTypes = this.clinicService.findPetTypes(); + + PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); + assertThat(petType1.getName()).isEqualTo("cat"); + PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); + assertThat(petType4.getName()).isEqualTo("snake"); + } + + @Test + @Transactional + public void shouldInsertPetIntoDatabaseAndGenerateId() { + Owner owner6 = this.clinicService.findOwnerById(6); + int found = owner6.getPets().size(); + + Pet pet = new Pet(); + pet.setName("bowser"); + Collection types = this.clinicService.findPetTypes(); + pet.setType(EntityUtils.getById(types, PetType.class, 2)); + pet.setBirthDate(new DateTime()); + owner6.addPet(pet); + assertThat(owner6.getPets().size()).isEqualTo(found + 1); + + this.clinicService.savePet(pet); + this.clinicService.saveOwner(owner6); + + owner6 = this.clinicService.findOwnerById(6); + assertThat(owner6.getPets().size()).isEqualTo(found + 1); + // checks that id has been generated + assertThat(pet.getId()).isNotNull(); + } + + @Test + @Transactional + public void shouldUpdatePetName() throws Exception { + Pet pet7 = this.clinicService.findPetById(7); + String oldName = pet7.getName(); + + String newName = oldName + "X"; + pet7.setName(newName); + this.clinicService.savePet(pet7); + + pet7 = this.clinicService.findPetById(7); + assertThat(pet7.getName()).isEqualTo(newName); + } + + @Test + public void shouldFindVets() { + Collection vets = this.clinicService.findVets(); + + Vet vet = EntityUtils.getById(vets, Vet.class, 3); + assertThat(vet.getLastName()).isEqualTo("Douglas"); + assertThat(vet.getNrOfSpecialties()).isEqualTo(2); + assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry"); + assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery"); + } + + @Test + @Transactional + public void shouldAddNewVisitForPet() { + Pet pet7 = this.clinicService.findPetById(7); + int found = pet7.getVisits().size(); + Visit visit = new Visit(); + pet7.addVisit(visit); + visit.setDescription("test"); + this.clinicService.saveVisit(visit); + this.clinicService.savePet(pet7); + + pet7 = this.clinicService.findPetById(7); + assertThat(pet7.getVisits().size()).isEqualTo(found + 1); + assertThat(visit.getId()).isNotNull(); + } } diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java index 49e57ea4021..74c5df7cf56 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java @@ -21,11 +21,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - *

    Integration test using the jdbc profile. - * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    + *

    Integration test using the jdbc profile. * * @author Thomas Risberg * @author Michael Isvy + * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    */ @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) @RunWith(SpringJUnit4ClassRunner.class) diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java index e024f21fd09..dba2b195a0b 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java @@ -1,4 +1,3 @@ - package org.springframework.samples.petclinic.service; import org.junit.runner.RunWith; @@ -7,12 +6,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - *

    Integration test using the jpa profile. - * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    + *

    Integration test using the jpa profile. * * @author Rod Johnson * @author Sam Brannen * @author Michael Isvy + * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    */ @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) @@ -20,4 +19,4 @@ @ActiveProfiles("jpa") public class ClinicServiceJpaTests extends AbstractClinicServiceTests { -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java index e01dda55168..31b62289fa1 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java @@ -1,4 +1,3 @@ - package org.springframework.samples.petclinic.service; import org.junit.runner.RunWith; @@ -7,9 +6,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - *

    Integration test using the 'Spring Data' profile. - * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    + *

    Integration test using the 'Spring Data' profile. + * * @author Michael Isvy + * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details.

    */ @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) @@ -17,4 +17,4 @@ @ActiveProfiles("spring-data-jpa") public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests { -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java index 61e6d32876f..28b9348a100 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java @@ -40,9 +40,9 @@ public void setup() { @Test public void testGetExistingUser() throws Exception { - ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()); - actions.andExpect(content().contentType("application/json;charset=UTF-8")) - .andExpect(jsonPath("$.vetList[0].id").value(1)); + ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + actions.andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$.vetList[0].id").value(1)); } }