Append To Response for Season and Episode

master
Stuart Boston 11 years ago
parent 84243703e3
commit e6e7fcc83e

@ -0,0 +1,65 @@
/*
* 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.enumeration;
import com.omertron.themoviedbapi.interfaces.AppendToResponseMethod;
import org.apache.commons.lang3.StringUtils;
/**
* List of TV methods
*
* @author Stuart
*/
public enum TVEpisodeMethod implements AppendToResponseMethod {
CREDITS,
EXTERNAL_IDS,
IMAGES,
VIDEOS;
/**
* Get the string to use in the URL
*
* @return
*/
@Override
public String getPropertyString() {
return this.name().toLowerCase();
}
/**
* Convert a string into an Enum type
*
* @param method
* @return
* @throws IllegalArgumentException If type is not recognised
*
*/
public static TVEpisodeMethod fromString(String method) {
if (StringUtils.isNotBlank(method)) {
try {
return TVEpisodeMethod.valueOf(method.trim().toUpperCase());
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException("Method " + method + " does not exist.", ex);
}
}
throw new IllegalArgumentException("Method must not be null");
}
}

@ -0,0 +1,65 @@
/*
* 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.enumeration;
import com.omertron.themoviedbapi.interfaces.AppendToResponseMethod;
import org.apache.commons.lang3.StringUtils;
/**
* List of TV methods
*
* @author Stuart
*/
public enum TVSeasonMethod implements AppendToResponseMethod {
CREDITS,
EXTERNAL_IDS,
IMAGES,
VIDEOS;
/**
* Get the string to use in the URL
*
* @return
*/
@Override
public String getPropertyString() {
return this.name().toLowerCase();
}
/**
* Convert a string into an Enum type
*
* @param method
* @return
* @throws IllegalArgumentException If type is not recognised
*
*/
public static TVSeasonMethod fromString(String method) {
if (StringUtils.isNotBlank(method)) {
try {
return TVSeasonMethod.valueOf(method.trim().toUpperCase());
} catch (IllegalArgumentException ex) {
throw new IllegalArgumentException("Method " + method + " does not exist.", ex);
}
}
throw new IllegalArgumentException("Method must not be null");
}
}

