Skip to content

Commit 2a94e84

Browse files
committed
Distribute springboot-petclinic-server among microservices
1 parent f600b1c commit 2a94e84

File tree

71 files changed

+786
-510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+786
-510
lines changed
File renamed without changes.

petclinic-clients-service/pom.xml

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<groupId>org.springframework.boot</groupId>
3737
<artifactId>spring-boot-starter-web</artifactId>
3838
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-actuator</artifactId>
42+
</dependency>
3943

4044
<dependency>
4145
<groupId>org.hsqldb</groupId>
@@ -62,6 +66,11 @@
6266
<artifactId>spring-boot-starter-test</artifactId>
6367
<scope>test</scope>
6468
</dependency>
69+
<dependency>
70+
<groupId>org.assertj</groupId>
71+
<artifactId>assertj-core</artifactId>
72+
<scope>test</scope>
73+
</dependency>
6574
</dependencies>
6675

6776
<build>

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/domain/model/owner/OwnerService.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/application/OwnerService.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package org.springframework.samples.petclinic.domain.model.owner;
1+
package org.springframework.samples.petclinic.clients.application;
22

33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.dao.DataAccessException;
5+
import org.springframework.samples.petclinic.clients.domain.model.owner.Owner;
6+
import org.springframework.samples.petclinic.clients.domain.model.owner.OwnerRepository;
57
import org.springframework.stereotype.Service;
68
import org.springframework.transaction.annotation.Transactional;
79

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/domain/model/pet/PetService.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/application/PetService.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
package org.springframework.samples.petclinic.domain.model.pet;
1+
package org.springframework.samples.petclinic.clients.application;
22

33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.dao.DataAccessException;
5+
import org.springframework.samples.petclinic.clients.domain.model.pet.Pet;
6+
import org.springframework.samples.petclinic.clients.domain.model.pet.PetRepository;
7+
import org.springframework.samples.petclinic.clients.domain.model.pet.PetType;
58
import org.springframework.stereotype.Service;
69
import org.springframework.transaction.annotation.Transactional;
710

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/boundary/web/owner/OwnerResource.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/owner/OwnerResource.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.boundary.web.owner;
16+
package org.springframework.samples.petclinic.clients.boundary.web.owner;
1717

1818
import org.springframework.beans.factory.annotation.Autowired;
1919
import org.springframework.http.HttpStatus;
20-
import org.springframework.samples.petclinic.domain.model.owner.Owner;
21-
import org.springframework.samples.petclinic.domain.model.owner.OwnerService;
22-
import org.springframework.samples.petclinic.support.web.AbstractResourceController;
20+
import org.springframework.samples.petclinic.clients.domain.model.owner.Owner;
21+
import org.springframework.samples.petclinic.clients.application.OwnerService;
2322
import org.springframework.web.bind.WebDataBinder;
2423
import org.springframework.web.bind.annotation.*;
2524

