Bladeren bron

AppendixText bootstrap

Andrew Grant 2 maanden geleden
bovenliggende
commit
7df9a44eb7

+ 14 - 1
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadTexts.java

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
 import scot.carricksoftware.grants.commands.text.*;
 import scot.carricksoftware.grants.services.people.PersonService;
 import scot.carricksoftware.grants.services.places.places.PlaceService;
+import scot.carricksoftware.grants.services.text.appendixtext.AppendixTextService;
 import scot.carricksoftware.grants.services.text.documenttext.DocumentTextService;
 import scot.carricksoftware.grants.services.text.persontext.PersonTextService;
 import scot.carricksoftware.grants.services.text.placetext.PlaceTextService;
@@ -27,15 +28,17 @@ public class DataLoadTexts {
     private final PlaceTextService placeTextService;
     private final PersonService personService;
     private final PlaceService placeService;
+    private final AppendixTextService appendixTextService;
 
     public DataLoadTexts(DocumentTextService documentTextService,
                          PersonTextService personTextService, PlaceTextService placeTextService,
-                         PersonService personService, PlaceService placeService) {
+                         PersonService personService, PlaceService placeService, AppendixTextService appendixTextService) {
         this.documentTextService = documentTextService;
         this.personTextService = personTextService;
         this.placeTextService = placeTextService;
         this.personService = personService;
         this.placeService = placeService;
+        this.appendixTextService = appendixTextService;
     }
 
     public void load() {
@@ -43,6 +46,7 @@ public class DataLoadTexts {
         loadDocumentText();
         loadPersonText();
         loadPlaceText();
+        loadAppendixText();
     }
 
     private void loadDocumentText() {
@@ -60,6 +64,15 @@ public class DataLoadTexts {
         personTextService.savePersonTextCommand(personTextCommand);
     }
 
+    private void loadAppendixText() {
+        AppendixTextCommand appendixTextCommand = new AppendixTextCommandImpl();
+        appendixTextCommand.setOrder(1L);
+        appendixTextCommand.setLevel(4L);
+        appendixTextCommand.setHeading("Edinburgh");
+
+        appendixTextService.saveAppendixTextCommand(appendixTextCommand);
+    }
+
     private void loadPlaceText() {
         PlaceTextCommand placeTextCommand = new PlaceTextCommandImpl();
         placeTextCommand.setPlace(placeService.findById(1L));

+ 33 - 0
src/main/java/scot/carricksoftware/grants/repositories/text/AppendixTextRepository.java

@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 19:47. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.repositories.text;
+
+import org.springframework.data.repository.PagingAndSortingRepository;
+import org.springframework.stereotype.Repository;
+import scot.carricksoftware.grants.domains.text.AppendixText;
+
+import java.util.Optional;
+
+
+@SuppressWarnings("unused")
+@Repository
+public interface AppendixTextRepository extends PagingAndSortingRepository<AppendixText, Long> {
+
+    @SuppressWarnings("unused")
+    AppendixText save(AppendixText appendixText);
+
+    @SuppressWarnings("unused")
+    long count();
+
+    @SuppressWarnings("unused")
+    void deleteById(Long id);
+
+    @SuppressWarnings("unused")
+    Optional<AppendixText> findById(Long id);
+
+    @SuppressWarnings("unused")
+    Iterable<AppendixText> findAll();
+}

+ 38 - 0
src/main/java/scot/carricksoftware/grants/services/text/appendixtext/AppendixTextService.java

@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 28/03/2025, 12:33. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.services.text.appendixtext;
+
+import org.springframework.stereotype.Service;
+import scot.carricksoftware.grants.commands.text.AppendixTextCommand;
+import scot.carricksoftware.grants.domains.text.AppendixText;
+
+import java.util.List;
+
+
+@Service
+public interface AppendixTextService {
+
+    @SuppressWarnings("unused")
+    AppendixText findById(Long id);
+
+    @SuppressWarnings({"unused", "UnusedReturnValue"})
+    AppendixText save(AppendixText appendixText);
+
+    @SuppressWarnings("unused")
+    void deleteById(Long id);
+
+    @SuppressWarnings("unused")
+    List<AppendixText> getPagedAppendixTexts(int pageNumber);
+
+    @SuppressWarnings("unused")
+    long count();
+
+    @SuppressWarnings({"unused", "UnusedReturnValue"})
+    AppendixTextCommand saveAppendixTextCommand(AppendixTextCommand appendixTextCommand);
+
+    @SuppressWarnings("unused")
+    List<AppendixText> findAll();
+}

+ 102 - 0
src/main/java/scot/carricksoftware/grants/services/text/appendixtext/AppendixTextServiceImpl.java

@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 20:23. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.services.text.appendixtext;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import scot.carricksoftware.grants.commands.text.AppendixTextCommand;
+import scot.carricksoftware.grants.constants.ApplicationConstants;
+import scot.carricksoftware.grants.converters.text.appendixtext.AppendixTextCommandConverterImpl;
+import scot.carricksoftware.grants.converters.text.appendixtext.AppendixTextConverterImpl;
+import scot.carricksoftware.grants.domains.text.AppendixText;
+import scot.carricksoftware.grants.repositories.text.AppendixTextRepository;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+@Service
+public class AppendixTextServiceImpl implements AppendixTextService {
+    private static final Logger logger = LogManager.getLogger(AppendixTextServiceImpl.class);
+
+    @SuppressWarnings({"unused"})
+    private final AppendixTextRepository appendixTextRepository;
+    private final AppendixTextConverterImpl appendixTextConverterImpl;
+    private final AppendixTextCommandConverterImpl appendixTextCommandConverterImpl;
+
+    public AppendixTextServiceImpl(
+            AppendixTextRepository appendixTextRepository,
+            AppendixTextConverterImpl appendixTextConverterImpl,
+            AppendixTextCommandConverterImpl appendixTextCommandConverterImpl) {
+
+        this.appendixTextRepository = appendixTextRepository;
+        this.appendixTextConverterImpl = appendixTextConverterImpl;
+        this.appendixTextCommandConverterImpl = appendixTextCommandConverterImpl;
+    }
+
+
+    @Override
+    public AppendixText findById(Long id) {
+        logger.debug("AppendixTextServiceImpl::findById");
+        Optional<AppendixText> appendixTextOptional = appendixTextRepository.findById(id);
+        return appendixTextOptional.orElse(null);
+    }
+
+    public AppendixText save(AppendixText appendixText) {
+        logger.debug("AppendixTextServiceImpl::save");
+        return appendixTextRepository.save(appendixText);
+    }
+
+    @Override
+    public void deleteById(Long id) {
+        logger.debug("AppendixTextServiceImpl::deleteBy");
+        appendixTextRepository.deleteById(id);
+    }
+
+    @Override
+    public List<AppendixText> getPagedAppendixTexts(int pageNumber) {
+        logger.debug("AppendixTextServiceImpl::getPagedCountries");
+        Pageable paging = PageRequest.of(pageNumber, ApplicationConstants.DEFAULT_PAGE_SIZE, getSort());
+        Page<AppendixText> pagedResult = appendixTextRepository.findAll(paging);
+        return pagedResult.getContent();
+    }
+
+    private Sort getSort() {
+        return Sort.by(Sort.Direction.ASC, "id");
+    }
+
+    @Override
+    public long count() {
+        logger.debug("AppendixTextServiceImpl::count");
+        return appendixTextRepository.count();
+    }
+
+    @Transactional
+    @Override
+    public AppendixTextCommand saveAppendixTextCommand(AppendixTextCommand appendixTextCommand) {
+        logger.debug("AppendixTextServiceImpl::saveAppendixTextCommand");
+        AppendixText appendixText = appendixTextCommandConverterImpl.convert(appendixTextCommand);
+        AppendixText savedAppendixText = appendixTextRepository.save(appendixText);
+        return appendixTextConverterImpl.convert(savedAppendixText);
+
+    }
+
+    @Override
+    public List<AppendixText> findAll() {
+        logger.debug("AppendixTextServiceImpl::findAll");
+        List<AppendixText> result = new ArrayList<>();
+        Iterable<AppendixText> appendixTextIterable = appendixTextRepository.findAll();
+        appendixTextIterable.forEach(result::add);
+        return result;
+    }
+
+}

+ 6 - 1
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadTextTest.java

@@ -13,6 +13,7 @@ import scot.carricksoftware.grants.domains.people.Person;
 import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.services.people.PersonServiceImpl;
 import scot.carricksoftware.grants.services.places.places.PlaceServiceImpl;
+import scot.carricksoftware.grants.services.text.appendixtext.AppendixTextServiceImpl;
 import scot.carricksoftware.grants.services.text.documenttext.DocumentTextServiceImpl;
 import scot.carricksoftware.grants.services.text.persontext.PersonTextServiceImpl;
 import scot.carricksoftware.grants.services.text.placetext.PlaceTextServiceImpl;
@@ -43,13 +44,17 @@ public class DataLoadTextTest {
     @Mock
     private PlaceServiceImpl placeServiceMock;
 
+    @Mock
+    private AppendixTextServiceImpl appendixTextServiceMock;
+
     @BeforeEach
     public void setUp() {
         dataLoadTexts = new DataLoadTexts(documentTextServiceMock,
                 personTextServiceMock,
                 placeTextServiceMock,
                 personServiceMock,
-                placeServiceMock);
+                placeServiceMock,
+                appendixTextServiceMock);
     }
 
     @Test