@ -20,17 +20,29 @@
package com.omertron.themoviedbapi.model.tv;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.omertron.themoviedbapi.enumeration.TVEpisodeMethod;
import com.omertron.themoviedbapi.interfaces.AppendToResponse;
import com.omertron.themoviedbapi.model.artwork.Artwork;
import com.omertron.themoviedbapi.model.credits.MediaCreditCast;
import com.omertron.themoviedbapi.model.credits.MediaCreditCrew;
import com.omertron.themoviedbapi.model.media.MediaCreditList;
import com.omertron.themoviedbapi.model.media.Video;
import com.omertron.themoviedbapi.model.person.ExternalID;
import com.omertron.themoviedbapi.results.WrapperGenericList;
import com.omertron.themoviedbapi.results.WrapperImages;
import java.io.Serializable;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
/**
* TV Episode information
*
* @author stuart.boston
*/
public class TVEpisodeInfo extends TVEpisodeBasic implements Serializable {
public class TVEpisodeInfo extends TVEpisodeBasic implements Serializable, AppendToResponse<TVEpisodeMethod> {
private static final long serialVersionUID = 4L;
@ -40,7 +52,15 @@ public class TVEpisodeInfo extends TVEpisodeBasic implements Serializable {
private List<MediaCreditCast> guestStars;
@JsonProperty("production_code")
private String productionCode;
// AppendToResponse
private final Set<TVEpisodeMethod> methods = EnumSet.noneOf(TVEpisodeMethod.class);
// AppendToResponse Properties
private MediaCreditList credits = new MediaCreditList();
private ExternalID externalIDs = new ExternalID();
private List<Artwork> images = Collections.emptyList();
private List<Video> videos = Collections.emptyList();
//<editor-fold defaultstate="collapsed" desc="Getters and Setters">
public List<MediaCreditCrew> getCrew() {
return crew;
}
@ -64,4 +84,59 @@ public class TVEpisodeInfo extends TVEpisodeBasic implements Serializable {
public void setProductionCode(String productionCode) {
this.productionCode = productionCode;
}
//</editor-fold>
private void addMethod(TVEpisodeMethod method) {
methods.add(method);
}
@Override
public boolean hasMethod(TVEpisodeMethod method) {
return methods.contains(method);
}
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Setters">
@JsonSetter("credits")
public void setCredits(MediaCreditList credits) {
this.credits = credits;
addMethod(TVEpisodeMethod.CREDITS);
}
@JsonSetter("external_ids")
public void setExternalIDs(ExternalID externalIDs) {
this.externalIDs = externalIDs;
addMethod(TVEpisodeMethod.EXTERNAL_IDS);
}
@JsonSetter("images")
public void setImages(WrapperImages images) {
this.images = images.getAll();
addMethod(TVEpisodeMethod.IMAGES);
}
@JsonSetter("videos")
public void setVideos(WrapperGenericList<Video> videos) {
this.videos = videos.getResults();
addMethod(TVEpisodeMethod.VIDEOS);
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Getters">
public MediaCreditList getCredits() {
return credits;
}
public ExternalID getExternalIDs() {
return externalIDs;
}
public List<Artwork> getImages() {
return images;
}
public List<Video> getVideos() {
return videos;
}
//</editor-fold>
}

@ -20,15 +20,27 @@
package com.omertron.themoviedbapi.model.tv;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.omertron.themoviedbapi.enumeration.TVSeasonMethod;
import com.omertron.themoviedbapi.interfaces.AppendToResponse;
import com.omertron.themoviedbapi.model.artwork.Artwork;
import com.omertron.themoviedbapi.model.media.MediaCreditList;
import com.omertron.themoviedbapi.model.media.Video;
import com.omertron.themoviedbapi.model.person.ExternalID;
import com.omertron.themoviedbapi.results.WrapperGenericList;
import com.omertron.themoviedbapi.results.WrapperImages;
import java.io.Serializable;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
/**
* TV Season information
*
* @author stuart.boston
*/
public class TVSeasonInfo extends TVSeasonBasic implements Serializable {
public class TVSeasonInfo extends TVSeasonBasic implements Serializable, AppendToResponse<TVSeasonMethod> {
private static final long serialVersionUID = 4L;
@ -38,7 +50,15 @@ public class TVSeasonInfo extends TVSeasonBasic implements Serializable {
private String overview;
@JsonProperty("episodes")
private List<TVEpisodeInfo> episodes;
// AppendToResponse
private final Set<TVSeasonMethod> methods = EnumSet.noneOf(TVSeasonMethod.class);
// AppendToResponse Properties
private MediaCreditList credits = new MediaCreditList();
private ExternalID externalIDs = new ExternalID();
private List<Artwork> images = Collections.emptyList();
private List<Video> videos = Collections.emptyList();
//<editor-fold defaultstate="collapsed" desc="Getters and Setters">
public String getName() {
return name;
}
@ -62,5 +82,59 @@ public class TVSeasonInfo extends TVSeasonBasic implements Serializable {
public void setEpisodes(List<TVEpisodeInfo> episodes) {
this.episodes = episodes;
}
//</editor-fold>
private void addMethod(TVSeasonMethod method) {
methods.add(method);
}
@Override
public boolean hasMethod(TVSeasonMethod method) {
return methods.contains(method);
}
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Setters">
@JsonSetter("credits")
public void setCredits(MediaCreditList credits) {
this.credits = credits;
addMethod(TVSeasonMethod.CREDITS);
}
@JsonSetter("external_ids")
public void setExternalIDs(ExternalID externalIDs) {
this.externalIDs = externalIDs;
addMethod(TVSeasonMethod.EXTERNAL_IDS);
}
@JsonSetter("images")
public void setImages(WrapperImages images) {
this.images = images.getAll();
addMethod(TVSeasonMethod.IMAGES);
}
@JsonSetter("videos")
public void setVideos(WrapperGenericList<Video> videos) {
this.videos = videos.getResults();
addMethod(TVSeasonMethod.VIDEOS);
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Getters">
public MediaCreditList getCredits() {
return credits;
}
public ExternalID getExternalIDs() {
return externalIDs;
}
public List<Artwork> getImages() {
return images;
}
public List<Video> getVideos() {
return videos;
}
//</editor-fold>
}

@ -19,19 +19,22 @@
*/
package com.omertron.themoviedbapi;
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 com.omertron.themoviedbapi.interfaces.AppendToResponse;
import com.omertron.themoviedbapi.interfaces.AppendToResponseMethod;
import com.omertron.themoviedbapi.interfaces.Identification;
import com.omertron.themoviedbapi.model.list.UserList;
import com.omertron.themoviedbapi.model.media.MediaCreditList;
import com.omertron.themoviedbapi.model.media.MediaState;
import com.omertron.themoviedbapi.model.movie.MovieBasic;
import com.omertron.themoviedbapi.model.movie.MovieInfo;
import com.omertron.themoviedbapi.model.person.ExternalID;
import com.omertron.themoviedbapi.model.person.PersonCreditList;
import com.omertron.themoviedbapi.model.person.PersonInfo;
import com.omertron.themoviedbapi.model.tv.TVBasic;
import com.omertron.themoviedbapi.model.tv.TVEpisodeInfo;
import com.omertron.themoviedbapi.model.tv.TVInfo;
import com.omertron.themoviedbapi.model.tv.TVSeasonInfo;
import com.omertron.themoviedbapi.results.ResultList;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang3.StringUtils;
@ -109,8 +112,8 @@ public class TestSuite {
String message = test.getClass().getSimpleName();
assertTrue(message + ": Missing ID", test.getId() > 0);
assertTrue(message + ": Missing name", StringUtils.isNotBlank(test.getName()));
assertTrue(message + ": Missing crew", test.getCrew().size() > 0);
assertTrue(message + ": Missing guest stars", test.getGuestStars().size() > 0);
assertFalse(message + ": Missing crew", test.getCrew().isEmpty());
assertFalse(message + ": Missing guest stars", test.getGuestStars().isEmpty());
}
public static void test(PersonInfo test) {
@ -134,13 +137,13 @@ public class TestSuite {
public static void test(ExternalID test) {
String message = test.getClass().getSimpleName();
assertTrue(message + ": Missing IMDB ID", StringUtils.isNotBlank(test.getImdbId()));
boolean found = false;
found |= StringUtils.isNotBlank(test.getImdbId());
found |= StringUtils.isNotBlank(test.getFreebaseId());
found |= StringUtils.isNotBlank(test.getFreebaseMid());
found |= StringUtils.isNotBlank(test.getTvdbId());
found |= StringUtils.isNotBlank(test.getTvrageId());
assertTrue(message + ": Missing one of the other IDs", found);
assertTrue(message + ": Missing all of the External IDs", found);
}
public static void test(MediaCreditList test) {
@ -152,6 +155,12 @@ public class TestSuite {
assertTrue(message + ": Missing cast/crew/guest stars information", found);
}
public static void test(MediaState test) {
String message = test.getClass().getSimpleName();
assertNotNull(message + ": Null result", test);
assertTrue(message + ": Invalid rating", test.getRated() > -2f);
}
public static void test(PersonCreditList<?> test, String message) {
boolean found = false;
found |= !test.getCast().isEmpty();
@ -173,4 +182,12 @@ public class TestSuite {
}
assertTrue(message + " ID " + id + " not found in list", found);
}
public static <T extends AppendToResponseMethod> void testATR(AppendToResponse<T> test, Class<T> methodClass) {
for (T method : methodClass.getEnumConstants()) {
assertTrue(test.getClass().getSimpleName() + ": Does not have " + method.getPropertyString(), test.hasMethod(method));
}
}
}

@ -25,6 +25,7 @@ import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestID;
import com.omertron.themoviedbapi.TestSuite;
import com.omertron.themoviedbapi.enumeration.ArtworkType;
import com.omertron.themoviedbapi.enumeration.TVEpisodeMethod;
import com.omertron.themoviedbapi.model.StatusCode;
import com.omertron.themoviedbapi.model.artwork.Artwork;
import com.omertron.themoviedbapi.model.credits.MediaCreditCast;
@ -92,12 +93,13 @@ public class TmdbEpisodesTest extends AbstractTests {
int seasonNumber = 1;
int episodeNumber = 1;
String language = LANGUAGE_DEFAULT;
String[] appendToResponse = null;
String appendToResponse = appendToResponseBuilder(TVEpisodeMethod.class);
for (TestID test : TV_IDS) {
LOG.info("Testing: {}", test);
TVEpisodeInfo result = instance.getEpisodeInfo(test.getTmdb(), seasonNumber, episodeNumber, language, appendToResponse);
TestSuite.test(result);
TestSuite.testATR(result, TVEpisodeMethod.class);
}
}
@ -241,15 +243,14 @@ public class TmdbEpisodesTest extends AbstractTests {
public void testGetEpisodeVideos() throws MovieDbException {
LOG.info("getEpisodeVideos");
int seasonNumber = 1;
// Game of thrones S03E01 has videos
int tvID = 1399;
int seasonNumber = 3;
int episodeNumber = 1;
String language = LANGUAGE_DEFAULT;
for (TestID test : TV_IDS) {
LOG.info("Testing: {}", test);
ResultList<Video> result = instance.getEpisodeVideos(test.getTmdb(), seasonNumber, episodeNumber, language);
// There are very few episodes that have videos
}
ResultList<Video> result = instance.getEpisodeVideos(tvID, seasonNumber, episodeNumber, language);
TestSuite.test(result, "Videos");
}
}

@ -101,9 +101,7 @@ public class TmdbMoviesTest extends AbstractTests {
assertEquals("Wrong IMDB ID", test.getImdb(), result.getImdbID());
assertEquals("Wrong title", test.getName(), result.getTitle());
TestSuite.test(result);
for (MovieMethod method : MovieMethod.values()) {
assertTrue("Does not have " + method.getPropertyString(), result.hasMethod(method));
}
TestSuite.testATR(result, MovieMethod.class);
TestSuite.test(result.getAlternativeTitles(), "Alt titles");
TestSuite.test(result.getCast(), "Cast");
TestSuite.test(result.getCrew(), "Crew");

@ -101,9 +101,7 @@ public class TmdbPeopleTest extends AbstractTests {
for (TestID test : TEST_IDS) {
PersonInfo result = instance.getPersonInfo(test.getTmdb(), appendToResponse);
TestSuite.test(result);
for (PeopleMethod method : PeopleMethod.values()) {
assertTrue("Does not have " + method.getPropertyString(), result.hasMethod(method));
}
TestSuite.testATR(result, PeopleMethod.class);
TestSuite.test(result.getExternalIDs());
TestSuite.test(result.getImages(), "Images");
TestSuite.test(result.getMovieCredits(), "Movie Credits");

@ -25,6 +25,7 @@ import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestID;
import com.omertron.themoviedbapi.TestSuite;
import com.omertron.themoviedbapi.enumeration.ArtworkType;
import com.omertron.themoviedbapi.enumeration.TVSeasonMethod;
import com.omertron.themoviedbapi.model.artwork.Artwork;
import com.omertron.themoviedbapi.model.credits.MediaCreditCast;
import com.omertron.themoviedbapi.model.media.MediaCreditList;
@ -89,12 +90,17 @@ public class TmdbSeasonsTest extends AbstractTests {
int seasonNumber = 1;
String language = LANGUAGE_DEFAULT;
String[] appendToResponse = null;
String appendToResponse = appendToResponseBuilder(TVSeasonMethod.class);
for (TestID test : TV_IDS) {
LOG.info("Testing: {}", test);
TVSeasonInfo result = instance.getSeasonInfo(test.getTmdb(), seasonNumber, language, appendToResponse);
TestSuite.test(result);
TestSuite.testATR(result, TVSeasonMethod.class);
TestSuite.test(result.getCredits());
TestSuite.test(result.getExternalIDs());
TestSuite.test(result.getImages(), "Images");
// Videos is usually empty for seasons, so skip the test
}
}
@ -121,8 +127,7 @@ public class TmdbSeasonsTest extends AbstractTests {
for (TestID test : TV_IDS) {
LOG.info("Testing: {}", test);
MediaState result = instance.getSeasonAccountState(test.getTmdb(), getSessionId());
assertNotNull("Null result", result);
assertTrue("Invalid rating", result.getRated() > -2f);
TestSuite.test(result);
}
}

@ -99,9 +99,7 @@ public class TmdbTVTest extends AbstractTests {
TVInfo result = instance.getTVInfo(test.getTmdb(), language, appendToResponse);
TestSuite.test(result);
for (TVMethod method : TVMethod.values()) {
assertTrue("Does not have " + method.getPropertyString(), result.hasMethod(method));
}
TestSuite.testATR(result, TVMethod.class);
TestSuite.test(result.getAlternativeTitles(), "Alt titles");
TestSuite.test(result.getContentRatings(), "Content Ratings");
TestSuite.test(result.getCredits());

Loading…
Cancel
Save