@@ -33,7 +32,7 @@
3332
* @author Michael Isvy
3433
*/
3534
@RestController
36-
public class OwnerResource extends AbstractResourceController {
35+
public class OwnerResource {
3736

3837
private final OwnerService ownerService;
3938

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/boundary/web/pet/PetResource.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetResource.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.boundary.web.pet;
16+
package org.springframework.samples.petclinic.clients.boundary.web.pet;
1717

1818
import com.fasterxml.jackson.annotation.JsonFormat;
1919
import org.springframework.beans.factory.annotation.Autowired;
2020
import org.springframework.format.annotation.DateTimeFormat;
2121
import org.springframework.http.HttpStatus;
22-
import org.springframework.samples.petclinic.domain.model.owner.Owner;
23-
import org.springframework.samples.petclinic.domain.model.owner.OwnerService;
24-
import org.springframework.samples.petclinic.domain.model.pet.Pet;
25-
import org.springframework.samples.petclinic.domain.model.pet.PetService;
26-
import org.springframework.samples.petclinic.domain.model.pet.PetType;
27-
import org.springframework.samples.petclinic.support.web.AbstractResourceController;
22+
import org.springframework.samples.petclinic.clients.domain.model.owner.Owner;
23+
import org.springframework.samples.petclinic.clients.application.OwnerService;
24+
import org.springframework.samples.petclinic.clients.domain.model.pet.Pet;
25+
import org.springframework.samples.petclinic.clients.application.PetService;
26+
import org.springframework.samples.petclinic.clients.domain.model.pet.PetType;
2827
import org.springframework.web.bind.annotation.*;
2928

3029
import javax.validation.constraints.Size;
@@ -37,7 +36,7 @@
3736
* @author Arjen Poutsma
3837
*/
3938
@RestController
40-
public class PetResource extends AbstractResourceController {
39+
public class PetResource {
4140

4241
private final PetService petService;
4342

@@ -66,8 +65,8 @@ public String initCreationForm(@PathVariable("ownerId") int ownerId, Map<String,
6665
@PostMapping("/owners/{ownerId}/pets")
6766
@ResponseStatus(HttpStatus.NO_CONTENT)
6867
public void processCreationForm(
69-
@RequestBody PetRequest petRequest,
70-
@PathVariable("ownerId") int ownerId) {
68+
@RequestBody PetRequest petRequest,
69+
@PathVariable("ownerId") int ownerId) {
7170

7271
Pet pet = new Pet();
7372
Owner owner = ownerService.findOwnerById(ownerId);

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/boundary/web/pet/PetValidator.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetValidator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.boundary.web.pet;
16+
package org.springframework.samples.petclinic.clients.boundary.web.pet;
1717

18-
import org.springframework.samples.petclinic.domain.model.pet.Pet;
18+
import org.springframework.samples.petclinic.clients.domain.model.pet.Pet;
1919
import org.springframework.util.StringUtils;
2020
import org.springframework.validation.Errors;
2121

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.samples.petclinic.clients.domain.model;
17+
18+
import org.hibernate.validator.constraints.NotEmpty;
19+
import org.springframework.samples.petclinic.clients.support.jpa.BaseEntity;
20+
21+
import javax.persistence.Column;
22+
import javax.persistence.MappedSuperclass;
23+
24+
/**
25+
* Simple JavaBean domain object representing an person.
26+
*
27+
* @author Ken Krebs
28+
*/
29+
@MappedSuperclass
30+
public class Person extends BaseEntity {
31+
32+
@Column(name = "first_name")
33+
@NotEmpty
34+
protected String firstName;
35+
36+
@Column(name = "last_name")
37+
@NotEmpty
38+
protected String lastName;
39+
40+
public String getFirstName() {
41+
return this.firstName;
42+
}
43+
44+
public void setFirstName(String firstName) {
45+
this.firstName = firstName;
46+
}
47+
48+
public String getLastName() {
49+
return this.lastName;
50+
}
51+
52+
public void setLastName(String lastName) {
53+
this.lastName = lastName;
54+
}
55+
56+
57+
}

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/domain/model/owner/Owner.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/domain/model/owner/Owner.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.domain.model.owner;
16+
package org.springframework.samples.petclinic.clients.domain.model.owner;
1717

1818
import org.hibernate.validator.constraints.NotEmpty;
1919
import org.springframework.beans.support.MutableSortDefinition;
2020
import org.springframework.beans.support.PropertyComparator;
2121
import org.springframework.core.style.ToStringCreator;
22-
import org.springframework.samples.petclinic.domain.model.pet.Pet;
23-
import org.springframework.samples.petclinic.domain.shared.Person;
22+
import org.springframework.samples.petclinic.clients.domain.model.Person;
23+
import org.springframework.samples.petclinic.clients.domain.model.pet.Pet;
2424

2525
import javax.persistence.*;
2626
import javax.validation.constraints.Digits;
@@ -53,7 +53,6 @@ public class Owner extends Person {
5353
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "owner")
5454
private Set<Pet> pets;
5555

56-
5756
public String getAddress() {
5857
return this.address;
5958
}
@@ -134,13 +133,13 @@ public Pet getPet(String name, boolean ignoreNew) {
134133
public String toString() {
135134
return new ToStringCreator(this)
136135

137-
.append("id", this.getId())
138-
.append("new", this.isNew())
139-
.append("lastName", this.getLastName())
140-
.append("firstName", this.getFirstName())
141-
.append("address", this.address)
142-
.append("city", this.city)
143-
.append("telephone", this.telephone)
144-
.toString();
136+
.append("id", this.getId())
137+
.append("new", this.isNew())
138+
.append("lastName", this.getLastName())
139+
.append("firstName", this.getFirstName())
140+
.append("address", this.address)
141+
.append("city", this.city)
142+
.append("telephone", this.telephone)
143+
.toString();
145144
}
146145
}

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/domain/model/owner/OwnerRepository.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/domain/model/owner/OwnerRepository.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.domain.model.owner;
16+
package org.springframework.samples.petclinic.clients.domain.model.owner;
1717

1818
import org.springframework.data.jpa.repository.JpaRepository;
1919

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/domain/model/pet/Pet.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/domain/model/pet/Pet.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.domain.model.pet;
16+
package org.springframework.samples.petclinic.clients.domain.model.pet;
1717

1818
import com.fasterxml.jackson.annotation.JsonIgnore;
19-
import org.springframework.samples.petclinic.domain.model.owner.Owner;
20-
import org.springframework.samples.petclinic.support.jpa.NamedEntity;
19+
import org.springframework.samples.petclinic.clients.domain.model.owner.Owner;
20+
import org.springframework.samples.petclinic.clients.support.jpa.NamedEntity;
2121

2222
import javax.persistence.*;
2323
import java.util.Date;

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/domain/model/pet/PetRepository.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/domain/model/pet/PetRepository.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.domain.model.pet;
16+
package org.springframework.samples.petclinic.clients.domain.model.pet;
1717

1818
import org.springframework.data.jpa.repository.Query;
1919
import org.springframework.data.repository.Repository;

springboot-petclinic-server/src/main/java/org/springframework/samples/petclinic/domain/model/pet/PetType.java petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/domain/model/pet/PetType.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.samples.petclinic.domain.model.pet;
16+
package org.springframework.samples.petclinic.clients.domain.model.pet;
1717

18-
import org.springframework.samples.petclinic.support.jpa.NamedEntity;
18+
import org.springframework.samples.petclinic.clients.support.jpa.NamedEntity;
1919

2020
import javax.persistence.Entity;
2121
import javax.persistence.Table;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.samples.petclinic.clients.support.jpa;
17+
18+
import javax.persistence.GeneratedValue;
19+
import javax.persistence.GenerationType;
20+
import javax.persistence.Id;
21+
import javax.persistence.MappedSuperclass;
22+
23+
/**
24+
* Simple JavaBean domain object with an id property. Used as a base class for objects needing this property.
25+
*
26+
* @author Ken Krebs
27+
* @author Juergen Hoeller
28+
*/
29+
@MappedSuperclass
30+
public class BaseEntity {
31+
@Id
32+
@GeneratedValue(strategy = GenerationType.IDENTITY)
33+
protected Integer id;
34+
35+
36+
public void setId(Integer id) {
37+
this.id = id;
38+
}
39+
40+
public Integer getId() {
41+
return id;
42+
}
43+
44+
public boolean isNew() {
45+
return (this.id == null);
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.samples.petclinic.clients.support.jpa;
17+
18+
import javax.persistence.Column;
19+
import javax.persistence.MappedSuperclass;
20+
21+
22+
/**
23+
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as a base class for objects
24+
* needing these properties.
25+
*
26+
* @author Ken Krebs
27+
* @author Juergen Hoeller
28+
*/
29+
@MappedSuperclass
30+
public class NamedEntity extends BaseEntity {
31+
32+
@Column(name = "name")
33+
private String name;
34+
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
public String getName() {
41+
return this.name;
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return this.getName();
47+
}
48+
49+
}

0 commit comments

Comments
 (0)