diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..de9af4689 --- /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 504e97c35..d4c16ce5b 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 + + + + + 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 - - 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 + javax.servlet.jsp.jstl + javax.servlet.jsp.jstl-api - - org.apache.taglibs - taglibs-standard-jstlel - - - + + 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 + - - - org.hsqldb - hsqldb - 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.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 - + + - - - com.github.dandelion - datatables-jsp - ${dandelion.version} - - - com.github.dandelion - datatables-export-itext - ${dandelion.version} - - - - com.googlecode.json-simple - json-simple - - + + + org.hibernate + hibernate-entitymanager + + + org.hibernate + hibernate-validator + - - - 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.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} + - demopetclinic + + + 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 + + + + + + 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 + + + + + + + + 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 8dfbfe90b..55b470e1e 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 cb36a6267..d66c97ae7 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 ca7c97ec2..d0158d907 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 class Owner extends Person { 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 @@ public class Owner extends Person { 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 class Owner extends Person { 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 536fe07e6..09eeb769e 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 @@ public class Pet extends NamedEntity { 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 99adf7591..f60a5cd27 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 @@ import javax.persistence.Table; /** * @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 61c518786..d93e14c46 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 @@ public class Vet extends Person { 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 2723dc9ab..2730958db 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 131833706..a273a1f7f 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 693b2e5e9..1770e8555 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 7103dc470..45de1aee0 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 class JdbcOwnerRepositoryImpl implements OwnerRepository { 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 class JdbcOwnerRepositoryImpl implements OwnerRepository { 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 class JdbcOwnerRepositoryImpl implements OwnerRepository { 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 class JdbcOwnerRepositoryImpl implements OwnerRepository { 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 39ba53b83..4c266b931 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 void setTypeId(int typeId) { - this.typeId = typeId; - } - public int getTypeId() { return this.typeId; } - public void setOwnerId(int ownerId) { - this.ownerId = ownerId; + public void setTypeId(int typeId) { + this.typeId = typeId; } public int getOwnerId() { return this.ownerId; } + public void setOwnerId(int ownerId) { + this.ownerId = 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 e3c02fc93..885c2bc2f 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 class JdbcPetRepositoryImpl implements PetRepository { 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 class JdbcPetRepositoryImpl implements PetRepository { 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 class JdbcPetRepositoryImpl implements PetRepository { 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 class JdbcPetRepositoryImpl implements PetRepository { 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 class JdbcPetRepositoryImpl implements PetRepository { */ 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 c40786d93..6a4ba62c3 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 @@ import java.sql.SQLException; * {@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 @@ public class JdbcPetVisitExtractor extends 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 79db917f9..0231275c1 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 class JdbcVetRepositoryImpl implements VetRepository { 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 a923b7652..330ca1a4c 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 class JdbcVisitRepositoryImpl implements VisitRepository { this.jdbcTemplate = new JdbcTemplate(dataSource); this.insertVisit = new SimpleJdbcInsert(dataSource) - .withTableName("visits") - .usingGeneratedKeyColumns("id"); + .withTableName("visits") + .usingGeneratedKeyColumns("id"); } @@ -59,7 +59,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository { 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 class JdbcVisitRepositoryImpl implements VisitRepository { */ 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 edd0bf855..376da279f 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 c7398df5b..3972dd349 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 class JpaOwnerRepositoryImpl implements OwnerRepository { @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 84d564da4..227140d96 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 class JpaPetRepositoryImpl implements PetRepository { @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 3415def96..5d1d42a07 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 13c8552ed..087dc15b6 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 ca1f709f6..24c573eb7 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 @@ import org.springframework.samples.petclinic.repository.OwnerRepository; * @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 494d6503e..fddf17dfa 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 @@ import org.springframework.util.StopWatch; /** * 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,17 +44,16 @@ public class CallMonitoringAspect { private long accumulatedCallTime = 0; - - @ManagedAttribute - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - @ManagedAttribute public boolean isEnabled() { return enabled; } + @ManagedAttribute + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + @ManagedOperation public void reset() { this.callCount = 0; @@ -68,10 +67,10 @@ public class CallMonitoringAspect { @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 41486a5a7..eee390694 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 e413f3f3b..29c55c1c0 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 9f2ffb05c..4b54e0f9b 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 class OwnerController { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; - } - else if (results.size() == 1) { - // 1 owner found - owner = results.iterator().next(); - return "redirect:/owners/" + owner.getId(); - } - else { + } else if (results.size() == 1) { + // 1 owner found + owner = results.iterator().next(); + return "redirect:/owners/" + owner.getId(); + } else { // multiple owners found model.put("selections", results); return "owners/ownersList"; } } - + @RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET) public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { Owner owner = this.clinicService.findOwnerById(ownerId); diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java b/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java index 5784278b9..3aefb024e 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java +++ b/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java @@ -41,14 +41,14 @@ public class PetValidator implements Validator { } else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) { errors.rejectValue("name", "duplicate", "already exists"); } - + // type validation if (pet.isNew() && pet.getType() == null) { errors.rejectValue("type", "required", "required"); } - + // birth date validation - if (pet.getBirthDate()==null) { + if (pet.getBirthDate() == null) { errors.rejectValue("birthDate", "required", "required"); } } diff --git a/src/main/java/org/springframework/samples/petclinic/web/VetController.java b/src/main/java/org/springframework/samples/petclinic/web/VetController.java index ebbb8d6e2..3121e60e8 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/web/VetController.java @@ -41,19 +41,21 @@ public class VetController { this.clinicService = clinicService; } - @RequestMapping(value={"/vets.xml","/vets.html"}) + @RequestMapping(value = {"/vets.xml", "/vets.html"}) public String showVetList(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 f3f6f3ffb..144eba2d9 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 class VisitController { 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 class VisitController { 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 c909ccf7f..ca189f19a 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 9a7a99675..8c5cb2cf3 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 830ef37de..ba2b51463 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 99cf4c1d3..a029c45ab 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 f74129963..aa705de14 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 eab2062dc..641ea4408 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 309707cf1..9ba6723c5 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 1be7e3b6c..61db5e57d 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 207a5b727..3cb66aa25 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 f1eea21e6..add28329f 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 a3cc2ade9..0086220ce 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 91d2ebabc..662ac7ffd 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 4ace4ba23..e4a970a2c 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 5e8eaaaaa..68e4b0666 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 a3d144135..387959b5d 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 501a0d48e..a5eb87fcd 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 040679c28..d2794718d 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 f33b84e55..4bd4f767f 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 e699ca92d..ea965de25 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 f8582b5d9..b836d0cc2 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.context.i18n.LocaleContextHolder; 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 class ValidatorTests { 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 473acdc6e..0dd87379b 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 abstract class AbstractClinicServiceTests { 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 abstract class AbstractClinicServiceTests { 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 abstract class AbstractClinicServiceTests { @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 abstract class AbstractClinicServiceTests { 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 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 + public void shouldFindAllPetTypes() { + Collection petTypes = this.clinicService.findPetTypes(); - @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); + 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"); + } - pet7 = this.clinicService.findPetById(7); - assertThat(pet7.getName()).isEqualTo(newName); - } + @Test + @Transactional + public void shouldInsertPetIntoDatabaseAndGenerateId() { + Owner owner6 = this.clinicService.findOwnerById(6); + int found = owner6.getPets().size(); - @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"); - } + 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); - @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); + this.clinicService.savePet(pet); + this.clinicService.saveOwner(owner6); - pet7 = this.clinicService.findPetById(7); - assertThat(pet7.getVisits().size()).isEqualTo(found + 1); - assertThat(visit.getId()).isNotNull(); - } + 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 49e57ea40..74c5df7cf 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.ContextConfiguration; 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 e024f21fd..dba2b195a 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.ContextConfiguration; 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 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @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 e01dda551..31b62289f 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.ContextConfiguration; 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 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @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 61e6d3287..28b9348a1 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 class VetControllerTests { @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)); } }