Skip to content

Commit

Permalink
Make autowired CacheManager nullable to support disabling dynamic upd…
Browse files Browse the repository at this point in the history
…ating
  • Loading branch information
EdwinHeuver92 committed Jan 20, 2024
1 parent a2e4574 commit 550df72
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Optional;
import java.util.Set;

import jakarta.annotation.Nullable;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Valid;
import jakarta.validation.Validator;
Expand All @@ -26,9 +27,10 @@
public class TestController {

private final Validator validator;

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public TestController(Validator validator, CacheManager<String, Bucket4JConfiguration> configCacheManager) {
public TestController(Validator validator, @Nullable CacheManager<String, Bucket4JConfiguration> configCacheManager) {
this.validator = validator;
this.configCacheManager = configCacheManager;
}
Expand Down Expand Up @@ -60,6 +62,7 @@ public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody @Valid Bucket4JConfiguration newConfig,
BindingResult bindingResult) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

import com.giffing.bucket4j.spring.boot.starter.utils.Bucket4JUtils;
import jakarta.annotation.Nullable;
import jakarta.validation.Valid;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand All @@ -29,7 +32,7 @@ public class TestController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public TestController(CacheManager<String, Bucket4JConfiguration> configCacheManager) {
public TestController(@Nullable CacheManager<String, Bucket4JConfiguration> configCacheManager) {
this.configCacheManager = configCacheManager;
}

Expand Down Expand Up @@ -93,6 +96,7 @@ public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody @Valid Bucket4JConfiguration newConfig,
BindingResult bindingResult) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.giffing.bucket4j.spring.boot.starter.examples.gateway;

import com.giffing.bucket4j.spring.boot.starter.utils.Bucket4JUtils;
import jakarta.annotation.Nullable;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Valid;
import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
Expand All @@ -14,6 +16,7 @@
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;

import java.util.List;
import java.util.Optional;
import java.util.Set;

@RestController
Expand All @@ -25,7 +28,7 @@ public class TestController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public TestController(CacheManager<String, Bucket4JConfiguration> configCacheManager){
public TestController(@Nullable CacheManager<String, Bucket4JConfiguration> configCacheManager){
this.configCacheManager = configCacheManager;
}

Expand All @@ -39,6 +42,7 @@ public TestController(CacheManager<String, Bucket4JConfiguration> configCacheMan
public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody Bucket4JConfiguration newConfig) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.giffing.bucket4j.spring.boot.starter.examples.hazelcast;

import com.giffing.bucket4j.spring.boot.starter.utils.Bucket4JUtils;
import jakarta.annotation.Nullable;
import jakarta.validation.Valid;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
Expand All @@ -18,7 +20,7 @@ public class TestController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public TestController(CacheManager<String, Bucket4JConfiguration> configCacheManager) {
public TestController(@Nullable CacheManager<String, Bucket4JConfiguration> configCacheManager) {
this.configCacheManager = configCacheManager;
}

Expand All @@ -40,6 +42,7 @@ public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody @Valid Bucket4JConfiguration newConfig,
BindingResult bindingResult) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.giffing.bucket4j.spring.boot.starter;

import com.giffing.bucket4j.spring.boot.starter.utils.Bucket4JUtils;
import jakarta.annotation.Nullable;
import jakarta.validation.Valid;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,7 +19,7 @@ public class TestController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public TestController(CacheManager<String,Bucket4JConfiguration> configCacheManager){
public TestController(@Nullable CacheManager<String,Bucket4JConfiguration> configCacheManager){
this.configCacheManager = configCacheManager;
}

Expand All @@ -44,6 +46,7 @@ public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody @Valid Bucket4JConfiguration newConfig,
BindingResult bindingResult) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;
import com.giffing.bucket4j.spring.boot.starter.utils.Bucket4JUtils;
import jakarta.annotation.Nullable;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -20,7 +22,7 @@ public class TestController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public TestController(CacheManager<String,Bucket4JConfiguration> configCacheManager){
public TestController(@Nullable CacheManager<String,Bucket4JConfiguration> configCacheManager){
this.configCacheManager = configCacheManager;
}

Expand All @@ -45,6 +47,7 @@ public ResponseEntity<String> world() {
public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody Bucket4JConfiguration newConfig) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public TestController(CacheManager<String, Bucket4JConfiguration> configCacheManager){
public TestController(@Nullable CacheManager<String, Bucket4JConfiguration> configCacheManager){
this.configCacheManager = configCacheManager;
}

Expand All @@ -45,6 +45,7 @@ public ResponseEntity<String> world() {
public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody Bucket4JConfiguration newConfig) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheManager;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration;
import com.giffing.bucket4j.spring.boot.starter.utils.Bucket4JUtils;
import jakarta.annotation.Nullable;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
Expand All @@ -22,7 +24,7 @@ public class MyController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public MyController(CacheManager<String, Bucket4JConfiguration> configCacheManager) {
public MyController(@Nullable CacheManager<String, Bucket4JConfiguration> configCacheManager) {
this.configCacheManager = configCacheManager;
}

Expand Down Expand Up @@ -55,6 +57,7 @@ public Mono<String> world(
public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody Bucket4JConfiguration newConfig) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.giffing.bucket4j.spring.boot.starter.examples.webflux;

import com.giffing.bucket4j.spring.boot.starter.utils.Bucket4JUtils;
import jakarta.annotation.Nullable;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Valid;
import jakarta.validation.Validator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
Expand All @@ -27,7 +29,7 @@ public class MyController {

private final CacheManager<String, Bucket4JConfiguration> configCacheManager;

public MyController(CacheManager<String, Bucket4JConfiguration> configCacheManager) {
public MyController(@Nullable CacheManager<String, Bucket4JConfiguration> configCacheManager) {
this.configCacheManager = configCacheManager;
}

Expand Down Expand Up @@ -60,6 +62,7 @@ public Mono<String> world(
public ResponseEntity<?> updateConfig(
@PathVariable String filterId,
@RequestBody Bucket4JConfiguration newConfig) {
if(configCacheManager == null) return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Dynamic updating is disabled");

//validate that the path id matches the body
if (!newConfig.getId().equals(filterId)) {
Expand Down

0 comments on commit 550df72

Please sign in to comment.