diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index 9bd9880f7..f5c7b22ff 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -46,7 +46,6 @@ import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; import com.omertron.themoviedbapi.wrapper.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; import com.omertron.themoviedbapi.wrapper.WrapperReleaseInfo; import com.omertron.themoviedbapi.wrapper.WrapperTranslations; @@ -80,7 +79,8 @@ public class TmdbMovies extends AbstractMethod { * * It will return the single highest rated poster and backdrop. * - * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found. + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies + * found. * * @param movieId * @param language @@ -112,7 +112,8 @@ public class TmdbMovies extends AbstractMethod { * * It will return the single highest rated poster and backdrop. * - * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found. + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies + * found. * * @param imdbId * @param language @@ -141,8 +142,8 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method lets a user get the status of whether or not the movie has been rated or added to their favourite or movie watch - * list. + * This method lets a user get the status of whether or not the movie has + * been rated or added to their favourite or movie watch list. * * A valid session id is required. * @@ -167,7 +168,8 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the alternative titles we have for a particular movie. + * This method is used to retrieve all of the alternative titles we have for + * a particular movie. * * @param movieId * @param country @@ -216,7 +218,8 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method should be used when you’re wanting to retrieve all of the images for a particular movie. + * This method should be used when you’re wanting to retrieve all of the + * images for a particular movie. * * @param movieId * @param language @@ -244,7 +247,8 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the keywords that have been added to a particular movie. + * This method is used to retrieve all of the keywords that have been added + * to a particular movie. * * Currently, only English keywords exist. * @@ -272,7 +276,8 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the release and certification data we have for a specific movie. + * This method is used to retrieve all of the release and certification data + * we have for a specific movie. * * @param movieId * @param language @@ -300,7 +305,8 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve all of the trailers for a particular movie. + * This method is used to retrieve all of the trailers for a particular + * movie. * * Supported sites are YouTube and QuickTime. * @@ -330,7 +336,8 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method is used to retrieve a list of the available translations for a specific movie. + * This method is used to retrieve a list of the available translations for + * a specific movie. * * @param movieId * @param appendToResponse @@ -356,9 +363,11 @@ public class TmdbMovies extends AbstractMethod { } /** - * The similar movies method will let you retrieve the similar movies for a particular movie. + * The similar movies method will let you retrieve the similar movies for a + * particular movie. * - * This data is created dynamically but with the help of users votes on TMDb. + * This data is created dynamically but with the help of users votes on + * TMDb. * * The data is much better with movies that have more keywords * @@ -377,16 +386,8 @@ public class TmdbMovies extends AbstractMethod { parameters.add(Param.APPEND, appendToResponse); URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.SIMILAR_MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get similar movies", url, ex); - } + WrapperGenericList wrapper = processWrapper(getTypeReference(MovieDb.class), url, "similar movies"); + return wrapper.getTmdbResultsList(); } /** @@ -445,7 +446,8 @@ public class TmdbMovies extends AbstractMethod { * * By default, only the last 24 hours of changes are returned. * - * The maximum number of days that can be returned in a single request is 14. + * The maximum number of days that can be returned in a single request is + * 14. * * The language is present on fields that are translatable. * @@ -542,23 +544,15 @@ public class TmdbMovies extends AbstractMethod { parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.UPCOMING).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get upcoming movies", url, ex); - } - + WrapperGenericList wrapper = processWrapper(getTypeReference(MovieDb.class), url, "upcoming movies"); + return wrapper.getTmdbResultsList(); } /** * This method is used to retrieve the movies currently in theatres. * - * This is a curated list that will normally contain 100 movies. The default response will return 20 movies. + * This is a curated list that will normally contain 100 movies. The default + * response will return 20 movies. * * @param language * @param page @@ -571,16 +565,8 @@ public class TmdbMovies extends AbstractMethod { parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.NOW_PLAYING).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get now playing movies", url, ex); - } + WrapperGenericList wrapper = processWrapper(getTypeReference(MovieDb.class), url, "now playing movies"); + return wrapper.getTmdbResultsList(); } /** @@ -599,20 +585,13 @@ public class TmdbMovies extends AbstractMethod { parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.POPULAR).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get popular movie list", url, ex); - } + WrapperGenericList wrapper = processWrapper(getTypeReference(MovieDb.class), url, "popular movie list"); + return wrapper.getTmdbResultsList(); } /** - * This method is used to retrieve the top rated movies that have over 10 votes on TMDb. + * This method is used to retrieve the top rated movies that have over 10 + * votes on TMDb. * * The default response will return 20 movies. * @@ -627,16 +606,8 @@ public class TmdbMovies extends AbstractMethod { parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.TOP_RATED).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get top rated movies", url, ex); - } + WrapperGenericList wrapper = processWrapper(getTypeReference(MovieDb.class), url, "top rated movies"); + return wrapper.getTmdbResultsList(); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/movie/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/movie/MovieDb.java index 55013a9d7..a194c681a 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/movie/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/movie/MovieDb.java @@ -20,6 +20,7 @@ package com.omertron.themoviedbapi.model.movie; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; import com.omertron.themoviedbapi.model.AbstractJsonMapping; import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model.Language; @@ -32,13 +33,12 @@ import com.omertron.themoviedbapi.model.media.MediaCreditCrew; import com.omertron.themoviedbapi.model.media.MediaCreditList; import com.omertron.themoviedbapi.model.review.Review; import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; +import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; import com.omertron.themoviedbapi.wrapper.WrapperReleaseInfo; import com.omertron.themoviedbapi.wrapper.WrapperReviews; import com.omertron.themoviedbapi.wrapper.WrapperTranslations; -import com.omertron.themoviedbapi.wrapper.WrapperUserList; import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.util.List; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -117,12 +117,10 @@ public class MovieDb extends AbstractJsonMapping { private WrapperVideos trailers; @JsonProperty("translations") private WrapperTranslations translations; - @JsonProperty("similar_movies") - private WrapperMovie similarMovies; + private List similarMovies; @JsonProperty("reviews") private WrapperReviews reviews; - @JsonProperty("lists") - private WrapperUserList lists; + private List lists; @JsonProperty("video") private Boolean video = null; @@ -372,11 +370,11 @@ public class MovieDb extends AbstractJsonMapping { } public List getSimilarMovies() { - return similarMovies.getMovies(); + return similarMovies; } public List getLists() { - return lists.getUserList(); + return lists; } public List getReviews() { @@ -413,12 +411,14 @@ public class MovieDb extends AbstractJsonMapping { this.translations = translations; } - public void setSimilarMovies(WrapperMovie similarMovies) { - this.similarMovies = similarMovies; + @JsonSetter("similar_movies") + public void setSimilarMovies(WrapperGenericList similarMovies) { + this.similarMovies = similarMovies.getResults(); } - public void setLists(WrapperUserList lists) { - this.lists = lists; + @JsonSetter("lists") + public void setLists(WrapperGenericList lists) { + this.lists = lists.getResults(); } public void setReviews(WrapperReviews reviews) { diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java deleted file mode 100644 index 2940dd261..000000000 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2004-2015 Stuart Boston - * - * This file is part of TheMovieDB API. - * - * TheMovieDB API is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * TheMovieDB API is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with TheMovieDB API. If not, see . - * - */ -package com.omertron.themoviedbapi.wrapper; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.collection.Collection; -import java.util.List; - -/** - * - * @author stuart.boston - */ -public class WrapperCollection extends AbstractWrapperAll { - - @JsonProperty("results") - private List results; - - public List getResults() { - return results; - } - - public void setResults(List results) { - this.results = results; - } -} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java deleted file mode 100644 index 78d24353f..000000000 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2004-2015 Stuart Boston - * - * This file is part of TheMovieDB API. - * - * TheMovieDB API is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * TheMovieDB API is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with TheMovieDB API. If not, see . - * - */ -package com.omertron.themoviedbapi.wrapper; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.company.Company; -import java.util.List; - -/** - * - * @author stuart.boston - */ -public class WrapperCompany extends AbstractWrapperAll { - - @JsonProperty("results") - private List results; - - public List getResults() { - return results; - } - - public void setResults(List results) { - this.results = results; - } -} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java deleted file mode 100644 index 13657fee6..000000000 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2004-2015 Stuart Boston - * - * This file is part of TheMovieDB API. - * - * TheMovieDB API is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * TheMovieDB API is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with TheMovieDB API. If not, see . - * - */ -package com.omertron.themoviedbapi.wrapper; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.movie.MovieBasic; -import java.util.List; - -/** - * - * @author stuart.boston - */ -public class WrapperCompanyMovies extends AbstractWrapperAll { - - @JsonProperty("results") - private List results; - - public List getResults() { - return results; - } - - public void setResults(List results) { - this.results = results; - } -} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java index be3aec7bb..c56255bd6 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java @@ -21,6 +21,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.results.TmdbResultsList; import java.io.Serializable; import java.util.List; @@ -43,4 +44,10 @@ public class WrapperGenericList extends AbstractWrapperAll implements Seriali public void setResults(List results) { this.results = results; } + + public TmdbResultsList getTmdbResultsList() { + TmdbResultsList resultsList = new TmdbResultsList(results); + resultsList.copyWrapper(this); + return resultsList; + } } diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java deleted file mode 100644 index 7b6bc4547..000000000 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2004-2015 Stuart Boston - * - * This file is part of TheMovieDB API. - * - * TheMovieDB API is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * TheMovieDB API is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with TheMovieDB API. If not, see . - * - */ -package com.omertron.themoviedbapi.wrapper; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.keyword.Keyword; -import java.util.List; - -/** - * - * @author stuart.boston - */ -public class WrapperKeywords extends AbstractWrapperAll { - - @JsonProperty("results") - private List results; - - public List getResults() { - return results; - } - - public void setResults(List results) { - this.results = results; - } -} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovie.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovie.java deleted file mode 100644 index 3a1462f67..000000000 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovie.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2004-2015 Stuart Boston - * - * This file is part of TheMovieDB API. - * - * TheMovieDB API is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * TheMovieDB API is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with TheMovieDB API. If not, see . - * - */ -package com.omertron.themoviedbapi.wrapper; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.movie.MovieDb; -import java.io.Serializable; -import java.util.List; - -/** - * - * @author stuart.boston - */ -public class WrapperMovie extends AbstractWrapperAll implements Serializable { - - private static final long serialVersionUID = 1L; - @JsonProperty("results") - private List movies; - - public List getMovies() { - return movies; - } - - public void setMovies(List movies) { - this.movies = movies; - } -} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperUserList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperUserList.java deleted file mode 100644 index fb81bf342..000000000 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperUserList.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2004-2015 Stuart Boston - * - * This file is part of TheMovieDB API. - * - * TheMovieDB API is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * TheMovieDB API is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with TheMovieDB API. If not, see . - * - */ -package com.omertron.themoviedbapi.wrapper; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.list.UserList; -import java.io.Serializable; -import java.util.List; - -/** - * - * @author Stuart - */ -public class WrapperUserList extends AbstractWrapperAll implements Serializable { - - private static final long serialVersionUID = 1L; - @JsonProperty("results") - private List userList; - - public List getUserList() { - return userList; - } - - public void setUserList(List userList) { - this.userList = userList; - } -}