Class ImageService

java.lang.Object
NTNU.IDATT1002.service.ImageService
All Implemented Interfaces:
PageableService<Image>

public class ImageService
extends java.lang.Object
implements PageableService<Image>
Image service
Version:
1.0 22.03.2020
Author:
Stian Mogen, Eirik Steira, madslun
  • Constructor Summary

    Constructors 
    Constructor Description
    ImageService​(javax.persistence.EntityManager entityManager)
    Inject entity manager instance to the repositories.
  • Method Summary

    Modifier and Type Method Description
    java.util.Optional<Image> createImage​(User user, java.io.File file, java.util.List<Tag> tags, java.lang.String title)
    Creates a new image from the input File Sets metadata to image by using MetaDataExtractor Sets a blob of image by using ImageUtil Finally sets user, path, title and tags to image
    Page<Image> findAll​(PageRequest pageRequest)
    Retrieve paginated results specified by given PageRequest.
    java.util.Optional<Image> findById​(java.lang.Long id)
    Retrieves a image with given id
    java.util.List<Image> getAllImages()
    Retrieves all images.
    java.util.List<Image> getImageFromUser​(User user)
    Finds each picture belonging to a specific user.
    java.util.List<Image> searchResult​(java.lang.String query)
    Searches images by tags and username, and merges the two list into one with all images uses removeDuplicates list to return a list with no duplicate images

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ImageService

      public ImageService​(javax.persistence.EntityManager entityManager)
      Inject entity manager instance to the repositories.
  • Method Details

    • findAll

      public Page<Image> findAll​(PageRequest pageRequest)
      Retrieve paginated results specified by given PageRequest.
      Specified by:
      findAll in interface PageableService<Image>
      Parameters:
      pageRequest - the PageRequest defining page number and size
      Returns:
      the page containing results found based on the PageRequest
    • createImage

      public java.util.Optional<Image> createImage​(User user, java.io.File file, java.util.List<Tag> tags, java.lang.String title)
      Creates a new image from the input File Sets metadata to image by using MetaDataExtractor Sets a blob of image by using ImageUtil Finally sets user, path, title and tags to image
      Parameters:
      user - the user of the image
      file - the file uploaded
      Returns:
      Optional containing the saved image
    • getImageFromUser

      public java.util.List<Image> getImageFromUser​(User user)
      Finds each picture belonging to a specific user.
      Parameters:
      user - the user who uploaded the images
      Returns:
      a list with all pictures from a user
    • getAllImages

      public java.util.List<Image> getAllImages()
      Retrieves all images.
      Returns:
      list of all images.
    • findById

      public java.util.Optional<Image> findById​(java.lang.Long id)
      Retrieves a image with given id
      Parameters:
      id - that will searched for
      Returns:
      Optional with image if found, empty else wise
    • searchResult

      public java.util.List<Image> searchResult​(java.lang.String query)
      Searches images by tags and username, and merges the two list into one with all images uses removeDuplicates list to return a list with no duplicate images
      Parameters:
      query -
      Returns:
      a list with no duplicate images