Package NTNU.IDATT1002.service
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 usingMetaDataExtractor
Sets a blob of image by usingImageUtil
Finally sets user, path, title and tags to imagePage<Image>
findAll(PageRequest pageRequest)
Retrieve paginated results specified by givenPageRequest
.java.util.Optional<Image>
findById(java.lang.Long id)
Retrieves a image with given idjava.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
-
Constructor Details
-
ImageService
public ImageService(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<Image>
- Parameters:
pageRequest
- thePageRequest
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 usingMetaDataExtractor
Sets a blob of image by usingImageUtil
Finally sets user, path, title and tags to image- Parameters:
user
- the user of the imagefile
- the file uploaded- Returns:
- Optional containing the saved image
-
getImageFromUser
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
Retrieves all images.- Returns:
- list of all images.
-
findById
Retrieves a image with given id- Parameters:
id
- that will searched for- Returns:
- Optional with image if found, empty else wise
-
searchResult
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
-