Przeglądaj źródła

Cache invalidation in controllers

Andrew Grant 3 miesięcy temu
rodzic
commit
bf95b69b0a
13 zmienionych plików z 77 dodań i 15 usunięć
  1. 6 2
      src/main/java/scot/carricksoftware/grants/controllers/people/PersonFormControllerImpl.java
  2. 5 1
      src/main/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerImpl.java
  3. 6 2
      src/main/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerImpl.java
  4. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/people/PageFormControllerCleansingTest.java
  5. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/people/PageFormControllerValidationAndValidationTest.java
  6. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/people/PersonFormControllerSaveOrUpdateTest.java
  7. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/people/PersonFormControllerTest.java
  8. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerCleansingTest.java
  9. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerSaveOrUpdateTest.java
  10. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerTest.java
  11. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerSaveOrUpdateTest.java
  12. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerTest.java
  13. 6 1
      src/test/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerValidationAndCapitalisationTest.java

+ 6 - 2
src/main/java/scot/carricksoftware/grants/controllers/people/PersonFormControllerImpl.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.people.CapitalisePerson;
 import scot.carricksoftware.grants.commands.people.PersonCommand;
 import scot.carricksoftware.grants.commands.people.PersonCommandImpl;
@@ -33,18 +34,19 @@ public class PersonFormControllerImpl implements PersonFormController {
     private static final Logger logger = LogManager.getLogger(PersonFormControllerImpl.class);
 
     private final PersonService personService;
-    @SuppressWarnings({"FieldCanBeLocal", "unused"})
+    @SuppressWarnings({"unused", "FieldCanBeLocal"})
     private final PersonCommandConverterImpl personCommandConverter;
     private final PersonConverterImpl personConverter;
     private final CapitalisePerson capitalisePerson;
     private final PersonCommandValidator personCommandValidator;
+    private final BMDCache bmdCache;
 
 
     public PersonFormControllerImpl(PersonService personService,
                                     PersonCommandConverterImpl personCommandConverter,
                                     PersonConverterImpl personConverter,
                                     CapitalisePerson capitalisePerson,
-                                    PersonCommandValidator personCommandValidator) {
+                                    PersonCommandValidator personCommandValidator, BMDCache bmdCache) {
         this.personService = personService;
         this.personCommandConverter = personCommandConverter;
 
@@ -52,6 +54,7 @@ public class PersonFormControllerImpl implements PersonFormController {
         this.personConverter = personConverter;
         this.capitalisePerson = capitalisePerson;
         this.personCommandValidator = personCommandValidator;
+        this.bmdCache = bmdCache;
     }
 
     @SuppressWarnings("SameReturnValue")
@@ -78,6 +81,7 @@ public class PersonFormControllerImpl implements PersonFormController {
 
         capitalisePerson.capitalise(personCommand);
         personCommandValidator.validate(personCommand, bindingResult);
+        bmdCache.invalidatePeople();
 
         if (bindingResult.hasErrors()) {
             bindingResult.getAllErrors().forEach(error -> logger.debug(error.getDefaultMessage()));

+ 5 - 1
src/main/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerImpl.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.CapitaliseString;
 import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
 import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommandImpl;
@@ -37,17 +38,19 @@ public class OrganisationFormControllerImpl implements OrganisationFormControlle
     private final OrganisationConverter organisationConverter;
     private final CapitaliseString capitaliseString;
     private final OrganisationCommandValidator organisationCommandValidator;
+    private final BMDCache bmdCache;
 
     public OrganisationFormControllerImpl(OrganisationService organisationService,
                                           OrganisationCommandConverter organisationCommandConverter,
                                           OrganisationConverter organisationConverter,
                                           CapitaliseString capitaliseString,
-                                          OrganisationCommandValidator organisationCommandValidator) {
+                                          OrganisationCommandValidator organisationCommandValidator, BMDCache bmdCache) {
         this.organisationService = organisationService;
         this.organisationCommandConverter = organisationCommandConverter;
         this.organisationConverter = organisationConverter;
         this.capitaliseString = capitaliseString;
         this.organisationCommandValidator = organisationCommandValidator;
+        this.bmdCache = bmdCache;
     }
 
     @SuppressWarnings("SameReturnValue")
@@ -65,6 +68,7 @@ public class OrganisationFormControllerImpl implements OrganisationFormControlle
         logger.debug("OrganisationFormControllerImpl::saveOrUpdate");
 
         organisationCommandValidator.validate(organisationCommand, bindingResult);
+        bmdCache.invalidateOrganisations();
 
         if (bindingResult.hasErrors()) {
             bindingResult.getAllErrors().forEach(error -> logger.debug(error.getDefaultMessage()));

+ 6 - 2
src/main/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerImpl.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.places.places.CapitalisePlace;
 import scot.carricksoftware.grants.commands.places.places.PlaceCommand;
 import scot.carricksoftware.grants.commands.places.places.PlaceCommandImpl;
@@ -33,12 +34,13 @@ public class PlaceFormControllerImpl implements PlaceFormController {
 
     private static final Logger logger = LogManager.getLogger(PlaceFormControllerImpl.class);
     private final PlaceService placeService;
-    @SuppressWarnings({"FieldCanBeLocal", "unused"})
+    @SuppressWarnings({"unused", "FieldCanBeLocal"})
     private final PlaceCommandConverterImpl placeCommandConverter;
     private final PlaceConverterImpl placeConverter;
     private final CapitalisePlace capitalisePlace;
     private final PlaceCommandValidator placeCommandValidator;
     private final RegionService regionService;
+    private final BMDCache bmdCache;
 
 
     public PlaceFormControllerImpl(PlaceService placeService,
@@ -46,7 +48,7 @@ public class PlaceFormControllerImpl implements PlaceFormController {
                                    PlaceConverterImpl placeConverter,
                                    CapitalisePlace capitalisePlace,
                                    PlaceCommandValidator placeCommandValidator,
-                                   RegionService regionService) {
+                                   RegionService regionService, BMDCache bmdCache) {
         this.placeService = placeService;
         this.placeCommandConverter = placeCommandConverter;
 
@@ -55,6 +57,7 @@ public class PlaceFormControllerImpl implements PlaceFormController {
         this.capitalisePlace = capitalisePlace;
         this.placeCommandValidator = placeCommandValidator;
         this.regionService = regionService;
+        this.bmdCache = bmdCache;
     }
 
     @SuppressWarnings("SameReturnValue")
@@ -83,6 +86,7 @@ public class PlaceFormControllerImpl implements PlaceFormController {
 
         capitalisePlace.capitalise(placeCommand);
         placeCommandValidator.validate(placeCommand, bindingResult);
+        bmdCache.invalidatePlaces();
 
         if (bindingResult.hasErrors()) {
             model.addAttribute(AttributeConstants.REGIONS, regionService.findAll());

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/people/PageFormControllerCleansingTest.java

@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.people.CapitalisePerson;
 import scot.carricksoftware.grants.converters.people.PersonCommandConverterImpl;
 import scot.carricksoftware.grants.converters.people.PersonConverterImpl;
@@ -38,6 +39,9 @@ public class PageFormControllerCleansingTest {
     @Mock
     private CapitalisePerson capitalisePersonMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
     @Mock
     PersonCommandValidator personCommandValidatorMock;
 
@@ -47,7 +51,8 @@ public class PageFormControllerCleansingTest {
                 personCommandConverterMock,
                 personConverterMock,
                 capitalisePersonMock,
-                personCommandValidatorMock);
+                personCommandValidatorMock,
+                bmdCacheMock);
     }
 
 

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/people/PageFormControllerValidationAndValidationTest.java

@@ -13,6 +13,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
 import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.people.CapitalisePerson;
 import scot.carricksoftware.grants.commands.people.PersonCommand;
 import scot.carricksoftware.grants.commands.people.PersonCommandImpl;
@@ -52,6 +53,9 @@ public class PageFormControllerValidationAndValidationTest {
     @Mock
     Model modelMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
 
     @BeforeEach
     public void setUp() {
@@ -59,7 +63,8 @@ public class PageFormControllerValidationAndValidationTest {
                 personCommandConverterMock,
                 personConverterMock,
                 capitalisePersonMock,
-                personCommandValidatorMock);
+                personCommandValidatorMock,
+                bmdCacheMock);
     }
 
 

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/people/PersonFormControllerSaveOrUpdateTest.java

@@ -12,6 +12,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
 import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.people.CapitalisePerson;
 import scot.carricksoftware.grants.commands.people.PersonCommand;
 import scot.carricksoftware.grants.commands.people.PersonCommandImpl;
@@ -52,6 +53,9 @@ public class PersonFormControllerSaveOrUpdateTest {
     @Mock
     PersonCommandValidator personCommandValidatorMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
     private PersonCommand personCommand;
 
 
@@ -61,7 +65,8 @@ public class PersonFormControllerSaveOrUpdateTest {
                 personCommandConverterMock,
                 personConverterMock,
                 capitalisePersonMock,
-                personCommandValidatorMock);
+                personCommandValidatorMock,
+                bmdCacheMock);
         personCommand = new PersonCommandImpl();
     }
 

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/people/PersonFormControllerTest.java

@@ -13,6 +13,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.people.CapitalisePerson;
 import scot.carricksoftware.grants.commands.people.PersonCommand;
 import scot.carricksoftware.grants.constants.AttributeConstants;
@@ -48,6 +49,9 @@ public class PersonFormControllerTest {
     @Mock
     private CapitalisePerson capitalisePersonMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
     @Mock
     private Model modelMock;
 
@@ -61,7 +65,8 @@ public class PersonFormControllerTest {
                 personCommandConverterMock,
                 personConverterMock,
                 capitalisePersonMock,
-                personCommandValidatorMock);
+                personCommandValidatorMock,
+                bmdCacheMock);
     }
 
     @Test

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerCleansingTest.java

@@ -13,6 +13,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
 import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.CapitaliseString;
 import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
 import scot.carricksoftware.grants.converters.places.organisations.OrganisationCommandConverterImpl;
@@ -55,6 +56,9 @@ public class OrganisationFormControllerCleansingTest {
     @Mock
     Model modelMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
 
     @BeforeEach
     public void setUp() {
@@ -62,7 +66,8 @@ public class OrganisationFormControllerCleansingTest {
                 organisationCommandConverterMock,
                 organisationConverterMock,
                 capitaliseStringMock,
-                organisationCommandValidatorMock);
+                organisationCommandValidatorMock,
+                bmdCacheMock);
     }
 
 

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerSaveOrUpdateTest.java

@@ -12,6 +12,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
 import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.CapitaliseString;
 import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
 import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommandImpl;
@@ -53,6 +54,9 @@ public class OrganisationFormControllerSaveOrUpdateTest {
     @Mock
     OrganisationCommandValidator organisationCommandValidatorMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
     private OrganisationCommand organisationCommand;
 
 
@@ -62,7 +66,8 @@ public class OrganisationFormControllerSaveOrUpdateTest {
                 organisationCommandConverterMock,
                 organisationConverterMock,
                 capitaliseStringMock,
-                organisationCommandValidatorMock);
+                organisationCommandValidatorMock,
+                bmdCacheMock);
         organisationCommand = new OrganisationCommandImpl();
     }
 

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/places/organisations/OrganisationFormControllerTest.java

@@ -13,6 +13,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.CapitaliseString;
 import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
 import scot.carricksoftware.grants.constants.AttributeConstants;
@@ -51,6 +52,9 @@ public class OrganisationFormControllerTest {
     @Mock
     private Model modelMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
     @Mock
     OrganisationCommandValidator organisationCommandValidatorMock;
 
@@ -61,7 +65,8 @@ public class OrganisationFormControllerTest {
                 organisationCommandConverterMock,
                 organisationConverterMock,
                 capitaliseString,
-                organisationCommandValidatorMock);
+                organisationCommandValidatorMock,
+                bmdCacheMock);
     }
 
     @Test

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerSaveOrUpdateTest.java

@@ -12,6 +12,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
 import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.places.places.CapitalisePlace;
 import scot.carricksoftware.grants.commands.places.places.PlaceCommand;
 import scot.carricksoftware.grants.commands.places.places.PlaceCommandImpl;
@@ -56,6 +57,9 @@ public class PlaceFormControllerSaveOrUpdateTest {
     @Mock
     PlaceCommandValidator placeCommandValidatorMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
     private PlaceCommand placeCommand;
 
 
@@ -66,7 +70,8 @@ public class PlaceFormControllerSaveOrUpdateTest {
                 placeConverterMock,
                 capitalisePlaceMock,
                 placeCommandValidatorMock,
-                regionServiceMock);
+                regionServiceMock,
+                bmdCacheMock);
         placeCommand = new PlaceCommandImpl();
     }
 

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerTest.java

@@ -13,6 +13,7 @@ import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.places.places.CapitalisePlace;
 import scot.carricksoftware.grants.commands.places.places.PlaceCommand;
 import scot.carricksoftware.grants.constants.AttributeConstants;
@@ -57,6 +58,9 @@ public class PlaceFormControllerTest {
     @Mock
     PlaceCommandValidator placeCommandValidatorMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
 
     @BeforeEach
     public void setUp() {
@@ -65,7 +69,8 @@ public class PlaceFormControllerTest {
                 placeConverterMock,
                 capitalisePlaceMock,
                 placeCommandValidatorMock,
-                regionServiceMock);
+                regionServiceMock,
+                bmdCacheMock);
     }
 
     @Test

+ 6 - 1
src/test/java/scot/carricksoftware/grants/controllers/places/places/PlaceFormControllerValidationAndCapitalisationTest.java

@@ -13,6 +13,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.springframework.ui.Model;
 import org.springframework.validation.BindingResult;
+import scot.carricksoftware.grants.cache.BMDCache;
 import scot.carricksoftware.grants.capitalisation.places.places.CapitalisePlace;
 import scot.carricksoftware.grants.commands.places.places.PlaceCommand;
 import scot.carricksoftware.grants.commands.places.places.PlaceCommandImpl;
@@ -53,6 +54,9 @@ public class PlaceFormControllerValidationAndCapitalisationTest {
     @Mock
     private BindingResult bindingResultMock;
 
+    @Mock
+    private BMDCache bmdCacheMock;
+
     @Mock
     Model modelMock;
 
@@ -65,7 +69,8 @@ public class PlaceFormControllerValidationAndCapitalisationTest {
                 placeConverterMock,
                 capitalisePlaceMock,
                 placeCommandValidatorMock,
-                regionServiceMock);
+                regionServiceMock,
+                bmdCacheMock);
         placeCommand = new PlaceCommandImpl();
     }