Ver código fonte

DocumentImage bootstrap

apg 3 semanas atrás
pai
commit
2ea6fadcbd

+ 18 - 4
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadImages.java

@@ -11,6 +11,7 @@ import org.springframework.context.annotation.Profile;
 import org.springframework.stereotype.Component;
 import scot.carricksoftware.grants.commands.images.*;
 import scot.carricksoftware.grants.services.images.appendiximage.AppendixImageService;
+import scot.carricksoftware.grants.services.images.documentimage.DocumentImageService;
 import scot.carricksoftware.grants.services.images.image.ImageService;
 import scot.carricksoftware.grants.services.images.personimage.PersonImageService;
 import scot.carricksoftware.grants.services.images.placeimage.PlaceImageService;
@@ -28,6 +29,7 @@ public class DataLoadImages {
     private final PersonImageService personImageService;
     private final PlaceImageService placeImageService;
     private final AppendixImageService appendixImageService;
+    private final DocumentImageService documentImageService;
     private final PlaceService placeService;
 
 
@@ -36,11 +38,13 @@ public class DataLoadImages {
                           PersonImageService personImageService,
                           PlaceImageService placeImageService,
                           AppendixImageService appendixImageService,
+                          DocumentImageService documentImageService,
                           PlaceService placeService) {
         this.imageService = imageService;
         this.personImageService = personImageService;
         this.placeImageService = placeImageService;
         this.appendixImageService = appendixImageService;
+        this.documentImageService = documentImageService;
         this.placeService = placeService;
     }
 
@@ -50,6 +54,7 @@ public class DataLoadImages {
         loadPersonImage();
         loadPlaceImage();
         loadAppendixImage();
+        loadDocumentImage();
     }
 
     private void loadImage() {
@@ -81,11 +86,20 @@ public class DataLoadImages {
 
     private void loadAppendixImage() {
         logger.debug("DataLoadCensus::loadAppendixImage");
-        AppendixImageCommand appendixCommand = new AppendixImageCommandImpl();
-        appendixCommand.setImage(imageService.findById(1L));
-        appendixCommand.setCaption("Appendix caption");
+        AppendixImageCommand appendixImageCommand = new AppendixImageCommandImpl();
+        appendixImageCommand.setImage(imageService.findById(1L));
+        appendixImageCommand.setCaption("Appendix caption");
 
-        appendixImageService.saveAppendixImageCommand(appendixCommand);
+        appendixImageService.saveAppendixImageCommand(appendixImageCommand);
+    }
+
+    private void loadDocumentImage() {
+        logger.debug("DataLoadCensus::loadDocumentImage");
+        DocumentImageCommand documentImageCommand = new DocumentImageCommandImpl();
+        documentImageCommand.setImage(imageService.findById(1L));
+        documentImageCommand.setCaption("Document caption");
+
+        documentImageService.saveDocumentImageCommand(documentImageCommand);
     }
 
 

+ 2 - 0
src/main/java/scot/carricksoftware/grants/repositories/images/AppendixImageRepository.java

@@ -6,10 +6,12 @@
 package scot.carricksoftware.grants.repositories.images;
 
 import org.springframework.data.repository.PagingAndSortingRepository;
+import org.springframework.stereotype.Repository;
 import scot.carricksoftware.grants.domains.images.AppendixImage;
 
 import java.util.Optional;
 
+@Repository
 public interface AppendixImageRepository extends PagingAndSortingRepository<AppendixImage, Long> {
 
     AppendixImage save(AppendixImage image);

+ 26 - 0
src/main/java/scot/carricksoftware/grants/repositories/images/DocumentImageRepository.java

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 28/03/2025, 11:02. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.repositories.images;
+
+import org.springframework.data.repository.PagingAndSortingRepository;
+import org.springframework.stereotype.Repository;
+import scot.carricksoftware.grants.domains.images.DocumentImage;
+
+import java.util.Optional;
+
+@Repository
+public interface DocumentImageRepository extends PagingAndSortingRepository<DocumentImage, Long> {
+
+    DocumentImage save(DocumentImage image);
+
+    long count();
+
+    void deleteById(Long id);
+
+    Optional<DocumentImage> findById(Long id);
+
+    Iterable<DocumentImage> findAll();
+}

+ 40 - 0
src/main/java/scot/carricksoftware/grants/services/images/documentimage/DocumentImageService.java

@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 28/03/2025, 12:33. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.services.images.documentimage;
+
+import org.springframework.stereotype.Service;
+import scot.carricksoftware.grants.commands.images.DocumentImageCommand;
+import scot.carricksoftware.grants.domains.images.DocumentImage;
+
+import java.util.List;
+
+
+@SuppressWarnings("unused")
+@Service
+public interface DocumentImageService {
+
+    @SuppressWarnings("unused")
+    DocumentImage findById(Long id);
+
+    @SuppressWarnings({"unused", "UnusedReturnValue"})
+    DocumentImage save(DocumentImage documentImage);
+
+    @SuppressWarnings("unused")
+    void deleteById(Long id);
+
+    @SuppressWarnings("unused")
+    List<DocumentImage> getPagedDocumentImages(int pageNumber);
+
+    @SuppressWarnings("unused")
+    long count();
+
+
+    @SuppressWarnings({"unused", "UnusedReturnValue"})
+    DocumentImageCommand saveDocumentImageCommand(DocumentImageCommand DocumentImageCommand);
+
+    @SuppressWarnings("unused")
+    List<DocumentImage> findAll();
+}

+ 105 - 0
src/main/java/scot/carricksoftware/grants/services/images/documentimage/DocumentImageServiceImpl.java

@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 20:23. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.services.images.documentimage;
+
+import jakarta.transaction.Transactional;
+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 scot.carricksoftware.grants.commands.images.DocumentImageCommand;
+import scot.carricksoftware.grants.constants.ApplicationConstants;
+import scot.carricksoftware.grants.converters.images.documentimage.DocumentImageCommandConverterImpl;
+import scot.carricksoftware.grants.converters.images.documentimage.DocumentImageConverterImpl;
+import scot.carricksoftware.grants.domains.images.DocumentImage;
+import scot.carricksoftware.grants.repositories.images.DocumentImageRepository;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+@Service
+public class DocumentImageServiceImpl implements DocumentImageService {
+    private static final Logger logger = LogManager.getLogger(DocumentImageServiceImpl.class);
+
+    @SuppressWarnings({"unused"})
+    private final DocumentImageRepository documentImageRepository;
+    private final DocumentImageConverterImpl documentImageConverterImpl;
+    private final DocumentImageCommandConverterImpl documentImageCommandConverterImpl;
+
+    public DocumentImageServiceImpl(
+            DocumentImageRepository documentImageRepository,
+            DocumentImageConverterImpl documentImageConverterImpl,
+            DocumentImageCommandConverterImpl documentImageCommandConverterImpl) {
+
+        this.documentImageRepository = documentImageRepository;
+        this.documentImageConverterImpl = documentImageConverterImpl;
+        this.documentImageCommandConverterImpl = documentImageCommandConverterImpl;
+    }
+
+
+    @Override
+    public DocumentImage findById(Long id) {
+        logger.debug("DocumentImageServiceImpl::findById");
+        Optional<DocumentImage> documentImageOptional = documentImageRepository.findById(id);
+        return documentImageOptional.orElse(null);
+    }
+
+    @Override
+    public DocumentImage save(DocumentImage documentImage) {
+        logger.debug("DocumentImageServiceImpl::save");
+        return documentImageRepository.save(documentImage);
+    }
+
+    @Override
+    public void deleteById(Long id) {
+        logger.debug("DocumentImageServiceImpl::deleteBy");
+        documentImageRepository.deleteById(id);
+    }
+    
+    
+    @Override
+    public List<DocumentImage> getPagedDocumentImages(int pageNumber) {
+        logger.debug("DocumentImageServiceImpl::getPagedCountries");
+        Pageable paging = PageRequest.of(pageNumber, ApplicationConstants.DEFAULT_PAGE_SIZE, getSort());
+        Page<DocumentImage> pagedResult = documentImageRepository.findAll(paging);
+        return pagedResult.getContent();
+    }
+
+    private Sort getSort() {
+        return Sort.by(Sort.Direction.ASC, "id");
+    }
+
+    @Override
+    public long count() {
+        logger.debug("DocumentImageServiceImpl::count");
+        return documentImageRepository.count();
+    }
+
+    @Transactional
+    @Override
+    public DocumentImageCommand saveDocumentImageCommand(DocumentImageCommand documentImageCommand) {
+        logger.debug("DocumentImageServiceImpl::saveDocumentImageCommand");
+        DocumentImage documentImage = documentImageCommandConverterImpl.convert(documentImageCommand);
+        DocumentImage savedDocumentImage = documentImageRepository.save(documentImage);
+        return documentImageConverterImpl.convert(savedDocumentImage);
+
+    }
+
+    @Override
+    public List<DocumentImage> findAll() {
+        logger.debug("DocumentImageServiceImpl::findAll");
+        List<DocumentImage> result = new ArrayList<>();
+        Iterable<DocumentImage> documentImageIterable = documentImageRepository.findAll();
+        documentImageIterable.forEach(result::add);
+        return result;
+    }
+
+}

+ 5 - 0
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadImagesImageAppendixTest.java

@@ -14,6 +14,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grants.commands.images.AppendixImageCommand;
 import scot.carricksoftware.grants.domains.images.Image;
 import scot.carricksoftware.grants.services.images.appendiximage.AppendixImageService;
+import scot.carricksoftware.grants.services.images.documentimage.DocumentImageService;
 import scot.carricksoftware.grants.services.images.image.ImageService;
 import scot.carricksoftware.grants.services.images.personimage.PersonImageService;
 import scot.carricksoftware.grants.services.images.placeimage.PlaceImageService;
@@ -40,6 +41,9 @@ class DataLoadImagesImageAppendixTest {
     @Mock
     private AppendixImageService appendixImageServiceMock;
 
+    @Mock
+    private DocumentImageService documentImageServiceMock;
+
     @Mock
     private PlaceService placeServiceMock;
 
@@ -50,6 +54,7 @@ class DataLoadImagesImageAppendixTest {
                 personImageServiceMock,
                 placeImageServiceMock,
                 appendixImageServiceMock,
+                documentImageServiceMock,
                 placeServiceMock);
     }
 

+ 5 - 0
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadImagesImagePeopleAndPlacesTest.java

@@ -16,6 +16,7 @@ import scot.carricksoftware.grants.commands.images.PlaceImageCommand;
 import scot.carricksoftware.grants.domains.images.Image;
 import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.services.images.appendiximage.AppendixImageService;
+import scot.carricksoftware.grants.services.images.documentimage.DocumentImageService;
 import scot.carricksoftware.grants.services.images.image.ImageService;
 import scot.carricksoftware.grants.services.images.personimage.PersonImageService;
 import scot.carricksoftware.grants.services.images.placeimage.PlaceImageService;
@@ -43,6 +44,9 @@ class DataLoadImagesImagePeopleAndPlacesTest {
     @Mock
     private AppendixImageService appendixImageServiceMock;
 
+    @Mock
+    private DocumentImageService documentImageServiceMock;
+
     @Mock
     private PlaceService placeServiceMock;
 
@@ -53,6 +57,7 @@ class DataLoadImagesImagePeopleAndPlacesTest {
                 personImageServiceMock,
                 placeImageServiceMock,
                 appendixImageServiceMock,
+                documentImageServiceMock,
                 placeServiceMock);
     }
 

+ 5 - 0
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadImagesImageTest.java

@@ -13,6 +13,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 import scot.carricksoftware.grants.commands.images.ImageCommand;
 import scot.carricksoftware.grants.services.images.appendiximage.AppendixImageService;
+import scot.carricksoftware.grants.services.images.documentimage.DocumentImageService;
 import scot.carricksoftware.grants.services.images.image.ImageService;
 import scot.carricksoftware.grants.services.images.personimage.PersonImageService;
 import scot.carricksoftware.grants.services.images.placeimage.PlaceImageService;
@@ -38,6 +39,9 @@ class DataLoadImagesImageTest {
     @Mock
     private AppendixImageService appendixImageServiceMock;
 
+    @Mock
+    private DocumentImageService documentImageServiceMock;
+
     @Mock
     private PlaceService placeServiceMock;
 
@@ -47,6 +51,7 @@ class DataLoadImagesImageTest {
                 personImageServiceMock,
                 placeImageServiceMock,
                 appendixImageServiceMock,
+                documentImageServiceMock,
                 placeServiceMock);
     }