From 48dc23970c55c66b51b99642acb0f3fd74da0b0b Mon Sep 17 00:00:00 2001 From: Manuel Resinas Date: Thu, 30 Sep 2021 20:19:16 +0200 Subject: [PATCH] Reorganized packages to a domain-oriented approach The packages are owner, pet, vet and user. We chose to keep pet out of owner because it is the central element of the application. However, visit is included in pet because a visit heavily depends on the pet that makes it. These were also the same packages that were used to organized the JSP code. --- .../petclinic/{model => owner}/Owner.java | 361 +++++++++--------- .../{web => owner}/OwnerController.java | 286 +++++++------- .../OwnerRepository.java | 5 +- .../{service => owner}/OwnerService.java | 158 ++++---- .../samples/petclinic/{model => pet}/Pet.java | 6 +- .../petclinic/{web => pet}/PetController.java | 14 +- .../{repository => pet}/PetRepository.java | 4 +- .../{service => pet}/PetService.java | 159 ++++---- .../petclinic/{model => pet}/PetType.java | 4 +- .../{web => pet}/PetTypeFormatter.java | 6 +- .../petclinic/{web => pet}/PetValidator.java | 3 +- .../petclinic/{model => pet}/Visit.java | 3 +- .../{web => pet}/VisitController.java | 7 +- .../{repository => pet}/VisitRepository.java | 3 +- .../DuplicatedPetNameException.java | 2 +- .../ElementInCollectionValidator.java | 5 - .../{model => user}/Authorities.java | 4 +- .../AuthoritiesRepository.java | 3 +- .../{service => user}/AuthoritiesService.java | 129 +++---- .../petclinic/{model => user}/User.java | 2 +- .../{web => user}/UserController.java | 148 ++++--- .../{repository => user}/UserRepository.java | 3 +- .../{service => user}/UserService.java | 104 +++-- .../petclinic/{model => vet}/Specialty.java | 4 +- .../samples/petclinic/{model => vet}/Vet.java | 3 +- .../petclinic/{web => vet}/VetController.java | 4 +- .../{repository => vet}/VetRepository.java | 3 +- .../{service => vet}/VetService.java | 116 +++--- .../petclinic/{model => vet}/Vets.java | 2 +- .../petclinic/web/WelcomeController.java | 4 +- .../{web => owner}/OwnerControllerTests.java | 13 +- .../{service => owner}/OwnerServiceTests.java | 19 +- .../{web => pet}/PetControllerTests.java | 16 +- .../{service => pet}/PetServiceTests.java | 17 +- .../{web => pet}/PetTypeFormatterTests.java | 9 +- .../{web => pet}/VisitControllerTests.java | 9 +- .../{web => vet}/VetControllerTests.java | 9 +- .../{service => vet}/VetServiceTests.java | 19 +- 38 files changed, 824 insertions(+), 842 deletions(-) rename src/main/java/org/springframework/samples/petclinic/{model => owner}/Owner.java (94%) rename src/main/java/org/springframework/samples/petclinic/{web => owner}/OwnerController.java (88%) rename src/main/java/org/springframework/samples/petclinic/{repository => owner}/OwnerRepository.java (92%) rename src/main/java/org/springframework/samples/petclinic/{service => owner}/OwnerService.java (72%) rename src/main/java/org/springframework/samples/petclinic/{model => pet}/Pet.java (92%) rename src/main/java/org/springframework/samples/petclinic/{web => pet}/PetController.java (89%) rename src/main/java/org/springframework/samples/petclinic/{repository => pet}/PetRepository.java (91%) rename src/main/java/org/springframework/samples/petclinic/{service => pet}/PetService.java (81%) rename src/main/java/org/springframework/samples/petclinic/{model => pet}/PetType.java (87%) rename src/main/java/org/springframework/samples/petclinic/{web => pet}/PetTypeFormatter.java (90%) rename src/main/java/org/springframework/samples/petclinic/{web => pet}/PetValidator.java (94%) rename src/main/java/org/springframework/samples/petclinic/{model => pet}/Visit.java (95%) rename src/main/java/org/springframework/samples/petclinic/{web => pet}/VisitController.java (90%) rename src/main/java/org/springframework/samples/petclinic/{repository => pet}/VisitRepository.java (93%) rename src/main/java/org/springframework/samples/petclinic/{service => pet}/exceptions/DuplicatedPetNameException.java (81%) delete mode 100644 src/main/java/org/springframework/samples/petclinic/service/businessrules/ElementInCollectionValidator.java rename src/main/java/org/springframework/samples/petclinic/{model => user}/Authorities.java (79%) rename src/main/java/org/springframework/samples/petclinic/{repository => user}/AuthoritiesRepository.java (55%) rename src/main/java/org/springframework/samples/petclinic/{service => user}/AuthoritiesService.java (86%) rename src/main/java/org/springframework/samples/petclinic/{model => user}/User.java (89%) rename src/main/java/org/springframework/samples/petclinic/{web => user}/UserController.java (81%) rename src/main/java/org/springframework/samples/petclinic/{repository => user}/UserRepository.java (54%) rename src/main/java/org/springframework/samples/petclinic/{service => user}/UserService.java (86%) rename src/main/java/org/springframework/samples/petclinic/{model => vet}/Specialty.java (88%) rename src/main/java/org/springframework/samples/petclinic/{model => vet}/Vet.java (95%) rename src/main/java/org/springframework/samples/petclinic/{web => vet}/VetController.java (91%) rename src/main/java/org/springframework/samples/petclinic/{repository => vet}/VetRepository.java (92%) rename src/main/java/org/springframework/samples/petclinic/{service => vet}/VetService.java (65%) rename src/main/java/org/springframework/samples/petclinic/{model => vet}/Vets.java (95%) rename src/test/java/org/springframework/samples/petclinic/{web => owner}/OwnerControllerTests.java (94%) rename src/test/java/org/springframework/samples/petclinic/{service => owner}/OwnerServiceTests.java (88%) rename src/test/java/org/springframework/samples/petclinic/{web => pet}/PetControllerTests.java (90%) rename src/test/java/org/springframework/samples/petclinic/{service => pet}/PetServiceTests.java (93%) rename src/test/java/org/springframework/samples/petclinic/{web => pet}/PetTypeFormatterTests.java (86%) rename src/test/java/org/springframework/samples/petclinic/{web => pet}/VisitControllerTests.java (91%) rename src/test/java/org/springframework/samples/petclinic/{web => vet}/VetControllerTests.java (90%) rename src/test/java/org/springframework/samples/petclinic/{service => vet}/VetServiceTests.java (84%) diff --git a/src/main/java/org/springframework/samples/petclinic/model/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java similarity index 94% rename from src/main/java/org/springframework/samples/petclinic/model/Owner.java rename to src/main/java/org/springframework/samples/petclinic/owner/Owner.java index 31b311aa9a6..8a2976828e1 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java @@ -1,179 +1,182 @@ -/* - * 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.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.JoinColumn; -import javax.persistence.OneToMany; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.validation.constraints.Digits; -import javax.validation.constraints.NotEmpty; - -import org.springframework.beans.support.MutableSortDefinition; -import org.springframework.beans.support.PropertyComparator; -import org.springframework.core.style.ToStringCreator; - -/** - * 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; - - // - @OneToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "username", referencedColumnName = "username") - private User user; - // - - public String getAddress() { - return this.address; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - 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) { - getPetsInternal().add(pet); - pet.setOwner(this); - } - - public boolean removePet(Pet pet) { - return getPetsInternal().remove(pet); - } - - /** - * 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); - } - - public Pet getPetwithIdDifferent(String name,Integer id) { - name = name.toLowerCase(); - for (Pet pet : getPetsInternal()) { - String compName = pet.getName(); - compName = compName.toLowerCase(); - if (compName.equals(name) && pet.getId()!=id) { - return pet; - } - } - return null; - } - - /** - * 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.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.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.validation.constraints.Digits; +import javax.validation.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; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.user.User; + +/** + * 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; + + // + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "username", referencedColumnName = "username") + private User user; + // + + public String getAddress() { + return this.address; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + 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) { + getPetsInternal().add(pet); + pet.setOwner(this); + } + + public boolean removePet(Pet pet) { + return getPetsInternal().remove(pet); + } + + /** + * 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); + } + + public Pet getPetwithIdDifferent(String name,Integer id) { + name = name.toLowerCase(); + for (Pet pet : getPetsInternal()) { + String compName = pet.getName(); + compName = compName.toLowerCase(); + if (compName.equals(name) && pet.getId()!=id) { + return pet; + } + } + return null; + } + + /** + * 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(); + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java similarity index 88% rename from src/main/java/org/springframework/samples/petclinic/web/OwnerController.java rename to src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java index 952d3b3033a..b923ad4faa3 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java @@ -1,144 +1,142 @@ -/* - * 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.web; - -import java.util.Collection; -import java.util.Map; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.service.AuthoritiesService; -import org.springframework.samples.petclinic.service.OwnerService; -import org.springframework.samples.petclinic.service.VetService; -import org.springframework.samples.petclinic.service.UserService; -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.*; -import org.springframework.web.servlet.ModelAndView; - -/** - * @author Juergen Hoeller - * @author Ken Krebs - * @author Arjen Poutsma - * @author Michael Isvy - */ -@Controller -public class OwnerController { - - private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; - - private final OwnerService ownerService; - - @Autowired - public OwnerController(OwnerService ownerService, UserService userService, AuthoritiesService authoritiesService) { - this.ownerService = ownerService; - } - - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); - } - - @GetMapping(value = "/owners/new") - public String initCreationForm(Map model) { - Owner owner = new Owner(); - model.put("owner", owner); - return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; - } - - @PostMapping(value = "/owners/new") - public String processCreationForm(@Valid Owner owner, BindingResult result) { - if (result.hasErrors()) { - return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; - } - else { - //creating owner, user and authorities - this.ownerService.saveOwner(owner); - - return "redirect:/owners/" + owner.getId(); - } - } - - @GetMapping(value = "/owners/find") - public String initFindForm(Map model) { - model.put("owner", new Owner()); - return "owners/findOwners"; - } - - @GetMapping(value = "/owners") - public String processFindForm(Owner owner, BindingResult result, Map model) { - - // allow parameterless GET request for /owners to return all records - if (owner.getLastName() == null) { - owner.setLastName(""); // empty string signifies broadest possible search - } - - // find owners by last name - Collection results = this.ownerService.findOwnerByLastName(owner.getLastName()); - if (results.isEmpty()) { - // no owners found - result.rejectValue("lastName", "notFound", "not found"); - return "owners/findOwners"; - } - else if (results.size() == 1) { - // 1 owner found - owner = results.iterator().next(); - return "redirect:/owners/" + owner.getId(); - } - else { - // multiple owners found - model.put("selections", results); - return "owners/ownersList"; - } - } - - @GetMapping(value = "/owners/{ownerId}/edit") - public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { - Owner owner = this.ownerService.findOwnerById(ownerId); - model.addAttribute(owner); - return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; - } - - @PostMapping(value = "/owners/{ownerId}/edit") - public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, - @PathVariable("ownerId") int ownerId) { - if (result.hasErrors()) { - return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; - } - else { - owner.setId(ownerId); - this.ownerService.saveOwner(owner); - return "redirect:/owners/{ownerId}"; - } - } - - /** - * Custom handler for displaying an owner. - * @param ownerId the ID of the owner to display - * @return a ModelMap with the model attributes for the view - */ - @GetMapping("/owners/{ownerId}") - public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { - ModelAndView mav = new ModelAndView("owners/ownerDetails"); - mav.addObject(this.ownerService.findOwnerById(ownerId)); - return mav; - } - -} +/* + * 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 java.util.Map; + +import javax.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.samples.petclinic.user.AuthoritiesService; +import org.springframework.samples.petclinic.user.UserService; +import org.springframework.samples.petclinic.vet.VetService; +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.*; +import org.springframework.web.servlet.ModelAndView; + +/** + * @author Juergen Hoeller + * @author Ken Krebs + * @author Arjen Poutsma + * @author Michael Isvy + */ +@Controller +public class OwnerController { + + private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + + private final OwnerService ownerService; + + @Autowired + public OwnerController(OwnerService ownerService, UserService userService, AuthoritiesService authoritiesService) { + this.ownerService = ownerService; + } + + @InitBinder + public void setAllowedFields(WebDataBinder dataBinder) { + dataBinder.setDisallowedFields("id"); + } + + @GetMapping(value = "/owners/new") + public String initCreationForm(Map model) { + Owner owner = new Owner(); + model.put("owner", owner); + return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; + } + + @PostMapping(value = "/owners/new") + public String processCreationForm(@Valid Owner owner, BindingResult result) { + if (result.hasErrors()) { + return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; + } + else { + //creating owner, user and authorities + this.ownerService.saveOwner(owner); + + return "redirect:/owners/" + owner.getId(); + } + } + + @GetMapping(value = "/owners/find") + public String initFindForm(Map model) { + model.put("owner", new Owner()); + return "owners/findOwners"; + } + + @GetMapping(value = "/owners") + public String processFindForm(Owner owner, BindingResult result, Map model) { + + // allow parameterless GET request for /owners to return all records + if (owner.getLastName() == null) { + owner.setLastName(""); // empty string signifies broadest possible search + } + + // find owners by last name + Collection results = this.ownerService.findOwnerByLastName(owner.getLastName()); + if (results.isEmpty()) { + // no owners found + result.rejectValue("lastName", "notFound", "not found"); + return "owners/findOwners"; + } + else if (results.size() == 1) { + // 1 owner found + owner = results.iterator().next(); + return "redirect:/owners/" + owner.getId(); + } + else { + // multiple owners found + model.put("selections", results); + return "owners/ownersList"; + } + } + + @GetMapping(value = "/owners/{ownerId}/edit") + public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { + Owner owner = this.ownerService.findOwnerById(ownerId); + model.addAttribute(owner); + return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; + } + + @PostMapping(value = "/owners/{ownerId}/edit") + public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, + @PathVariable("ownerId") int ownerId) { + if (result.hasErrors()) { + return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; + } + else { + owner.setId(ownerId); + this.ownerService.saveOwner(owner); + return "redirect:/owners/{ownerId}"; + } + } + + /** + * Custom handler for displaying an owner. + * @param ownerId the ID of the owner to display + * @return a ModelMap with the model attributes for the view + */ + @GetMapping("/owners/{ownerId}") + public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { + ModelAndView mav = new ModelAndView("owners/ownerDetails"); + mav.addObject(this.ownerService.findOwnerById(ownerId)); + return mav; + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java similarity index 92% rename from src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java rename to src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java index 21eb1b7e50b..9ab61ac0842 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/OwnerRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.repository; +package org.springframework.samples.petclinic.owner; import java.util.Collection; @@ -22,8 +22,7 @@ import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.Param; import org.springframework.samples.petclinic.model.BaseEntity; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.repository.OwnerRepository; +import org.springframework.samples.petclinic.owner.OwnerRepository; /** * Spring Data JPA OwnerRepository interface diff --git a/src/main/java/org/springframework/samples/petclinic/service/OwnerService.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerService.java similarity index 72% rename from src/main/java/org/springframework/samples/petclinic/service/OwnerService.java rename to src/main/java/org/springframework/samples/petclinic/owner/OwnerService.java index 73e745095d3..8de1db1112d 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/OwnerService.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerService.java @@ -1,79 +1,79 @@ -/* - * 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.service; - -import java.util.Collection; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.model.Vet; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.repository.OwnerRepository; -import org.springframework.samples.petclinic.repository.PetRepository; -import org.springframework.samples.petclinic.repository.VetRepository; -import org.springframework.samples.petclinic.repository.VisitRepository; -import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ -@Service -public class OwnerService { - - private OwnerRepository ownerRepository; - - @Autowired - private UserService userService; - - @Autowired - private AuthoritiesService authoritiesService; - - @Autowired - public OwnerService(OwnerRepository ownerRepository) { - this.ownerRepository = ownerRepository; - } - - @Transactional(readOnly = true) - public Owner findOwnerById(int id) throws DataAccessException { - return ownerRepository.findById(id); - } - - @Transactional(readOnly = true) - public Collection findOwnerByLastName(String lastName) throws DataAccessException { - return ownerRepository.findByLastName(lastName); - } - - @Transactional - public void saveOwner(Owner owner) throws DataAccessException { - //creating owner - ownerRepository.save(owner); - //creating user - userService.saveUser(owner.getUser()); - //creating authorities - authoritiesService.saveAuthorities(owner.getUser().getUsername(), "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.petclinic.owner; + +import java.util.Collection; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.dao.DataAccessException; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.pet.PetRepository; +import org.springframework.samples.petclinic.pet.PetType; +import org.springframework.samples.petclinic.pet.Visit; +import org.springframework.samples.petclinic.pet.VisitRepository; +import org.springframework.samples.petclinic.pet.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.user.AuthoritiesService; +import org.springframework.samples.petclinic.user.UserService; +import org.springframework.samples.petclinic.vet.Vet; +import org.springframework.samples.petclinic.vet.VetRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +/** + * Mostly used as a facade for all Petclinic controllers Also a placeholder + * for @Transactional and @Cacheable annotations + * + * @author Michael Isvy + */ +@Service +public class OwnerService { + + private OwnerRepository ownerRepository; + + @Autowired + private UserService userService; + + @Autowired + private AuthoritiesService authoritiesService; + + @Autowired + public OwnerService(OwnerRepository ownerRepository) { + this.ownerRepository = ownerRepository; + } + + @Transactional(readOnly = true) + public Owner findOwnerById(int id) throws DataAccessException { + return ownerRepository.findById(id); + } + + @Transactional(readOnly = true) + public Collection findOwnerByLastName(String lastName) throws DataAccessException { + return ownerRepository.findByLastName(lastName); + } + + @Transactional + public void saveOwner(Owner owner) throws DataAccessException { + //creating owner + ownerRepository.save(owner); + //creating user + userService.saveUser(owner.getUser()); + //creating authorities + authoritiesService.saveAuthorities(owner.getUser().getUsername(), "owner"); + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/model/Pet.java b/src/main/java/org/springframework/samples/petclinic/pet/Pet.java similarity index 92% rename from src/main/java/org/springframework/samples/petclinic/model/Pet.java rename to src/main/java/org/springframework/samples/petclinic/pet/Pet.java index 06a3ae0c0b4..948215dbf81 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/Pet.java @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.pet; 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.owner.Owner; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -83,7 +85,7 @@ public Owner getOwner() { return this.owner; } - protected void setOwner(Owner owner) { + public void setOwner(Owner owner) { this.owner = owner; } diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetController.java b/src/main/java/org/springframework/samples/petclinic/pet/PetController.java similarity index 89% rename from src/main/java/org/springframework/samples/petclinic/web/PetController.java rename to src/main/java/org/springframework/samples/petclinic/pet/PetController.java index 725b2b48bec..437ab15788c 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/PetController.java @@ -13,13 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.pet; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.service.VetService; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.util.StringUtils; @@ -34,10 +30,10 @@ import java.util.logging.Logger; import org.springframework.beans.BeanUtils; import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.service.OwnerService; -import org.springframework.samples.petclinic.service.PetService; -import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.OwnerService; +import org.springframework.samples.petclinic.pet.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.vet.VetService; /** * @author Juergen Hoeller diff --git a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java b/src/main/java/org/springframework/samples/petclinic/pet/PetRepository.java similarity index 91% rename from src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java rename to src/main/java/org/springframework/samples/petclinic/pet/PetRepository.java index c9848dd6e67..3767b31bd4e 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/PetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/PetRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.repository; +package org.springframework.samples.petclinic.pet; import java.util.List; @@ -21,8 +21,6 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; import org.springframework.samples.petclinic.model.BaseEntity; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; /** * Spring Data JPA specialization of the {@link PetRepository} interface diff --git a/src/main/java/org/springframework/samples/petclinic/service/PetService.java b/src/main/java/org/springframework/samples/petclinic/pet/PetService.java similarity index 81% rename from src/main/java/org/springframework/samples/petclinic/service/PetService.java rename to src/main/java/org/springframework/samples/petclinic/pet/PetService.java index f05f05fef38..09331bb7857 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/PetService.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/PetService.java @@ -1,82 +1,77 @@ -/* - * 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.service; - -import java.util.Collection; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.repository.PetRepository; -import org.springframework.samples.petclinic.repository.VisitRepository; -import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ -@Service -public class PetService { - - private PetRepository petRepository; - - private VisitRepository visitRepository; - - - @Autowired - public PetService(PetRepository petRepository, - VisitRepository visitRepository) { - this.petRepository = petRepository; - this.visitRepository = visitRepository; - } - - @Transactional(readOnly = true) - public Collection findPetTypes() throws DataAccessException { - return petRepository.findPetTypes(); - } - - @Transactional - public void saveVisit(Visit visit) throws DataAccessException { - visitRepository.save(visit); - } - - @Transactional(readOnly = true) - public Pet findPetById(int id) throws DataAccessException { - return petRepository.findById(id); - } - - @Transactional(rollbackFor = DuplicatedPetNameException.class) - public void savePet(Pet pet) throws DataAccessException, DuplicatedPetNameException { - Pet otherPet=pet.getOwner().getPetwithIdDifferent(pet.getName(), pet.getId()); - if (StringUtils.hasLength(pet.getName()) && (otherPet!= null && otherPet.getId()!=pet.getId())) { - throw new DuplicatedPetNameException(); - }else - petRepository.save(pet); - } - - - public Collection findVisitsByPetId(int petId) { - return visitRepository.findByPetId(petId); - } - -} +/* + * 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.pet; + +import java.util.Collection; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.samples.petclinic.pet.exceptions.DuplicatedPetNameException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +/** + * Mostly used as a facade for all Petclinic controllers Also a placeholder + * for @Transactional and @Cacheable annotations + * + * @author Michael Isvy + */ +@Service +public class PetService { + + private PetRepository petRepository; + + private VisitRepository visitRepository; + + + @Autowired + public PetService(PetRepository petRepository, + VisitRepository visitRepository) { + this.petRepository = petRepository; + this.visitRepository = visitRepository; + } + + @Transactional(readOnly = true) + public Collection findPetTypes() throws DataAccessException { + return petRepository.findPetTypes(); + } + + @Transactional + public void saveVisit(Visit visit) throws DataAccessException { + visitRepository.save(visit); + } + + @Transactional(readOnly = true) + public Pet findPetById(int id) throws DataAccessException { + return petRepository.findById(id); + } + + @Transactional(rollbackFor = DuplicatedPetNameException.class) + public void savePet(Pet pet) throws DataAccessException, DuplicatedPetNameException { + Pet otherPet=pet.getOwner().getPetwithIdDifferent(pet.getName(), pet.getId()); + if (StringUtils.hasLength(pet.getName()) && (otherPet!= null && otherPet.getId()!=pet.getId())) { + throw new DuplicatedPetNameException(); + }else + petRepository.save(pet); + } + + + public Collection findVisitsByPetId(int petId) { + return visitRepository.findByPetId(petId); + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/model/PetType.java b/src/main/java/org/springframework/samples/petclinic/pet/PetType.java similarity index 87% rename from src/main/java/org/springframework/samples/petclinic/model/PetType.java rename to src/main/java/org/springframework/samples/petclinic/pet/PetType.java index eb44dd8a683..54947771e3b 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/PetType.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/PetType.java @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.pet; import javax.persistence.Entity; import javax.persistence.Table; +import org.springframework.samples.petclinic.model.NamedEntity; + /** * @author Juergen Hoeller Can be Cat, Dog, Hamster... */ diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java b/src/main/java/org/springframework/samples/petclinic/pet/PetTypeFormatter.java similarity index 90% rename from src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java rename to src/main/java/org/springframework/samples/petclinic/pet/PetTypeFormatter.java index 6daac427ac9..587a415aae7 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetTypeFormatter.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/PetTypeFormatter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.pet; import java.text.ParseException; import java.util.Collection; @@ -21,9 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.Formatter; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.service.PetService; -import org.springframework.samples.petclinic.service.VetService; +import org.springframework.samples.petclinic.vet.VetService; import org.springframework.stereotype.Component; /** diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java b/src/main/java/org/springframework/samples/petclinic/pet/PetValidator.java similarity index 94% rename from src/main/java/org/springframework/samples/petclinic/web/PetValidator.java rename to src/main/java/org/springframework/samples/petclinic/pet/PetValidator.java index b70aac5fce7..9b1160613bd 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/PetValidator.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.pet; -import org.springframework.samples.petclinic.model.Pet; import org.springframework.util.StringUtils; import org.springframework.validation.Errors; import org.springframework.validation.Validator; diff --git a/src/main/java/org/springframework/samples/petclinic/model/Visit.java b/src/main/java/org/springframework/samples/petclinic/pet/Visit.java similarity index 95% rename from src/main/java/org/springframework/samples/petclinic/model/Visit.java rename to src/main/java/org/springframework/samples/petclinic/pet/Visit.java index b626199c7bd..b91eeb76587 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/Visit.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.pet; import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.samples.petclinic.model.BaseEntity; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/org/springframework/samples/petclinic/web/VisitController.java b/src/main/java/org/springframework/samples/petclinic/pet/VisitController.java similarity index 90% rename from src/main/java/org/springframework/samples/petclinic/web/VisitController.java rename to src/main/java/org/springframework/samples/petclinic/pet/VisitController.java index 0518de9732e..cd2731e5c78 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/VisitController.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/VisitController.java @@ -13,17 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.pet; import java.util.Map; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.service.PetService; -import org.springframework.samples.petclinic.service.VetService; +import org.springframework.samples.petclinic.vet.VetService; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java b/src/main/java/org/springframework/samples/petclinic/pet/VisitRepository.java similarity index 93% rename from src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java rename to src/main/java/org/springframework/samples/petclinic/pet/VisitRepository.java index fd3d9181d51..b59136b8fe6 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/VisitRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/VisitRepository.java @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.repository; +package org.springframework.samples.petclinic.pet; import java.util.List; import org.springframework.dao.DataAccessException; import org.springframework.data.repository.Repository; import org.springframework.samples.petclinic.model.BaseEntity; -import org.springframework.samples.petclinic.model.Visit; /** * Repository class for Visit domain objects All method names are compliant diff --git a/src/main/java/org/springframework/samples/petclinic/service/exceptions/DuplicatedPetNameException.java b/src/main/java/org/springframework/samples/petclinic/pet/exceptions/DuplicatedPetNameException.java similarity index 81% rename from src/main/java/org/springframework/samples/petclinic/service/exceptions/DuplicatedPetNameException.java rename to src/main/java/org/springframework/samples/petclinic/pet/exceptions/DuplicatedPetNameException.java index b10347ea519..53a1d9e3175 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/exceptions/DuplicatedPetNameException.java +++ b/src/main/java/org/springframework/samples/petclinic/pet/exceptions/DuplicatedPetNameException.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.springframework.samples.petclinic.service.exceptions; +package org.springframework.samples.petclinic.pet.exceptions; /** * diff --git a/src/main/java/org/springframework/samples/petclinic/service/businessrules/ElementInCollectionValidator.java b/src/main/java/org/springframework/samples/petclinic/service/businessrules/ElementInCollectionValidator.java deleted file mode 100644 index 33bc7f67d1a..00000000000 --- a/src/main/java/org/springframework/samples/petclinic/service/businessrules/ElementInCollectionValidator.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.springframework.samples.petclinic.service.businessrules; - -public class ElementInCollectionValidator { - -} diff --git a/src/main/java/org/springframework/samples/petclinic/model/Authorities.java b/src/main/java/org/springframework/samples/petclinic/user/Authorities.java similarity index 79% rename from src/main/java/org/springframework/samples/petclinic/model/Authorities.java rename to src/main/java/org/springframework/samples/petclinic/user/Authorities.java index 405e91135bc..66e681fec9c 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Authorities.java +++ b/src/main/java/org/springframework/samples/petclinic/user/Authorities.java @@ -1,4 +1,4 @@ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.user; import javax.persistence.Entity; import javax.persistence.JoinColumn; @@ -6,6 +6,8 @@ import javax.persistence.Table; import javax.validation.constraints.Size; +import org.springframework.samples.petclinic.model.BaseEntity; + import lombok.Data; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/AuthoritiesRepository.java b/src/main/java/org/springframework/samples/petclinic/user/AuthoritiesRepository.java similarity index 55% rename from src/main/java/org/springframework/samples/petclinic/repository/AuthoritiesRepository.java rename to src/main/java/org/springframework/samples/petclinic/user/AuthoritiesRepository.java index 4cd6137cf80..367cee340ad 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/AuthoritiesRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/user/AuthoritiesRepository.java @@ -1,7 +1,6 @@ -package org.springframework.samples.petclinic.repository; +package org.springframework.samples.petclinic.user; import org.springframework.data.repository.CrudRepository; -import org.springframework.samples.petclinic.model.Authorities; diff --git a/src/main/java/org/springframework/samples/petclinic/service/AuthoritiesService.java b/src/main/java/org/springframework/samples/petclinic/user/AuthoritiesService.java similarity index 86% rename from src/main/java/org/springframework/samples/petclinic/service/AuthoritiesService.java rename to src/main/java/org/springframework/samples/petclinic/user/AuthoritiesService.java index 8b9219e4c29..b7695965d93 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/AuthoritiesService.java +++ b/src/main/java/org/springframework/samples/petclinic/user/AuthoritiesService.java @@ -1,66 +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.service; - - -import java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Authorities; -import org.springframework.samples.petclinic.model.User; -import org.springframework.samples.petclinic.repository.AuthoritiesRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ -@Service -public class AuthoritiesService { - - private AuthoritiesRepository authoritiesRepository; - private UserService userService; - - @Autowired - public AuthoritiesService(AuthoritiesRepository authoritiesRepository,UserService userService) { - this.authoritiesRepository = authoritiesRepository; - this.userService = userService; - } - - @Transactional - public void saveAuthorities(Authorities authorities) throws DataAccessException { - authoritiesRepository.save(authorities); - } - - @Transactional - public void saveAuthorities(String username, String role) throws DataAccessException { - Authorities authority = new Authorities(); - Optional user = userService.findUser(username); - if(user.isPresent()) { - authority.setUser(user.get()); - authority.setAuthority(role); - //user.get().getAuthorities().add(authority); - authoritiesRepository.save(authority); - }else - throw new DataAccessException("User '"+username+"' not found!") {}; - } - - -} +/* + * 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.user; + + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * Mostly used as a facade for all Petclinic controllers Also a placeholder + * for @Transactional and @Cacheable annotations + * + * @author Michael Isvy + */ +@Service +public class AuthoritiesService { + + private AuthoritiesRepository authoritiesRepository; + private UserService userService; + + @Autowired + public AuthoritiesService(AuthoritiesRepository authoritiesRepository,UserService userService) { + this.authoritiesRepository = authoritiesRepository; + this.userService = userService; + } + + @Transactional + public void saveAuthorities(Authorities authorities) throws DataAccessException { + authoritiesRepository.save(authorities); + } + + @Transactional + public void saveAuthorities(String username, String role) throws DataAccessException { + Authorities authority = new Authorities(); + Optional user = userService.findUser(username); + if(user.isPresent()) { + authority.setUser(user.get()); + authority.setAuthority(role); + //user.get().getAuthorities().add(authority); + authoritiesRepository.save(authority); + }else + throw new DataAccessException("User '"+username+"' not found!") {}; + } + + +} diff --git a/src/main/java/org/springframework/samples/petclinic/model/User.java b/src/main/java/org/springframework/samples/petclinic/user/User.java similarity index 89% rename from src/main/java/org/springframework/samples/petclinic/model/User.java rename to src/main/java/org/springframework/samples/petclinic/user/User.java index 9a05f6fb1ef..11632e746fb 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/User.java +++ b/src/main/java/org/springframework/samples/petclinic/user/User.java @@ -1,4 +1,4 @@ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.user; import java.util.Set; diff --git a/src/main/java/org/springframework/samples/petclinic/web/UserController.java b/src/main/java/org/springframework/samples/petclinic/user/UserController.java similarity index 81% rename from src/main/java/org/springframework/samples/petclinic/web/UserController.java rename to src/main/java/org/springframework/samples/petclinic/user/UserController.java index a1de38ac5e3..4dbc6da2629 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/UserController.java +++ b/src/main/java/org/springframework/samples/petclinic/user/UserController.java @@ -1,75 +1,73 @@ -/* - * 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.web; - -import java.util.Map; - -import javax.validation.Valid; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.service.AuthoritiesService; -import org.springframework.samples.petclinic.service.OwnerService; -import org.springframework.samples.petclinic.service.VetService; -import org.springframework.samples.petclinic.service.UserService; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.*; - -/** - * @author Juergen Hoeller - * @author Ken Krebs - * @author Arjen Poutsma - * @author Michael Isvy - */ -@Controller -public class UserController { - - private static final String VIEWS_OWNER_CREATE_FORM = "users/createOwnerForm"; - - private final OwnerService ownerService; - - @Autowired - public UserController(OwnerService clinicService) { - this.ownerService = clinicService; - } - - @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { - dataBinder.setDisallowedFields("id"); - } - - @GetMapping(value = "/users/new") - public String initCreationForm(Map model) { - Owner owner = new Owner(); - model.put("owner", owner); - return VIEWS_OWNER_CREATE_FORM; - } - - @PostMapping(value = "/users/new") - public String processCreationForm(@Valid Owner owner, BindingResult result) { - if (result.hasErrors()) { - return VIEWS_OWNER_CREATE_FORM; - } - else { - //creating owner, user, and authority - this.ownerService.saveOwner(owner); - return "redirect:/"; - } - } - -} +/* + * 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.user; + +import java.util.Map; + +import javax.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.OwnerService; +import org.springframework.samples.petclinic.vet.VetService; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.*; + +/** + * @author Juergen Hoeller + * @author Ken Krebs + * @author Arjen Poutsma + * @author Michael Isvy + */ +@Controller +public class UserController { + + private static final String VIEWS_OWNER_CREATE_FORM = "users/createOwnerForm"; + + private final OwnerService ownerService; + + @Autowired + public UserController(OwnerService clinicService) { + this.ownerService = clinicService; + } + + @InitBinder + public void setAllowedFields(WebDataBinder dataBinder) { + dataBinder.setDisallowedFields("id"); + } + + @GetMapping(value = "/users/new") + public String initCreationForm(Map model) { + Owner owner = new Owner(); + model.put("owner", owner); + return VIEWS_OWNER_CREATE_FORM; + } + + @PostMapping(value = "/users/new") + public String processCreationForm(@Valid Owner owner, BindingResult result) { + if (result.hasErrors()) { + return VIEWS_OWNER_CREATE_FORM; + } + else { + //creating owner, user, and authority + this.ownerService.saveOwner(owner); + return "redirect:/"; + } + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/repository/UserRepository.java b/src/main/java/org/springframework/samples/petclinic/user/UserRepository.java similarity index 54% rename from src/main/java/org/springframework/samples/petclinic/repository/UserRepository.java rename to src/main/java/org/springframework/samples/petclinic/user/UserRepository.java index c85d5c0bc51..d325214ac96 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/UserRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/user/UserRepository.java @@ -1,7 +1,6 @@ -package org.springframework.samples.petclinic.repository; +package org.springframework.samples.petclinic.user; import org.springframework.data.repository.CrudRepository; -import org.springframework.samples.petclinic.model.User; public interface UserRepository extends CrudRepository{ diff --git a/src/main/java/org/springframework/samples/petclinic/service/UserService.java b/src/main/java/org/springframework/samples/petclinic/user/UserService.java similarity index 86% rename from src/main/java/org/springframework/samples/petclinic/service/UserService.java rename to src/main/java/org/springframework/samples/petclinic/user/UserService.java index 882bd2759ee..0de8ca36ded 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/UserService.java +++ b/src/main/java/org/springframework/samples/petclinic/user/UserService.java @@ -1,53 +1,51 @@ -/* - * 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.service; - - -import java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.User; -import org.springframework.samples.petclinic.repository.UserRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ -@Service -public class UserService { - - private UserRepository userRepository; - - @Autowired - public UserService(UserRepository userRepository) { - this.userRepository = userRepository; - } - - @Transactional - public void saveUser(User user) throws DataAccessException { - user.setEnabled(true); - userRepository.save(user); - } - - public Optional findUser(String username) { - return userRepository.findById(username); - } -} +/* + * 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.user; + + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * Mostly used as a facade for all Petclinic controllers Also a placeholder + * for @Transactional and @Cacheable annotations + * + * @author Michael Isvy + */ +@Service +public class UserService { + + private UserRepository userRepository; + + @Autowired + public UserService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Transactional + public void saveUser(User user) throws DataAccessException { + user.setEnabled(true); + userRepository.save(user); + } + + public Optional findUser(String username) { + return userRepository.findById(username); + } +} diff --git a/src/main/java/org/springframework/samples/petclinic/model/Specialty.java b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java similarity index 88% rename from src/main/java/org/springframework/samples/petclinic/model/Specialty.java rename to src/main/java/org/springframework/samples/petclinic/vet/Specialty.java index 6ea209cd45a..826e04afce9 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Specialty.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Specialty.java @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.vet; 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). * diff --git a/src/main/java/org/springframework/samples/petclinic/model/Vet.java b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java similarity index 95% rename from src/main/java/org/springframework/samples/petclinic/model/Vet.java rename to src/main/java/org/springframework/samples/petclinic/vet/Vet.java index 9f5de9c523c..fbe814bd5c1 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.vet; import java.util.ArrayList; import java.util.Collections; @@ -31,6 +31,7 @@ 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. diff --git a/src/main/java/org/springframework/samples/petclinic/web/VetController.java b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java similarity index 91% rename from src/main/java/org/springframework/samples/petclinic/web/VetController.java rename to src/main/java/org/springframework/samples/petclinic/vet/VetController.java index 3696f20ab28..4dfdace1987 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.vet; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.samples.petclinic.model.Vets; -import org.springframework.samples.petclinic.service.VetService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; diff --git a/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java similarity index 92% rename from src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java rename to src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java index a83ff1b3cca..c51a8b40724 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/VetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.repository; +package org.springframework.samples.petclinic.vet; import java.util.Collection; import org.springframework.dao.DataAccessException; import org.springframework.data.repository.Repository; -import org.springframework.samples.petclinic.model.Vet; /** * Repository class for Vet domain objects All method names are compliant diff --git a/src/main/java/org/springframework/samples/petclinic/service/VetService.java b/src/main/java/org/springframework/samples/petclinic/vet/VetService.java similarity index 65% rename from src/main/java/org/springframework/samples/petclinic/service/VetService.java rename to src/main/java/org/springframework/samples/petclinic/vet/VetService.java index 4516fd7380a..9d30bf19c97 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/VetService.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetService.java @@ -1,59 +1,57 @@ -/* - * 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.service; - -import java.util.Collection; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.model.Vet; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.repository.OwnerRepository; -import org.springframework.samples.petclinic.repository.PetRepository; -import org.springframework.samples.petclinic.repository.VetRepository; -import org.springframework.samples.petclinic.repository.VisitRepository; -import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - -/** - * Mostly used as a facade for all Petclinic controllers Also a placeholder - * for @Transactional and @Cacheable annotations - * - * @author Michael Isvy - */ -@Service -public class VetService { - - private VetRepository vetRepository; - - - @Autowired - public VetService(VetRepository vetRepository) { - this.vetRepository = vetRepository; - } - - @Transactional(readOnly = true) - public Collection findVets() throws DataAccessException { - return vetRepository.findAll(); - } - -} +/* + * 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.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.dao.DataAccessException; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.OwnerRepository; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.pet.PetRepository; +import org.springframework.samples.petclinic.pet.PetType; +import org.springframework.samples.petclinic.pet.Visit; +import org.springframework.samples.petclinic.pet.VisitRepository; +import org.springframework.samples.petclinic.pet.exceptions.DuplicatedPetNameException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +/** + * Mostly used as a facade for all Petclinic controllers Also a placeholder + * for @Transactional and @Cacheable annotations + * + * @author Michael Isvy + */ +@Service +public class VetService { + + private VetRepository vetRepository; + + + @Autowired + public VetService(VetRepository vetRepository) { + this.vetRepository = vetRepository; + } + + @Transactional(readOnly = true) + public Collection findVets() throws DataAccessException { + return vetRepository.findAll(); + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/model/Vets.java b/src/main/java/org/springframework/samples/petclinic/vet/Vets.java similarity index 95% rename from src/main/java/org/springframework/samples/petclinic/model/Vets.java rename to src/main/java/org/springframework/samples/petclinic/vet/Vets.java index c3b569a1c28..7c74b45330f 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Vets.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vets.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.model; +package org.springframework.samples.petclinic.vet; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/springframework/samples/petclinic/web/WelcomeController.java b/src/main/java/org/springframework/samples/petclinic/web/WelcomeController.java index b57ffa5a097..b1dc6cf2f38 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/WelcomeController.java +++ b/src/main/java/org/springframework/samples/petclinic/web/WelcomeController.java @@ -3,10 +3,10 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.samples.petclinic.repository.UserRepository; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.samples.petclinic.model.User; +import org.springframework.samples.petclinic.user.User; +import org.springframework.samples.petclinic.user.UserRepository; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import java.util.List; diff --git a/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java similarity index 94% rename from src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java rename to src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java index 4813861af39..59a05e2f3e0 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java @@ -1,12 +1,15 @@ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.owner; import org.assertj.core.util.Lists; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.samples.petclinic.configuration.SecurityConfiguration; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.service.VetService; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.OwnerController; +import org.springframework.samples.petclinic.owner.OwnerService; +import org.springframework.samples.petclinic.user.AuthoritiesService; +import org.springframework.samples.petclinic.user.UserService; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -18,9 +21,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; -import org.springframework.samples.petclinic.service.AuthoritiesService; -import org.springframework.samples.petclinic.service.OwnerService; -import org.springframework.samples.petclinic.service.UserService; +import org.springframework.samples.petclinic.vet.VetService; import org.springframework.security.config.annotation.web.WebSecurityConfigurer; import org.springframework.security.test.context.support.WithMockUser; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; diff --git a/src/test/java/org/springframework/samples/petclinic/service/OwnerServiceTests.java b/src/test/java/org/springframework/samples/petclinic/owner/OwnerServiceTests.java similarity index 88% rename from src/test/java/org/springframework/samples/petclinic/service/OwnerServiceTests.java rename to src/test/java/org/springframework/samples/petclinic/owner/OwnerServiceTests.java index 863b3a40ab8..3001ebba592 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/OwnerServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/OwnerServiceTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.service; +package org.springframework.samples.petclinic.owner; import static org.assertj.core.api.Assertions.assertThat; @@ -28,15 +28,16 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.model.Vet; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.model.User; -import org.springframework.samples.petclinic.model.Authorities; -import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.OwnerService; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.pet.PetType; +import org.springframework.samples.petclinic.pet.Visit; +import org.springframework.samples.petclinic.pet.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.user.Authorities; +import org.springframework.samples.petclinic.user.User; import org.springframework.samples.petclinic.util.EntityUtils; +import org.springframework.samples.petclinic.vet.Vet; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; diff --git a/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/pet/PetControllerTests.java similarity index 90% rename from src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java rename to src/test/java/org/springframework/samples/petclinic/pet/PetControllerTests.java index 8764973e39a..83543cbdd0e 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/pet/PetControllerTests.java @@ -1,4 +1,4 @@ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.pet; /* * Copyright 2012-2019 the original author or authors. @@ -33,12 +33,14 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; import org.springframework.samples.petclinic.configuration.SecurityConfiguration; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.service.OwnerService; -import org.springframework.samples.petclinic.service.PetService; -import org.springframework.samples.petclinic.service.VetService; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.OwnerService; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.pet.PetController; +import org.springframework.samples.petclinic.pet.PetService; +import org.springframework.samples.petclinic.pet.PetType; +import org.springframework.samples.petclinic.pet.PetTypeFormatter; +import org.springframework.samples.petclinic.vet.VetService; import org.springframework.security.config.annotation.web.WebSecurityConfigurer; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; diff --git a/src/test/java/org/springframework/samples/petclinic/service/PetServiceTests.java b/src/test/java/org/springframework/samples/petclinic/pet/PetServiceTests.java similarity index 93% rename from src/test/java/org/springframework/samples/petclinic/service/PetServiceTests.java rename to src/test/java/org/springframework/samples/petclinic/pet/PetServiceTests.java index 936e735f3d5..a028acb5e0b 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/PetServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/pet/PetServiceTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.service; +package org.springframework.samples.petclinic.pet; import static org.assertj.core.api.Assertions.assertThat; @@ -28,14 +28,15 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.model.Vet; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.model.User; -import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.owner.OwnerService; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.pet.PetService; +import org.springframework.samples.petclinic.pet.PetType; +import org.springframework.samples.petclinic.pet.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.user.User; import org.springframework.samples.petclinic.util.EntityUtils; +import org.springframework.samples.petclinic.vet.Vet; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/test/java/org/springframework/samples/petclinic/web/PetTypeFormatterTests.java b/src/test/java/org/springframework/samples/petclinic/pet/PetTypeFormatterTests.java similarity index 86% rename from src/test/java/org/springframework/samples/petclinic/web/PetTypeFormatterTests.java rename to src/test/java/org/springframework/samples/petclinic/pet/PetTypeFormatterTests.java index a90613f154c..c631040dabe 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/PetTypeFormatterTests.java +++ b/src/test/java/org/springframework/samples/petclinic/pet/PetTypeFormatterTests.java @@ -1,4 +1,4 @@ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.pet; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -7,8 +7,9 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.service.VetService; +import org.springframework.samples.petclinic.pet.PetService; +import org.springframework.samples.petclinic.pet.PetType; +import org.springframework.samples.petclinic.pet.PetTypeFormatter; import java.text.ParseException; import java.util.ArrayList; @@ -17,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.samples.petclinic.service.PetService; +import org.springframework.samples.petclinic.vet.VetService; /** * Test class for {@link PetTypeFormatter} diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java b/src/test/java/org/springframework/samples/petclinic/pet/VisitControllerTests.java similarity index 91% rename from src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java rename to src/test/java/org/springframework/samples/petclinic/pet/VisitControllerTests.java index 87451fd9462..bae4cf2fd11 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/pet/VisitControllerTests.java @@ -1,4 +1,4 @@ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.pet; import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -15,9 +15,10 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; import org.springframework.samples.petclinic.configuration.SecurityConfiguration; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.service.PetService; -import org.springframework.samples.petclinic.service.VetService; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.pet.PetService; +import org.springframework.samples.petclinic.pet.VisitController; +import org.springframework.samples.petclinic.vet.VetService; import org.springframework.security.config.annotation.web.WebSecurityConfigurer; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; diff --git a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java similarity index 90% rename from src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java rename to src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java index f648c48ba09..d12172c5405 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java @@ -1,4 +1,4 @@ -package org.springframework.samples.petclinic.web; +package org.springframework.samples.petclinic.vet; import org.assertj.core.util.Lists; import org.junit.jupiter.api.BeforeEach; @@ -6,9 +6,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.samples.petclinic.configuration.SecurityConfiguration; -import org.springframework.samples.petclinic.model.Specialty; -import org.springframework.samples.petclinic.model.Vet; -import org.springframework.samples.petclinic.service.VetService; +import org.springframework.samples.petclinic.vet.Specialty; +import org.springframework.samples.petclinic.vet.Vet; +import org.springframework.samples.petclinic.vet.VetController; +import org.springframework.samples.petclinic.vet.VetService; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; diff --git a/src/test/java/org/springframework/samples/petclinic/service/VetServiceTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetServiceTests.java similarity index 84% rename from src/test/java/org/springframework/samples/petclinic/service/VetServiceTests.java rename to src/test/java/org/springframework/samples/petclinic/vet/VetServiceTests.java index 10732a019f6..f6948f6de1e 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/VetServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetServiceTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.service; +package org.springframework.samples.petclinic.vet; import static org.assertj.core.api.Assertions.assertThat; @@ -28,15 +28,16 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.dao.DataAccessException; -import org.springframework.samples.petclinic.model.Owner; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; -import org.springframework.samples.petclinic.model.Vet; -import org.springframework.samples.petclinic.model.Visit; -import org.springframework.samples.petclinic.model.User; -import org.springframework.samples.petclinic.model.Authorities; -import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.owner.Owner; +import org.springframework.samples.petclinic.pet.Pet; +import org.springframework.samples.petclinic.pet.PetType; +import org.springframework.samples.petclinic.pet.Visit; +import org.springframework.samples.petclinic.pet.exceptions.DuplicatedPetNameException; +import org.springframework.samples.petclinic.user.Authorities; +import org.springframework.samples.petclinic.user.User; import org.springframework.samples.petclinic.util.EntityUtils; +import org.springframework.samples.petclinic.vet.Vet; +import org.springframework.samples.petclinic.vet.VetService; import org.springframework.stereotype.Service; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension;