Skip to content

Commit

Permalink
Uplift to SB 3.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan Whiteley committed Mar 17, 2024
1 parent 3696070 commit 44e1bd9
Show file tree
Hide file tree
Showing 31 changed files with 91 additions and 128 deletions.
33 changes: 26 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.1</version>
<version>3.2.3</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -134,12 +134,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>de.bwaldvogel</groupId>
Expand All @@ -151,6 +145,12 @@
<artifactId>greenmail</artifactId>
<version>2.0.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- An easy way to bring in the Wiremock depedendency via Spring Cloud Contract -->
<dependency>
Expand Down Expand Up @@ -281,6 +281,25 @@
</configuration>
</plugin>

<!-- mvn rewrite:run -->
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.24.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>5.6.0</version>
</dependency>
</dependencies>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.aidanwhiteley.books.repository.dtos.BooksByGenre;
import com.aidanwhiteley.books.service.StatsService;
import com.aidanwhiteley.books.service.dtos.SummaryStats;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -38,7 +37,6 @@ public class BookController {
@Value("${books.users.max.page.size}")
private int maxPageSize;

@Autowired
public BookController(BookRepository bookRepository, StatsService statsService) {
this.bookRepository = bookRepository;
this.statsService = statsService;
Expand All @@ -50,75 +48,75 @@ public Page<Book> findAllByCreatedDateTimeDesc(Principal principal) {
}

@GetMapping(value = {"/books", "/books/"}, params = {"page", "size"})
public Page<Book> findAllByCreatedDateTimeDesc(@RequestParam(value = "page") int page,
@RequestParam(value = "size") int size, Principal principal) {
public Page<Book> findAllByCreatedDateTimeDesc(@RequestParam int page,
@RequestParam int size, Principal principal) {

PageRequest pageObj = PageRequest.of(page, size);
return bookRepository.findAllByOrderByCreatedDateTimeDesc(pageObj);
}

@GetMapping(value = "/books/{id}")
public Book findBookById(@PathVariable("id") String id, Principal principal) {
public Book findBookById(@PathVariable String id, Principal principal) {
return bookRepository.findById(id).orElseThrow(() -> new NotFoundException("Book id " + id + " not found"));
}

@GetMapping(value = {"/books", "/books/"}, params = {"author"})
public Page<Book> findByAuthor(@RequestParam("author") String author, Principal principal) {
public Page<Book> findByAuthor(@RequestParam String author, Principal principal) {
return findByAuthor(author, 0, defaultPageSize, principal);
}

@GetMapping(value = {"/books", "books/"}, params = {"author", "page", "size"})
public Page<Book> findByAuthor(@RequestParam("author") String author, @RequestParam(value = "page") int page,
@RequestParam(value = "size") int size, Principal principal) {
public Page<Book> findByAuthor(@RequestParam String author, @RequestParam int page,
@RequestParam int size, Principal principal) {

if (null == author || author.trim().isEmpty()) {
throw new IllegalArgumentException("Author parameter cannot be empty");
}

if (size > maxPageSize) {
throw new IllegalArgumentException(String.format(PAGE_REQUEST_TOO_BIG_MESSAGE, maxPageSize));
throw new IllegalArgumentException(PAGE_REQUEST_TOO_BIG_MESSAGE.formatted(maxPageSize));
}

PageRequest pageObj = PageRequest.of(page, size);
return bookRepository.findAllByAuthorOrderByCreatedDateTimeDesc(pageObj, author);
}

@GetMapping(value = {"/books", "/books/"}, params = {"search"})
public Page<Book> findBySearch(@RequestParam("search") String search, Principal principal) {
public Page<Book> findBySearch(@RequestParam String search, Principal principal) {
return findBySearch(search, 0, defaultPageSize, principal);
}

@GetMapping(value = {"/books", "/books/"}, params = {"search", "page", "size"})
public Page<Book> findBySearch(@RequestParam("search") String search, @RequestParam(value = "page") int page,
@RequestParam(value = "size") int size, Principal principal) {
public Page<Book> findBySearch(@RequestParam String search, @RequestParam int page,
@RequestParam int size, Principal principal) {

if (null == search || search.trim().isEmpty()) {
throw new IllegalArgumentException("Search query string cannot be empty");
}

if (size > maxPageSize) {
throw new IllegalArgumentException(String.format(PAGE_REQUEST_TOO_BIG_MESSAGE, maxPageSize));
throw new IllegalArgumentException(PAGE_REQUEST_TOO_BIG_MESSAGE.formatted(maxPageSize));
}

PageRequest pageObj = PageRequest.of(page, size);
return bookRepository.searchForBooks(search, pageObj);
}

@GetMapping(value = {"/books", "/books/"}, params = {"genre"})
public Page<Book> findByGenre(@RequestParam("genre") String genre, Principal principal) {
public Page<Book> findByGenre(@RequestParam String genre, Principal principal) {
return findByGenre(genre, 0, defaultPageSize, principal);
}

@GetMapping(value = {"/books", "/books/"}, params = {"genre", "page", "size"})
public Page<Book> findByGenre(@RequestParam("genre") String genre, @RequestParam(value = "page") int page,
@RequestParam(value = "size") int size, Principal principal) {
public Page<Book> findByGenre(@RequestParam String genre, @RequestParam int page,
@RequestParam int size, Principal principal) {

if (null == genre || genre.trim().isEmpty()) {
throw new IllegalArgumentException("Genre parameter cannot be empty");
}

if (size > maxPageSize) {
throw new IllegalArgumentException(String.format(PAGE_REQUEST_TOO_BIG_MESSAGE, maxPageSize));
throw new IllegalArgumentException(PAGE_REQUEST_TOO_BIG_MESSAGE.formatted(maxPageSize));
}

PageRequest pageObj = PageRequest.of(page, size);
Expand All @@ -141,13 +139,13 @@ public List<BooksByAuthor> findBookAuthors() {
}

@GetMapping(value = {"/books", "/books/"}, params = {"rating"})
public Page<Book> findByRating(@RequestParam("rating") String rating, Principal principal) {
public Page<Book> findByRating(@RequestParam String rating, Principal principal) {
return findByRating(rating, 0, defaultPageSize, principal);
}

@GetMapping(value = {"/books", "/books/"}, params = {"rating", "page", "size"})
public Page<Book> findByRating(@RequestParam("rating") String rating, @RequestParam(value = "page") int page,
@RequestParam(value = "size") int size, Principal principal) {
public Page<Book> findByRating(@RequestParam String rating, @RequestParam int page,
@RequestParam int size, Principal principal) {

if (null == rating || rating.trim().isEmpty()) {
throw new IllegalArgumentException("Rating parameter cannot be empty");
Expand All @@ -159,7 +157,7 @@ public Page<Book> findByRating(@RequestParam("rating") String rating, @RequestPa
}

if (size > maxPageSize) {
throw new IllegalArgumentException(String.format(PAGE_REQUEST_TOO_BIG_MESSAGE, maxPageSize));
throw new IllegalArgumentException(PAGE_REQUEST_TOO_BIG_MESSAGE.formatted(maxPageSize));
}

PageRequest pageObj = PageRequest.of(page, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.aidanwhiteley.books.util.JwtAuthenticationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -67,7 +66,6 @@ public class BookSecureController {
@Value("${books.users.max.page.size}")
private int maxPageSize;

@Autowired
public BookSecureController(BookRepository bookRepository, GoogleBooksDaoSync googleBooksDaoSync,
GoogleBooksDaoAsync googleBooksDaoAsync, JwtAuthenticationUtils jwtAuthenticationUtils) {
this.bookRepository = bookRepository;
Expand Down Expand Up @@ -140,7 +138,7 @@ public ResponseEntity<Book> updateBook(@Valid @RequestBody Book book, Principal
}

@DeleteMapping(value = "/books/{id}")
public ResponseEntity<Book> deleteBookById(@PathVariable("id") String id, Principal principal) {
public ResponseEntity<Book> deleteBookById(@PathVariable String id, Principal principal) {

Optional<User> user = authUtils.extractUserFromPrincipal(principal, false);
if (user.isPresent()) {
Expand All @@ -159,7 +157,7 @@ public ResponseEntity<Book> deleteBookById(@PathVariable("id") String id, Princi
}

@PostMapping(value = "/books/{id}/comments")
public Book addCommentToBook(@PathVariable("id") String id, @Valid @RequestBody Comment comment,
public Book addCommentToBook(@PathVariable String id, @Valid @RequestBody Comment comment,
Principal principal) {

Optional<User> user = authUtils.extractUserFromPrincipal(principal, false);
Expand All @@ -173,7 +171,7 @@ public Book addCommentToBook(@PathVariable("id") String id, @Valid @RequestBody
}

@DeleteMapping(value = "/books/{id}/comments/{commentId}")
public Book removeCommentFromBook(@PathVariable("id") String id, @PathVariable("commentId") String commentId,
public Book removeCommentFromBook(@PathVariable String id, @PathVariable String commentId,
Principal principal) {

Optional<User> user = authUtils.extractUserFromPrincipal(principal, false);
Expand Down Expand Up @@ -203,23 +201,23 @@ public Book removeCommentFromBook(@PathVariable("id") String id, @PathVariable("
* least ROLE_EDITOR
*/
@GetMapping(value = {"/books", "/books/"})
public Page<Book> findByReader(@RequestParam String reader, @RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "5") int size, Principal principal) {
public Page<Book> findByReader(@RequestParam String reader, @RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size, Principal principal) {

if (null == reader || reader.trim().isEmpty()) {
throw new IllegalArgumentException("Reader parameter cannot be empty");
}

if (size > maxPageSize) {
throw new IllegalArgumentException(String.format("Cannot request a page of data containing more that %s elements", maxPageSize));
throw new IllegalArgumentException("Cannot request a page of data containing more that %s elements".formatted(maxPageSize));
}

PageRequest pageObj = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdDateTime"));
return bookRepository.findByReaderOrderByCreatedDateTimeDesc(pageObj, reader);
}

@GetMapping(value = {"/googlebooks", "googlebooks/"}, params = "title")
public BookSearchResult findGoogleBooksByTitle(@RequestParam("title") String title) {
public BookSearchResult findGoogleBooksByTitle(@RequestParam String title) {
return googleBooksDaoSync.searchGoogBooksByTitle(title);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.aidanwhiteley.books.util.SiteRssFeed;
import com.rometools.rome.feed.rss.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -13,7 +12,6 @@ public class FeedsController {

private final SiteRssFeed siteRssFeed;

@Autowired
public FeedsController(SiteRssFeed siteRssFeed) {
this.siteRssFeed = siteRssFeed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.aidanwhiteley.books.util.JwtAuthenticationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
Expand Down Expand Up @@ -40,7 +39,6 @@ public class UserController {

private final JwtAuthenticationService authService;

@Autowired
public UserController(UserRepository userRepository, JwtAuthenticationUtils jwtAuthenticationUtils,
JwtAuthenticationService jwtAuthenticationService) {
this.userRepository = userRepository;
Expand Down Expand Up @@ -80,7 +78,7 @@ public List<User> users(Principal principal) {

@DeleteMapping(value = "/users/{id}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<Object> deleteUserById(@PathVariable("id") String id, Principal principal) {
public ResponseEntity<Object> deleteUserById(@PathVariable String id, Principal principal) {

Optional<User> user = authUtils.extractUserFromPrincipal(principal, false);
if (user.isPresent()) {
Expand All @@ -100,7 +98,7 @@ public ResponseEntity<Object> deleteUserById(@PathVariable("id") String id, Prin

@PatchMapping(value = "/users/{id}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public ResponseEntity<Object> patchUserRolesById(@PathVariable("id") String id, @RequestBody ClientRoles clientRoles,
public ResponseEntity<Object> patchUserRolesById(@PathVariable String id, @RequestBody ClientRoles clientRoles,
Principal principal) {

Optional<User> user = authUtils.extractUserFromPrincipal(principal, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -45,7 +44,6 @@ public class LimitDataVisibilityAspect {

private final JwtAuthenticationUtils authUtils;

@Autowired
public LimitDataVisibilityAspect(JwtAuthenticationUtils jwtAuthenticationUtils) {
this.authUtils = jwtAuthenticationUtils;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository;
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
Expand All @@ -31,7 +30,7 @@ class HttpCookieOAuth2AuthorizationRequestRepository implements AuthorizationReq

public static final String COOKIE_NAME = "cloudy-oauth2-auth";

public HttpCookieOAuth2AuthorizationRequestRepository(@Autowired ObjectMapper authRequestJsonMapper) {
public HttpCookieOAuth2AuthorizationRequestRepository(ObjectMapper authRequestJsonMapper) {
this.authRequestJsonMapper = authRequestJsonMapper;
}

Expand Down
Loading

0 comments on commit 44e1bd9

Please sign in to comment.