Fixed Multi search

This commit is contained in:
Stuart Boston
2015-03-02 22:03:06 +00:00
parent e850ba1589
commit e9945654c9
4 changed files with 92 additions and 19 deletions
@@ -53,6 +53,7 @@ import com.omertron.themoviedbapi.model.Video;
import com.omertron.themoviedbapi.model2.keyword.Keyword;
import com.omertron.themoviedbapi.model.keyword.KeywordMovie;
import com.omertron.themoviedbapi.model2.FindResults;
import com.omertron.themoviedbapi.model2.MediaBasic;
import com.omertron.themoviedbapi.model2.StatusCode;
import com.omertron.themoviedbapi.model2.account.Account;
import com.omertron.themoviedbapi.model2.artwork.Artwork;
@@ -1406,7 +1407,7 @@ public class TheMovieDbApi {
* @return
* @throws MovieDbException
*/
public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException {
public TmdbResultsList<MediaBasic> searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException {
return tmdbSearch.searchMulti(query, page, language, includeAdult);
}
@@ -1422,7 +1423,7 @@ public class TheMovieDbApi {
* @return
* @throws MovieDbException
*/
public TmdbResultsList<Person> searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException {
public TmdbResultsList<PersonFind> searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException {
return tmdbSearch.searchPeople(query, page, includeAdult, searchType);
}
@@ -21,7 +21,9 @@ package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.enumeration.SearchType;
import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER;
import com.omertron.themoviedbapi.model.MovieDb;
import com.omertron.themoviedbapi.model2.MediaBasic;
import com.omertron.themoviedbapi.model2.keyword.Keyword;
import com.omertron.themoviedbapi.model2.collection.Collection;
import com.omertron.themoviedbapi.model2.company.Company;
@@ -36,7 +38,10 @@ import com.omertron.themoviedbapi.tools.MethodSub;
import com.omertron.themoviedbapi.tools.Param;
import com.omertron.themoviedbapi.tools.TmdbParameters;
import com.omertron.themoviedbapi.wrapper.WrapperGenericList;
import com.omertron.themoviedbapi.wrapper.WrapperMultiSearch;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.yamj.api.common.exception.ApiExceptionType;
/**
@@ -197,7 +202,7 @@ public class TmdbSearch extends AbstractMethod {
* @return
* @throws MovieDbException
*/
public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException {
public TmdbResultsList<MediaBasic> searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.QUERY, query);
parameters.add(Param.PAGE, page);
@@ -205,8 +210,18 @@ public class TmdbSearch extends AbstractMethod {
parameters.add(Param.ADULT, includeAdult);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MULTI).buildUrl(parameters);
throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet");
}
String webpage = httpTools.getRequest(url);
try {
WrapperMultiSearch wrapper = MAPPER.readValue(webpage, WrapperMultiSearch.class);
TmdbResultsList<MediaBasic> results = new TmdbResultsList<MediaBasic>(null);
List<? extends MediaBasic> x = wrapper.getResults();
results.getResults().addAll(wrapper.getResults());
results.copyWrapper(wrapper);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get multi search", url, ex);
} }
/**
* This is a good starting point to start finding people on TMDb.
@@ -0,0 +1,59 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.wrapper;
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;
/**
*
* @author stuart.boston
*/
public class WrapperMultiSearch extends AbstractWrapperAll {
private List<? extends MediaBasic> results;
public List<? extends MediaBasic> getResults() {
return results;
}
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
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("results")
public void setResults(List<? extends MediaBasic> results) {
this.results = results;
}
}
@@ -23,6 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.enumeration.SearchType;
import com.omertron.themoviedbapi.model.MovieDb;
import com.omertron.themoviedbapi.model2.MediaBasic;
import com.omertron.themoviedbapi.model2.keyword.Keyword;
import com.omertron.themoviedbapi.model2.collection.Collection;
import com.omertron.themoviedbapi.model2.company.Company;
@@ -32,11 +33,9 @@ import com.omertron.themoviedbapi.model2.tv.TVBasic;
import com.omertron.themoviedbapi.results.TmdbResultsList;
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;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -76,7 +75,7 @@ public class TmdbSearchTest extends AbstractTests {
*
* @throws MovieDbException
*/
@Test
// @Test
public void testSearchCompanies() throws MovieDbException {
LOG.info("searchCompanies");
TmdbResultsList<Company> result = instance.searchCompanies(COMPANY_NAME, 0);
@@ -90,7 +89,7 @@ public class TmdbSearchTest extends AbstractTests {
*
* @throws MovieDbException
*/
@Test
// @Test
public void testSearchCollection() throws MovieDbException {
LOG.info("searchCollection");
String query = "batman";
@@ -106,7 +105,7 @@ public class TmdbSearchTest extends AbstractTests {
*
* @throws MovieDbException
*/
@Test
// @Test
public void testSearchKeyword() throws MovieDbException {
LOG.info("searchKeyword");
String query = "action";
@@ -122,7 +121,7 @@ public class TmdbSearchTest extends AbstractTests {
*
* @throws MovieDbException
*/
@Test
// @Test
public void testSearchList() throws MovieDbException {
LOG.info("searchList");
String query = "watch";
@@ -138,7 +137,7 @@ public class TmdbSearchTest extends AbstractTests {
*
* @throws MovieDbException
*/
@Test
// @Test
public void testSearchMovie() throws MovieDbException {
LOG.info("searchMovie");
@@ -167,11 +166,10 @@ public class TmdbSearchTest extends AbstractTests {
Integer page = null;
String language = "";
Boolean includeAdult = null;
String expResult = "";
String result = instance.searchMulti(query, page, language, includeAdult);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
TmdbResultsList<MediaBasic> result = instance.searchMulti(query, page, language, includeAdult);
for (MediaBasic item : result.getResults()) {
LOG.info("{}", item);
}
}
/**
@@ -179,7 +177,7 @@ public class TmdbSearchTest extends AbstractTests {
*
* @throws MovieDbException
*/
@Test
// @Test
public void testSearchPeople() throws MovieDbException {
LOG.info("searchPeople");
String personName = "Bruce Willis";
@@ -194,7 +192,7 @@ public class TmdbSearchTest extends AbstractTests {
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
// @Test
public void testSearchTV() throws MovieDbException {
System.out.println("searchTV");
String query = "The Walking Dead";