From 46a50703d70d5f2b459b9839237dd1c7931992ab Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sun, 1 Mar 2015 19:25:47 +0000 Subject: [PATCH] People (partial) --- .../omertron/themoviedbapi/TheMovieDbApi.java | 74 +------ .../enumeration/ArtworkType.java | 39 +++- .../themoviedbapi/enumeration/CreditType.java | 30 +++ .../themoviedbapi/enumeration/MediaType.java | 27 ++- .../themoviedbapi/methods/AbstractMethod.java | 2 +- .../methods/TmdbCollections.java | 2 +- .../themoviedbapi/methods/TmdbMovies.java | 2 +- .../themoviedbapi/methods/TmdbPeople.java | 110 ++++++++--- .../themoviedbapi/methods/TmdbSearch.java | 5 + .../themoviedbapi/methods/_Method_List.txt | 2 +- .../omertron/themoviedbapi/model/MovieDb.java | 1 + .../themoviedbapi/model/person/Person.java | 7 +- .../{model => model2/artwork}/Artwork.java | 84 ++++---- .../model2/artwork/ArtworkMedia.java | 74 +++++++ .../model2/person/CreditBasic.java | 126 ++++++++++++ .../model2/person/CreditMovieBasic.java | 77 ++++++++ .../model2/person/CreditTVBasic.java | 77 ++++++++ .../model2/person/ExternalID.java | 82 ++++++++ .../themoviedbapi/model2/person/Person.java | 133 +++++++++++++ .../model2/person/PersonCredits.java | 63 ++++++ .../model2/tv/TVEpisodeBasic.java | 14 +- .../themoviedbapi/tools/MethodSub.java | 2 + .../themoviedbapi/tools/TmdbParameters.java | 4 +- .../themoviedbapi/wrapper/WrapperImages.java | 4 +- .../methods/TmdbCollectionsTest.java | 2 +- .../themoviedbapi/methods/TmdbMoviesTest.java | 2 +- .../themoviedbapi/methods/TmdbPeopleTest.java | 184 +++++++++++++++--- 27 files changed, 1048 insertions(+), 181 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java rename src/main/java/com/omertron/themoviedbapi/{model => model2/artwork}/Artwork.java (94%) create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/Person.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 666148b9f..0ae73f0a3 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -41,7 +41,7 @@ import com.omertron.themoviedbapi.methods.TmdbSearch; import com.omertron.themoviedbapi.methods.TmdbTV; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model.Certification; import com.omertron.themoviedbapi.model.change.ChangedMedia; import com.omertron.themoviedbapi.model2.collection.Collection; @@ -57,7 +57,6 @@ import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model2.list.ListItem; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.person.Person; -import com.omertron.themoviedbapi.model.person.PersonCredit; import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.StatusCode; @@ -1155,79 +1154,10 @@ public class TheMovieDbApi { // // - /** - * This method is used to retrieve all of the basic person information. - * - * It will return the single highest rated profile image. - * - * @param personId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public Person getPersonInfo(int personId, String... appendToResponse) throws MovieDbException { - return tmdbPeople.getPersonInfo(personId, appendToResponse); - } - /** - * This method is used to retrieve all of the cast & crew information for the person. - * - * It will return the single highest rated poster for each movie record. - * - * @param personId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonCredits(int personId, String... appendToResponse) throws MovieDbException { - return tmdbPeople.getPersonCredits(personId, appendToResponse); - } + null; - /** - * This method is used to retrieve all of the profile images for a person. - * - * @param personId - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonImages(int personId) throws MovieDbException { - return tmdbPeople.getPersonImages(personId); - } - /** - * Get the list of popular people on The Movie Database. - * - * This list refreshes every day. - * - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonPopular() throws MovieDbException { - return tmdbPeople.getPersonPopular(0); - } - - /** - * Get the list of popular people on The Movie Database. - * - * This list refreshes every day. - * - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonPopular(int page) throws MovieDbException { - return tmdbPeople.getPersonPopular(page); - } - - /** - * Get the latest person id. - * - * @return - * @throws MovieDbException - */ - public Person getPersonLatest() throws MovieDbException { - return tmdbPeople.getPersonLatest(); - } // // diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java index 373dd9886..3ade5fcb8 100644 --- a/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java @@ -19,15 +19,46 @@ */ package com.omertron.themoviedbapi.enumeration; +import org.apache.commons.lang3.StringUtils; + /** * ArtworkType enum List of the artwork types that are available */ public enum ArtworkType { - // Poster artwork + /** + * Poster artwork + */ POSTER, - // Fanart/backdrop + /** + * Fanart/backdrop + */ BACKDROP, - // Person image - PROFILE + /** + * Person image + */ + PROFILE, + /** + * Still (Video image) + */ + STILL; + + /** + * Convert a string into an Enum type + * + * @param artworkType + * @return + * @throws IllegalArgumentException If type is not recognised + * + */ + public static ArtworkType fromString(String artworkType) { + if (StringUtils.isNotBlank(artworkType)) { + try { + return ArtworkType.valueOf(artworkType.trim().toUpperCase()); + } catch (IllegalArgumentException ex) { + throw new IllegalArgumentException("ArtworkType " + artworkType + " does not exist.", ex); + } + } + throw new IllegalArgumentException("ArtworkType must not be null"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java new file mode 100644 index 000000000..72ffd3b31 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java @@ -0,0 +1,30 @@ +/* + * 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.enumeration; + +/** + * + * @author Stuart + */ +public enum CreditType { + + CAST, + CREW; +} diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java index 015ec5e2b..839a41ed6 100644 --- a/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java @@ -19,6 +19,8 @@ */ package com.omertron.themoviedbapi.enumeration; +import org.apache.commons.lang3.StringUtils; + /** * Media type options * @@ -33,5 +35,28 @@ public enum MediaType { /** * TV Show media type */ - TV; + TV, + /** + * TV Episode media type + */ + EPISODE; + + /** + * Convert a string into an Enum type + * + * @param mediaType + * @return + * @throws IllegalArgumentException If type is not recognised + * + */ + public static MediaType fromString(String mediaType) { + if (StringUtils.isNotBlank(mediaType)) { + try { + return MediaType.valueOf(mediaType.trim().toUpperCase()); + } catch (IllegalArgumentException ex) { + throw new IllegalArgumentException("MediaType " + mediaType + " does not exist.", ex); + } + } + throw new IllegalArgumentException("MediaType must not be null"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index f94fe5c83..71d25bdaf 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -53,7 +53,7 @@ public class AbstractMethod { protected static final TypeReference> TR_TV_BASIC = getTypeReference(TVBasic.class); protected static final TypeReference> TR_USER_LIST = getTypeReference(UserList.class); - protected static TypeReference getTypeReference(T Class) { + private static TypeReference getTypeReference(T Class) { return new TypeReference>() { }; } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java index 49c1cafaf..baac02a1f 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.results.TmdbResultsList; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index 19333b55f..b17fbb1f6 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index b0ca3158a..c0b46b2e2 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -19,12 +19,16 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; -import static com.omertron.themoviedbapi.methods.AbstractMethod.getTypeReference; -import com.omertron.themoviedbapi.model.person.Person; -import com.omertron.themoviedbapi.model.person.PersonCredit; +import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; +import com.omertron.themoviedbapi.model2.person.CreditTVBasic; +import com.omertron.themoviedbapi.model2.person.ExternalID; +import com.omertron.themoviedbapi.model2.person.Person; +import com.omertron.themoviedbapi.model2.person.PersonCredits; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -88,17 +92,21 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonMovieCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + public PersonCredits getPersonMovieCredits(int personId, String language, String... appendToResponse) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, personId); parameters.add(Param.LANGUAGE, language); parameters.add(Param.APPEND, appendToResponse); + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.MOVIE_CREDITS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); - WrapperGenericList wrapper = processWrapper(getTypeReference(PersonCredit.class), url, "person movie credits"); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; + try { + return MAPPER.readValue(webpage, new TypeReference>() { + }); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -114,8 +122,21 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonTVCredits(int personId, String language, String... appendToResponse) throws MovieDbException { - return null; + public PersonCredits getPersonTVCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.TV_CREDITS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, new TypeReference>() { + }); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -131,8 +152,21 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonCombinedCredits(int personId, String language, String... appendToResponse) throws MovieDbException { - return null; + public PersonCredits getPersonCombinedCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.COMBINED_CREDITS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, new TypeReference>() { + }); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -142,8 +176,18 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonExternalIds(int personId) throws MovieDbException { - return null; + public ExternalID getPersonExternalIds(int personId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.EXTERNAL_IDS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, ExternalID.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -179,9 +223,28 @@ public class TmdbPeople extends AbstractMethod { * @param page * @param language * @return + * @throws com.omertron.themoviedbapi.MovieDbException */ - public TmdbResultsList getPersonTaggedImages(int personId, Integer page, String language) { - return null; + public TmdbResultsList getPersonTaggedImages(int personId, Integer page, String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.TAGGED_IMAGES).buildUrl(parameters); + + WrapperGenericList wrapper; + + String webpage = httpTools.getRequest(url); + try { + TypeReference tr = new TypeReference>() { + }; + wrapper = MAPPER.readValue(webpage, tr); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get tagged images", url, ex); + } + + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } /** @@ -199,9 +262,10 @@ public class TmdbPeople extends AbstractMethod { * @param startDate * @param endDate * @return + * @throws com.omertron.themoviedbapi.MovieDbException */ - public TmdbResultsList getPersonChanges(int persondId, String startDate, String endDate) { - return null; + public TmdbResultsList getPersonChanges(int persondId, String startDate, String endDate) throws MovieDbException { + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not done"); } /** @@ -222,9 +286,10 @@ public class TmdbPeople extends AbstractMethod { try { WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); - results.copyWrapper(wrapper); - return results; +// TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); +// results.copyWrapper(wrapper); +// return results; + return null; } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get popular person", url, ex); } @@ -246,5 +311,4 @@ public class TmdbPeople extends AbstractMethod { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get latest person", url, ex); } } - } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index bde166555..e8c24d0dd 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -19,6 +19,7 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model2.collection.Collection; @@ -264,4 +265,8 @@ public class TmdbSearch extends AbstractMethod { return results; } + private static TypeReference getTypeReference(T Class) { + return new TypeReference>() { + }; + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index 0e2023986..20c105b60 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -94,7 +94,7 @@ People /person/{id} Get the general person information for a specific id /person/{id}/movie_credits Get the movie credits for a specific person id. /person/{id}/tv_credits Get the TV credits for a specific person id. -/person/{id}/combined_credits Get the combined (movie and TV) credits for a specific person id. +*** /person/{id}/combined_credits Get the combined (movie and TV) credits for a specific person id. /person/{id}/external_ids Get the external ids for a specific person id. /person/{id}/images Get the images for a specific person id. /person/{id}/tagged_images Get the images that have been tagged with a specific person id diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index fa9b9cbed..5a6226bea 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -19,6 +19,7 @@ */ package com.omertron.themoviedbapi.model; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.model2.collection.Collection; diff --git a/src/main/java/com/omertron/themoviedbapi/model/person/Person.java b/src/main/java/com/omertron/themoviedbapi/model/person/Person.java index b76ffe852..f3d99b4a5 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/person/Person.java +++ b/src/main/java/com/omertron/themoviedbapi/model/person/Person.java @@ -34,15 +34,10 @@ public class Person extends AbstractJsonMapping { private static final long serialVersionUID = 1L; - /* - * Static fields for default cast information - */ private static final String CAST_DEPARTMENT = "acting"; private static final String CAST_JOB = "actor"; private static final String DEFAULT_STRING = ""; - /* - * Properties - */ + // Properties @JsonProperty("id") private int id = -1; @JsonProperty("name") diff --git a/src/main/java/com/omertron/themoviedbapi/model/Artwork.java b/src/main/java/com/omertron/themoviedbapi/model2/artwork/Artwork.java similarity index 94% rename from src/main/java/com/omertron/themoviedbapi/model/Artwork.java rename to src/main/java/com/omertron/themoviedbapi/model2/artwork/Artwork.java index a60009016..19bb4f91b 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Artwork.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/artwork/Artwork.java @@ -17,11 +17,12 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.artwork; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.enumeration.ArtworkType; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -54,84 +55,89 @@ public class Artwork extends AbstractJsonMapping { private String flag; private ArtworkType artworkType = ArtworkType.POSTER; - public ArtworkType getArtworkType() { - return artworkType; + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; } public float getAspectRatio() { return aspectRatio; } - public String getFilePath() { - return filePath; + public void setAspectRatio(float aspectRatio) { + this.aspectRatio = aspectRatio; } - public int getHeight() { - return height; + public String getFilePath() { + return filePath; } - public String getLanguage() { - return language; + public void setFilePath(String filePath) { + this.filePath = filePath; } - public int getWidth() { - return width; + public int getHeight() { + return height; } - public float getVoteAverage() { - return voteAverage; + public void setHeight(int height) { + this.height = height; } - public int getVoteCount() { - return voteCount; + public String getLanguage() { + return language; } - public String getFlag() { - return flag; + public void setLanguage(String language) { + this.language = language; } - public String getId() { - return id; + public int getWidth() { + return width; } - public void setArtworkType(ArtworkType artworkType) { - this.artworkType = artworkType; + public void setWidth(int width) { + this.width = width; } - public void setAspectRatio(float aspectRatio) { - this.aspectRatio = aspectRatio; + public float getVoteAverage() { + return voteAverage; } - public void setFilePath(String filePath) { - this.filePath = filePath; + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; } - public void setHeight(int height) { - this.height = height; + public int getVoteCount() { + return voteCount; } - public void setLanguage(String language) { - this.language = language; + public void setVoteCount(int voteCount) { + this.voteCount = voteCount; } - public void setWidth(int width) { - this.width = width; + public String getFlag() { + return flag; } - public void setVoteAverage(float voteAverage) { - this.voteAverage = voteAverage; + public void setFlag(String flag) { + this.flag = flag; } - public void setVoteCount(int voteCount) { - this.voteCount = voteCount; + public ArtworkType getArtworkType() { + return artworkType; } - public void setFlag(String flag) { - this.flag = flag; + public void setArtworkType(ArtworkType artworkType) { + this.artworkType = artworkType; } - public void setId(String id) { - this.id = id; + @JsonSetter("image_type") + public void setArtworkType(String artworkType){ + this.artworkType=ArtworkType.fromString(artworkType); } @Override diff --git a/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java b/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java new file mode 100644 index 000000000..5905ea6f9 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java @@ -0,0 +1,74 @@ +/* + * 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.model2.artwork; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.model2.MediaBasic; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; + +/** + * + * @author Stuart + */ +public class ArtworkMedia extends Artwork { + + private MediaType mediaType; + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXTERNAL_PROPERTY, + property = "media_type", + defaultImpl = MediaBasic.class + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = MovieBasic.class, name = "movie"), + @JsonSubTypes.Type(value = TVBasic.class, name = "tv"), + @JsonSubTypes.Type(value = TVEpisodeBasic.class, name = "episode") + }) + @JsonProperty("media") + private MediaBasic media; + + public MediaType getMediaType() { + return mediaType; + } + + public void setMediaType(MediaType mediaType) { + this.mediaType = mediaType; + } + + @JsonSetter("media_type") + public void setMediaType(String mediaType) { + this.mediaType = MediaType.fromString(mediaType); + } + + public MediaBasic getMedia() { + return media; + } + + public void setMedia(MediaBasic media) { + this.media = media; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java new file mode 100644 index 000000000..eebf5f736 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java @@ -0,0 +1,126 @@ +/* + * 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.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.omertron.themoviedbapi.enumeration.CreditType; +import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; + +/** + * @author stuart.boston + */ +public class CreditBasic extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + private CreditType creditType; + private MediaType mediaType; + + @JsonProperty("credit_id") + private String creditId; + @JsonProperty("id") + private int id; + @JsonProperty("poster_path") + private String posterPath; + + //cast + @JsonProperty("character") + private String character; + //crew + @JsonProperty("department") + private String department; + @JsonProperty("job") + private String job; + + public CreditType getCreditType() { + return creditType; + } + + public void setCreditType(CreditType creditType) { + this.creditType = creditType; + } + + public MediaType getMediaType() { + return mediaType; + } + + @JsonSetter("media_type") + public void setMediaType(String mediaType) { + this.mediaType = MediaType.fromString(mediaType); + } + + public void setMediaType(MediaType mediaType) { + this.mediaType = mediaType; + } + + public String getCreditId() { + return creditId; + } + + public void setCreditId(String creditId) { + this.creditId = creditId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public String getCharacter() { + return character; + } + + public void setCharacter(String character) { + this.character = character; + setCreditType(CreditType.CAST); + } + + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + setCreditType(CreditType.CREW); + } + + public String getJob() { + return job; + } + + public void setJob(String job) { + this.job = job; + setCreditType(CreditType.CREW); + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java new file mode 100644 index 000000000..b160c18b3 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java @@ -0,0 +1,77 @@ +/* + * 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.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.enumeration.MediaType; + +/** + * @author stuart.boston + */ +public class CreditMovieBasic extends CreditBasic { + + private static final long serialVersionUID = 1L; + + @JsonProperty("adult") + private boolean adult; + @JsonProperty("original_title") + private String originalTitle; + @JsonProperty("release_date") + private String releaseDate; + @JsonProperty("title") + private String title; + + public CreditMovieBasic() { + setMediaType(MediaType.MOVIE); + } + + public boolean isAdult() { + return adult; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } + + public String getOriginalTitle() { + return originalTitle; + } + + public void setOriginalTitle(String originalTitle) { + this.originalTitle = originalTitle; + } + + public String getReleaseDate() { + return releaseDate; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java new file mode 100644 index 000000000..3d055ac19 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java @@ -0,0 +1,77 @@ +/* + * 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.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.enumeration.MediaType; + +/** + * @author stuart.boston + */ +public class CreditTVBasic extends CreditBasic { + + private static final long serialVersionUID = 1L; + + @JsonProperty("episode_count") + private int episodeCount; + @JsonProperty("first_air_date") + private String firstAirDate; + @JsonProperty("name") + private String name; + @JsonProperty("original_name") + private String originalName; + + public CreditTVBasic() { + setMediaType(MediaType.TV); + } + + public int getEpisodeCount() { + return episodeCount; + } + + public void setEpisodeCount(int episodeCount) { + this.episodeCount = episodeCount; + } + + public String getFirstAirDate() { + return firstAirDate; + } + + public void setFirstAirDate(String firstAirDate) { + this.firstAirDate = firstAirDate; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOriginalName() { + return originalName; + } + + public void setOriginalName(String originalName) { + this.originalName = originalName; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java b/src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java new file mode 100644 index 000000000..805163069 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java @@ -0,0 +1,82 @@ +/* + * 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.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; + +/** + * + * @author Stuart + */ +public class ExternalID extends AbstractJsonMapping { + + @JsonProperty("id") + private String id; + @JsonProperty("imdb_id") + private String imdbId; + @JsonProperty("freebase_mid") + private String freebaseMid; + @JsonProperty("freebase_id") + private String freebaseId; + @JsonProperty("tvrage_id") + private String tvrageId; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getImdbId() { + return imdbId; + } + + public void setImdbId(String imdbId) { + this.imdbId = imdbId; + } + + public String getFreebaseMid() { + return freebaseMid; + } + + public void setFreebaseMid(String freebaseMid) { + this.freebaseMid = freebaseMid; + } + + public String getFreebaseId() { + return freebaseId; + } + + public void setFreebaseId(String freebaseId) { + this.freebaseId = freebaseId; + } + + public String getTvrageId() { + return tvrageId; + } + + public void setTvrageId(String tvrageId) { + this.tvrageId = tvrageId; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/Person.java b/src/main/java/com/omertron/themoviedbapi/model2/person/Person.java new file mode 100644 index 000000000..63f1a0d79 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/Person.java @@ -0,0 +1,133 @@ +/* + * 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.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** + * @author stuart.boston + */ +public class Person extends PersonBasic { + + private static final long serialVersionUID = 1L; + + @JsonProperty("adult") + private boolean adult; + @JsonProperty("also_known_as") + private List alsoKnownAs; + @JsonProperty("biography") + private String biography; + @JsonProperty("birthday") + private String birthday; + @JsonProperty("deathday") + private String deathday; + @JsonProperty("homepage") + private String homepage; + @JsonProperty("imdb_id") + private String imdbId; + @JsonProperty("place_of_birth") + private String placeOfBirth; + @JsonProperty("popularity") + private float popularity; + @JsonProperty("profile_path") + private String profilePath; + + public boolean isAdult() { + return adult; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } + + public List getAlsoKnownAs() { + return alsoKnownAs; + } + + public void setAlsoKnownAs(List alsoKnownAs) { + this.alsoKnownAs = alsoKnownAs; + } + + public String getBiography() { + return biography; + } + + public void setBiography(String biography) { + this.biography = biography; + } + + public String getBirthday() { + return birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getDeathday() { + return deathday; + } + + public void setDeathday(String deathday) { + this.deathday = deathday; + } + + public String getHomepage() { + return homepage; + } + + public void setHomepage(String homepage) { + this.homepage = homepage; + } + + public String getImdbId() { + return imdbId; + } + + public void setImdbId(String imdbId) { + this.imdbId = imdbId; + } + + public String getPlaceOfBirth() { + return placeOfBirth; + } + + public void setPlaceOfBirth(String placeOfBirth) { + this.placeOfBirth = placeOfBirth; + } + + public float getPopularity() { + return popularity; + } + + public void setPopularity(float popularity) { + this.popularity = popularity; + } + + public String getProfilePath() { + return profilePath; + } + + public void setProfilePath(String profilePath) { + this.profilePath = profilePath; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java new file mode 100644 index 000000000..29c3fbfe5 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java @@ -0,0 +1,63 @@ +/* + * 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.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import java.util.List; + +/** + * @author stuart.boston + */ +public class PersonCredits extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + @JsonProperty("id") + private int id; + @JsonProperty("cast") + private List cast; + @JsonProperty("crew") + private List crew; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public List getCast() { + return cast; + } + + public void setCast(List cast) { + this.cast = cast; + } + + public List getCrew() { + return crew; + } + + public void setCrew(List crew) { + this.crew = crew; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java index 7af9f79ec..9854bf559 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java @@ -19,15 +19,15 @@ */ package com.omertron.themoviedbapi.model2.tv; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.MediaBasic; /** * TV Favorite information * * @author stuart.boston */ -public class TVEpisodeBasic extends AbstractJsonMapping { +public class TVEpisodeBasic extends MediaBasic { @JsonProperty("air_date") private String airDate; @@ -41,6 +41,8 @@ public class TVEpisodeBasic extends AbstractJsonMapping { private String overview; @JsonProperty("still_path") private String stillPath; + @JsonProperty("show_id") + private String showId; public String getAirDate() { return airDate; @@ -90,4 +92,12 @@ public class TVEpisodeBasic extends AbstractJsonMapping { this.stillPath = stillPath; } + public String getShowId() { + return showId; + } + + public void setShowId(String showId) { + this.showId = showId; + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index 96615675a..b015f7f29 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -33,6 +33,7 @@ public enum MethodSub { COMBINED_CREDITS("combined_credits"), COMPANY("company"), CREDITS("credits"), + EXTERNAL_IDS("external_ids"), FAVORITE("favorite"), FAVORITE_MOVIES("favorite/movies"), FAVORITE_TV("favorite/tv"), @@ -61,6 +62,7 @@ public enum MethodSub { REVIEWS("reviews"), SESSION_NEW("session/new"), SIMILAR_MOVIES("similar_movies"), + TAGGED_IMAGES("tagged_images"), TOKEN_NEW("token/new"), TOKEN_VALIDATE("token/validate_with_login"), TOP_RATED("top-rated"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java b/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java index d063ea6dc..efedeebbf 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java @@ -57,7 +57,9 @@ public class TmdbParameters { * @param value The array value to use (will be converted into a comma separated list) */ public void add(final Param key, final String[] value) { - parameters.put(key, toList(value)); + if (value != null && value.length > 0) { + parameters.put(key, toList(value)); + } } /** diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java index f2243153c..98e7a660e 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; import java.io.Serializable; import java.util.ArrayList; @@ -96,7 +96,7 @@ public class WrapperImages extends AbstractWrapperAll implements Serializable { artwork.addAll(backdrops); } - // Add all the backdrops to the list + // Add all the profiles to the list if (types.contains(ArtworkType.PROFILE)) { updateArtworkType(profiles, ArtworkType.PROFILE); artwork.addAll(profiles); diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java index a50a3e4ff..3a64526e1 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.AfterClass; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java index 828efd858..c0a3c2140 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index deac5be78..645a72cc0 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -21,14 +21,25 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; -import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.TestID; +import com.omertron.themoviedbapi.enumeration.ArtworkType; +import com.omertron.themoviedbapi.model2.artwork.Artwork; +import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; +import com.omertron.themoviedbapi.model2.person.CreditTVBasic; +import com.omertron.themoviedbapi.model2.person.ExternalID; +import com.omertron.themoviedbapi.model2.person.Person; +import com.omertron.themoviedbapi.model2.person.PersonCredits; import com.omertron.themoviedbapi.results.TmdbResultsList; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; @@ -45,6 +56,7 @@ public class TmdbPeopleTest extends AbstractTests { private static final int ID_BRUCE_WILLIS = 62; private static final int ID_SEAN_BEAN = 48; private static final int ID_DICK_WOLF = 117443; + private static final List testIDs = new ArrayList(); public TmdbPeopleTest() { } @@ -53,6 +65,8 @@ public class TmdbPeopleTest extends AbstractTests { public static void setUpClass() throws MovieDbException { doConfiguration(); instance = new TmdbPeople(getApiKey(), getHttpTools()); + testIDs.add(new TestID("Bruce Willis", "nm0000246", 62)); + testIDs.add(new TestID("Will Smith", "nm0000226", 2888)); } @AfterClass @@ -75,33 +89,150 @@ public class TmdbPeopleTest extends AbstractTests { // @Test public void testGetPersonInfo() throws MovieDbException { LOG.info("getPersonInfo"); - Person result = instance.getPersonInfo(ID_BRUCE_WILLIS); - assertTrue("Wrong actor returned", result.getId() == ID_BRUCE_WILLIS); - assertTrue("Missing bio", StringUtils.isNotBlank(result.getBiography())); - assertTrue("Missing birthday", StringUtils.isNotBlank(result.getBirthday())); - assertTrue("Missing homepage", StringUtils.isNotBlank(result.getHomepage())); - assertTrue("Missing IMDB", StringUtils.isNotBlank(result.getImdbId())); - assertTrue("Missing name", StringUtils.isNotBlank(result.getName())); - assertTrue("Missing birth place", StringUtils.isNotBlank(result.getBirthplace())); - assertTrue("Missing artwork", StringUtils.isNotBlank(result.getProfilePath())); - assertTrue("Missing bio", result.getPopularity() > 0F); + Person result; + + for (TestID test : testIDs) { + result = instance.getPersonInfo(test.getTmdb()); + assertEquals("Wrong actor returned", test.getTmdb(), result.getId()); + assertTrue("Missing bio", StringUtils.isNotBlank(result.getBiography())); + assertTrue("Missing birthday", StringUtils.isNotBlank(result.getBirthday())); + assertTrue("Missing homepage", StringUtils.isNotBlank(result.getHomepage())); + assertEquals("Missing IMDB", test.getImdb(), result.getImdbId()); + assertTrue("Missing name", StringUtils.isNotBlank(result.getName())); + assertTrue("Missing birth place", StringUtils.isNotBlank(result.getPlaceOfBirth())); + assertTrue("Missing artwork", StringUtils.isNotBlank(result.getProfilePath())); + assertTrue("Missing bio", result.getPopularity() > 0F); + } } /** - * Test of getPersonMovieOldImages method, of class TheMovieDbApi. + * Test of getPersonMovieCredits method, of class TmdbPeople. * - * @throws MovieDbException + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonMovieCredits() throws MovieDbException { + LOG.info("getPersonMovieCredits"); + String language = LANGUAGE_DEFAULT; + String[] appendToResponse = null; + + for (TestID test : testIDs) { + PersonCredits result = instance.getPersonMovieCredits(test.getTmdb(), language, appendToResponse); + LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); + assertEquals("Incorrect ID", test.getTmdb(), result.getId()); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + } + } + + /** + * Test of getPersonTVCredits method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonTVCredits() throws MovieDbException { + LOG.info("getPersonTVCredits"); + String language = LANGUAGE_DEFAULT; + String[] appendToResponse = null; + + for (TestID test : testIDs) { + PersonCredits result = instance.getPersonTVCredits(test.getTmdb(), language, appendToResponse); + LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); + assertEquals("Incorrect ID", test.getTmdb(), result.getId()); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + } + } + + /** + * Test of getPersonCombinedCredits method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonCombinedCredits() throws MovieDbException { + LOG.info("getPersonCombinedCredits"); + String language = LANGUAGE_DEFAULT; + String[] appendToResponse = null; + + for (TestID test : testIDs) { + PersonCredits result = instance.getPersonCombinedCredits(test.getTmdb(), language, appendToResponse); + LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); + assertEquals("Incorrect ID", test.getTmdb(), result.getId()); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + } + fail("Not working"); + } + + /** + * Test of getPersonExternalIds method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonExternalIds() throws MovieDbException { + LOG.info("getPersonExternalIds"); + + for (TestID test : testIDs) { + ExternalID result = instance.getPersonExternalIds(test.getTmdb()); + assertEquals("Wrong IMDB ID", test.getImdb(), result.getImdbId()); + } + } + + /** + * Test of getPersonImages method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException */ // @Test public void testGetPersonImages() throws MovieDbException { LOG.info("getPersonImages"); - TmdbResultsList result = instance.getPersonImages(ID_BRUCE_WILLIS); - assertTrue("No cast information", result.getResults().size() > 0); - for (Artwork artwork : result.getResults()) { - assertTrue("Artwork is blank", StringUtils.isNotBlank(artwork.getFilePath())); + for (TestID test : testIDs) { + TmdbResultsList result = instance.getPersonImages(test.getTmdb()); + assertFalse("No artwork", result.isEmpty()); + assertEquals("Wrong artwork type", ArtworkType.PROFILE, result.getResults().get(0).getArtworkType()); + } + } + + /** + * Test of getPersonTaggedImages method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonTaggedImages() throws MovieDbException { + LOG.info("getPersonTaggedImages"); + Integer page = null; + String language = LANGUAGE_DEFAULT; + + for (TestID test : testIDs) { + TmdbResultsList result = instance.getPersonTaggedImages(test.getTmdb(), page, language); + for (ArtworkMedia am : result.getResults()) { + LOG.info("{}", ToStringBuilder.reflectionToString(am, ToStringStyle.DEFAULT_STYLE)); + } } + } + /** + * Test of getPersonChanges method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetPersonChanges() throws MovieDbException { + LOG.info("getPersonChanges"); + int persondId = 0; + String startDate = ""; + String endDate = ""; + + TmdbResultsList expResult = null; + TmdbResultsList result = instance.getPersonChanges(persondId, startDate, endDate); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); } /** @@ -112,9 +243,12 @@ public class TmdbPeopleTest extends AbstractTests { @Test public void testGetPersonPopular() throws MovieDbException { LOG.info("getPersonPopular"); - int page = 0; + Integer page = null; + + TmdbResultsList expResult = null; TmdbResultsList result = instance.getPersonPopular(page); - assertFalse("No popular people", result.getResults().isEmpty()); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } @@ -123,14 +257,14 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testGetPersonLatest() throws MovieDbException { LOG.info("getPersonLatest"); + Person expResult = null; Person result = instance.getPersonLatest(); - - assertNotNull("No results found", result); - assertTrue("No results found", StringUtils.isNotBlank(result.getName())); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }