Class AlbumService

java.lang.Object
NTNU.IDATT1002.service.AlbumService
All Implemented Interfaces:
PageableService<Album>

public class AlbumService
extends java.lang.Object
implements PageableService<Album>
Album Service. Supports common domain specific operations such as creating and retrieving albums.
Version:
1.1 01.04.20
  • Constructor Summary

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

    Modifier and Type Method Description
    java.util.Optional<Album> addImage​(Album album, Image image)
    Add given image to given album.
    java.util.Optional<Album> createAlbum​(java.lang.String title, java.lang.String description, User user, java.util.List<Tag> tags, java.util.List<Image> images)
    Create a new album with all fields populated.
    java.util.Optional<Album> createEmptyAlbum​(java.lang.String title, java.lang.String description, User user, java.util.List<Tag> tags)
    Retrieves all albums created by the given user by username.
    Page<Album> findAll​(PageRequest pageRequest)
    Retrieve paginated results specified by given PageRequest.
    java.util.Optional<Image> findPreviewImage​(Album album)
    Find a single image as an album preview.
    java.util.Optional<Album> getAlbumById​(java.lang.Long albumId)  
    java.util.List<Album> getAlbumsByUser​(java.lang.String user)
    Takes in a string and searched through all albums username.
    java.util.List<Album> getAllAlbums()
    Retrieves all albums.
    AlbumDocument getDocument​(java.lang.Long albumId)
    Create and return a new document for the album with the given id.
    java.util.List<Album> removeDuplicates​(java.util.List<Album> albums)
    Removes all duplicate elements in given list.
    java.util.List<Album> searchResult​(java.lang.String query)
    Takes in a string and searched through all album by tags, username and title to find results.

    Methods inherited from class java.lang.Object

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

    • AlbumService

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

    • findAll

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

      public java.util.Optional<Album> getAlbumById​(java.lang.Long albumId)
    • getAllAlbums

      public java.util.List<Album> getAllAlbums()
      Retrieves all albums.
      Returns:
      list of all albums.
    • getAlbumsByUser

      public java.util.List<Album> getAlbumsByUser​(java.lang.String user)
      Takes in a string and searched through all albums username.
      Parameters:
      user - the query string
      Returns:
      list of results
    • createAlbum

      public java.util.Optional<Album> createAlbum​(java.lang.String title, java.lang.String description, User user, java.util.List<Tag> tags, java.util.List<Image> images)
      Create a new album with all fields populated.
      Parameters:
      title - the title of the album
      description - the description of the album
      user - the user of the album
      tags - the tags of the album
      images - the images of the album
      Returns:
      Optional containing the saved album
    • addImage

      public java.util.Optional<Album> addImage​(Album album, Image image)
      Add given image to given album.
      Parameters:
      album - the album to add the image to
      image - the image to add
      Returns:
      the updated album
    • findPreviewImage

      public java.util.Optional<Image> findPreviewImage​(Album album)
      Find a single image as an album preview.
      Parameters:
      album - the album to get a preview from
      Returns:
      An optional image if found
    • createEmptyAlbum

      public java.util.Optional<Album> createEmptyAlbum​(java.lang.String title, java.lang.String description, User user, java.util.List<Tag> tags)
      Retrieves all albums created by the given user by username.
      Parameters:
      title - the title of the album
      description - the description of the album
      user - the user of the album
      tags - the tags of the album
    • getDocument

      public AlbumDocument getDocument​(java.lang.Long albumId)
      Create and return a new document for the album with the given id. The document is saved to the users dowloads folder.
      Parameters:
      albumId - the album id to get a document for
      Returns:
      the document created
    • searchResult

      public java.util.List<Album> searchResult​(java.lang.String query)
      Takes in a string and searched through all album by tags, username and title to find results.
      Parameters:
      query - the query string
      Returns:
      list of results without duplocates
    • removeDuplicates

      public java.util.List<Album> removeDuplicates​(java.util.List<Album> albums)
      Removes all duplicate elements in given list.
      Parameters:
      albums - the list of albums to remove duplicates
      Returns:
      list without duplicates