Skip to content

Commit

Permalink
Get rid of Lombok #251 (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
arey authored Dec 27, 2024
1 parent 104410a commit b9c725f
Show file tree
Hide file tree
Showing 28 changed files with 458 additions and 273 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ and the Eureka Service Discovery from the [Spring Cloud Netflix](https://github.

## Starting services locally without Docker

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).
Every microservice is a Spring Boot application and can be started locally using IDE 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).
Startup of Tracing server, Admin server, Grafana and Prometheus is optional.
If everything goes well, you can access the following services at given location:
* Discovery Server - http://localhost:8761
Expand Down
9 changes: 0 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<chaos-monkey-spring-boot.version>3.1.0</chaos-monkey-spring-boot.version>
<jolokia-core.version>1.7.1</jolokia-core.version>

<!-- Workaround for resolving the issue while using the provided lombok dependency in upgraded Java version.
Should be removed while future upgrading-->
<lombok.version>1.18.30</lombok.version>

<docker.image.prefix>springcommunity</docker.image.prefix>
<docker.image.exposed.port>9090</docker.image.exposed.port>
<docker.image.dockerfile.dir>${basedir}</docker.image.dockerfile.dir>
Expand Down Expand Up @@ -69,11 +65,6 @@
<artifactId>jolokia-core</artifactId>
<version>${jolokia-core.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
5 changes: 0 additions & 5 deletions spring-petclinic-api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.springframework.samples.petclinic.api.application;

import lombok.RequiredArgsConstructor;
import org.springframework.samples.petclinic.api.dto.OwnerDetails;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -25,11 +24,14 @@
* @author Maciej Szarlinski
*/
@Component
@RequiredArgsConstructor
public class CustomersServiceClient {

private final WebClient.Builder webClientBuilder;

public CustomersServiceClient(WebClient.Builder webClientBuilder) {
this.webClientBuilder = webClientBuilder;
}

public Mono<OwnerDetails> getOwner(final int ownerId) {
return webClientBuilder.build().get()
.uri("http://customers-service/owners/{ownerId}", ownerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.springframework.samples.petclinic.api.application;

import lombok.RequiredArgsConstructor;
import org.springframework.samples.petclinic.api.dto.Visits;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -29,14 +28,17 @@
* @author Maciej Szarlinski
*/
@Component
@RequiredArgsConstructor
public class VisitsServiceClient {

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

private final WebClient.Builder webClientBuilder;

public VisitsServiceClient(WebClient.Builder webClientBuilder) {
this.webClientBuilder = webClientBuilder;
}

public Mono<Visits> getVisitsForPets(final List<Integer> petIds) {
return webClientBuilder.build()
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.springframework.samples.petclinic.api.boundary.web;

import lombok.RequiredArgsConstructor;
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker;
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
import org.springframework.samples.petclinic.api.application.CustomersServiceClient;
Expand All @@ -28,14 +27,13 @@
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* @author Maciej Szarlinski
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/gateway")
public class ApiGatewayController {

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

private final ReactiveCircuitBreakerFactory cbFactory;

public ApiGatewayController(CustomersServiceClient customersServiceClient,
VisitsServiceClient visitsServiceClient,
ReactiveCircuitBreakerFactory cbFactory) {
this.customersServiceClient = customersServiceClient;
this.visitsServiceClient = visitsServiceClient;
this.cbFactory = cbFactory;
}

@GetMapping(value = "owners/{ownerId}")
public Mono<OwnerDetails> getOwnerDetails(final @PathVariable int ownerId) {
return customersServiceClient.getOwner(ownerId)
Expand All @@ -61,17 +67,17 @@ public Mono<OwnerDetails> getOwnerDetails(final @PathVariable int ownerId) {

private Function<Visits, OwnerDetails> addVisitsToOwner(OwnerDetails owner) {
return visits -> {
owner.getPets()
.forEach(pet -> pet.getVisits()
.addAll(visits.getItems().stream()
.filter(v -> v.getPetId() == pet.getId())
.collect(Collectors.toList()))
owner.pets()
.forEach(pet -> pet.visits()
.addAll(visits.items().stream()
.filter(v -> v.petId() == pet.id())
.toList())
);
return owner;
};
}

private Mono<Visits> emptyVisitsForPets() {
return Mono.just(new Visits());
return Mono.just(new Visits(List.of()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,82 @@
package org.springframework.samples.petclinic.api.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
* @author Maciej Szarlinski
*/
@Data
public class OwnerDetails {
public record OwnerDetails(
int id,
String firstName,
String lastName,
String address,
String city,
String telephone,
List<PetDetails> pets) {

private int id;
@JsonIgnore
public List<Integer> getPetIds() {
return pets.stream()
.map(PetDetails::id)
.toList();
}

private String firstName;

private String lastName;
public static final class OwnerDetailsBuilder {
private int id;
private String firstName;
private String lastName;
private String address;
private String city;
private String telephone;
private List<PetDetails> pets;

private String address;
private OwnerDetailsBuilder() {
}

private String city;
public static OwnerDetailsBuilder anOwnerDetails() {
return new OwnerDetailsBuilder();
}

private String telephone;
public OwnerDetailsBuilder id(int id) {
this.id = id;
return this;
}

private final List<PetDetails> pets = new ArrayList<>();
public OwnerDetailsBuilder firstName(String firstName) {
this.firstName = firstName;
return this;
}

@JsonIgnore
public List<Integer> getPetIds() {
return pets.stream()
.map(PetDetails::getId)
.collect(toList());
public OwnerDetailsBuilder lastName(String lastName) {
this.lastName = lastName;
return this;
}

public OwnerDetailsBuilder address(String address) {
this.address = address;
return this;
}

public OwnerDetailsBuilder city(String city) {
this.city = city;
return this;
}

public OwnerDetailsBuilder telephone(String telephone) {
this.telephone = telephone;
return this;
}

public OwnerDetailsBuilder pets(List<PetDetails> pets) {
this.pets = pets;
return this;
}

public OwnerDetails build() {
return new OwnerDetails(id, firstName, lastName, address, city, telephone, pets);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,67 @@
*/
package org.springframework.samples.petclinic.api.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
* @author Maciej Szarlinski
*/
@Data
public class PetDetails {
public record PetDetails(
int id,
String name,
String birthDate,
PetType type,
List<VisitDetails> visits) {

private int id;
public PetDetails {
if (visits == null) {
visits = new ArrayList<>();
}
}

private String name;
public static final class PetDetailsBuilder {
private int id;
private String name;
private String birthDate;
private PetType type;
private List<VisitDetails> visits;

private String birthDate;
private PetDetailsBuilder() {
}

private PetType type;
public static PetDetailsBuilder aPetDetails() {
return new PetDetailsBuilder();
}

private final List<VisitDetails> visits = new ArrayList<>();
public PetDetailsBuilder id(int id) {
this.id = id;
return this;
}

public PetDetailsBuilder name(String name) {
this.name = name;
return this;
}

public PetDetailsBuilder birthDate(String birthDate) {
this.birthDate = birthDate;
return this;
}

public PetDetailsBuilder type(PetType type) {
this.type = type;
return this;
}

public PetDetailsBuilder visits(List<VisitDetails> visits) {
this.visits = visits;
return this;
}

public PetDetails build() {
return new PetDetails(id, name, birthDate, type, visits);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@
*/
package org.springframework.samples.petclinic.api.dto;

import lombok.Data;

/**
* @author Maciej Szarlinski
*/
@Data
public class PetType {

private String name;
public record PetType(String name) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@
*/
package org.springframework.samples.petclinic.api.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
* @author Maciej Szarlinski
*/
@Data
@NoArgsConstructor
public class VisitDetails {

private Integer id = null;

private Integer petId = null;

private String date = null;

private String description = null;
public record VisitDetails (
Integer id,
Integer petId,
String date,
String description) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import java.util.ArrayList;
import java.util.List;

import lombok.NoArgsConstructor;
import lombok.Value;

/**
* @author Maciej Szarlinski
*/
@Value
public class Visits {

private List<VisitDetails> items = new ArrayList<>();

public record Visits (
List<VisitDetails> items
) {
public Visits() {
this(new ArrayList<>());
}
}
Loading

0 comments on commit b9c725f

Please sign in to comment.