فهرست منبع

CensusService added to SelectedCensusListControllerImpl

Andrew Grant 7 ماه پیش
والد
کامیت
08c04e89b0

+ 2 - 2
src/main/java/scot/carricksoftware/grants/constants/ViewConstants.java

@@ -32,8 +32,8 @@ public class ViewConstants {
     public static final String CENSUS_LIST = "census/list";
     public static final String CENSUS_FORM = "census/form";
 
-    public static final String CENSUS_ENTRY_LIST = "censusentry/list";
-    public static final String CENSUS_ENTRY_FORM = "censusentry/form";
+    public static final String CENSUS_ENTRY_LIST = "censusEntry/list";
+    public static final String CENSUS_ENTRY_FORM = "censusEntry/form";
 
     public static final String SELECTED_CENSUS_LIST = "selectedCensus/list";
 

+ 10 - 10
src/main/java/scot/carricksoftware/grants/controllers/census/selectedcensus/SelectedCensusListControllerImpl.java

@@ -17,7 +17,7 @@ import scot.carricksoftware.grants.controllers.ControllerHelper;
 import scot.carricksoftware.grants.controllers.census.censusentry.CensusEntryListController;
 import scot.carricksoftware.grants.domains.census.Census;
 import scot.carricksoftware.grants.services.census.census.CensusService;
-import scot.carricksoftware.grants.services.census.selectedcensus.SelectedCensusService;
+import scot.carricksoftware.grants.services.census.selectedcensus.SelectedCensusEntryService;
 
 import static java.lang.Integer.max;
 
@@ -28,19 +28,19 @@ public class SelectedCensusListControllerImpl implements CensusEntryListControll
 
 
     private int currentPage = 0;
-    @SuppressWarnings("unused")
+    @SuppressWarnings({"unused", "FieldCanBeLocal"})
     private Census census;
 
     private final ControllerHelper controllerHelper;
-    private final SelectedCensusService censusEntryService;
+    private final SelectedCensusEntryService selectedCensusEntryService;
     private final CensusService censusService;
 
 
     public SelectedCensusListControllerImpl(ControllerHelper controllerHelper,
-                                            SelectedCensusService censusEntryService,
+                                            SelectedCensusEntryService selectedCensusEntryService,
                                             CensusService censusService) {
         this.controllerHelper = controllerHelper;
-        this.censusEntryService = censusEntryService;
+        this.selectedCensusEntryService = selectedCensusEntryService;
         this.censusService = censusService;
     }
 
@@ -55,7 +55,7 @@ public class SelectedCensusListControllerImpl implements CensusEntryListControll
 
     @SuppressWarnings("SameReturnValue")
     private String sendAttributesAndReturn(Model model) {
-        model.addAttribute(AttributeConstants.CENSUS_ENTRIES, censusEntryService.getPagedCensusEntries(currentPage));
+        model.addAttribute(AttributeConstants.CENSUS_ENTRIES, selectedCensusEntryService.getPagedCensusEntries(currentPage));
         controllerHelper.addAttributes(model);
         return ViewConstants.SELECTED_CENSUS_LIST;
     }
@@ -91,7 +91,7 @@ public class SelectedCensusListControllerImpl implements CensusEntryListControll
     @Override
     public final String getLastPage(final Model model) {
         logger.debug("SelectedCensusListControllerImpl:getLastPage");
-        long censusEntryCount = censusEntryService.count();
+        long censusEntryCount = selectedCensusEntryService.count();
         currentPage = (int) (censusEntryCount / ApplicationConstants.DEFAULT_PAGE_SIZE);
         return sendAttributesAndReturn(model);
     }
@@ -103,7 +103,7 @@ public class SelectedCensusListControllerImpl implements CensusEntryListControll
     @Override
     public final String censusEntryDelete(@PathVariable final String id) {
         logger.debug("SelectedCensusListControllerImpl::censusEntryDelete");
-        censusEntryService.deleteById(Long.valueOf(id));
+        selectedCensusEntryService.deleteById(Long.valueOf(id));
         return MappingConstants.REDIRECT + CensusMappingConstants.SELECTED_CENSUS_LIST;
     }
 
@@ -112,8 +112,8 @@ public class SelectedCensusListControllerImpl implements CensusEntryListControll
     public final String censusEntryList(@Valid @PathVariable final String id, Model model) {
         logger.debug("");
         census = censusService.findById(Long.valueOf(id));
-        model.addAttribute(AttributeConstants.CENSUS, censusEntryService.findById(Long.valueOf(id)));
-        model.addAttribute(AttributeConstants.CENSUS_ENTRIES, censusEntryService.getPagedCensusEntries(currentPage));
+        model.addAttribute(AttributeConstants.CENSUS,  selectedCensusEntryService.findById(Long.valueOf(id)));
+        model.addAttribute(AttributeConstants.CENSUS_ENTRIES, selectedCensusEntryService.getPagedCensusEntries(currentPage));
         return ViewConstants.SELECTED_CENSUS_LIST;
     }
 

+ 1 - 1
src/main/java/scot/carricksoftware/grants/services/census/selectedcensus/SelectedCensusService.java → src/main/java/scot/carricksoftware/grants/services/census/selectedcensus/SelectedCensusEntryService.java

@@ -12,7 +12,7 @@ import scot.carricksoftware.grants.domains.census.CensusEntry;
 import java.util.List;
 
 @Service
-public interface SelectedCensusService {
+public interface SelectedCensusEntryService {
 
     @SuppressWarnings("unused")
     CensusEntry findById(Long id);

+ 3 - 4
src/main/java/scot/carricksoftware/grants/services/census/selectedcensus/SelectedCensusServiceImpl.java → src/main/java/scot/carricksoftware/grants/services/census/selectedcensus/SelectedCensusEntryServiceImpl.java

@@ -19,22 +19,21 @@ import scot.carricksoftware.grants.converters.census.CensusEntryCommandConverter
 import scot.carricksoftware.grants.converters.census.CensusEntryConverterImpl;
 import scot.carricksoftware.grants.domains.census.CensusEntry;
 import scot.carricksoftware.grants.repositories.census.CensusEntryRepository;
-import scot.carricksoftware.grants.services.census.censusentry.CensusEntryService;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 
 @Service
-public class SelectedCensusServiceImpl implements CensusEntryService {
-    private static final Logger logger = LogManager.getLogger(SelectedCensusServiceImpl.class);
+public class SelectedCensusEntryServiceImpl implements SelectedCensusEntryService {
+    private static final Logger logger = LogManager.getLogger(SelectedCensusEntryServiceImpl.class);
 
     @SuppressWarnings({"unused"})
     private final CensusEntryRepository censusEntryRepository;
     private final CensusEntryConverterImpl censusEntryConverterImpl;
     private final CensusEntryCommandConverterImpl censusEntryCommandConverterImpl;
 
-    public SelectedCensusServiceImpl(CensusEntryRepository censusEntryRepository, CensusEntryConverterImpl censusEntryConverterImpl, CensusEntryCommandConverterImpl censusEntryCommandConverterImpl) {
+    public SelectedCensusEntryServiceImpl(CensusEntryRepository censusEntryRepository, CensusEntryConverterImpl censusEntryConverterImpl, CensusEntryCommandConverterImpl censusEntryCommandConverterImpl) {
         this.censusEntryRepository = censusEntryRepository;
         this.censusEntryConverterImpl = censusEntryConverterImpl;
         this.censusEntryCommandConverterImpl = censusEntryCommandConverterImpl;

+ 1 - 1
src/main/resources/templates/censusEntries/form.html → src/main/resources/templates/censusEntry/form.html

@@ -181,7 +181,7 @@ rounded-3 text-center p-4">
         </div>
 
         <button type="submit" class="btn btn-primary">Commit</button>
-        <a class="btn btn-secondary" th:href="@{/censusEntries}" th:text="${'List all'}">List all</a>
+        <a class="btn btn-secondary" th:href="@{/templates/censusEntry}" th:text="${'List all'}">List all</a>
         <a class="btn btn-success" th:href="@{/}" th:text="${'Home'}">Home</a>
         <h6><span style="color: rgb(255,0,0);">*</span><span> Cannot be edited</span></h6>
         <h6><span style="color: rgb(255,0,0);">+</span><span>Not further recorded</span></h6>

+ 4 - 4
src/main/resources/templates/censusEntries/list.html → src/main/resources/templates/censusEntry/list.html

@@ -53,17 +53,17 @@
             <tfoot>
             <tr>
                 <td colspan="4"><span>
-                        <a th:action="rewind" class="btn btn-secondary btn-sm" th:href="@{/censusEntries/rewind}"
+                        <a th:action="rewind" class="btn btn-secondary btn-sm" th:href="@{/templates/censusEntry/rewind}"
                            th:text="'<<'"></a>
                          <a th:action="back" class="btn btn-secondary btn-sm"
-                            th:href="@{/censusEntries/prev}" th:text="'<'"></a>
+                            th:href="@{/templates/censusEntry/prev}" th:text="'<'"></a>
                          <a th:action="new" class="btn btn-primary btn-sm" th:href="@{censusEntry/new}"
                             th:text="'New Entry'"></a>
                          <a th:action="home" class="btn btn-success btn-sm"
                             th:href="@{/}" th:text="'Home'"></a>
                          <a th:action="forward" class="btn btn-secondary btn-sm"
-                            th:href="@{/censusEntries/next}" th:text="'>'"></a>
-                         <a th:action="end" class="btn btn-secondary btn-sm" th:href="@{/censusEntries/ff}"
+                            th:href="@{/templates/censusEntry/next}" th:text="'>'"></a>
+                         <a th:action="end" class="btn btn-secondary btn-sm" th:href="@{/templates/censusEntry/ff}"
                             th:text="'>>'"></a>
                         </span></td>
             </tr>

+ 4 - 4
src/main/resources/templates/selectedCensus/list.html

@@ -53,17 +53,17 @@
             <tfoot>
             <tr>
                 <td colspan="4"><span>
-                        <a th:action="rewind" class="btn btn-secondary btn-sm" th:href="@{/censusEntries/rewind}"
+                        <a th:action="rewind" class="btn btn-secondary btn-sm" th:href="@{/templates/censusEntry/rewind}"
                            th:text="'<<'"></a>
                          <a th:action="back" class="btn btn-secondary btn-sm"
-                            th:href="@{/censusEntries/prev}" th:text="'<'"></a>
+                            th:href="@{/templates/censusEntry/prev}" th:text="'<'"></a>
                          <a th:action="new" class="btn btn-primary btn-sm" th:href="@{censusEntry/new}"
                             th:text="'New Entry'"></a>
                          <a th:action="home" class="btn btn-success btn-sm"
                             th:href="@{/}" th:text="'Home'"></a>
                          <a th:action="forward" class="btn btn-secondary btn-sm"
-                            th:href="@{/censusEntries/next}" th:text="'>'"></a>
-                         <a th:action="end" class="btn btn-secondary btn-sm" th:href="@{/censusEntries/ff}"
+                            th:href="@{/templates/censusEntry/next}" th:text="'>'"></a>
+                         <a th:action="end" class="btn btn-secondary btn-sm" th:href="@{/templates/censusEntry/ff}"
                             th:text="'>>'"></a>
                         </span></td>
             </tr>

+ 1 - 2
src/test/java/scot/carricksoftware/grants/controllers/census/censusentry/CensusEntryFormControllerSaveOrUpdateTest.java

@@ -89,8 +89,7 @@ public class CensusEntryFormControllerSaveOrUpdateTest {
         Long id = 4L;
         censusEntryCommand.setId(id);
         when(bindingResultMock.hasErrors()).thenReturn(true);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/form", censusEntryController.saveOrUpdate(censusEntryCommand, bindingResultMock, modelMock));
+        assertEquals("censusEntry/form", censusEntryController.saveOrUpdate(censusEntryCommand, bindingResultMock, modelMock));
     }
 
     @Test

+ 3 - 6
src/test/java/scot/carricksoftware/grants/controllers/census/censusentry/CensusEntryFormControllerTest.java

@@ -79,8 +79,7 @@ public class CensusEntryFormControllerTest {
     public void getNewCensusEntryTest() {
         ArgumentCaptor<Object> objectCaptor = ArgumentCaptor.forClass(Object.class);
         ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/form", censusEntryController.getNewCensusEntry(modelMock));
+        assertEquals("censusEntry/form", censusEntryController.getNewCensusEntry(modelMock));
         verify(modelMock, atLeast(2)).addAttribute(stringCaptor.capture(), objectCaptor.capture());
 
         boolean foundCensusEntryCommand = false;
@@ -108,8 +107,7 @@ public class CensusEntryFormControllerTest {
         CensusEntry censusEntry = GetRandomCensusEntry();
         when(censusEntryServiceMock.findById(id)).thenReturn(censusEntry);
 
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/form", censusEntryController.censusEntryEdit(id + "", modelMock));
+        assertEquals("censusEntry/form", censusEntryController.censusEntryEdit(id + "", modelMock));
         verify(modelMock).addAttribute(AttributeConstants.CENSUS_ENTRY_COMMAND, censusEntry);
     }
 
@@ -121,8 +119,7 @@ public class CensusEntryFormControllerTest {
 
         when(censusEntryServiceMock.findById(id)).thenReturn(censusEntry);
         when(censusEntryConverterMock.convert(censusEntry)).thenReturn(censusEntryCommand);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/form", censusEntryController.showById(id + "", modelMock));
+        assertEquals("censusEntry/form", censusEntryController.showById(id + "", modelMock));
         verify(modelMock).addAttribute(AttributeConstants.CENSUS_ENTRY_COMMAND, censusEntryCommand);
     }
 

+ 6 - 12
src/test/java/scot/carricksoftware/grants/controllers/census/censusentry/CensusEntryListControllerTest.java

@@ -50,8 +50,7 @@ public class CensusEntryListControllerTest {
     @Test
     public void getListPageTest() {
         when(censusEntryServiceMock.getPagedCensusEntries(0)).thenReturn(censusEntryListMock);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/list", controller.getListPage(modelMock));
+        assertEquals("censusEntry/list", controller.getListPage(modelMock));
         verify(modelMock).addAttribute("censusEntries", censusEntryListMock);
         verify(controllerHelperMock).addAttributes(modelMock);
     }
@@ -63,8 +62,7 @@ public class CensusEntryListControllerTest {
         when(censusEntryServiceMock.count()).thenReturn((long) count);
         controller.getLastPage(modelMock);
         controller.getPreviousPage(modelMock);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/list", controller.getLastPage(modelMock));
+        assertEquals("censusEntry/list", controller.getLastPage(modelMock));
         verify(censusEntryServiceMock, times(2)).getPagedCensusEntries(page);
     }
 
@@ -81,8 +79,7 @@ public class CensusEntryListControllerTest {
         censusEntryList.add(GetRandomCensusEntry());
         when(censusEntryServiceMock.getPagedCensusEntries(0)).thenReturn(censusEntryList);
 
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/list", controller.getFirstPage(modelMock));
+        assertEquals("censusEntry/list", controller.getFirstPage(modelMock));
         assertEquals(0, controller.getPageNumber());
         verify(modelMock).addAttribute("censusEntries", censusEntryList);
     }
@@ -94,8 +91,7 @@ public class CensusEntryListControllerTest {
         when(censusEntryServiceMock.getPagedCensusEntries(0)).thenReturn(censusEntryList);
 
         controller.getFirstPage(modelMock);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/list", controller.getNextPage(modelMock));
+        assertEquals("censusEntry/list", controller.getNextPage(modelMock));
         assertEquals(1, controller.getPageNumber());
         verify(modelMock).addAttribute("censusEntries", censusEntryList);
 
@@ -108,8 +104,7 @@ public class CensusEntryListControllerTest {
         when(censusEntryServiceMock.getPagedCensusEntries(0)).thenReturn(censusEntryList);
 
         controller.getFirstPage(modelMock);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/list", controller.getPreviousPage(modelMock));
+        assertEquals("censusEntry/list", controller.getPreviousPage(modelMock));
         assertEquals(0, controller.getPageNumber());
         verify(modelMock, times(2)).addAttribute("censusEntries", censusEntryList);
     }
@@ -120,8 +115,7 @@ public class CensusEntryListControllerTest {
         int count = page * ApplicationConstants.DEFAULT_PAGE_SIZE;
         when(censusEntryServiceMock.count()).thenReturn((long) count);
         controller.getLastPage(modelMock);
-        //noinspection SpellCheckingInspection
-        assertEquals("censusentry/list", controller.getPreviousPage(modelMock));
+        assertEquals("censusEntry/list", controller.getPreviousPage(modelMock));
         assertEquals(24, controller.getPageNumber());
     }