From f17702626121c4c39dd6d7ea6198dd7b92152a48 Mon Sep 17 00:00:00 2001 From: Omertron <> Date: Sun, 3 Feb 2013 21:09:41 +0000 Subject: [PATCH] Added keyword searches --- .../omertron/themoviedbapi/TheMovieDbApi.java | 15 +- .../themoviedbapi/model/KeywordMovie.java | 145 ++++++++++++++++++ .../omertron/themoviedbapi/model/MovieDb.java | 15 +- .../wrapper/WrapperKeywordMovies.java | 50 ++++++ .../themoviedbapi/TheMovieDbApiTest.java | 25 +-- 5 files changed, 229 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/model/KeywordMovie.java create mode 100644 src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywordMovies.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index f0369814d..9163820fa 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -1479,7 +1479,7 @@ public class TheMovieDbApi { * @return List of movies with the keyword * @throws MovieDbException */ - public List getKeywordMovies(String keywordId, String language, int page) throws MovieDbException { + public List getKeywordMovies(String keywordId, String language, int page) throws MovieDbException { ApiUrl apiUrl = new ApiUrl(this, BASE_KEYWORD, "/movies"); apiUrl.addArgument(PARAM_ID, keywordId); @@ -1495,8 +1495,8 @@ public class TheMovieDbApi { String webpage = WebBrowser.request(url); try { - WrapperMovieList wrapper = mapper.readValue(webpage, WrapperMovieList.class); - return wrapper.getMovieList(); + WrapperKeywordMovies wrapper = mapper.readValue(webpage, WrapperKeywordMovies.class); + return wrapper.getResults(); } catch (IOException ex) { logger.warn("Failed to get top rated movies: " + ex.getMessage()); throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); @@ -1506,5 +1506,14 @@ public class TheMovieDbApi { // // // + + public void getMovieChangesList(int page, String startDate, String endDate) throws MovieDbException { + throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + public void getPersonChangesList(int page, String startDate, String endDate) throws MovieDbException { + throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + // } diff --git a/src/main/java/com/omertron/themoviedbapi/model/KeywordMovie.java b/src/main/java/com/omertron/themoviedbapi/model/KeywordMovie.java new file mode 100644 index 000000000..75ffaeb42 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/KeywordMovie.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2004-2013 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; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import org.apache.log4j.Logger; + +/** + * + * @author Stuart + */ +public class KeywordMovie implements Serializable { + + private static final long serialVersionUID = 1L; + + /* + * Logger + */ + private static final Logger logger = Logger.getLogger(KeywordMovie.class); + /* + * Properties + */ + @JsonProperty("id") + private String id; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("original_title") + private String originalTitle; + @JsonProperty("release_date") + private String releaseDate; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("title") + private String title; + @JsonProperty("vote_average") + private float voteAverage; + @JsonProperty("vote_count") + private double voteCount; + + // + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public String getBackdropPath() { + return backdropPath; + } + + public String getId() { + return id; + } + + public String getOriginalTitle() { + return originalTitle; + } + + public String getReleaseDate() { + return releaseDate; + } + + public String getPosterPath() { + return posterPath; + } + + public String getTitle() { + return title; + } + + public float getVoteAverage() { + return voteAverage; + } + + public double getVoteCount() { + return voteCount; + } + // + + // + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public void setId(String id) { + this.id = id; + } + + public void setOriginalTitle(String originalTitle) { + this.originalTitle = originalTitle; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; + } + + public void setVoteCount(double voteCount) { + this.voteCount = voteCount; + } + // + + /** + * 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("'"); + logger.trace(sb.toString()); + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index 8b4b4f30a..481800b8c 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -40,19 +40,19 @@ public class MovieDb implements Serializable { /* * Properties */ - @JsonProperty(("backdrop_path")) + @JsonProperty("backdrop_path") private String backdropPath; - @JsonProperty(("id")) + @JsonProperty("id") private int id; - @JsonProperty(("original_title")) + @JsonProperty("original_title") private String originalTitle; - @JsonProperty(("popularity")) + @JsonProperty("popularity") private float popularity; - @JsonProperty(("poster_path")) + @JsonProperty("poster_path") private String posterPath; - @JsonProperty(("release_date")) + @JsonProperty("release_date") private String releaseDate; - @JsonProperty(("title")) + @JsonProperty("title") private String title; @JsonProperty("adult") private boolean adult; @@ -275,7 +275,6 @@ public class MovieDb implements Serializable { } // - /** * Handle unknown properties and print a message * diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywordMovies.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywordMovies.java new file mode 100644 index 000000000..56d6daab1 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywordMovies.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2013 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.wrapper; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.KeywordMovie; +import java.util.List; +import org.apache.log4j.Logger; + +/** + * + * @author stuart.boston + */ +public class WrapperKeywordMovies extends WrapperBase { + /* + * Properties + */ + @JsonProperty("results") + private List results; + + public WrapperKeywordMovies() { + super(Logger.getLogger(WrapperKeywordMovies.class)); + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index 77318fb90..d80057355 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -26,6 +26,7 @@ import com.omertron.themoviedbapi.model.CollectionInfo; import com.omertron.themoviedbapi.model.Company; import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.KeywordMovie; import com.omertron.themoviedbapi.model.MovieChanges; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieDbList; @@ -74,7 +75,6 @@ public class TheMovieDbApiTest { private static final String LANGUAGE_ENGLISH = "en"; public TheMovieDbApiTest() throws MovieDbException { - tmdb = new TheMovieDbApi(API_KEY); } @BeforeClass @@ -82,6 +82,7 @@ public class TheMovieDbApiTest { BasicConfigurator.configure(); // Set the logger level to TRACE Logger.getRootLogger().setLevel(Level.TRACE); + tmdb = new TheMovieDbApi(API_KEY); } @AfterClass @@ -501,8 +502,9 @@ public class TheMovieDbApiTest { /** * Test of getSessionToken method, of class TheMovieDbApi. + * + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication */ -// Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication public void testGetSessionToken() throws Exception { logger.info("getSessionToken"); TokenAuthorisation token = tmdb.getAuthorisationToken(); @@ -536,7 +538,11 @@ public class TheMovieDbApiTest { assertTrue("No results found", results.size() > 0); } -// Do not test this until it is fixed + /** + * Test of getMovieChanges method,of class TheMovieDbApi + * + * TODO: Do not test this until it is fixed + */ public void testGetMovieChanges() throws Exception { logger.info("getMovieChanges"); @@ -606,8 +612,9 @@ public class TheMovieDbApiTest { /** * Test of postMovieRating method, of class TheMovieDbApi. + * + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication */ - @Test public void testPostMovieRating() throws Exception { logger.info("postMovieRating"); String sessionId = ""; @@ -621,16 +628,14 @@ public class TheMovieDbApiTest { /** * Test of getPersonChanges method, of class TheMovieDbApi. + * + * TODO: Fix the method before testing */ - @Test public void testGetPersonChanges() throws Exception { logger.info("getPersonChanges"); - int personId = 0; String startDate = ""; String endDate = ""; - tmdb.getPersonChanges(personId, startDate, endDate); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + tmdb.getPersonChanges(ID_PERSON_BRUCE_WILLIS, startDate, endDate); } /** @@ -661,7 +666,7 @@ public class TheMovieDbApiTest { public void testGetKeywordMovies() throws Exception { logger.info("getKeywordMovies"); int page = 0; - List result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page); + List result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page); assertFalse("No keyword movies found", result.isEmpty()); } }