Skip to content

Commit

Permalink
Upgrade to Spring Boot 2.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
arey committed Jun 14, 2019
1 parent 0ac7ab1 commit 2cd2f9c
Show file tree
Hide file tree
Showing 28 changed files with 145 additions and 118 deletions.
94 changes: 47 additions & 47 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,23 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId>
<version>1.5.2</version>
<packaging>war</packaging>
<artifactId>spring-petclinic-rest</artifactId>
<version>2.1.5</version>

<name>petclinic</name>
<description>Spring petclinic project</description>
<description>REST version of the Spring Petclinic sample application</description>
<url>https://spring-petclinic.github.io/</url>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from Maven repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>

<spring-data-jdbc.version>1.2.1.RELEASE</spring-data-jdbc.version>
<cobertura.version>2.7</cobertura.version>

<start-class>org.springframework.samples.petclinic.PetClinicApplication</start-class>

<springfox-swagger.version>2.6.1</springfox-swagger.version>
<jacoco.version>0.8.2</jacoco.version>
</properties>

<!-- repository for springfox plugin -->
Expand Down Expand Up @@ -96,11 +89,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -129,12 +117,12 @@
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<version>${springfox-swagger.version}</version>
</dependency>

<dependency>
Expand All @@ -143,13 +131,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand All @@ -162,25 +143,44 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<!-- Spring Boot Actuator displays build-related information
if a META-INF/build-info.properties file is present -->
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<encoding.source>${project.build.sourceEncoding}</encoding.source>
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- integrate maven-cobertura-plugin to project site -->

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<reportSets>
<reportSet>
<reports>
<report>cobertura</report>
</reports>
</reportSet>
</reportSets>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</reporting>
<url>demopetclinic</url>
</plugins>
</build>
</project>
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ In its default configuration, Petclinic doesn't have authentication and authoriz
### Basic Authentication
In order to use the basic authentication functionality, turn in on from the application.properties file
```
basic.authentication.enabled=true
petclinic.security.enable=true
```
This will secure all APIs and in order to access them, basic authentication is required.
Apart from authentication, APIs also require authorization. This is done via roles that a user can have.
Expand All @@ -95,7 +95,7 @@ The existing roles are listed below with the corresponding permissions
* VET_ADMIN -> PetTypeController, SpecialityController, VetController
* ADMIN -> UserController

