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;
}
}