diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java index 6fc6c702c..43ea08827 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java @@ -22,8 +22,6 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.model2.FindResults; -import com.omertron.themoviedbapi.model2.MediaBasic; -import com.omertron.themoviedbapi.model2.MediaTypeMixIn; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -48,7 +46,7 @@ public class TmdbFind extends AbstractMethod { */ public TmdbFind(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); - MAPPER.addMixIn(MediaBasic.class, MediaTypeMixIn.class); +// MAPPER.addMixIn(MediaBasic.class, MediaTypeMixIn.class); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index c0b46b2e2..1a2639493 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -29,6 +29,7 @@ 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.model2.person.PersonFind; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -38,7 +39,6 @@ import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; -import com.omertron.themoviedbapi.wrapper.WrapperPersonList; import java.io.IOException; import java.net.URL; import org.yamj.api.common.exception.ApiExceptionType; @@ -277,21 +277,23 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonPopular(Integer page) throws MovieDbException { + public TmdbResultsList getPersonPopular(Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.POPULAR).buildUrl(parameters); String webpage = httpTools.getRequest(url); + WrapperGenericList wrapper; try { - WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class); -// TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); -// results.copyWrapper(wrapper); -// return results; - return null; + TypeReference tr = new TypeReference>() { + }; + wrapper = MAPPER.readValue(webpage, tr); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get popular person", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get tagged images", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java index f74bd886d..1a169baa7 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, @@ -13,7 +14,8 @@ import com.omertron.themoviedbapi.model2.tv.TVBasic; ) @JsonSubTypes({ @JsonSubTypes.Type(value = MovieBasic.class, name = "movie"), - @JsonSubTypes.Type(value = TVBasic.class, name = "tv") + @JsonSubTypes.Type(value = TVBasic.class, name = "tv"), + @JsonSubTypes.Type(value = TVEpisodeBasic.class, name = "episode") }) public class MediaTypeMixIn { diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java index 506a972c0..cbf3a9484 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java @@ -20,7 +20,13 @@ package com.omertron.themoviedbapi.model2.person; 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.model2.MediaBasic; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; import java.util.List; /** @@ -35,7 +41,7 @@ public class PersonFind extends PersonBasic { private Float popularity; @JsonProperty("profile_path") private String profilePath; - @JsonProperty("known_for") +// @JsonProperty("known_for") private List knownFor; public Boolean getAdult() { @@ -66,6 +72,19 @@ public class PersonFind extends PersonBasic { return knownFor; } + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, +// include = JsonTypeInfo.As.EXTERNAL_PROPERTY, + include = JsonTypeInfo.As.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") + }) + @JsonSetter("known_for") public void setKnownFor(List knownFor) { this.knownFor = knownFor; } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java index cf7b3faa3..2c9d78b50 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java @@ -84,7 +84,7 @@ public class TmdbFindTest extends AbstractTests { * * @throws MovieDbException */ -// @Test + @Test public void testFindMoviesImdbID() throws MovieDbException { LOG.info("findMoviesImdbID"); FindResults result; @@ -109,7 +109,7 @@ public class TmdbFindTest extends AbstractTests { * @throws MovieDbException * @throws IOException */ -// @Test + @Test public void testFindPersonImdbID() throws MovieDbException, IOException { LOG.info("findPersonImdbID"); FindResults result; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index 645a72cc0..39fd86041 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -23,6 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.TestID; import com.omertron.themoviedbapi.enumeration.ArtworkType; +import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; @@ -30,6 +31,7 @@ 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.model2.person.PersonFind; import com.omertron.themoviedbapi.results.TmdbResultsList; import java.util.ArrayList; import java.util.List; @@ -53,8 +55,6 @@ import org.junit.Test; public class TmdbPeopleTest extends AbstractTests { private static TmdbPeople instance; - 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(); @@ -244,12 +244,15 @@ public class TmdbPeopleTest extends AbstractTests { public void testGetPersonPopular() throws MovieDbException { LOG.info("getPersonPopular"); Integer page = null; - - TmdbResultsList expResult = null; - TmdbResultsList result = instance.getPersonPopular(page); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + TmdbResultsList result = instance.getPersonPopular(page); + assertFalse("No results", result.isEmpty()); + assertTrue("No results", result.getResults().size() > 0); + for (PersonFind p : result.getResults()) { + LOG.info("{} ({}) = {}", p.getName(), p.getId(), p.getKnownFor().size()); + for (MediaBasic k : p.getKnownFor()) { + LOG.info(" {}", k.toString()); + } + } } /**