Compare commits

...

20 commits

Author SHA1 Message Date
MMarceticGrid
15584ebd26
Merge f23aa04562 into 2aa53f929d 2025-03-07 14:22:38 +00:00
Mihailo
f23aa04562 Modify Jenkins file to build image every time 2025-03-07 15:22:14 +01:00
Mihailo
15b228d198 Add config file for KIND cluster 2025-03-07 13:17:58 +01:00
MMarceticGrid
fd0e30c72f
Merge branch 'main' into feature_branch 2025-03-07 13:13:11 +01:00
Mihailo
29b73475db Add more stages to Jenkinsfile 2025-03-07 12:43:55 +01:00
Mihailo
61a75b5570 Add deployment and service for kind cluster
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
MMarceticGrid
0dce1f7d2b Update Jenkinsfile
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
Mihailo Marcetic
684e04e703 Add Jenkinsfile
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
Mihailo Marcetic
ba9fd2a991 Add Dockerfile
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
Mihailo Marcetic
a2848f9132 Add docker-compose file that run application with database
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
Mihailo Marcetic
ceb2bc79db Remove dependence on Nexus in build.gradle file
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
Mihailo Marcetic
89511d3b42 Add task for deploying artifacts to Nexus
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
Mihailo Marcetic
f32d17fd42 Create task that opens test results
Signed-off-by: Mihailo <mmarcetic@griddynamcis.com>
2025-03-07 10:23:11 +01:00
VishantOwO
2aa53f929d Fix pet update functionality
Some checks failed
Java CI with Gradle / build (17) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
- 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
2025-03-01 15:29:15 +00:00
Dave Syer
6328d2c9dc Add DCO to README
Some checks failed
Java CI with Gradle / build (17) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
2025-02-12 14:58:27 +00:00
Dave Syer
7bce202762 Add dco config 2025-02-12 14:56:15 +00:00
Dave Syer
aa2273e955 Make sure MySQL test app works
Some checks failed
Java CI with Gradle / build (17) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
2025-02-04 09:15:54 +00:00
Dave Syer
1f89996e1f Update Spring Boot to 3.4.2 2025-02-04 08:47:30 +00:00
Antoine Rey
73d73609b5 Use Java Streams to sort the Specialty objects by their name
Signed-off-by: Antoine Rey <antoine.rey@free.fr>
2025-02-04 08:09:03 +00:00
Antoine Rey
b46b97a3e7 Remove unused Transactional import
Signed-off-by: Antoine Rey <antoine.rey@free.fr>
2025-02-04 08:07:44 +00:00
12 changed files with 158 additions and 23 deletions

2
.github/dco.yml vendored Normal file
View file

@ -0,0 +1,2 @@
require:
members: false

83
Jenkinsfile vendored
View file

@ -4,7 +4,9 @@ pipeline {
environment {
// Define environment variables
DOCKER_REGISTRY = "docker.io"
DOCKER_IMAGE = "mmarcetic/main"
DOCKER_IMAGE_MAIN = 'mmarcetic/main'
DOCKER_IMAGE_MR = 'mmarcetic/mr'
GIT_COMMIT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
}
stages {
@ -15,23 +17,88 @@ pipeline {
}
}
stage('Build Docker Image') {
stage('Set Docker Image') {
steps {
script {
// Build the Docker image
def gitCommit = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${gitCommit} ."
// Set Docker image based on the branch name
if (env.BRANCH_NAME == 'main') {
env.DOCKER_IMAGE = DOCKER_IMAGE_MAIN
} else {
env.DOCKER_IMAGE = DOCKER_IMAGE_MR
}
echo "Using Docker image: ${env.DOCKER_IMAGE}"
}
}
}
stage('Push Docker Image') {
stage('Checkstyle Report') {
when {
changeRequest()
}
steps {
script {
// Checkstyle with Gradle
sh './gradlew checkstyleMain'
archiveArtifacts artifacts: 'build/reports/checkstyle/*.xml', allowEmptyArchive: true
}
}
}
stage('Test') {
when {
changeRequest()
}
steps {
// Test using Gradle
sh './gradlew clean test'
}
}
stage('Build Without Tests') {
when {
changeRequest()
}
steps {
script {
// Build without tests using Gradle
sh './gradlew build -x test'
}
}
}
stage('Build Docker Image') {
steps {
script {
// Build the Docker image
sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${GIT_COMMIT} ."
}
}
}
stage('Push Docker Image for Change Request') {
when {
changeRequest()
}
steps {
script {
def gitCommit = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
withCredentials([usernamePassword(credentialsId: "docker-login", usernameVariable: "DOCKER_USER", passwordVariable: "DOCKER_PASSWORD")]) {
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}"
sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${gitCommit}"
sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${GIT_COMMIT}"
}
}
}
}
stage('Push Docker Image for Main') {
when {
branch "main"
}
steps {
script {
withCredentials([usernamePassword(credentialsId: "docker-login", usernameVariable: "DOCKER_USER", passwordVariable: "DOCKER_PASSWORD")]) {
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}"
sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${GIT_COMMIT}"
}
}
}

View file

@ -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 <https://editorconfig.org>. 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 <https://editorconfig.org>. 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

View file

@ -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'

11
config.yaml Normal file
View file

@ -0,0 +1,11 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30950
hostPort: 30950
listenAddress: "127.0.0.1"
protocol: TCP

22
deployment.yaml Normal file
View file

@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot-app
namespace: petclinic
spec:
replicas: 2
selector:
matchLabels:
app: spring-boot-app
template:
metadata:
labels:
app: spring-boot-app
spec:
containers:
- name: spring-boot-app
image: docker.io/mmarcetic/main:2.0
imagePullPolicy: Always
ports:
- containerPort: 8080

View file

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<version>3.4.2</version>
<relativePath></relativePath>
</parent>

15
service.yaml Normal file
View file

@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: spring-boot-app-service
namespace: petclinic
spec:
selector:
app: spring-boot-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 30950
type: NodePort

View file

@ -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 <code>Owner</code> domain objects All method names are compliant

View file

@ -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);
}
}

View file

@ -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<Specialty> getSpecialties() {
List<Specialty> 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() {

View file

@ -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");
}
}