From b46b97a3e702c2f3bf03d85ef5d9d593ab9297dc Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Sun, 19 Jan 2025 19:43:29 +0100 Subject: [PATCH 1/7] Remove unused Transactional import Signed-off-by: Antoine Rey --- .../springframework/samples/petclinic/owner/OwnerRepository.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java index 5d7a40fbb..ab594841c 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java @@ -23,7 +23,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.springframework.transaction.annotation.Transactional; /** * Repository class for Owner domain objects All method names are compliant From 73d73609b5dafb11e070f19150f66a4fc679d314 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Sun, 19 Jan 2025 19:13:56 +0100 Subject: [PATCH 2/7] Use Java Streams to sort the Specialty objects by their name Signed-off-by: Antoine Rey --- .../springframework/samples/petclinic/vet/Vet.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java index d8a1fc84d..00c7ec1c8 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vet.java @@ -15,14 +15,13 @@ */ package org.springframework.samples.petclinic.vet; -import java.util.ArrayList; -import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; -import org.springframework.beans.support.MutableSortDefinition; -import org.springframework.beans.support.PropertyComparator; +import org.springframework.samples.petclinic.model.NamedEntity; import org.springframework.samples.petclinic.model.Person; import jakarta.persistence.Entity; @@ -59,9 +58,9 @@ public class Vet extends Person { @XmlElement public List getSpecialties() { - List sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); - PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true)); - return Collections.unmodifiableList(sortedSpecs); + return getSpecialtiesInternal().stream() + .sorted(Comparator.comparing(NamedEntity::getName)) + .collect(Collectors.toList()); } public int getNrOfSpecialties() { From 1f89996e1ff53eb0d3990bbb68e382b118b1b556 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 4 Feb 2025 08:47:30 +0000 Subject: [PATCH 3/7] Update Spring Boot to 3.4.2 --- build.gradle | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 17c3763e2..b52d8e185 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.4.0' + id 'org.springframework.boot' version '3.4.2' id 'io.spring.dependency-management' version '1.1.6' id 'org.graalvm.buildtools.native' version '0.10.3' id 'org.cyclonedx.bom' version '1.10.0' diff --git a/pom.xml b/pom.xml index 9b9b815df..27fb9a6bd 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.4.0 + 3.4.2 From aa2273e955c3a5e9d17201c0f81ad3d25b602a08 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 4 Feb 2025 09:08:45 +0000 Subject: [PATCH 4/7] Make sure MySQL test app works --- .../samples/petclinic/MysqlTestApplication.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java b/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java index 8c7560a19..f98d892d3 100644 --- a/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java +++ b/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java @@ -40,7 +40,8 @@ public class MysqlTestApplication { } public static void main(String[] args) { - SpringApplication.run(PetClinicApplication.class, "--spring.profiles.active=mysql"); + SpringApplication.run(PetClinicApplication.class, "--spring.profiles.active=mysql", + "--spring.docker.compose.enabled=false"); } } From 7bce202762cf793ad5c51cb71678a1a2b05236ff Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 12 Feb 2025 14:56:15 +0000 Subject: [PATCH 5/7] Add dco config --- .github/dco.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/dco.yml diff --git a/.github/dco.yml b/.github/dco.yml new file mode 100644 index 000000000..37e411e1b --- /dev/null +++ b/.github/dco.yml @@ -0,0 +1,2 @@ +require: + members: false \ No newline at end of file From 6328d2c9dc8eb2c367c6a613a1ae959c994003c7 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 12 Feb 2025 14:58:27 +0000 Subject: [PATCH 6/7] Add DCO to README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e15a3247f..e34511b86 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,8 @@ Here is a list of them: The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, feature requests and submitting pull requests. -For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring). +For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin. +For additional details, please refer to the blog post [Hello DCO, Goodbye CLA: Simplifying Contributions to Spring](https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring). ## License From 2aa53f929d32b0d41e0fe0391b8385eabe9a3432 Mon Sep 17 00:00:00 2001 From: VishantOwO Date: Wed, 1 Jan 2025 03:52:27 +0530 Subject: [PATCH 7/7] Fix pet update functionality - Fixed issue where editing a pet's type or name wasn't persisting - Updated processUpdateForm to modify existing pet instead of adding new one - Added proper handling of existing pet update Fixes #1752 --- .../petclinic/owner/PetController.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java index fcf431bff..3234e39d6 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -129,7 +129,7 @@ class PetController { String petName = pet.getName(); - // checking if the pet name already exist for the owner + // checking if the pet name already exists for the owner if (StringUtils.hasText(petName)) { Pet existingPet = owner.getPet(petName, false); if (existingPet != null && !existingPet.getId().equals(pet.getId())) { @@ -146,10 +146,28 @@ class PetController { return VIEWS_PETS_CREATE_OR_UPDATE_FORM; } - owner.addPet(pet); - this.owners.save(owner); + updatePetDetails(owner, pet); redirectAttributes.addFlashAttribute("message", "Pet details has been edited"); return "redirect:/owners/{ownerId}"; } + /** + * Updates the pet details if it exists or adds a new pet to the owner. + * @param owner The owner of the pet + * @param pet The pet with updated details + */ + private void updatePetDetails(Owner owner, Pet pet) { + Pet existingPet = owner.getPet(pet.getId()); + if (existingPet != null) { + // Update existing pet's properties + existingPet.setName(pet.getName()); + existingPet.setBirthDate(pet.getBirthDate()); + existingPet.setType(pet.getType()); + } + else { + owner.addPet(pet); + } + this.owners.save(owner); + } + }