There is an existing user with the username admin and password admin that has access to all APIs.
There is an existing user with the username `admin` and password `admin` that has access to all APIs.
In order to add a new user, please use the following API:
```
POST /api/users
Expand Down Expand Up @@ -139,7 +139,7 @@ File -> Import -> Maven -> Existing Maven project
|--|--|
| REST API controllers | [REST folder](src/main/java/org/springframework/samples/petclinic/rest) |
| Service | [ClinicServiceImpl.java](src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java) |
|JDBC | [jdbc folder](src/main/java/org/springframework/samples/petclinic/repository/jdb) |
| JDBC | [jdbc folder](src/main/java/org/springframework/samples/petclinic/repository/jdbc) |
| JPA | [jpa folder](src/main/java/org/springframework/samples/petclinic/repository/jpa) |
| Spring Data JPA | [springdatajpa folder](src/main/java/org/springframework/samples/petclinic/repository/springdatajpa) |
| Tests | [AbstractClinicServiceTests.java](src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class PetClinicApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(PetClinicApplication.class);
}

public static void main(String[] args) {
SpringApplication.run(PetClinicApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotEmpty;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotEmpty;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator;
import org.springframework.core.style.ToStringCreator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotEmpty;

/**
* Simple JavaBean domain object representing an person.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.samples.petclinic.rest.JacksonCustomVisitDeserializer;
import org.springframework.samples.petclinic.rest.JacksonCustomVisitSerializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.springframework.context.annotation.Profile;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void save(Owner owner) {
}

}

@SuppressWarnings("unchecked")
@Override
public Collection<Owner> findAll() throws DataAccessException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ public void save(PetType petType) throws DataAccessException {
@Override
public void delete(PetType petType) throws DataAccessException {
this.em.remove(this.em.contains(petType) ? petType : this.em.merge(petType));
String petTypeId = petType.getId().toString();
Integer petTypeId = petType.getId();

List<Pet> pets = new ArrayList<Pet>();
pets = this.em.createQuery("SELECT pet FROM Pet pet WHERE type_id=" + petTypeId).getResultList();
List<Pet> pets = this.em.createQuery("SELECT pet FROM Pet pet WHERE type_id=" + petTypeId).getResultList();
for (Pet pet : pets){
List<Visit> visits = new ArrayList<Visit>();
visits = pet.getVisits();
List<Visit> visits = pet.getVisits();
for (Visit visit : visits){
this.em.createQuery("DELETE FROM Visit visit WHERE id=" + visit.getId().toString()).executeUpdate();
this.em.createQuery("DELETE FROM Visit visit WHERE id=" + visit.getId()).executeUpdate();
}
this.em.createQuery("DELETE FROM Pet pet WHERE id=" + pet.getId().toString()).executeUpdate();
this.em.createQuery("DELETE FROM Pet pet WHERE id=" + pet.getId()).executeUpdate();
}
this.em.createQuery("DELETE FROM PetType pettype WHERE id=" + petTypeId).executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void save(Specialty specialty) throws DataAccessException {
@Override
public void delete(Specialty specialty) throws DataAccessException {
this.em.remove(this.em.contains(specialty) ? specialty : this.em.merge(specialty));
String specId = specialty.getId().toString();
Integer specId = specialty.getId();
this.em.createNativeQuery("DELETE FROM vet_specialties WHERE specialty_id=" + specId).executeUpdate();
this.em.createQuery("DELETE FROM Specialty specialty WHERE id=" + specId).executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ public Collection<Visit> findAll() throws DataAccessException {

@Override
public void delete(Visit visit) throws DataAccessException {
String visitId = visit.getId().toString();
this.em.createQuery("DELETE FROM Visit visit WHERE id=" + visitId).executeUpdate();
if (em.contains(visit)) {
em.remove(visit);
}
this.em.remove(this.em.contains(visit) ? visit : this.em.merge(visit));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
@Profile("spring-data-jpa")
public interface PetRepositoryOverride {

public void delete(Pet pet);
void delete(Pet pet);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
@Profile("spring-data-jpa")
public interface PetTypeRepositoryOverride {

public void delete(PetType petType);
void delete(PetType petType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
@Profile("spring-data-jpa")
public interface SpecialtyRepositoryOverride {

public void delete(Specialty specialty);
void delete(Specialty specialty);

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public interface SpringDataOwnerRepository extends OwnerRepository, Repository<O

@Override
@Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
public Collection<Owner> findByLastName(@Param("lastName") String lastName);
Collection<Owner> findByLastName(@Param("lastName") String lastName);

@Override
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
public Owner findById(@Param("id") int id);
Owner findById(@Param("id") int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public void delete(Pet pet) {
String petId = pet.getId().toString();
this.em.createQuery("DELETE FROM Visit visit WHERE pet_id=" + petId).executeUpdate();
this.em.createQuery("DELETE FROM Pet pet WHERE id=" + petId).executeUpdate();
if (em.contains(pet)) {
em.remove(pet);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ public class SpringDataPetTypeRepositoryImpl implements PetTypeRepositoryOverrid
@SuppressWarnings("unchecked")
@Override
public void delete(PetType petType) {
String petTypeId = petType.getId().toString();
this.em.remove(this.em.contains(petType) ? petType : this.em.merge(petType));
Integer petTypeId = petType.getId();

List<Pet> pets = new ArrayList<Pet>();
pets = this.em.createQuery("SELECT pet FROM Pet pet WHERE type_id=" + petTypeId).getResultList();
List<Pet> pets = this.em.createQuery("SELECT pet FROM Pet pet WHERE type_id=" + petTypeId).getResultList();
for (Pet pet : pets){
List<Visit> visits = new ArrayList<Visit>();
visits = pet.getVisits();
List<Visit> visits = pet.getVisits();
for (Visit visit : visits){
this.em.createQuery("DELETE FROM Visit visit WHERE id=" + visit.getId().toString()).executeUpdate();
this.em.createQuery("DELETE FROM Visit visit WHERE id=" + visit.getId()).executeUpdate();
}
this.em.createQuery("DELETE FROM Pet pet WHERE id=" + pet.getId().toString()).executeUpdate();
this.em.createQuery("DELETE FROM Pet pet WHERE id=" + pet.getId()).executeUpdate();
}
this.em.createQuery("DELETE FROM PetType pettype WHERE id=" + petTypeId).executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class SpringDataSpecialtyRepositoryImpl implements SpecialtyRepositoryOve

@Override
public void delete(Specialty specialty) {
String specId = specialty.getId().toString();
this.em.remove(this.em.contains(specialty) ? specialty : this.em.merge(specialty));
Integer specId = specialty.getId();
this.em.createNativeQuery("DELETE FROM vet_specialties WHERE specialty_id=" + specId).executeUpdate();
this.em.createQuery("DELETE FROM Specialty specialty WHERE id=" + specId).executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class SpringDataVisitRepositoryImpl implements VisitRepositoryOverride {
public void delete(Visit visit) throws DataAccessException {
String visitId = visit.getId().toString();
this.em.createQuery("DELETE FROM Visit visit WHERE id=" + visitId).executeUpdate();
if (em.contains(visit)) {
em.remove(visit);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
@Profile("spring-data-jpa")
public interface VisitRepositoryOverride {

public void delete(Visit visit);
void delete(Visit visit);

}
Loading

0 comments on commit 2cd2f9c

Please sign in to comment.