Package NTNU.IDATT1002.service
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 givenPageRequest
.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.
-
Constructor Details
-
AlbumService
public AlbumService(javax.persistence.EntityManager entityManager)Inject entity manager instance to the repositories.
-
-
Method Details
-
findAll
Retrieve paginated results specified by givenPageRequest
.- Specified by:
findAll
in interfacePageableService<Album>
- Parameters:
pageRequest
- thePageRequest
defining page number and size- Returns:
- the page containing results found based on the
PageRequest
-
getAlbumById
-
getAllAlbums
Retrieves all albums.- Returns:
- list of all albums.
-
getAlbumsByUser
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 albumdescription
- the description of the albumuser
- the user of the albumtags
- the tags of the albumimages
- the images of the album- Returns:
- Optional containing the saved album
-
addImage
Add given image to given album.- Parameters:
album
- the album to add the image toimage
- the image to add- Returns:
- the updated album
-
findPreviewImage
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 albumdescription
- the description of the albumuser
- the user of the albumtags
- the tags of the album
-
getDocument
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
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
Removes all duplicate elements in given list.- Parameters:
albums
- the list of albums to remove duplicates- Returns:
- list without duplicates
-