Package com.espacogeek.geek.utils
Class MediaUtils
java.lang.Object
com.espacogeek.geek.utils.MediaUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.data.domain.PageablegetPageable(graphql.schema.DataFetchingEnvironment dataFetchingEnvironment) Returns a Pageable object based on the "page" and "size" arguments of the given DataFetchingEnvironment.getRequestedFields(graphql.schema.DataFetchingEnvironment environment) Returns a map of requested fields where the key is the field name and the value is a list of its subfields.static List<MediaModel> updateGenericMedia(List<MediaModel> medias, MediaDataController mediaDataController, TypeReferenceModel typeReference, MediaApi mediaApi) Updates all medias in the list when the last time update is more than one day ago.static List<MediaModel> updateMedia(List<MediaModel> medias, MediaDataController mediaDataController) Updates all medias in the list when the last time update is more than one day ago.static BooleanChecks if the media needs an update by determining if the last update was more than one day ago.
-
Constructor Details
-
MediaUtils
public MediaUtils()
-
-
Method Details
-
updateMediaWhenLastTimeUpdateMoreThanOneDay
Checks if the media needs an update by determining if the last update was more than one day ago.- Parameters:
media- the media object to check- Returns:
trueif the media should be updated (i.e., the last update was more than one day ago or if the update date is null),falseotherwise
-
updateGenericMedia
public static List<MediaModel> updateGenericMedia(List<MediaModel> medias, MediaDataController mediaDataController, TypeReferenceModel typeReference, MediaApi mediaApi) Updates all medias in the list when the last time update is more than one day ago. Use the givenmediaDataControllerto update the media.- Parameters:
medias- the list of medias to updatemediaDataController- the controller to update the mediatypeReference- reference source of information to the Media.mediaApi- implementation of MediaAPI.- Returns:
- the list of updated medias
-
updateMedia
public static List<MediaModel> updateMedia(List<MediaModel> medias, MediaDataController mediaDataController) Updates all medias in the list when the last time update is more than one day ago.- Parameters:
medias- the list of medias to updatemediaDataController- the controller to update the media- Returns:
- the list of updated medias
-
getRequestedFields
public static Map<String,List<String>> getRequestedFields(graphql.schema.DataFetchingEnvironment environment) Returns a map of requested fields where the key is the field name and the value is a list of its subfields.This is useful to select only the fields that are requested by the client, which can be used to reduce the amount of data that needs to be retrieved from the database.
For example, if the client requests the following fields:
{ media { id title genres { name } } }This method will return a map like this:{ "media": [ "id", "title", "genres" ], "genres": [ "name" ] }This can be used to create a JPA query that only selects the requested fields, which can improve performance.
- Parameters:
environment- theDataFetchingEnvironmentthat contains information about the fields that were requested by the client- Returns:
- a map of requested fields
-
getPageable
public static org.springframework.data.domain.Pageable getPageable(graphql.schema.DataFetchingEnvironment dataFetchingEnvironment) Returns a Pageable object based on the "page" and "size" arguments of the given DataFetchingEnvironment.If the "page" argument is not provided, it defaults to 0. If the "size" argument is not provided, it defaults to 10.
The returned Pageable object can be used to construct a JPA query that will return the requested page of data.
- Parameters:
dataFetchingEnvironment- the DataFetchingEnvironment that contains the "page" and "size" arguments- Returns:
- a Pageable object
-