diff --git a/.editorconfig b/.editorconfig
index 8d67bc7a5..86fab8827 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,12 +1,12 @@
-# top-most EditorConfig file
-root = true
-
-[*]
-charset = utf-8
-end_of_line = lf
-insert_final_newline = true
-indent_style = space
-
-[*.{java,xml}]
-indent_size = 4
-trim_trailing_whitespace = true
+# top-most EditorConfig file
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+
+[*.{java,xml}]
+indent_size = 4
+trim_trailing_whitespace = true
diff --git a/.gitignore b/.gitignore
index b00af803d..7930f3799 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,15 @@
-target/*
-.settings/*
-.classpath
-.project
-.idea
-*.iml
-/target
-_site/
+target/*
+.settings/*
+.classpath
+.project
+.idea
+*.iml
+/target
+_site/
+.DS_Store
+.log
+.editorconfig
+.springBeans
+Servers
+.metadata
+bin
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index 25cc8af3c..35a6d06c3 100644
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -1 +1 @@
-distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
+distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
diff --git a/.springBeans b/.springBeans
index 44f18becd..3a9e788ac 100644
--- a/.springBeans
+++ b/.springBeans
@@ -1,20 +1,20 @@
-
-
- 1
-
-
-
-
-
-
- src/main/resources/spring/datasource-config.xml
- src/main/resources/spring/mvc-core-config.xml
- src/main/resources/spring/mvc-view-config.xml
- src/main/resources/spring/business-config.xml
-
-
- src/main/resources/spring/tools-config.xml
-
-
-
-
+
+
+ 1
+
+
+
+
+
+
+ src/main/resources/spring/datasource-config.xml
+ src/main/resources/spring/mvc-core-config.xml
+ src/main/resources/spring/mvc-view-config.xml
+ src/main/resources/spring/business-config.xml
+
+
+ src/main/resources/spring/tools-config.xml
+
+
+
+
diff --git a/.travis.yml b/.travis.yml
index c0f28cfa4..9ff99e4ad 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,2 +1,2 @@
-language: java
-jdk: oraclejdk8
+language: java
+jdk: oraclejdk8
diff --git a/docker-compose.yml b/docker-compose.yml
index 1631ec9fa..f11113f73 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,9 +1,9 @@
-mysql:
- image: mysql
- ports:
- - "3306:3306"
- environment:
- - MYSQL_ROOT_PASSWORD=root
- - MYSQL_DATABASE=test
- volumes:
+mysql:
+ image: mysql
+ ports:
+ - "3306:3306"
+ environment:
+ - MYSQL_ROOT_PASSWORD=root
+ - MYSQL_DATABASE=test
+ volumes:
- "./conf.d:/etc/mysql/conf.d:ro"
\ No newline at end of file
diff --git a/kidclinic b/kidclinic
new file mode 160000
index 000000000..f08660d47
--- /dev/null
+++ b/kidclinic
@@ -0,0 +1 @@
+Subproject commit f08660d47ba9b90d4416860808decf90768838e7
diff --git a/kill.sh b/kill.sh
new file mode 100755
index 000000000..702b526d0
--- /dev/null
+++ b/kill.sh
@@ -0,0 +1 @@
+killall java
diff --git a/pom.xml b/pom.xml
index ff677d097..6010d2c56 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,229 +1,229 @@
-
-
- 4.0.0
- org.springframework.samples
- spring-petclinic
- 1.5.1
-
-
- org.springframework.boot
- spring-boot-starter-parent
- 1.5.1.RELEASE
-
- petclinic
-
-
-
-
- 1.8
- UTF-8
- UTF-8
-
-
- 3.3.6
- 1.11.4
- 2.2.4
- 1.8.0
-
- 3.0.2.RELEASE
-
- 2.7
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
- org.springframework.boot
- spring-boot-starter-cache
-
-
- org.springframework.boot
- spring-boot-starter-data-jpa
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- org.springframework.boot
- spring-boot-starter-thymeleaf
-
-
- nz.net.ultraq.thymeleaf
- thymeleaf-layout-dialect
-
-
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
-
- org.hsqldb
- hsqldb
- runtime
-
-
- mysql
- mysql-connector-java
- runtime
-
-
-
-
- javax.cache
- cache-api
-
-
- org.ehcache
- ehcache
-
-
-
-
- org.webjars
- webjars-locator
-
-
- org.webjars
- jquery
- ${webjars-jquery.version}
-
-
- org.webjars
- jquery-ui
- ${webjars-jquery-ui.version}
-
-
- org.webjars
- bootstrap
- ${webjars-bootstrap.version}
-
-
-
-
- org.springframework.boot
- spring-boot-devtools
- runtime
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
-
- build-info
-
-
-
- ${project.build.sourceEncoding}
- ${project.reporting.outputEncoding}
- ${maven.compiler.source}
- ${maven.compiler.target}
-
-
-
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- ${cobertura.version}
-
-
-
-
-
-
- clean
- check
-
-
-
-
-
-
-
- pl.project13.maven
- git-commit-id-plugin
-
-
-
- revision
-
-
-
-
- true
- yyyy-MM-dd'T'HH:mm:ssZ
- true
- ${project.build.outputDirectory}/git.properties
-
- false
-
-
-
-
- ro.isdc.wro4j
- wro4j-maven-plugin
- ${wro4j.version}
-
-
- generate-resources
-
- run
-
-
-
-
- ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory
- ${project.build.directory}/classes/static/resources/css
- ${basedir}/src/main/wro/wro.xml
- ${basedir}/src/main/wro/wro.properties
- ${basedir}/src/main/less
-
-
-
- org.webjars
- bootstrap
- ${webjars-bootstrap.version}
-
-
-
-
-
-
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- ${cobertura.version}
-
-
- html
-
-
-
-
-
-
-
-
+
+
+ 4.0.0
+ org.springframework.samples
+ kidclinic
+ mvp
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.5.1.RELEASE
+
+ kidclinic
+
+
+
+
+ 1.8
+ UTF-8
+ UTF-8
+
+
+ 3.3.6
+ 1.11.4
+ 2.2.4
+ 1.8.0
+
+ 3.0.2.RELEASE
+
+ 2.7
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+ org.springframework.boot
+ spring-boot-starter-cache
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+ nz.net.ultraq.thymeleaf
+ thymeleaf-layout-dialect
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+ org.hsqldb
+ hsqldb
+ runtime
+
+
+ mysql
+ mysql-connector-java
+ runtime
+
+
+
+
+ javax.cache
+ cache-api
+
+
+ org.ehcache
+ ehcache
+
+
+
+
+ org.webjars
+ webjars-locator
+
+
+ org.webjars
+ jquery
+ ${webjars-jquery.version}
+
+
+ org.webjars
+ jquery-ui
+ ${webjars-jquery-ui.version}
+
+
+ org.webjars
+ bootstrap
+ ${webjars-bootstrap.version}
+
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+ build-info
+
+
+
+ ${project.build.sourceEncoding}
+ ${project.reporting.outputEncoding}
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ ${cobertura.version}
+
+
+
+
+
+
+ clean
+ check
+
+
+
+
+
+
+
+ pl.project13.maven
+ git-commit-id-plugin
+
+
+
+ revision
+
+
+
+
+ true
+ yyyy-MM-dd'T'HH:mm:ssZ
+ true
+ ${project.build.outputDirectory}/git.properties
+
+ false
+
+
+
+
+ ro.isdc.wro4j
+ wro4j-maven-plugin
+ ${wro4j.version}
+
+
+ generate-resources
+
+ run
+
+
+
+
+ ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory
+ ${project.build.directory}/classes/static/resources/css
+ ${basedir}/src/main/wro/wro.xml
+ ${basedir}/src/main/wro/wro.properties
+ ${basedir}/src/main/less
+
+
+
+ org.webjars
+ bootstrap
+ ${webjars-bootstrap.version}
+
+
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ ${cobertura.version}
+
+
+ html
+
+
+
+
+
+
+
+
diff --git a/readme.md b/readme.md
index ac30d6392..9e3971642 100644
--- a/readme.md
+++ b/readme.md
@@ -1,105 +1,52 @@
-# Spring PetClinic Sample Application [](https://travis-ci.org/spring-projects/spring-petclinic/)
-
-## Understanding the Spring Petclinic application with a few diagrams
-See the presentation here
-
-## Running petclinic locally
-```
- git clone https://github.com/spring-projects/spring-petclinic.git
- cd spring-petclinic
- ./mvnw spring-boot:run
-```
-
-You can then access petclinic here: http://localhost:8080/
-
-
-
-## In case you find a bug/suggested improvement for Spring Petclinic
-Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues
-
-
-## Database configuration
-
-In its default configuration, Petclinic uses an in-memory database (HSQLDB) which
-gets populated at startup with data. A similar setup is provided for MySql in case a persistent database configuration is needed.
-Note that whenever the database type is changed, the data-access.properties file needs to be updated and the mysql-connector-java artifact from the pom.xml needs to be uncommented.
-
-You could start a MySql database with docker:
-
-```
-docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
-```
-
-## Working with Petclinic in Eclipse/STS
-
-### prerequisites
-The following items should be installed in your system:
-* Maven 3 (http://www.sonatype.com/books/mvnref-book/reference/installation.html)
-* git command line tool (https://help.github.com/articles/set-up-git)
-* Eclipse with the m2e plugin (m2e is installed by default when using the STS (http://www.springsource.org/sts) distribution of Eclipse)
-
-Note: when m2e is available, there is an m2 icon in Help -> About dialog.
-If m2e is not there, just follow the install process here: http://eclipse.org/m2e/download/
-
-
-### Steps:
-
-1) In the command line
-```
-git clone https://github.com/spring-projects/spring-petclinic.git
-```
-2) Inside Eclipse
-```
-File -> Import -> Maven -> Existing Maven project
-```
-
-
-## Looking for something in particular?
-
-|Spring Boot Configuration | Class or Java property files |
-|--------------------------|---|
-|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
-|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/resources) |
-|Caching | [CacheConfig](https://github.com/spring-projects/spring-petclinic/blob/master/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java) |
-
-## Interesting Spring Petclinic branches and forks
-
-The Spring Petclinic master branch in the main
-[spring-projects](https://github.com/spring-projects/spring-petclinic)
-GitHub org is the "canonical" implementation, currently based on
-Spring Boot and Thymeleaf. There are quite a few forks in a special
-GitHub org [spring-petclinic](https://github.com/spring-petclinic). If
-you have a special interest in a different technology stack that could
-be used to implement the Pet Clinic then please join the community
-there.
-
-| Link | Main technologies |
-|----------------|-------------------|
-| [spring-framework-petclinic](https://github.com/spring-petclinic/spring-framework-petclinic) | Spring Framework XML configuration, JSP pages, 3 persistence layers: JDBC, JPA and Spring Data JPA |
-| [javaconfig branch](https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig) | Same frameworks as the [spring-framework-petclinic](https://github.com/spring-petclinic/spring-framework-petclinic) but with Java Configuration instead of XML |
-| [spring-petclinic-angular](https://github.com/spring-petclinic/spring-petclinic-angularjs) | AngularJS 1.x, Spring Boot and Spring Data JPA |
-| [spring-petclinic-microservices](https://github.com/spring-petclinic/spring-petclinic-microservices) | Distributed version of Spring Petclinic built with Spring Cloud |
-| [spring-petclinic-reactjs](https://github.com/spring-petclinic/spring-petclinic-reactjs) | ReactJS (with TypeScript) and Spring Boot |
-
-
-## Interaction with other open source projects
-
-One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
-Here is a list of them:
-
-| Name | Issue |
-|------|-------|
-| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) |
-| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
-| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) |
-
-
-# Contributing
-
-The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests.
-
-For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at .
-
-
-
-
+# GlowTouch KidClinic (built on Spring)
+
+## Running Kidclinic locally
+```bash
+ git clone https://github.com/sasankglowtouch/kidclinic.git
+ cd kidclinic
+ ./mvnw spring-boot:run
+```
+
+You can then access KidClinic here: http://localhost:8080/
+
+## The Purpose of KidClinic
+The purpose of KidClinic is to simulate the building of an enterprise application using Java and Spring. Being built off of Spring's PetClinic, KidClinic is used to understand the process of building an app in order to gain knowledge and make future development more efficient and successful.
+
+## Current Features
+- [x] Adding new parents and children
+- [x] View current list of doctors and their specialities
+- [x] Search through database of parents
+
+### Adding parents and children
+When viewing the parents page, users have an option of searching the parents database or adding a parent. Once a parent is chosen or added, a child can be added to that parent.
+
+## Upcoming Additions
+| Addition | Stage of Development | Expected Development Time | Lead |
+| :-------- | :-------------------- | :------------------------- | :--- |
+| Login system | Research | Short Term | Emily |
+| Updated child's information | Implementation | Immediate | Daniel |
+| Google Map API integration | Research | Long Term | Austin |
+| Add reviews section for doctors | Development | Short Term | Sasank |
+| Calendar Scheduling | Research | Long Term | Sasank |
+
+### Login System
+THe login system is meant to create three different views for users. There will be three categories of users: parents, nurses, and doctors. Each must login to view certain aspects of the website. Without the login system, the all the information of the parents is viewable without any security.
+
+#### How to incorporate the login system
+In order to create a login system, we need to create a subfolder for the login controller. This follows [DoctorController.java](/src/main/java/org/springframework/samples/kidclinic/doctor/DoctorController.java) for the methods.
+
+### Reviews section for Doctors
+The reviews section is meant to show the location of the doctors and include a view reviews for each doctor.
+
+#### How to incorporate the reviews
+In order the create the reviews section, we must create a controller similar to [DoctorController.java](/src/main/java/org/springframework/samples/kidclinic/doctor/DoctorController.java). Then we need to add some reviews to the database as well as locations of each doctor. Then, using [Thymeleaf](http://www.thymeleaf.org/), we can display this information in [reviews.html](/src/main/resources/templates/reviews.html).
+
+## Contact
+If you are interested in the development of this app, you can contact any of the developers. You can reach us at
+
+| Name | Email |
+| :--- | :---- |
+| Emily Liu | emily.liu@glowtouch.com |
+| Austin Mills | austin.mills@glowtouch.com |
+| Daniel Ryan | daniel.ryan@glowtouch.com |
+| Sasank Vishnubhatla | sasank.vishnubhatla@glowtouch.com |
diff --git a/run.sh b/run.sh
new file mode 100755
index 000000000..22d797a49
--- /dev/null
+++ b/run.sh
@@ -0,0 +1 @@
+./mvnw spring-boot:run &
diff --git a/sonar-project.properties b/sonar-project.properties
index d84ed7c2d..104418194 100755
--- a/sonar-project.properties
+++ b/sonar-project.properties
@@ -1,13 +1,13 @@
-# Required metadata
-sonar.projectKey=java-sonar-runner-simple
-sonar.projectName=Simple Java project analyzed with the SonarQube Runner
-sonar.projectVersion=1.0
-
-# Comma-separated paths to directories with sources (required)
-sonar.sources=src
-
-# Language
-sonar.language=java
-
-# Encoding of the source files
+# Required metadata
+sonar.projectKey=java-sonar-runner-simple
+sonar.projectName=Simple Java project analyzed with the SonarQube Runner
+sonar.projectVersion=1.0
+
+# Comma-separated paths to directories with sources (required)
+sonar.sources=src
+
+# Language
+sonar.language=java
+
+# Encoding of the source files
sonar.sourceEncoding=UTF-8
\ No newline at end of file
diff --git a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java b/src/main/java/org/springframework/samples/kidclinic/KidClinicApplication.java
similarity index 79%
rename from src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
rename to src/main/java/org/springframework/samples/kidclinic/KidClinicApplication.java
index 224c326c7..5b7677f64 100644
--- a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java
+++ b/src/main/java/org/springframework/samples/kidclinic/KidClinicApplication.java
@@ -1,35 +1,35 @@
-/*
- * Copyright 2002-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.samples.petclinic;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-/**
- * PetClinic Spring Boot Application.
- *
- * @author Dave Syer
- *
- */
-@SpringBootApplication
-public class PetClinicApplication {
-
- public static void main(String[] args) throws Exception {
- SpringApplication.run(PetClinicApplication.class, args);
- }
-
-}
+/*
+ * Copyright 2002-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.samples.kidclinic;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * KidClinic Spring Boot Application.
+ *
+ * @author Dave Syer
+ *
+ */
+@SpringBootApplication
+public class KidClinicApplication {
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(KidClinicApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java b/src/main/java/org/springframework/samples/kidclinic/doctor/Doctor.java
similarity index 65%
rename from src/main/java/org/springframework/samples/petclinic/vet/Vet.java
rename to src/main/java/org/springframework/samples/kidclinic/doctor/Doctor.java
index 43aecc41e..153adbbbe 100644
--- a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java
+++ b/src/main/java/org/springframework/samples/kidclinic/doctor/Doctor.java
@@ -1,79 +1,117 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.vet;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-import javax.xml.bind.annotation.XmlElement;
-
-import org.springframework.beans.support.MutableSortDefinition;
-import org.springframework.beans.support.PropertyComparator;
-import org.springframework.samples.petclinic.model.Person;
-
-/**
- * Simple JavaBean domain object representing a veterinarian.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Arjen Poutsma
- */
-@Entity
-@Table(name = "vets")
-public class Vet extends Person {
-
- @ManyToMany(fetch = FetchType.EAGER)
- @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), inverseJoinColumns = @JoinColumn(name = "specialty_id"))
- private Set specialties;
-
- protected Set getSpecialtiesInternal() {
- if (this.specialties == null) {
- this.specialties = new HashSet<>();
- }
- return this.specialties;
- }
-
- protected void setSpecialtiesInternal(Set specialties) {
- this.specialties = specialties;
- }
-
- @XmlElement
- public List getSpecialties() {
- List sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
- PropertyComparator.sort(sortedSpecs,
- new MutableSortDefinition("name", true, true));
- return Collections.unmodifiableList(sortedSpecs);
- }
-
- public int getNrOfSpecialties() {
- return getSpecialtiesInternal().size();
- }
-
- public void addSpecialty(Specialty specialty) {
- getSpecialtiesInternal().add(specialty);
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.doctor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlElement;
+
+import org.hibernate.validator.constraints.NotEmpty;
+import org.springframework.beans.support.MutableSortDefinition;
+import org.springframework.beans.support.PropertyComparator;
+import org.springframework.samples.kidclinic.model.Person;
+
+/**
+ * Simple JavaBean domain object representing a veterinarian.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Arjen Poutsma
+ */
+@Entity
+@Table(name = "doctors")
+public class Doctor extends Person {
+
+ @ManyToMany(fetch = FetchType.EAGER)
+ @JoinTable(name = "doctor_specialties", joinColumns = @JoinColumn(name = "doctor_id"), inverseJoinColumns = @JoinColumn(name = "specialty_id"))
+ private Set specialties;
+
+ @Column(name = "address")
+ @NotEmpty
+ private String address;
+
+ @Column(name = "city")
+ @NotEmpty
+ private String city;
+
+ @Column(name = "state")
+ @NotEmpty
+ private String state;
+
+ protected Set getSpecialtiesInternal() {
+ if (this.specialties == null) {
+ this.specialties = new HashSet<>();
+ }
+ return this.specialties;
+ }
+
+ protected void setSpecialtiesInternal(Set specialties) {
+ this.specialties = specialties;
+ }
+
+ @XmlElement
+ public List getSpecialties() {
+ List sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
+ PropertyComparator.sort(sortedSpecs,
+ new MutableSortDefinition("name", true, true));
+ return Collections.unmodifiableList(sortedSpecs);
+ }
+
+ public int getNrOfSpecialties() {
+ return getSpecialtiesInternal().size();
+ }
+
+ public void addSpecialty(Specialty specialty) {
+ getSpecialtiesInternal().add(specialty);
+ }
+
+ public String getAddress() {
+ return this.address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getCity() {
+ return this.city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState(){
+ return this.state;
+ }
+
+ public void setState(String state){
+ this.state = state;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/kidclinic/doctor/DoctorController.java b/src/main/java/org/springframework/samples/kidclinic/doctor/DoctorController.java
new file mode 100644
index 000000000..cfc99d4e9
--- /dev/null
+++ b/src/main/java/org/springframework/samples/kidclinic/doctor/DoctorController.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.doctor;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+/**
+ * @author Juergen Hoeller
+ * @author Mark Fisher
+ * @author Ken Krebs
+ * @author Arjen Poutsma
+ */
+@Controller
+class DoctorController {
+
+ private final DoctorRepository doctors;
+
+ @Autowired
+ public DoctorController(DoctorRepository clinicService) {
+ this.doctors = clinicService;
+ }
+
+ @RequestMapping(value = { "/doctors.html" })
+ public String showDoctorList(Map model) {
+ // Here we are returning an object of type 'Doctors' rather than a collection of Doctor
+ // objects so it is simpler for Object-Xml mapping
+ Doctors doctors = new Doctors();
+ doctors.getDoctorList().addAll(this.doctors.findAll());
+ model.put("doctors", doctors);
+ return "doctors/doctorList";
+ }
+
+ @RequestMapping(value = { "/map.html" })
+ public String showDoctorLists(Map model) {
+ // Here we are returning an object of type 'Doctors' rather than a collection of Doctor
+ // objects so it is simpler for Object-Xml mapping
+ Doctors doctors = new Doctors();
+ doctors.getDoctorList().addAll(this.doctors.findAll());
+ model.put("doctors", doctors);
+ return "mapList";
+ }
+
+
+
+ @RequestMapping(value = { "/doctors.json", "/doctors.xml" })
+ public @ResponseBody Doctors showResourcesVetList() {
+ // Here we are returning an object of type 'Doctors' rather than a collection of Doctor
+ // objects so it is simpler for JSon/Object mapping
+ Doctors doctors = new Doctors();
+ doctors.getDoctorList().addAll(this.doctors.findAll());
+ return doctors;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java b/src/main/java/org/springframework/samples/kidclinic/doctor/DoctorRepository.java
similarity index 71%
rename from src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java
rename to src/main/java/org/springframework/samples/kidclinic/doctor/DoctorRepository.java
index 20863ce76..f8412afa7 100644
--- a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java
+++ b/src/main/java/org/springframework/samples/kidclinic/doctor/DoctorRepository.java
@@ -1,46 +1,46 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.vet;
-
-import java.util.Collection;
-
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.dao.DataAccessException;
-import org.springframework.data.repository.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * Repository class for Vet domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-public interface VetRepository extends Repository {
-
- /**
- * Retrieve all Vets from the data store.
- *
- * @return a Collection of Vets
- */
- @Transactional(readOnly = true)
- @Cacheable("vets")
- Collection findAll() throws DataAccessException;
-
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.doctor;
+
+import java.util.Collection;
+
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.repository.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Repository class for Doctor domain objects All method names are compliant with Spring Data naming
+ * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Michael Isvy
+ */
+public interface DoctorRepository extends Repository {
+
+ /**
+ * Retrieve all Doctors from the data store.
+ *
+ * @return a Collection of Doctors
+ */
+ @Transactional(readOnly = true)
+ @Cacheable("doctors")
+ Collection findAll() throws DataAccessException;
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vets.java b/src/main/java/org/springframework/samples/kidclinic/doctor/Doctors.java
similarity index 69%
rename from src/main/java/org/springframework/samples/petclinic/vet/Vets.java
rename to src/main/java/org/springframework/samples/kidclinic/doctor/Doctors.java
index f5b24c3fc..d44fcc570 100644
--- a/src/main/java/org/springframework/samples/petclinic/vet/Vets.java
+++ b/src/main/java/org/springframework/samples/kidclinic/doctor/Doctors.java
@@ -1,43 +1,43 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.vet;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link
- * org.springframework.web.servlet.view.xml.MarshallingView}.
- *
- * @author Arjen Poutsma
- */
-@XmlRootElement
-public class Vets {
-
- private List vets;
-
- @XmlElement
- public List getVetList() {
- if (vets == null) {
- vets = new ArrayList<>();
- }
- return vets;
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.doctor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Simple domain object representing a list of doctors. Mostly here to be used for the 'doctors' {@link
+ * org.springframework.web.servlet.view.xml.MarshallingView}.
+ *
+ * @author Arjen Poutsma
+ */
+@XmlRootElement
+public class Doctors {
+
+ private List doctors;
+
+ @XmlElement
+ public List getDoctorList() {
+ if (doctors == null) {
+ doctors = new ArrayList<>();
+ }
+ return doctors;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java b/src/main/java/org/springframework/samples/kidclinic/doctor/Specialty.java
similarity index 79%
rename from src/main/java/org/springframework/samples/petclinic/vet/Specialty.java
rename to src/main/java/org/springframework/samples/kidclinic/doctor/Specialty.java
index 5691c2434..17d41ecdf 100644
--- a/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java
+++ b/src/main/java/org/springframework/samples/kidclinic/doctor/Specialty.java
@@ -1,34 +1,34 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.vet;
-
-import java.io.Serializable;
-
-import javax.persistence.Entity;
-import javax.persistence.Table;
-
-import org.springframework.samples.petclinic.model.NamedEntity;
-
-/**
- * Models a {@link Vet Vet's} specialty (for example, dentistry).
- *
- * @author Juergen Hoeller
- */
-@Entity
-@Table(name = "specialties")
-public class Specialty extends NamedEntity implements Serializable {
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.doctor;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import org.springframework.samples.kidclinic.model.NamedEntity;
+
+/**
+ * Models a {@link Doctor Doctor's} specialty (for example, dentistry).
+ *
+ * @author Juergen Hoeller
+ */
+@Entity
+@Table(name = "specialties")
+public class Specialty extends NamedEntity implements Serializable {
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java b/src/main/java/org/springframework/samples/kidclinic/model/BaseEntity.java
similarity index 92%
rename from src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
rename to src/main/java/org/springframework/samples/kidclinic/model/BaseEntity.java
index 86cc21092..8e35af234 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java
+++ b/src/main/java/org/springframework/samples/kidclinic/model/BaseEntity.java
@@ -1,50 +1,50 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.model;
-
-import java.io.Serializable;
-
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.MappedSuperclass;
-
-/**
- * Simple JavaBean domain object with an id property. Used as a base class for objects
- * needing this property.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- */
-@MappedSuperclass
-public class BaseEntity implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- public boolean isNew() {
- return this.id == null;
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.model;
+
+import java.io.Serializable;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+/**
+ * Simple JavaBean domain object with an id property. Used as a base class for objects
+ * needing this property.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+@MappedSuperclass
+public class BaseEntity implements Serializable {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = 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/kidclinic/model/NamedEntity.java
similarity index 92%
rename from src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
rename to src/main/java/org/springframework/samples/kidclinic/model/NamedEntity.java
index d66c97ae7..151712ae1 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java
+++ b/src/main/java/org/springframework/samples/kidclinic/model/NamedEntity.java
@@ -1,48 +1,48 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.model;
-
-import javax.persistence.Column;
-import javax.persistence.MappedSuperclass;
-
-
-/**
- * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects
- * needing these properties.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- */
-@MappedSuperclass
-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;
- }
-
- @Override
- public String toString() {
- return this.getName();
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.model;
+
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+
+
+/**
+ * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects
+ * needing these properties.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+@MappedSuperclass
+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;
+ }
+
+ @Override
+ public String toString() {
+ return this.getName();
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/Person.java b/src/main/java/org/springframework/samples/kidclinic/model/Person.java
similarity index 92%
rename from src/main/java/org/springframework/samples/petclinic/model/Person.java
rename to src/main/java/org/springframework/samples/kidclinic/model/Person.java
index 4cb7481e0..38fa1ca95 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/Person.java
+++ b/src/main/java/org/springframework/samples/kidclinic/model/Person.java
@@ -1,55 +1,55 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.model;
-
-import javax.persistence.Column;
-import javax.persistence.MappedSuperclass;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-/**
- * Simple JavaBean domain object representing an person.
- *
- * @author Ken Krebs
- */
-@MappedSuperclass
-public class Person extends BaseEntity {
-
- @Column(name = "first_name")
- @NotEmpty
- private String firstName;
-
- @Column(name = "last_name")
- @NotEmpty
- private String lastName;
-
- public String getFirstName() {
- return this.firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return this.lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.model;
+
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+/**
+ * Simple JavaBean domain object representing an person.
+ *
+ * @author Ken Krebs
+ */
+@MappedSuperclass
+public class Person extends BaseEntity {
+
+ @Column(name = "first_name")
+ @NotEmpty
+ private String firstName;
+
+ @Column(name = "last_name")
+ @NotEmpty
+ private String lastName;
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return this.lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/model/package-info.java b/src/main/java/org/springframework/samples/kidclinic/model/package-info.java
similarity index 57%
rename from src/main/java/org/springframework/samples/petclinic/model/package-info.java
rename to src/main/java/org/springframework/samples/kidclinic/model/package-info.java
index 78294d130..bac1b029c 100644
--- a/src/main/java/org/springframework/samples/petclinic/model/package-info.java
+++ b/src/main/java/org/springframework/samples/kidclinic/model/package-info.java
@@ -1,5 +1,5 @@
-/**
- * The classes in this package represent utilities used by the domain.
- */
-package org.springframework.samples.petclinic.model;
-
+/**
+ * The classes in this package represent utilities used by the domain.
+ */
+package org.springframework.samples.kidclinic.model;
+
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java b/src/main/java/org/springframework/samples/kidclinic/parent/Kid.java
similarity index 65%
rename from src/main/java/org/springframework/samples/petclinic/owner/Pet.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/Kid.java
index e8df85e91..c0d0afd96 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/Kid.java
@@ -1,117 +1,139 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-
-import org.springframework.beans.support.MutableSortDefinition;
-import org.springframework.beans.support.PropertyComparator;
-import org.springframework.format.annotation.DateTimeFormat;
-import org.springframework.samples.petclinic.model.NamedEntity;
-import org.springframework.samples.petclinic.visit.Visit;
-
-/**
- * Simple business object representing a pet.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- */
-@Entity
-@Table(name = "pets")
-public class Pet extends NamedEntity {
-
- @Column(name = "birth_date")
- @Temporal(TemporalType.DATE)
- @DateTimeFormat(pattern = "yyyy/MM/dd")
- private Date birthDate;
-
- @ManyToOne
- @JoinColumn(name = "type_id")
- private PetType type;
-
- @ManyToOne
- @JoinColumn(name = "owner_id")
- private Owner owner;
-
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "petId", fetch = FetchType.EAGER)
- private Set visits = new LinkedHashSet<>();
-
- public void setBirthDate(Date birthDate) {
- this.birthDate = birthDate;
- }
-
- public Date getBirthDate() {
- return this.birthDate;
- }
-
- public PetType getType() {
- return this.type;
- }
-
- public void setType(PetType type) {
- this.type = type;
- }
-
- public Owner getOwner() {
- return this.owner;
- }
-
- protected void setOwner(Owner owner) {
- this.owner = owner;
- }
-
- protected Set getVisitsInternal() {
- if (this.visits == null) {
- this.visits = new HashSet<>();
- }
- 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));
- return Collections.unmodifiableList(sortedVisits);
- }
-
- public void addVisit(Visit visit) {
- getVisitsInternal().add(visit);
- visit.setPetId(this.getId());
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.springframework.beans.support.MutableSortDefinition;
+import org.springframework.beans.support.PropertyComparator;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.samples.kidclinic.model.NamedEntity;
+import org.springframework.samples.kidclinic.visit.Visit;
+
+/**
+ * Simple business object representing a pet.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ */
+@Entity
+@Table(name = "kids")
+public class Kid extends NamedEntity {
+
+ @Column(name = "birth_date")
+ @Temporal(TemporalType.DATE)
+ @DateTimeFormat(pattern = "yyyy/MM/dd")
+ private Date birthDate;
+
+ @ManyToOne
+ @JoinColumn(name = "gender_id")
+ private KidGender gender;
+
+ @ManyToOne
+ @JoinColumn(name = "parent_id")
+ private Parent parent;
+
+ @Column(name = "allergies")
+ private String allergies;
+
+ @Column(name = "medications")
+ private String medications;
+
+ @OneToMany(cascade = CascadeType.ALL, mappedBy = "kidId", fetch = FetchType.EAGER)
+ private Set visits = new LinkedHashSet<>();
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ public Date getBirthDate() {
+ return this.birthDate;
+ }
+
+ public KidGender getGender() {
+ return this.gender;
+ }
+
+ public void setGender(KidGender gender) {
+ this.gender = gender;
+ }
+
+ public Parent getParent() {
+ return this.parent;
+ }
+
+ protected void setParent(Parent parent) {
+ this.parent = parent;
+ }
+
+ public String getAllergies(){
+ return this.allergies;
+ }
+
+ public void setAllergies(String allergies){
+ this.allergies = allergies;
+ }
+
+ public String getMedications(){
+ return this.medications;
+ }
+
+ public void setMedications(String medications){
+ this.medications = medications;
+ }
+
+ protected Set getVisitsInternal() {
+ if (this.visits == null) {
+ this.visits = new HashSet<>();
+ }
+ 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));
+ return Collections.unmodifiableList(sortedVisits);
+ }
+
+ public void addVisit(Visit visit) {
+ getVisitsInternal().add(visit);
+ visit.setKidId(this.getId());
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/kidclinic/parent/KidController.java b/src/main/java/org/springframework/samples/kidclinic/parent/KidController.java
new file mode 100644
index 000000000..216dc9147
--- /dev/null
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/KidController.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import java.util.Collection;
+
+import javax.validation.Valid;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.util.StringUtils;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ * @author Arjen Poutsma
+ */
+@Controller
+@RequestMapping("/parents/{parentId}")
+class KidController {
+
+ private static final String VIEWS_KIDS_CREATE_OR_UPDATE_FORM = "kids/createOrUpdateKidForm";
+ private final KidRepository kids;
+ private final ParentRepository parents;
+
+ @Autowired
+ public KidController(KidRepository kids, ParentRepository parents) {
+ this.kids = kids;
+ this.parents = parents;
+ }
+
+ @ModelAttribute("gender")
+ public Collection populateKidGenders() {
+ return this.kids.findKidGenders();
+ }
+
+ @ModelAttribute("parent")
+ public Parent findParent(@PathVariable("parentId") int parentId) {
+ return this.parents.findById(parentId);
+ }
+
+ @InitBinder("parent")
+ public void initParentBinder(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
+
+ @InitBinder("kid")
+ public void initKidBinder(WebDataBinder dataBinder) {
+ dataBinder.setValidator(new KidValidator());
+ }
+
+ @RequestMapping(value = "/kids/new", method = RequestMethod.GET)
+ public String initCreationForm(Parent parent, ModelMap model) {
+ Kid kid = new Kid();
+ parent.addKid(kid);
+ model.put("kid", kid);
+ return VIEWS_KIDS_CREATE_OR_UPDATE_FORM;
+ }
+
+ @RequestMapping(value = "/kids/new", method = RequestMethod.POST)
+ public String processCreationForm(Parent parent, @Valid Kid kid, BindingResult result, ModelMap model) {
+ if (StringUtils.hasLength(kid.getName()) && kid.isNew() && parent.getKid(kid.getName(), true) != null){
+ result.rejectValue("name", "duplicate", "already exists");
+ }
+ if (result.hasErrors()) {
+ model.put("kid", kid);
+ return VIEWS_KIDS_CREATE_OR_UPDATE_FORM;
+ } else {
+ parent.addKid(kid);
+ this.kids.save(kid);
+ return "redirect:/parents/{parentId}";
+ }
+ }
+
+ @RequestMapping(value = "/kids/{kidId}/edit", method = RequestMethod.GET)
+ public String initUpdateForm(@PathVariable("kidId") int kidId, ModelMap model) {
+ Kid kid = this.kids.findById(kidId);
+ model.put("kid", kid);
+ return VIEWS_KIDS_CREATE_OR_UPDATE_FORM;
+ }
+
+ @RequestMapping(value = "/kids/{kidsId}/edit", method = RequestMethod.POST)
+ public String processUpdateForm(@Valid Kid kid, BindingResult result, Parent parent, ModelMap model) {
+ if (result.hasErrors()) {
+ kid.setParent(parent);
+ model.put("kid", kid);
+ return VIEWS_KIDS_CREATE_OR_UPDATE_FORM;
+ } else {
+ parent.addKid(kid);
+ this.kids.save(kid);
+ return "redirect:/parents/{parentId}";
+ }
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetType.java b/src/main/java/org/springframework/samples/kidclinic/parent/KidGender.java
similarity index 78%
rename from src/main/java/org/springframework/samples/petclinic/owner/PetType.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/KidGender.java
index ac827b310..b06ef4bd4 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetType.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/KidGender.java
@@ -1,31 +1,31 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-import javax.persistence.Entity;
-import javax.persistence.Table;
-
-import org.springframework.samples.petclinic.model.NamedEntity;
-
-/**
- * @author Juergen Hoeller
- * Can be Cat, Dog, Hamster...
- */
-@Entity
-@Table(name = "types")
-public class PetType extends NamedEntity {
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import org.springframework.samples.kidclinic.model.NamedEntity;
+
+/**
+ * @author Juergen Hoeller
+ * Can be Cat, Dog, Hamster...
+ */
+@Entity
+@Table(name = "gender")
+public class KidGender extends NamedEntity {
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java b/src/main/java/org/springframework/samples/kidclinic/parent/KidGenderFormatter.java
similarity index 65%
rename from src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/KidGenderFormatter.java
index 78451ca28..74467002a 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetTypeFormatter.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/KidGenderFormatter.java
@@ -1,65 +1,65 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-
-import java.text.ParseException;
-import java.util.Collection;
-import java.util.Locale;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.format.Formatter;
-import org.springframework.stereotype.Component;
-
-/**
- * Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting from Spring 3.0, Formatters have
- * come as an improvement in comparison to legacy PropertyEditors. See the following links for more details: - The
- * Spring ref doc: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html#format-Formatter-SPI
- * - A nice blog entry from Gordon Dickens: http://gordondickens.com/wordpress/2010/09/30/using-spring-3-0-custom-type-converter/
- *
- *
- * @author Mark Fisher
- * @author Juergen Hoeller
- * @author Michael Isvy
- */
-@Component
-public class PetTypeFormatter implements Formatter {
-
- private final PetRepository pets;
-
-
- @Autowired
- public PetTypeFormatter(PetRepository pets) {
- this.pets = pets;
- }
-
- @Override
- public String print(PetType petType, Locale locale) {
- return petType.getName();
- }
-
- @Override
- public PetType parse(String text, Locale locale) throws ParseException {
- Collection findPetTypes = this.pets.findPetTypes();
- for (PetType type : findPetTypes) {
- if (type.getName().equals(text)) {
- return type;
- }
- }
- throw new ParseException("type not found: " + text, 0);
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Locale;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.format.Formatter;
+import org.springframework.stereotype.Component;
+
+/**
+ * Instructs Spring MVC on how to parse and print elements of type 'KidGender'. Starting from Spring 3.0, Formatters have
+ * come as an improvement in comparison to legacy PropertyEditors. See the following links for more details: - The
+ * Spring ref doc: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html#format-Formatter-SPI
+ * - A nice blog entry from Gordon Dickens: http://gordondickens.com/wordpress/2010/09/30/using-spring-3-0-custom-type-converter/
+ *
+ *
+ * @author Mark Fisher
+ * @author Juergen Hoeller
+ * @author Michael Isvy
+ */
+@Component
+public class KidGenderFormatter implements Formatter {
+
+ private final KidRepository kids;
+
+
+ @Autowired
+ public KidGenderFormatter(KidRepository kids) {
+ this.kids = kids;
+ }
+
+ @Override
+ public String print(KidGender kidGender, Locale locale) {
+ return kidGender.getName();
+ }
+
+ @Override
+ public KidGender parse(String text, Locale locale) throws ParseException {
+ Collection findKidGenders = this.kids.findKidGenders();
+ for (KidGender gender : findKidGenders) {
+ if (gender.getName().equals(text)) {
+ return gender;
+ }
+ }
+ throw new ParseException("gender not found: " + text, 0);
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java b/src/main/java/org/springframework/samples/kidclinic/parent/KidRepository.java
similarity index 65%
rename from src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/KidRepository.java
index b0ec5db23..d0ca26503 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/KidRepository.java
@@ -1,58 +1,58 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-import java.util.List;
-
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * Repository class for Pet domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-public interface PetRepository extends Repository {
-
- /**
- * Retrieve all {@link PetType}s from the data store.
- * @return a Collection of {@link PetType}s.
- */
- @Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
- @Transactional(readOnly = true)
- List findPetTypes();
-
- /**
- * Retrieve a {@link Pet} from the data store by id.
- * @param id the id to search for
- * @return the {@link Pet} if found
- */
- @Transactional(readOnly = true)
- Pet findById(Integer id);
-
- /**
- * Save a {@link Pet} to the data store, either inserting or updating it.
- * @param pet the {@link Pet} to save
- */
- void save(Pet pet);
-
-}
-
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Repository class for Kid domain objects All method names are compliant with Spring Data naming
+ * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Michael Isvy
+ */
+public interface KidRepository extends Repository {
+
+ /**
+ * Retrieve all {@link KidGender}s from the data store.
+ * @return a Collection of {@link KidGender}s.
+ */
+ @Query("SELECT ptype FROM KidGender ptype ORDER BY ptype.name")
+ @Transactional(readOnly = true)
+ List findKidGenders();
+
+ /**
+ * Retrieve a {@link Kid} from the data store by id.
+ * @param id the id to search for
+ * @return the {@link Kid} if found
+ */
+ @Transactional(readOnly = true)
+ Kid findById(Integer id);
+
+ /**
+ * Save a {@link Kid} to the data store, either inserting or updating it.
+ * @param kid the {@link Kid} to save
+ */
+ void save(Kid kid);
+
+}
+
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java b/src/main/java/org/springframework/samples/kidclinic/parent/KidValidator.java
similarity index 58%
rename from src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/KidValidator.java
index 1a3d92e9e..3ba883ff9 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/PetValidator.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/KidValidator.java
@@ -1,64 +1,76 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-import org.springframework.util.StringUtils;
-import org.springframework.validation.Errors;
-import org.springframework.validation.Validator;
-
-/**
- * Validator for Pet forms.
- *
- * We're not using Bean Validation annotations here because it is easier to define such validation rule in Java.
- *
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- */
-public class PetValidator implements Validator {
-
- private static final String REQUIRED = "required";
-
- @Override
- public void validate(Object obj, Errors errors) {
- Pet pet = (Pet) obj;
- String name = pet.getName();
- // name validation
- if (!StringUtils.hasLength(name)) {
- errors.rejectValue("name", REQUIRED, REQUIRED);
- }
-
- // type validation
- if (pet.isNew() && pet.getType() == null) {
- errors.rejectValue("type", REQUIRED, REQUIRED);
- }
-
- // birth date validation
- if (pet.getBirthDate() == null) {
- errors.rejectValue("birthDate", REQUIRED, REQUIRED);
- }
- }
-
- /**
- * This Validator validates *just* Pet instances
- */
- @Override
- public boolean supports(Class> clazz) {
- return Pet.class.isAssignableFrom(clazz);
- }
-
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import org.springframework.util.StringUtils;
+import org.springframework.validation.Errors;
+import org.springframework.validation.Validator;
+
+/**
+ * Validator for Kid forms.
+ *
+ * We're not using Bean Validation annotations here because it is easier to define such validation rule in Java.
+ *
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ */
+public class KidValidator implements Validator {
+
+ private static final String REQUIRED = "required";
+
+ @Override
+ public void validate(Object obj, Errors errors) {
+ Kid kid = (Kid) obj;
+ String name = kid.getName();
+ String medications = kid.getMedications();
+ String allergies = kid.getAllergies();
+
+ // name validation
+ if (!StringUtils.hasLength(name)) {
+ errors.rejectValue("name", REQUIRED, REQUIRED);
+ }
+
+ // allergies validation
+ if (!StringUtils.hasLength(allergies)) {
+ errors.rejectValue("allergies", REQUIRED, REQUIRED);
+ }
+
+ // medications validation
+ if (!StringUtils.hasLength(medications)) {
+ errors.rejectValue("medications", REQUIRED, REQUIRED);
+ }
+
+ if (kid.isNew() && kid.getGender() == null) {
+ errors.rejectValue("gender", REQUIRED, REQUIRED);
+ }
+
+ // birth date validation
+ if (kid.getBirthDate() == null) {
+ errors.rejectValue("birthDate", REQUIRED, REQUIRED);
+ }
+ }
+
+ /**
+ * This Validator validates *just* Kid instances
+ */
+ @Override
+ public boolean supports(Class> clazz) {
+ return Kid.class.isAssignableFrom(clazz);
+ }
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/kidclinic/parent/Parent.java
similarity index 60%
rename from src/main/java/org/springframework/samples/petclinic/owner/Owner.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/Parent.java
index f6fcae7ac..5be5fc030 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/Parent.java
@@ -1,156 +1,168 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.validation.constraints.Digits;
-
-import org.hibernate.validator.constraints.NotEmpty;
-import org.springframework.beans.support.MutableSortDefinition;
-import org.springframework.beans.support.PropertyComparator;
-import org.springframework.core.style.ToStringCreator;
-import org.springframework.samples.petclinic.model.Person;
-
-/**
- * Simple JavaBean domain object representing an owner.
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-@Entity
-@Table(name = "owners")
-public class Owner extends Person {
- @Column(name = "address")
- @NotEmpty
- private String address;
-
- @Column(name = "city")
- @NotEmpty
- private String city;
-
- @Column(name = "telephone")
- @NotEmpty
- @Digits(fraction = 0, integer = 10)
- private String telephone;
-
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
- private Set pets;
-
-
- public String getAddress() {
- return this.address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
- public String getCity() {
- return this.city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getTelephone() {
- return this.telephone;
- }
-
- public void setTelephone(String telephone) {
- this.telephone = telephone;
- }
-
- protected Set getPetsInternal() {
- if (this.pets == null) {
- this.pets = new HashSet<>();
- }
- 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));
- return Collections.unmodifiableList(sortedPets);
- }
-
- public void addPet(Pet pet) {
- if (pet.isNew()) {
- getPetsInternal().add(pet);
- }
- pet.setOwner(this);
- }
-
- /**
- * Return the Pet with the given name, or null if none found for this Owner.
- *
- * @param name to test
- * @return true if pet name is already in use
- */
- public Pet getPet(String name) {
- return getPet(name, false);
- }
-
- /**
- * Return the Pet with the given name, or null if none found for this Owner.
- *
- * @param name to test
- * @return true if pet name is already in use
- */
- public Pet getPet(String name, boolean ignoreNew) {
- name = name.toLowerCase();
- for (Pet pet : getPetsInternal()) {
- if (!ignoreNew || !pet.isNew()) {
- String compName = pet.getName();
- compName = compName.toLowerCase();
- if (compName.equals(name)) {
- return pet;
- }
- }
- }
- return null;
- }
-
- @Override
- 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();
- }
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.validation.constraints.Digits;
+
+import org.hibernate.validator.constraints.NotEmpty;
+import org.springframework.beans.support.MutableSortDefinition;
+import org.springframework.beans.support.PropertyComparator;
+import org.springframework.core.style.ToStringCreator;
+import org.springframework.samples.kidclinic.model.Person;
+
+/**
+ * Simple JavaBean domain object representing an parent.
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Michael Isvy
+ */
+@Entity
+@Table(name = "parents")
+public class Parent extends Person {
+ @Column(name = "address")
+ @NotEmpty
+ private String address;
+
+ @Column(name = "city")
+ @NotEmpty
+ private String city;
+
+ @Column(name = "state")
+ @NotEmpty
+ private String state;
+
+ @Column(name = "telephone")
+ @NotEmpty
+ @Digits(fraction = 0, integer = 10)
+ private String telephone;
+
+ @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
+ private Set kids;
+
+
+ public String getAddress() {
+ return this.address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getCity() {
+ return this.city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState(){
+ return this.state;
+ }
+
+ public void setState(String state){
+ this.state = state;
+ }
+
+ public String getTelephone() {
+ return this.telephone;
+ }
+
+ public void setTelephone(String telephone) {
+ this.telephone = telephone;
+ }
+
+ protected Set getKidsInternal() {
+ if (this.kids == null) {
+ this.kids = new HashSet<>();
+ }
+ return this.kids;
+ }
+
+ protected void setKidsInternal(Set kids) {
+ this.kids = kids;
+ }
+
+ public List getKids() {
+ List sortedKids = new ArrayList<>(getKidsInternal());
+ PropertyComparator.sort(sortedKids, new MutableSortDefinition("name", true, true));
+ return Collections.unmodifiableList(sortedKids);
+ }
+
+ public void addKid(Kid kid) {
+ if (kid.isNew()) {
+ getKidsInternal().add(kid);
+ }
+ kid.setParent(this);
+ }
+
+ /**
+ * Return the Kid with the given name, or null if none found for this Parent.
+ *
+ * @param name to test
+ * @return true if kid name is already in use
+ */
+ public Kid getKid(String name) {
+ return getKid(name, false);
+ }
+
+ /**
+ * Return the Kid with the given name, or null if none found for this Kid.
+ *
+ * @param name to test
+ * @return true if kid name is already in use
+ */
+ public Kid getKid(String name, boolean ignoreNew) {
+ name = name.toLowerCase();
+ for (Kid kid : getKidsInternal()) {
+ if (!ignoreNew || !kid.isNew()) {
+ String compName = kid.getName();
+ compName = compName.toLowerCase();
+ if (compName.equals(name)) {
+ return kid;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ 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();
+ }
+}
diff --git a/src/main/java/org/springframework/samples/kidclinic/parent/ParentController.java b/src/main/java/org/springframework/samples/kidclinic/parent/ParentController.java
new file mode 100644
index 000000000..9c94b46ab
--- /dev/null
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/ParentController.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import java.util.Collection;
+import java.util.Map;
+
+import javax.validation.Valid;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ * @author Arjen Poutsma
+ * @author Michael Isvy
+ */
+@Controller
+class ParentController {
+
+ private static final String VIEWS_PARENT_CREATE_OR_UPDATE_FORM = "parents/createOrUpdateParentForm";
+ private final ParentRepository parents;
+
+
+ @Autowired
+ public ParentController(ParentRepository clinicService) {
+ this.parents = clinicService;
+ }
+
+ @InitBinder
+ public void setAllowedFields(WebDataBinder dataBinder) {
+ dataBinder.setDisallowedFields("id");
+ }
+
+ @RequestMapping(value = "/parents/new", method = RequestMethod.GET)
+ public String initCreationForm(Map model) {
+ Parent parent = new Parent();
+ model.put("parent", parent);
+ return VIEWS_PARENT_CREATE_OR_UPDATE_FORM;
+ }
+
+ @RequestMapping(value = "/parents/new", method = RequestMethod.POST)
+ public String processCreationForm(@Valid Parent parent, BindingResult result) {
+ if (result.hasErrors()) {
+ return VIEWS_PARENT_CREATE_OR_UPDATE_FORM;
+ } else {
+ this.parents.save(parent);
+ return "redirect:/parents/" + parent.getId();
+ }
+ }
+
+ @RequestMapping(value = "/parents/find", method = RequestMethod.GET)
+ public String initFindForm(Map model) {
+ model.put("parent", new Parent());
+ return "parents/findParents";
+ }
+
+ @RequestMapping(value = "/parents", method = RequestMethod.GET)
+ public String processFindForm(Parent parent, BindingResult result, Map model) {
+
+ // allow parameterless GET request for /parents to return all records
+ if (parent.getLastName() == null) {
+ parent.setLastName(""); // empty string signifies broadest possible search
+ }
+
+ // find parents by last name
+ Collection results = this.parents.findByLastName(parent.getLastName());
+ if (results.isEmpty()) {
+ // no parents found
+ result.rejectValue("lastName", "notFound", "not found");
+ return "parents/findParents";
+ } else if (results.size() == 1) {
+ // 1 parent found
+ parent = results.iterator().next();
+ return "redirect:/parents/" + parent.getId();
+ } else {
+ // multiple parents found
+ model.put("selections", results);
+ return "parents/parentsList";
+ }
+ }
+
+ @RequestMapping(value = "/parents/{parentId}/edit", method = RequestMethod.GET)
+ public String initUpdateParentForm(@PathVariable("parentId") int parentId, Model model) {
+ Parent parent = this.parents.findById(parentId);
+ model.addAttribute(parent);
+ return VIEWS_PARENT_CREATE_OR_UPDATE_FORM;
+ }
+
+ @RequestMapping(value = "/parents/{parentId}/edit", method = RequestMethod.POST)
+ public String processUpdateParentForm(@Valid Parent parent, BindingResult result, @PathVariable("parentId") int parentId) {
+ if (result.hasErrors()) {
+ return VIEWS_PARENT_CREATE_OR_UPDATE_FORM;
+ } else {
+ parent.setId(parentId);
+ this.parents.save(parent);
+ return "redirect:/parents/{parentId}";
+ }
+ }
+
+ /**
+ * Custom handler for displaying an parent.
+ *
+ * @param parentId the ID of the parent to display
+ * @return a ModelMap with the model attributes for the view
+ */
+ @RequestMapping("/parents/{parentId}")
+ public ModelAndView showParent(@PathVariable("parentId") int parentId) {
+ ModelAndView mav = new ModelAndView("parents/parentDetails");
+ mav.addObject(this.parents.findById(parentId));
+ return mav;
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java b/src/main/java/org/springframework/samples/kidclinic/parent/ParentRepository.java
similarity index 57%
rename from src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/ParentRepository.java
index 068f5245d..32b281b1e 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/ParentRepository.java
@@ -1,63 +1,63 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-import java.util.Collection;
-
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.Repository;
-import org.springframework.data.repository.query.Param;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * Repository class for Owner domain objects All method names are compliant with Spring Data naming
- * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
- *
- * @author Ken Krebs
- * @author Juergen Hoeller
- * @author Sam Brannen
- * @author Michael Isvy
- */
-public interface OwnerRepository extends Repository {
-
- /**
- * Retrieve {@link Owner}s from the data store by last name, returning all owners
- * whose last name starts with the given name.
- * @param lastName Value to search for
- * @return a Collection of matching {@link Owner}s (or an empty Collection if none
- * found)
- */
- @Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
- @Transactional(readOnly = true)
- Collection findByLastName(@Param("lastName") String lastName);
-
- /**
- * Retrieve an {@link Owner} from the data store by id.
- * @param id the id to search for
- * @return the {@link Owner} if found
- */
- @Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
- @Transactional(readOnly = true)
- Owner findById(@Param("id") Integer id);
-
- /**
- * Save an {@link Owner} to the data store, either inserting or updating it.
- * @param owner the {@link Owner} to save
- */
- void save(Owner owner);
-
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import java.util.Collection;
+
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.Repository;
+import org.springframework.data.repository.query.Param;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Repository class for Parent domain objects All method names are compliant with Spring Data naming
+ * conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
+ *
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ * @author Michael Isvy
+ */
+public interface ParentRepository extends Repository {
+
+ /**
+ * Retrieve {@link Parent}s from the data store by last name, returning all parents
+ * whose last name starts with the given name.
+ * @param lastName Value to search for
+ * @return a Collection of matching {@link Parent}s (or an empty Collection if none
+ * found)
+ */
+ @Query("SELECT DISTINCT parent FROM Parent parent left join fetch parent.kids WHERE parent.lastName LIKE :lastName%")
+ @Transactional(readOnly = true)
+ Collection findByLastName(@Param("lastName") String lastName);
+
+ /**
+ * Retrieve an {@link Parent} from the data store by id.
+ * @param id the id to search for
+ * @return the {@link Parent} if found
+ */
+ @Query("SELECT parent FROM Parent parent left join fetch parent.kids WHERE parent.id =:id")
+ @Transactional(readOnly = true)
+ Parent findById(@Param("id") Integer id);
+
+ /**
+ * Save an {@link Parent} to the data store, either inserting or updating it.
+ * @param owner the {@link Parent} to save
+ */
+ void save(Parent parent);
+
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java b/src/main/java/org/springframework/samples/kidclinic/parent/VisitController.java
similarity index 62%
rename from src/main/java/org/springframework/samples/petclinic/owner/VisitController.java
rename to src/main/java/org/springframework/samples/kidclinic/parent/VisitController.java
index d98c5dd0f..f63a2debc 100644
--- a/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java
+++ b/src/main/java/org/springframework/samples/kidclinic/parent/VisitController.java
@@ -1,95 +1,95 @@
-/*
- * Copyright 2002-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.samples.petclinic.owner;
-
-import java.util.Map;
-
-import javax.validation.Valid;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.samples.petclinic.visit.Visit;
-import org.springframework.samples.petclinic.visit.VisitRepository;
-import org.springframework.stereotype.Controller;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.WebDataBinder;
-import org.springframework.web.bind.annotation.InitBinder;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-
-/**
- * @author Juergen Hoeller
- * @author Ken Krebs
- * @author Arjen Poutsma
- * @author Michael Isvy
- * @author Dave Syer
- */
-@Controller
-class VisitController {
-
- private final VisitRepository visits;
- private final PetRepository pets;
-
-
- @Autowired
- public VisitController(VisitRepository visits, PetRepository pets) {
- this.visits = visits;
- this.pets = pets;
- }
-
- @InitBinder
- 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)
- *
- * @param petId
- * @return Pet
- */
- @ModelAttribute("visit")
- public Visit loadPetWithVisit(@PathVariable("petId") int petId, Map model) {
- Pet pet = this.pets.findById(petId);
- model.put("pet", pet);
- Visit visit = new Visit();
- pet.addVisit(visit);
- return visit;
- }
-
- // 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
- @RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
- public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
- if (result.hasErrors()) {
- return "pets/createOrUpdateVisitForm";
- } else {
- this.visits.save(visit);
- return "redirect:/owners/{ownerId}";
- }
- }
-
-}
+/*
+ * Copyright 2002-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.samples.kidclinic.parent;
+
+import java.util.Map;
+
+import javax.validation.Valid;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.samples.kidclinic.visit.Visit;
+import org.springframework.samples.kidclinic.visit.VisitRepository;
+import org.springframework.stereotype.Controller;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.InitBinder;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * @author Juergen Hoeller
+ * @author Ken Krebs
+ * @author Arjen Poutsma
+ * @author Michael Isvy
+ * @author Dave Syer
+ */
+@Controller
+class VisitController {
+
+ private final VisitRepository visits;
+ private final KidRepository kids;
+
+
+ @Autowired
+ public VisitController(VisitRepository visits, KidRepository kids) {
+ this.visits = visits;
+ this.kids = kids;
+ }
+
+ @InitBinder
+ 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 Kid object always has an id
+ * (Even though id is not part of the form fields)
+ *
+ * @param kidId
+ * @return Kid
+ */
+ @ModelAttribute("visit")
+ public Visit loadKidWithVisit(@PathVariable("kidId") int kidId, Map model) {
+ Kid kid = this.kids.findById(kidId);
+ model.put("kid", kid);
+ Visit visit = new Visit();
+ kid.addVisit(visit);
+ return visit;
+ }
+
+ // Spring MVC calls method loadKidWithVisit(...) before initNewVisitForm is called
+ @RequestMapping(value = "/parents/*/kids/{kidId}/visits/new", method = RequestMethod.GET)
+ public String initNewVisitForm(@PathVariable("kidId") int kidId, Map model) {
+ return "kids/createOrUpdateVisitForm";
+ }
+
+ // Spring MVC calls method loadKidWithVisit(...) before processNewVisitForm is called
+ @RequestMapping(value = "/parents/{parentId}/kids/{kidId}/visits/new", method = RequestMethod.POST)
+ public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
+ if (result.hasErrors()) {
+ return "kids/createOrUpdateVisitForm";
+ } else {
+ this.visits.save(visit);
+ return "redirect:/parents/{parentId}";
+ }
+ }
+
+}
diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java b/src/main/java/org/springframework/samples/kidclinic/reviews/ReviewsController.java
similarity index 54%
rename from src/main/java/org/springframework/samples/petclinic/vet/VetController.java
rename to src/main/java/org/springframework/samples/kidclinic/reviews/ReviewsController.java
index 8ddcca60a..dac61a53c 100644
--- a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java
+++ b/src/main/java/org/springframework/samples/kidclinic/reviews/ReviewsController.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.samples.petclinic.vet;
+package org.springframework.samples.kidclinic.reviews;
import java.util.Map;
@@ -29,32 +29,17 @@ import org.springframework.web.bind.annotation.ResponseBody;
* @author Arjen Poutsma
*/
@Controller
-class VetController {
-
- private final VetRepository vets;
+class ReviewsController {
@Autowired
- public VetController(VetRepository clinicService) {
- this.vets = clinicService;
+ public ReviewsController() {
}
- @RequestMapping(value = { "/vets.html" })
- public String showVetList(Map model) {
- // Here we are returning an object of type 'Vets' rather than a collection of Vet
+ @RequestMapping(value = { "/reviews.html" })
+ public String showReviews(Map model) {
+ // Here we are returning an object of type 'Doctors' rather than a collection of Doctor
// objects so it is simpler for Object-Xml mapping
- Vets vets = new Vets();
- vets.getVetList().addAll(this.vets.findAll());
- model.put("vets", vets);
- return "vets/vetList";
- }
-
- @RequestMapping(value = { "/vets.json", "/vets.xml" })
- 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.vets.findAll());
- return vets;
+ return "reviews";
}
}
diff --git a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java b/src/main/java/org/springframework/samples/kidclinic/system/CacheConfig.java
similarity index 87%
rename from src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java
rename to src/main/java/org/springframework/samples/kidclinic/system/CacheConfig.java
index 13e194c35..c071553fe 100755
--- a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java
+++ b/src/main/java/org/springframework/samples/kidclinic/system/CacheConfig.java
@@ -1,32 +1,32 @@
-package org.springframework.samples.petclinic.system;
-
-import javax.cache.configuration.Configuration;
-import javax.cache.configuration.MutableConfiguration;
-
-import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
-import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Profile;
-
-/**
- * Cache could be disabled in unit test.
- */
-@org.springframework.context.annotation.Configuration
-@EnableCaching
-@Profile("production")
-class CacheConfig {
-
- @Bean
- public JCacheManagerCustomizer cacheManagerCustomizer() {
- return cm -> {
- Configuration