From 4134594de5c361e97a995692dad24c35871141bc Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sat, 29 Aug 2015 21:23:08 +0100 Subject: [PATCH] Revert "Add more information to CollectionInfo" This reverts commit b5b84cc962f1ba6e1f8778b5d915c8f6e954296a. --- .../omertron/themoviedbapi/TheMovieDbApi.java | 3 +- .../themoviedbapi/methods/AbstractMethod.java | 6 + .../themoviedbapi/methods/TmdbSearch.java | 6 +- .../model/collection/Collection.java | 134 ++++++++++++++++++ .../model/collection/CollectionInfo.java | 7 +- .../themoviedbapi/model/movie/MovieInfo.java | 8 +- .../themoviedbapi/methods/TmdbSearchTest.java | 4 +- 7 files changed, 154 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/model/collection/Collection.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index f74c7adf1..bef7e1a9c 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -55,6 +55,7 @@ import com.omertron.themoviedbapi.model.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model.authentication.TokenSession; import com.omertron.themoviedbapi.model.change.ChangeKeyItem; import com.omertron.themoviedbapi.model.change.ChangeListItem; +import com.omertron.themoviedbapi.model.collection.Collection; import com.omertron.themoviedbapi.model.collection.CollectionInfo; import com.omertron.themoviedbapi.model.company.Company; import com.omertron.themoviedbapi.model.config.Configuration; @@ -1326,7 +1327,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public ResultList searchCollection(String query, Integer page, String language) throws MovieDbException { + public ResultList searchCollection(String query, Integer page, String language) throws MovieDbException { return tmdbSearch.searchCollection(query, page, language); } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 1229f8d3f..7e4f4dcd3 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -25,7 +25,9 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.artwork.ArtworkMedia; import com.omertron.themoviedbapi.model.change.ChangeKeyItem; import com.omertron.themoviedbapi.model.change.ChangeListItem; +import com.omertron.themoviedbapi.model.collection.Collection; import com.omertron.themoviedbapi.model.company.Company; +import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.model.media.AlternativeTitle; import com.omertron.themoviedbapi.model.movie.MovieBasic; @@ -76,6 +78,10 @@ public class AbstractMethod { }); TYPE_REFS.put(Company.class, new TypeReference>() { }); + TYPE_REFS.put(Collection.class, new TypeReference>() { + }); + TYPE_REFS.put(Keyword.class, new TypeReference>() { + }); TYPE_REFS.put(MovieInfo.class, new TypeReference>() { }); TYPE_REFS.put(PersonInfo.class, new TypeReference>() { diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index dcfd301ee..ae578d797 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -22,11 +22,11 @@ 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.collection.Collection; import com.omertron.themoviedbapi.model.company.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.model.media.MediaBasic; -import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.movie.MovieInfo; import com.omertron.themoviedbapi.model.person.PersonFind; import com.omertron.themoviedbapi.model.tv.TVBasic; @@ -92,14 +92,14 @@ public class TmdbSearch extends AbstractMethod { * @return * @throws MovieDbException */ - public ResultList searchCollection(String query, Integer page, String language) throws MovieDbException { + public ResultList searchCollection(String query, Integer page, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.QUERY, query); parameters.add(Param.PAGE, page); parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.COLLECTION).buildUrl(parameters); - WrapperGenericList wrapper = processWrapper(getTypeReference(MovieBasic.class), url, "collection"); + WrapperGenericList wrapper = processWrapper(getTypeReference(Collection.class), url, "collection"); return wrapper.getResultsList(); } diff --git a/src/main/java/com/omertron/themoviedbapi/model/collection/Collection.java b/src/main/java/com/omertron/themoviedbapi/model/collection/Collection.java new file mode 100644 index 000000000..8fedc56ff --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/collection/Collection.java @@ -0,0 +1,134 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model.collection; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import com.omertron.themoviedbapi.interfaces.Identification; +import com.omertron.themoviedbapi.model.AbstractJsonMapping; +import java.io.Serializable; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +/** + * @author stuart.boston + */ +@JsonRootName("collection") +public class Collection extends AbstractJsonMapping implements Serializable, Identification { + + private static final long serialVersionUID = 100L; + + @JsonProperty("id") + private int id; + @JsonProperty("title") + private String title; + @JsonProperty("name") + private String name; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("release_date") + private String releaseDate; + + public String getBackdropPath() { + return backdropPath; + } + + @Override + public int getId() { + return id; + } + + public String getPosterPath() { + return posterPath; + } + + public String getReleaseDate() { + return releaseDate; + } + + public String getTitle() { + if (StringUtils.isBlank(title)) { + return name; + } + return title; + } + + public String getName() { + if (StringUtils.isBlank(name)) { + return title; + } + return name; + } + + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + @Override + public void setId(int id) { + this.id = id; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Collection) { + final Collection other = (Collection) obj; + return new EqualsBuilder() + .append(id, other.id) + .append(name, other.name) + .append(title, other.title) + .append(backdropPath, other.backdropPath) + .isEquals(); + } else { + return false; + } + } + + @Override + public int hashCode() { + return new HashCodeBuilder() + .append(id) + .append(backdropPath) + .append(title) + .append(name) + .append(posterPath) + .append(releaseDate) + .toHashCode(); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/collection/CollectionInfo.java b/src/main/java/com/omertron/themoviedbapi/model/collection/CollectionInfo.java index 62f1786e1..d1c77bbe2 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/collection/CollectionInfo.java +++ b/src/main/java/com/omertron/themoviedbapi/model/collection/CollectionInfo.java @@ -22,7 +22,6 @@ package com.omertron.themoviedbapi.model.collection; import com.fasterxml.jackson.annotation.JsonProperty; import com.omertron.themoviedbapi.interfaces.Identification; import com.omertron.themoviedbapi.model.AbstractJsonMapping; -import com.omertron.themoviedbapi.model.movie.MovieBasic; import java.io.Serializable; import java.util.ArrayList; @@ -46,7 +45,7 @@ public class CollectionInfo extends AbstractJsonMapping implements Serializable, @JsonProperty("backdrop_path") private String backdropPath; @JsonProperty("parts") - private List parts = new ArrayList<>(); + private List parts = new ArrayList<>(); public String getBackdropPath() { return backdropPath; @@ -65,7 +64,7 @@ public class CollectionInfo extends AbstractJsonMapping implements Serializable, return overview; } - public List getParts() { + public List getParts() { return parts; } @@ -90,7 +89,7 @@ public class CollectionInfo extends AbstractJsonMapping implements Serializable, this.overview = overview; } - public void setParts(List parts) { + public void setParts(List parts) { this.parts = parts; } diff --git a/src/main/java/com/omertron/themoviedbapi/model/movie/MovieInfo.java b/src/main/java/com/omertron/themoviedbapi/model/movie/MovieInfo.java index 9870e7cb0..d60a7bd2d 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/movie/MovieInfo.java +++ b/src/main/java/com/omertron/themoviedbapi/model/movie/MovieInfo.java @@ -31,7 +31,7 @@ import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model.Language; import com.omertron.themoviedbapi.model.artwork.Artwork; import com.omertron.themoviedbapi.model.change.ChangeKeyItem; -import com.omertron.themoviedbapi.model.collection.CollectionInfo; +import com.omertron.themoviedbapi.model.collection.Collection; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.model.credits.MediaCreditCast; @@ -62,7 +62,7 @@ public class MovieInfo extends MovieBasic implements Serializable, Identificatio private static final long serialVersionUID = 100L; @JsonProperty("belongs_to_collection") - private CollectionInfo belongsToCollection; + private Collection belongsToCollection; @JsonProperty("budget") private long budget; @JsonProperty("genres") @@ -99,7 +99,7 @@ public class MovieInfo extends MovieBasic implements Serializable, Identificatio private List changes = Collections.emptyList(); // - public CollectionInfo getBelongsToCollection() { + public Collection getBelongsToCollection() { return belongsToCollection; } @@ -145,7 +145,7 @@ public class MovieInfo extends MovieBasic implements Serializable, Identificatio // // - public void setBelongsToCollection(CollectionInfo belongsToCollection) { + public void setBelongsToCollection(Collection belongsToCollection) { this.belongsToCollection = belongsToCollection; } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index f5c989e47..9d8ccfdc2 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -24,11 +24,11 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.enumeration.SearchType; +import com.omertron.themoviedbapi.model.collection.Collection; import com.omertron.themoviedbapi.model.company.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.model.media.MediaBasic; -import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.movie.MovieInfo; import com.omertron.themoviedbapi.model.person.PersonFind; import com.omertron.themoviedbapi.model.tv.TVBasic; @@ -77,7 +77,7 @@ public class TmdbSearchTest extends AbstractTests { LOG.info("searchCollection"); String query = "batman"; int page = 0; - ResultList result = instance.searchCollection(query, page, LANGUAGE_DEFAULT); + ResultList result = instance.searchCollection(query, page, LANGUAGE_DEFAULT); TestSuite.test(result, "Collection"); TestSuite.testId(result, 263, "Collection"); }