Skip to content

Commit b9c725f

Browse files
authored
Get rid of Lombok #251 (#300)
1 parent 104410a commit b9c725f

File tree

28 files changed

+458
-273
lines changed

28 files changed

+458
-273
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ and the Eureka Service Discovery from the [Spring Cloud Netflix](https://github.
1313

1414
## Starting services locally without Docker
1515

16-
Every microservice is a Spring Boot application and can be started locally using IDE ([Lombok](https://projectlombok.org/) plugin has to be set up) or `../mvnw spring-boot:run` command. Please note that supporting services (Config and Discovery Server) must be started before any other application (Customers, Vets, Visits and API).
16+
Every microservice is a Spring Boot application and can be started locally using IDE or `../mvnw spring-boot:run` command.
17+
Please note that supporting services (Config and Discovery Server) must be started before any other application (Customers, Vets, Visits and API).
1718
Startup of Tracing server, Admin server, Grafana and Prometheus is optional.
1819
If everything goes well, you can access the following services at given location:
1920
* Discovery Server - http://localhost:8761

pom.xml

-9
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
<chaos-monkey-spring-boot.version>3.1.0</chaos-monkey-spring-boot.version>
3434
<jolokia-core.version>1.7.1</jolokia-core.version>
3535

36-
<!-- Workaround for resolving the issue while using the provided lombok dependency in upgraded Java version.
37-
Should be removed while future upgrading-->
38-
<lombok.version>1.18.30</lombok.version>
39-
4036
<docker.image.prefix>springcommunity</docker.image.prefix>
4137
<docker.image.exposed.port>9090</docker.image.exposed.port>
4238
<docker.image.dockerfile.dir>${basedir}</docker.image.dockerfile.dir>
@@ -69,11 +65,6 @@
6965
<artifactId>jolokia-core</artifactId>
7066
<version>${jolokia-core.version}</version>
7167
</dependency>
72-
<dependency>
73-
<groupId>org.projectlombok</groupId>
74-
<artifactId>lombok</artifactId>
75-
<version>${lombok.version}</version>
76-
</dependency>
7768
</dependencies>
7869
</dependencyManagement>
7970

spring-petclinic-api-gateway/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@
7171
<groupId>org.jolokia</groupId>
7272
<artifactId>jolokia-core</artifactId>
7373
</dependency>
74-
<dependency>
75-
<groupId>org.projectlombok</groupId>
76-
<artifactId>lombok</artifactId>
77-
<scope>provided</scope>
78-
</dependency>
7974
<dependency>
8075
<groupId>io.micrometer</groupId>
8176
<artifactId>micrometer-registry-prometheus</artifactId>

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/CustomersServiceClient.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.samples.petclinic.api.application;
1717

18-
import lombok.RequiredArgsConstructor;
1918
import org.springframework.samples.petclinic.api.dto.OwnerDetails;
2019
import org.springframework.stereotype.Component;
2120
import org.springframework.web.reactive.function.client.WebClient;
@@ -25,11 +24,14 @@
2524
* @author Maciej Szarlinski
2625
*/
2726
@Component
28-
@RequiredArgsConstructor
2927
public class CustomersServiceClient {
3028

3129
private final WebClient.Builder webClientBuilder;
3230

31+
public CustomersServiceClient(WebClient.Builder webClientBuilder) {
32+
this.webClientBuilder = webClientBuilder;
33+
}
34+
3335
public Mono<OwnerDetails> getOwner(final int ownerId) {
3436
return webClientBuilder.build().get()
3537
.uri("http://customers-service/owners/{ownerId}", ownerId)

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/VisitsServiceClient.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.samples.petclinic.api.application;
1717

18-
import lombok.RequiredArgsConstructor;
1918
import org.springframework.samples.petclinic.api.dto.Visits;
2019
import org.springframework.stereotype.Component;
2120
import org.springframework.web.reactive.function.client.WebClient;
@@ -29,14 +28,17 @@
2928
* @author Maciej Szarlinski
3029
*/
3130
@Component
32-
@RequiredArgsConstructor
3331
public class VisitsServiceClient {
3432

3533
// Could be changed for testing purpose
3634
private String hostname = "http://visits-service/";
3735

3836
private final WebClient.Builder webClientBuilder;
3937

38+
public VisitsServiceClient(WebClient.Builder webClientBuilder) {
39+
this.webClientBuilder = webClientBuilder;
40+
}
41+
4042
public Mono<Visits> getVisitsForPets(final List<Integer> petIds) {
4143
return webClientBuilder.build()
4244
.get()

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.samples.petclinic.api.boundary.web;
1717

18-
import lombok.RequiredArgsConstructor;
1918
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker;
2019
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
2120
import org.springframework.samples.petclinic.api.application.CustomersServiceClient;
@@ -28,14 +27,13 @@
2827
import org.springframework.web.bind.annotation.RestController;
2928
import reactor.core.publisher.Mono;
3029

30+
import java.util.List;
3131
import java.util.function.Function;
32-
import java.util.stream.Collectors;
3332

3433
/**
3534
* @author Maciej Szarlinski
3635
*/
3736
@RestController
38-
@RequiredArgsConstructor
3937
@RequestMapping("/api/gateway")
4038
public class ApiGatewayController {
4139

@@ -45,6 +43,14 @@ public class ApiGatewayController {
4543

4644
private final ReactiveCircuitBreakerFactory cbFactory;
4745

46+
public ApiGatewayController(CustomersServiceClient customersServiceClient,
47+
VisitsServiceClient visitsServiceClient,
48+
ReactiveCircuitBreakerFactory cbFactory) {
49+
this.customersServiceClient = customersServiceClient;
50+
this.visitsServiceClient = visitsServiceClient;
51+
this.cbFactory = cbFactory;
52+
}
53+
4854
@GetMapping(value = "owners/{ownerId}")
4955
public Mono<OwnerDetails> getOwnerDetails(final @PathVariable int ownerId) {
5056
return customersServiceClient.getOwner(ownerId)
@@ -61,17 +67,17 @@ public Mono<OwnerDetails> getOwnerDetails(final @PathVariable int ownerId) {
6167

6268
private Function<Visits, OwnerDetails> addVisitsToOwner(OwnerDetails owner) {
6369
return visits -> {
64-
owner.getPets()
65-
.forEach(pet -> pet.getVisits()
66-
.addAll(visits.getItems().stream()
67-
.filter(v -> v.getPetId() == pet.getId())
68-
.collect(Collectors.toList()))
70+
owner.pets()
71+
.forEach(pet -> pet.visits()
72+
.addAll(visits.items().stream()
73+
.filter(v -> v.petId() == pet.id())
74+
.toList())
6975
);
7076
return owner;
7177
};
7278
}
7379

7480
private Mono<Visits> emptyVisitsForPets() {
75-
return Mono.just(new Visits());
81+
return Mono.just(new Visits(List.of()));
7682
}
7783
}

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/OwnerDetails.java

+63-18
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,82 @@
1616
package org.springframework.samples.petclinic.api.dto;
1717

1818
import com.fasterxml.jackson.annotation.JsonIgnore;
19-
import lombok.Data;
2019

21-
import java.util.ArrayList;
2220
import java.util.List;
2321

24-
import static java.util.stream.Collectors.toList;
25-
2622
/**
2723
* @author Maciej Szarlinski
2824
*/
29-
@Data
30-
public class OwnerDetails {
25+
public record OwnerDetails(
26+
int id,
27+
String firstName,
28+
String lastName,
29+
String address,
30+
String city,
31+
String telephone,
32+
List<PetDetails> pets) {
3133

32-
private int id;
34+
@JsonIgnore
35+
public List<Integer> getPetIds() {
36+
return pets.stream()
37+
.map(PetDetails::id)
38+
.toList();
39+
}
3340

34-
private String firstName;
3541

36-
private String lastName;
42+
public static final class OwnerDetailsBuilder {
43+
private int id;
44+
private String firstName;
45+
private String lastName;
46+
private String address;
47+
private String city;
48+
private String telephone;
49+
private List<PetDetails> pets;
3750

38-
private String address;
51+
private OwnerDetailsBuilder() {
52+
}
3953

40-
private String city;
54+
public static OwnerDetailsBuilder anOwnerDetails() {
55+
return new OwnerDetailsBuilder();
56+
}
4157

42-
private String telephone;
58+
public OwnerDetailsBuilder id(int id) {
59+
this.id = id;
60+
return this;
61+
}
4362

44-
private final List<PetDetails> pets = new ArrayList<>();
63+
public OwnerDetailsBuilder firstName(String firstName) {
64+
this.firstName = firstName;
65+
return this;
66+
}
4567

46-
@JsonIgnore
47-
public List<Integer> getPetIds() {
48-
return pets.stream()
49-
.map(PetDetails::getId)
50-
.collect(toList());
68+
public OwnerDetailsBuilder lastName(String lastName) {
69+
this.lastName = lastName;
70+
return this;
71+
}
72+
73+
public OwnerDetailsBuilder address(String address) {
74+
this.address = address;
75+
return this;
76+
}
77+
78+
public OwnerDetailsBuilder city(String city) {
79+
this.city = city;
80+
return this;
81+
}
82+
83+
public OwnerDetailsBuilder telephone(String telephone) {
84+
this.telephone = telephone;
85+
return this;
86+
}
87+
88+
public OwnerDetailsBuilder pets(List<PetDetails> pets) {
89+
this.pets = pets;
90+
return this;
91+
}
92+
93+
public OwnerDetails build() {
94+
return new OwnerDetails(id, firstName, lastName, address, city, telephone, pets);
95+
}
5196
}
5297
}

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetDetails.java

+50-8
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,67 @@
1515
*/
1616
package org.springframework.samples.petclinic.api.dto;
1717

18-
import lombok.Data;
1918

2019
import java.util.ArrayList;
2120
import java.util.List;
2221

2322
/**
2423
* @author Maciej Szarlinski
2524
*/
26-
@Data
27-
public class PetDetails {
25+
public record PetDetails(
26+
int id,
27+
String name,
28+
String birthDate,
29+
PetType type,
30+
List<VisitDetails> visits) {
2831

29-
private int id;
32+
public PetDetails {
33+
if (visits == null) {
34+
visits = new ArrayList<>();
35+
}
36+
}
3037

31-
private String name;
38+
public static final class PetDetailsBuilder {
39+
private int id;
40+
private String name;
41+
private String birthDate;
42+
private PetType type;
43+
private List<VisitDetails> visits;
3244

33-
private String birthDate;
45+
private PetDetailsBuilder() {
46+
}
3447

35-
private PetType type;
48+
public static PetDetailsBuilder aPetDetails() {
49+
return new PetDetailsBuilder();
50+
}
3651

37-
private final List<VisitDetails> visits = new ArrayList<>();
52+
public PetDetailsBuilder id(int id) {
53+
this.id = id;
54+
return this;
55+
}
3856

57+
public PetDetailsBuilder name(String name) {
58+
this.name = name;
59+
return this;
60+
}
61+
62+
public PetDetailsBuilder birthDate(String birthDate) {
63+
this.birthDate = birthDate;
64+
return this;
65+
}
66+
67+
public PetDetailsBuilder type(PetType type) {
68+
this.type = type;
69+
return this;
70+
}
71+
72+
public PetDetailsBuilder visits(List<VisitDetails> visits) {
73+
this.visits = visits;
74+
return this;
75+
}
76+
77+
public PetDetails build() {
78+
return new PetDetails(id, name, birthDate, type, visits);
79+
}
80+
}
3981
}

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetType.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@
1515
*/
1616
package org.springframework.samples.petclinic.api.dto;
1717

18-
import lombok.Data;
19-
2018
/**
2119
* @author Maciej Szarlinski
2220
*/
23-
@Data
24-
public class PetType {
25-
26-
private String name;
21+
public record PetType(String name) {
2722
}

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/VisitDetails.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,12 @@
1515
*/
1616
package org.springframework.samples.petclinic.api.dto;
1717

18-
import lombok.Data;
19-
import lombok.NoArgsConstructor;
20-
2118
/**
2219
* @author Maciej Szarlinski
2320
*/
24-
@Data
25-
@NoArgsConstructor
26-
public class VisitDetails {
27-
28-
private Integer id = null;
29-
30-
private Integer petId = null;
31-
32-
private String date = null;
33-
34-
private String description = null;
21+
public record VisitDetails (
22+
Integer id,
23+
Integer petId,
24+
String date,
25+
String description) {
3526
}

spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/Visits.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import java.util.ArrayList;
1919
import java.util.List;
2020

21-
import lombok.NoArgsConstructor;
22-
import lombok.Value;
2321

2422
/**
2523
* @author Maciej Szarlinski
2624
*/
27-
@Value
28-
public class Visits {
29-
30-
private List<VisitDetails> items = new ArrayList<>();
31-
25+
public record Visits (
26+
List<VisitDetails> items
27+
) {
28+
public Visits() {
29+
this(new ArrayList<>());
30+
}
3231
}

0 commit comments

Comments
 (0)