Append To Response for Season and Episode

This commit is contained in:
Stuart Boston
2015-03-16 11:27:11 +00:00
parent 84243703e3
commit e6e7fcc83e
10 changed files with 325 additions and 29 deletions
@@ -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>
}