Skip to content

Commit

Permalink
delombok
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 22, 2024
1 parent d34246a commit d86bc51
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The following table list all sample codes related to the spring boot integration
| [Rabbit Mq Implementation](./boot-rabbitmq-thymeleaf) | The application, demonstrates how rabbitmq works with producer side acknowledgement | Completed |
| [Spring Batch Implementation](./batch-boot-jpa-sample) | The application, demonstrates implementing Spring Batch 5 using simple config and creating batch tables using liquibase | Completed |
| [Rest API Documentation with examples](./boot-rest-docs-sample) | This application, demonstrates ability to generate pdf API documentation using spring rest docs | Completed |
| [Custom SequenceNumber and LazyConnectionDataSourceProxy for db connection improvement](./jpa/boot-data-customsequence) | This application, demonstrated ability to create custom sequences, using datasource-proxy and LazyConnectionDataSourceProxy for db connection improvement using mariadb | Completed |
| [Custom SequenceNumber and LazyConnectionDataSourceProxy for db connection improvement](./jpa/boot-data-customsequence) | This application, demonstrated ability to create custom sequences, using datasource-proxy, LazyConnectionDataSourceProxy for db connection improvement using mariadb, SQLStatementCountValidator for validating SQLCounts and ValidationGroups for dynamic Validation | Completed |
| [KeySet pagination and dynamic search](./jpa/keyset-pagination/blaze-persistence) | Implements KeySet Pagination using Blaze Persistence and enable dynamic search using specifications | Completed |

For More info about this repository, Please visit [here](https://rajadilipkolli.github.io/my-spring-boot-experiments/)
Expand Down
5 changes: 0 additions & 5 deletions jpa/boot-data-customsequence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<!-- database related dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,66 @@
package com.example.custom.sequence.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

@Data
@ConfigurationProperties("application")
public class ApplicationProperties {
private Cors cors = new Cors();

@Data
@NestedConfigurationProperty private Cors cors = new Cors();

public Cors getCors() {
return cors;
}

public void setCors(Cors cors) {
this.cors = cors;
}

public static class Cors {
private String pathPattern = "/api/**";
private String allowedMethods = "*";
private String allowedHeaders = "*";
private String allowedOriginPatterns = "*";
private boolean allowCredentials = true;

public String getPathPattern() {
return pathPattern;
}

public void setPathPattern(String pathPattern) {
this.pathPattern = pathPattern;
}

public String getAllowedMethods() {
return allowedMethods;
}

public void setAllowedMethods(String allowedMethods) {
this.allowedMethods = allowedMethods;
}

public String getAllowedHeaders() {
return allowedHeaders;
}

public void setAllowedHeaders(String allowedHeaders) {
this.allowedHeaders = allowedHeaders;
}

public String getAllowedOriginPatterns() {
return allowedOriginPatterns;
}

public void setAllowedOriginPatterns(String allowedOriginPatterns) {
this.allowedOriginPatterns = allowedOriginPatterns;
}

public boolean isAllowCredentials() {
return allowCredentials;
}

public void setAllowCredentials(boolean allowCredentials) {
this.allowCredentials = allowCredentials;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.example.custom.sequence.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class Initializer implements CommandLineRunner {

private static final Logger log = LoggerFactory.getLogger(Initializer.class);
private final ApplicationProperties properties;

Check warning on line 12 in jpa/boot-data-customsequence/src/main/java/com/example/custom/sequence/config/Initializer.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Field can be local

Field can be converted to a local variable

public Initializer(ApplicationProperties properties) {
this.properties = properties;
}

@Override
public void run(String... args) {
log.info("Running Initializer.....");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.example.custom.sequence.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration(proxyBeanMethods = false)
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

private final ApplicationProperties properties;

public WebMvcConfig(ApplicationProperties properties) {
this.properties = properties;
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(properties.getCors().getPathPattern())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.Hibernate;

@Entity
@Table(name = "customers")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Customer {

@Id
Expand All @@ -37,18 +29,55 @@ public class Customer {
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Order> orders = new ArrayList<>();

public Customer() {}

public Customer(String id, String text, List<Order> orders) {
this.id = id;
this.text = text;
this.orders = orders;
}

public Customer(String text) {
this.text = text;
}

public void addOrder(Order order) {
public String getId() {
return id;
}

public Customer setId(String id) {
this.id = id;
return this;
}

public String getText() {
return text;
}

public Customer setText(String text) {
this.text = text;
return this;
}

public List<Order> getOrders() {
return orders;
}

public Customer setOrders(List<Order> orders) {
this.orders = orders;
return this;
}

public Customer addOrder(Order order) {
orders.add(order);
order.setCustomer(this);
return this;
}

public void removeOrder(Order removedOrder) {
public Customer removeOrder(Order removedOrder) {
orders.remove(removedOrder);
removedOrder.setCustomer(null);
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.Hibernate;

@Entity
@Table(name = "orders")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Order {

@Id
Expand All @@ -37,6 +29,41 @@ public class Order {
@JoinColumn(name = "customer_id")
private Customer customer;

public Order() {}

public Order(String id, String text, Customer customer) {
this.id = id;
this.text = text;
this.customer = customer;
}

public String getId() {
return id;
}

public Order setId(String id) {
this.id = id;
return this;
}

public String getText() {
return text;
}

public Order setText(String text) {
this.text = text;
return this;
}

public Customer getCustomer() {
return customer;
}

public Order setCustomer(Customer customer) {
this.customer = customer;
return this;
}

@Override
public boolean equals(Object o) {

Check warning on line 68 in jpa/boot-data-customsequence/src/main/java/com/example/custom/sequence/entities/Order.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

'equals()' method which does not check class of parameter

`equals()` should check the class of its parameter
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.example.custom.sequence.utils.AppConstants;
import com.example.custom.sequence.web.api.CustomerAPI;
import jakarta.validation.groups.Default;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -26,7 +25,6 @@

@RestController
@RequestMapping("/api/customers")
@Slf4j
public class CustomerController implements CustomerAPI {

private final CustomerService customerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.example.custom.sequence.services.OrderService;
import com.example.custom.sequence.utils.AppConstants;
import jakarta.validation.groups.Default;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -23,7 +22,6 @@

@RestController
@RequestMapping("/api/orders")
@Slf4j
public class OrderController {

private final OrderService orderService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OrderControllerTest {

@BeforeEach
void setUp() {
customer = new Customer("CUST_01", "customer1", new ArrayList<>());
customer = new Customer("CUST_01", "customer1", List.of());
this.orderList = new ArrayList<>();
this.orderList.add(new Order("1", "text 1", customer));
this.orderList.add(new Order("2", "text 2", customer));
Expand Down

0 comments on commit d86bc51

Please sign in to comment.