Updated Results #1

master
Stuart Boston 11 years ago
parent 23fffe38cf
commit a89cd9c923

@ -194,7 +194,7 @@ public class TheMovieDbApi {
* @return The lists
* @throws MovieDbException
*/
public List<UserList> getUserLists(String sessionId, int accountId) throws MovieDbException {
public ResultList<UserList> getUserLists(String sessionId, int accountId) throws MovieDbException {
return tmdbAccount.getUserLists(sessionId, accountId);
}
@ -541,7 +541,7 @@ public class TheMovieDbApi {
* @return
* @throws MovieDbException
*/
public List<MovieBasic> getCompanyMovies(int companyId, String language, Integer page) throws MovieDbException {
public ResultList<MovieBasic> getCompanyMovies(int companyId, String language, Integer page) throws MovieDbException {
return tmdbCompany.getCompanyMovies(companyId, language, page);
}
//</editor-fold>

@ -39,7 +39,6 @@ import com.omertron.themoviedbapi.tools.TmdbParameters;
import com.omertron.themoviedbapi.wrapper.WrapperGenericList;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.yamj.api.common.exception.ApiExceptionType;
/**
@ -88,13 +87,14 @@ public class TmdbAccount extends AbstractMethod {
* @return The lists
* @throws MovieDbException
*/
public List<UserList> getUserLists(String sessionId, int accountId) throws MovieDbException {
public ResultList<UserList> getUserLists(String sessionId, int accountId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.SESSION_ID, sessionId);
parameters.add(Param.ID, accountId);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.LISTS).buildUrl(parameters);
return processWrapperList(getTypeReference(UserList.class), url, "user list");
WrapperGenericList<UserList> wrapper = processWrapper(getTypeReference(UserList.class), url, "user list");
return wrapper.getResultsList();
}
/**

@ -98,7 +98,7 @@ public class TmdbCollections extends AbstractMethod {
try {
WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class);
ResultList<Artwork> results = new ResultList<Artwork>(wrapper.getAll(ArtworkType.POSTER, ArtworkType.BACKDROP));
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get collection images", url, ex);

@ -96,7 +96,7 @@ public class TmdbConfiguration extends AbstractMethod {
try {
WrapperJobList wrapper = MAPPER.readValue(webpage, WrapperJobList.class);
ResultList<JobDepartment> results = new ResultList<JobDepartment>(wrapper.getJobs());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get job list", url, ex);

@ -76,6 +76,7 @@ public class TmdbGenres extends AbstractMethod {
/**
* Get the list of genres for movies or TV
*
* @param language
* @param sub
* @return
@ -91,7 +92,7 @@ public class TmdbGenres extends AbstractMethod {
try {
WrapperGenres wrapper = MAPPER.readValue(webpage, WrapperGenres.class);
ResultList<Genre> results = new ResultList<Genre>(wrapper.getGenres());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre " + sub.toString(), url, ex);

@ -187,7 +187,7 @@ public class TmdbMovies extends AbstractMethod {
try {
WrapperAlternativeTitles wrapper = MAPPER.readValue(webpage, WrapperAlternativeTitles.class);
ResultList<AlternativeTitle> results = new ResultList<AlternativeTitle>(wrapper.getTitles());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get alternative titles", url, ex);
@ -238,7 +238,7 @@ public class TmdbMovies extends AbstractMethod {
try {
WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class);
ResultList<Artwork> results = new ResultList<Artwork>(wrapper.getAll());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get images", url, ex);
@ -267,7 +267,7 @@ public class TmdbMovies extends AbstractMethod {
try {
WrapperMovieKeywords wrapper = MAPPER.readValue(webpage, WrapperMovieKeywords.class);
ResultList<Keyword> results = new ResultList<Keyword>(wrapper.getKeywords());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get keywords", url, ex);
@ -296,7 +296,7 @@ public class TmdbMovies extends AbstractMethod {
try {
WrapperReleaseInfo wrapper = MAPPER.readValue(webpage, WrapperReleaseInfo.class);
ResultList<ReleaseInfo> results = new ResultList<ReleaseInfo>(wrapper.getCountries());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get release information", url, ex);
@ -327,7 +327,7 @@ public class TmdbMovies extends AbstractMethod {
try {
WrapperVideos wrapper = MAPPER.readValue(webpage, WrapperVideos.class);
ResultList<Video> results = new ResultList<Video>(wrapper.getVideos());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get videos", url, ex);
@ -354,7 +354,7 @@ public class TmdbMovies extends AbstractMethod {
try {
WrapperTranslations wrapper = MAPPER.readValue(webpage, WrapperTranslations.class);
ResultList<Translation> results = new ResultList<Translation>(wrapper.getTranslations());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get translations", url, ex);

@ -220,7 +220,7 @@ public class TmdbPeople extends AbstractMethod {
try {
WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class);
ResultList<Artwork> results = new ResultList<Artwork>(wrapper.getAll(ArtworkType.PROFILE));
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person images", url, ex);

@ -203,9 +203,9 @@ public class TmdbSearch extends AbstractMethod {
try {
WrapperMultiSearch wrapper = MAPPER.readValue(webpage, WrapperMultiSearch.class);
ResultList<MediaBasic> results = new ResultList<MediaBasic>(null);
ResultList<MediaBasic> results = new ResultList<MediaBasic>();
results.getResults().addAll(wrapper.getResults());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get multi search", url, ex);

@ -246,7 +246,7 @@ public class TmdbTV extends AbstractMethod {
try {
WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class);
ResultList<Artwork> results = new ResultList<Artwork>(wrapper.getAll());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get images", url, ex);
@ -346,7 +346,7 @@ public class TmdbTV extends AbstractMethod {
try {
WrapperTranslations wrapper = MAPPER.readValue(webpage, WrapperTranslations.class);
ResultList<Translation> results = new ResultList<Translation>(wrapper.getTranslations());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get translations", url, ex);
@ -373,7 +373,7 @@ public class TmdbTV extends AbstractMethod {
try {
WrapperVideos wrapper = MAPPER.readValue(webpage, WrapperVideos.class);
ResultList<Video> results = new ResultList<Video>(wrapper.getVideos());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get videos", url, ex);

@ -224,7 +224,7 @@ public class TmdbTVEpisodes extends AbstractMethod {
try {
WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class);
ResultList<Artwork> results = new ResultList<Artwork>(wrapper.getAll());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get images", url, ex);
@ -293,7 +293,7 @@ public class TmdbTVEpisodes extends AbstractMethod {
try {
WrapperVideos wrapper = MAPPER.readValue(webpage, WrapperVideos.class);
ResultList<Video> results = new ResultList<Video>(wrapper.getVideos());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get videos", url, ex);

@ -207,7 +207,7 @@ public class TmdbTVSeasons extends AbstractMethod {
try {
WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class);
ResultList<Artwork> results = new ResultList<Artwork>(wrapper.getAll());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get images", url, ex);
@ -236,7 +236,7 @@ public class TmdbTVSeasons extends AbstractMethod {
try {
WrapperVideos wrapper = MAPPER.readValue(webpage, WrapperVideos.class);
ResultList<Video> results = new ResultList<Video>(wrapper.getVideos());
results.copyWrapper(wrapper);
wrapper.setResultProperties(results);
return results;
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get videos", url, ex);

@ -34,9 +34,6 @@ public class Collection extends AbstractJsonMapping {
private static final long serialVersionUID = 1L;
/*
* Properties
*/
@JsonProperty("id")
private int id;
@JsonProperty("title")

@ -32,9 +32,6 @@ public class CollectionInfo extends AbstractJsonMapping {
private static final long serialVersionUID = 1L;
/*
* Properties
*/
@JsonProperty("id")
private int id;
@JsonProperty("name")

@ -19,9 +19,6 @@
*/
package com.omertron.themoviedbapi.results;
import com.omertron.themoviedbapi.wrapper.AbstractWrapper;
import com.omertron.themoviedbapi.wrapper.AbstractWrapperAll;
import com.omertron.themoviedbapi.wrapper.AbstractWrapperId;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -37,7 +34,6 @@ public abstract class AbstractResults {
private int totalPages = 0;
private int totalResults = 0;
//<editor-fold defaultstate="collapsed" desc="Getters">
public int getId() {
return id;
}
@ -53,9 +49,7 @@ public abstract class AbstractResults {
public int getTotalResults() {
return totalResults;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Setters">
public void setId(int id) {
this.id = id;
}
@ -71,36 +65,6 @@ public abstract class AbstractResults {
public void setTotalResults(int totalResults) {
this.totalResults = totalResults;
}
//</editor-fold>
/**
* This wrapper does not have anything to copy.
*
* @param wrapper
*/
public void copyWrapper(AbstractWrapper wrapper) {
}
/**
* Copy the Id from the wrapper
*
* @param wrapper
*/
public void copyWrapper(AbstractWrapperId wrapper) {
this.id = wrapper.getId();
}
/**
* Copy the Id and pages from the wrapper
*
* @param wrapper
*/
public void copyWrapper(AbstractWrapperAll wrapper) {
this.id = wrapper.getId();
this.page = wrapper.getPage();
this.totalPages = wrapper.getTotalPages();
this.totalResults = wrapper.getTotalResults();
}
@Override
public String toString() {

@ -25,6 +25,9 @@ import java.util.List;
/**
* List of the results from TheMovieDb
*
* If the original request contains, or could contain, a page of results, this wrapper is returned to indicate what page was
* returned and how many are available
*
* @author Stuart
* @param <T>
*/
@ -32,11 +35,15 @@ public final class ResultList<T> extends AbstractResults {
private List<T> results;
public ResultList() {
this(null);
}
public ResultList(List<T> resultList) {
if (resultList != null) {
results = new ArrayList<T>(resultList);
if (resultList == null) {
results = new ArrayList<T>();
} else {
results = new ArrayList<T>(0);
results = new ArrayList<T>(resultList);
}
}

@ -25,6 +25,9 @@ import java.util.Map;
/**
* Map of the results from TheMovieDb
*
* If the original request contains, or could contain, a page of results, this wrapper is returned to indicate what page was
* returned and how many are available
*
* @author Stuart
* @param <K>
* @param <V>
@ -33,8 +36,16 @@ public final class ResultsMap<K, V> extends AbstractResults {
private Map<K, V> results;
public ResultsMap() {
this(null);
}
public ResultsMap(Map<K, V> resultsMap) {
results = new HashMap<K, V>(resultsMap);
if (resultsMap == null) {
results = new HashMap<K, V>();
} else {
results = new HashMap<K, V>(resultsMap);
}
}
public Map<K, V> getResults() {

@ -20,6 +20,7 @@
package com.omertron.themoviedbapi.wrapper;
import com.omertron.themoviedbapi.model.AbstractJsonMapping;
import com.omertron.themoviedbapi.results.AbstractResults;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
@ -45,4 +46,17 @@ public abstract class AbstractWrapper extends AbstractJsonMapping implements Ser
return new ArrayList<E>(EnumSet.allOf(clz));
}
}
/**
* Copy the wrapper values to the results
*
* @param results
*/
public void setResultProperties(AbstractResults results) {
// There are no values to copy
results.setId(0);
results.setPage(0);
results.setTotalPages(0);
results.setTotalResults(0);
}
}

@ -20,6 +20,7 @@
package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.results.AbstractResults;
/**
* Base class for the wrappers
@ -76,4 +77,17 @@ public class AbstractWrapperAll extends AbstractWrapperId implements IWrapperId,
public void setDates(ResultDates dates) {
this.dates = dates;
}
/**
* Copy the wrapper values to the results
*
* @param results
*/
@Override
public void setResultProperties(AbstractResults results) {
super.setResultProperties(results);
results.setPage(page);
results.setTotalPages(totalPages);
results.setTotalResults(totalResults);
}
}

@ -20,6 +20,7 @@
package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.results.AbstractResults;
/**
* Base class for the wrappers
@ -28,7 +29,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/
public class AbstractWrapperId extends AbstractWrapper implements IWrapperId {
private static final long serialVersionUID = 1L;
@JsonProperty("id")
private int id;
@ -41,4 +41,16 @@ public class AbstractWrapperId extends AbstractWrapper implements IWrapperId {
public void setId(int id) {
this.id = id;
}
/**
* Copy the wrapper values to the results
*
* @param results
*/
@Override
public void setResultProperties(AbstractResults results) {
super.setResultProperties(results);
results.setId(id);
}
}

@ -19,35 +19,20 @@
*/
package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.omertron.themoviedbapi.model.AbstractJsonMapping;
/**
*
* @author Stuart
*/
public class ResultDates implements Serializable {
public class ResultDates extends AbstractJsonMapping {
private static final long serialVersionUID = 1L;
/*
* Logger
*/
private static final Logger LOG = LoggerFactory.getLogger(ResultDates.class);
/*
* Properties
*/
@JsonProperty("minimum")
private String minimum = "";
@JsonProperty("maximum")
private String maximum = "";
// <editor-fold defaultstate="collapsed" desc="Getter methods">
public String getMinimum() {
return minimum;
}
@ -55,9 +40,7 @@ public class ResultDates implements Serializable {
public String getMaximum() {
return maximum;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Setter methods">
public void setMinimum(String minimum) {
this.minimum = minimum;
}
@ -65,24 +48,4 @@ public class ResultDates implements Serializable {
public void setMaximum(String maximum) {
this.maximum = maximum;
}
// </editor-fold>
/**
* Handle unknown properties and print a message
*
* @param key
* @param value
*/
@JsonAnySetter
public void handleUnknown(String key, Object value) {
StringBuilder sb = new StringBuilder();
sb.append("Unknown property: '").append(key);
sb.append("' value: '").append(value).append("'");
LOG.trace(sb.toString());
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE);
}
}

@ -21,16 +21,14 @@ package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model.media.AlternativeTitle;
import java.io.Serializable;
import java.util.List;
/**
*
* @author Stuart
*/
public class WrapperAlternativeTitles extends AbstractWrapperId implements Serializable {
public class WrapperAlternativeTitles extends AbstractWrapperId {
private static final long serialVersionUID = 1L;
@JsonProperty("titles")
private List<AlternativeTitle> titles;

@ -22,7 +22,6 @@ package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.results.ResultList;
import java.io.Serializable;
import java.util.List;
/**
@ -31,7 +30,7 @@ import java.util.List;
* @author Stuart
* @param <T>
*/
public class WrapperGenericList<T> extends AbstractWrapperAll implements Serializable {
public class WrapperGenericList<T> extends AbstractWrapperAll {
@JsonProperty("results")
private List<T> results;
@ -47,7 +46,7 @@ public class WrapperGenericList<T> extends AbstractWrapperAll implements Seriali
public ResultList<T> getResultsList() {
ResultList<T> resultsList = new ResultList<T>(results);
resultsList.copyWrapper(this);
setResultProperties(resultsList);
return resultsList;
}
}

@ -22,7 +22,6 @@ package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.enumeration.ArtworkType;
import com.omertron.themoviedbapi.model.artwork.Artwork;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -32,9 +31,8 @@ import java.util.List;
*
* @author Stuart
*/
public class WrapperImages extends AbstractWrapperAll implements Serializable {
public class WrapperImages extends AbstractWrapperAll {
private static final long serialVersionUID = 1L;
@JsonProperty("backdrops")
private List<Artwork> backdrops = Collections.emptyList();
@JsonProperty("posters")

@ -30,7 +30,6 @@ import com.omertron.themoviedbapi.model.list.UserList;
import com.omertron.themoviedbapi.model.movie.MovieBasic;
import com.omertron.themoviedbapi.model.tv.TVBasic;
import com.omertron.themoviedbapi.results.ResultList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.junit.After;
@ -97,10 +96,10 @@ public class TmdbAccountTest extends AbstractTests {
@Test
public void testGetUserLists() throws MovieDbException {
LOG.info("getUserLists");
List<UserList> results = instance.getUserLists(getSessionId(), getAccountId());
ResultList<UserList> results = instance.getUserLists(getSessionId(), getAccountId());
assertNotNull("No list found", results);
assertFalse("No entries found", results.isEmpty());
for (UserList result : results) {
for (UserList result : results.getResults()) {
TestSuite.test(result);
}
}

@ -23,7 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.model.company.Company;
import com.omertron.themoviedbapi.model.movie.MovieBasic;
import java.util.List;
import com.omertron.themoviedbapi.results.ResultList;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
@ -84,7 +84,7 @@ public class TmdbCompaniesTest extends AbstractTests {
@Test
public void testGetCompanyMovies() throws MovieDbException {
LOG.info("getCompanyMovies");
List<MovieBasic> result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0);
ResultList<MovieBasic> result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0);
assertFalse("No company movies found", result.isEmpty());
}
}

Loading…
Cancel
Save