Fixes issue #4 Company parent correctly de-serialised now

master
Stuart Boston 13 years ago
parent 20349013cc
commit 72186feaf9

@ -1,135 +1,143 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.model;
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;
/**
* Company information
*
* @author Stuart
*/
public class Company implements Serializable {
private static final long serialVersionUID = 1L;
// Logger
private static final Logger LOG = LoggerFactory.getLogger(Company.class);
private static final String DEFAULT_STRING = "";
// Properties
@JsonProperty("id")
private int companyId = 0;
@JsonProperty("name")
private String name = DEFAULT_STRING;
@JsonProperty("description")
private String description = DEFAULT_STRING;
@JsonProperty("headquarters")
private String headquarters = DEFAULT_STRING;
@JsonProperty("homepage")
private String homepage = DEFAULT_STRING;
@JsonProperty("logo_path")
private String logoPath = DEFAULT_STRING;
@JsonProperty("parent_company")
private String parentCompany = DEFAULT_STRING;
//<editor-fold defaultstate="collapsed" desc="Getter Methods">
public int getCompanyId() {
return companyId;
}
public String getDescription() {
return description;
}
public String getHeadquarters() {
return headquarters;
}
public String getHomepage() {
return homepage;
}
public String getLogoPath() {
return logoPath;
}
public String getName() {
return name;
}
public String getParentCompany() {
return parentCompany;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Setter Methods">
public void setCompanyId(int companyId) {
this.companyId = companyId;
}
public void setDescription(String description) {
this.description = description;
}
public void setHeadquarters(String headquarters) {
this.headquarters = headquarters;
}
public void setHomepage(String homepage) {
this.homepage = homepage;
}
public void setLogoPath(String logoPath) {
this.logoPath = logoPath;
}
public void setName(String name) {
this.name = name;
}
public void setParentCompany(String parentCompany) {
this.parentCompany = parentCompany;
}
//</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.DEFAULT_STYLE);
}
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.model;
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;
/**
* Company information
*
* @author Stuart
*/
public class Company implements Serializable {
private static final long serialVersionUID = 1L;
// Logger
private static final Logger LOG = LoggerFactory.getLogger(Company.class);
private static final String DEFAULT_STRING = "";
// Properties
@JsonProperty("id")
private int companyId = 0;
@JsonProperty("name")
private String name = DEFAULT_STRING;
@JsonProperty("description")
private String description = DEFAULT_STRING;
@JsonProperty("headquarters")
private String headquarters = DEFAULT_STRING;
@JsonProperty("homepage")
private String homepage = DEFAULT_STRING;
@JsonProperty("logo_path")
private String logoPath = DEFAULT_STRING;
@JsonProperty("parent_company")
private Company parentCompany = null;
//<editor-fold defaultstate="collapsed" desc="Getter Methods">
public int getCompanyId() {
return companyId;
}
public String getDescription() {
return description;
}
public String getHeadquarters() {
return headquarters;
}
public String getHomepage() {
return homepage;
}
public String getLogoPath() {
return logoPath;
}
public String getName() {
return name;
}
public Company getParentCompany() {
return parentCompany;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Setter Methods">
public void setCompanyId(int companyId) {
this.companyId = companyId;
}
public void setDescription(String description) {
this.description = description;
}
public void setHeadquarters(String headquarters) {
this.headquarters = headquarters;
}
public void setHomepage(String homepage) {
this.homepage = homepage;
}
public void setLogoPath(String logoPath) {
this.logoPath = logoPath;
}
public void setName(String name) {
this.name = name;
}
public void setParentCompany(Company parentCompany) {
this.parentCompany = parentCompany;
}
public void setParentCompany(int id, String name, String logoPath) {
Company parent = new Company();
parent.setCompanyId(companyId);
parent.setName(name);
parent.setLogoPath(logoPath);
this.parentCompany = parent;
}
//</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.DEFAULT_STYLE);
}
}

@ -69,7 +69,7 @@ public class TheMovieDbApiTest {
private static final int ID_MOVIE_THE_AVENGERS = 24428;
private static final int ID_COLLECTION_STAR_WARS = 10;
private static final int ID_PERSON_BRUCE_WILLIS = 62;
private static final int ID_COMPANY_LUCASFILM = 1;
private static final int ID_COMPANY = 2;
private static final String COMPANY_NAME = "Marvel Studios";
private static final int ID_GENRE_ACTION = 28;
private static final String ID_KEYWORD = "1721";
@ -413,8 +413,9 @@ public class TheMovieDbApiTest {
@Test
public void testGetCompanyInfo() throws MovieDbException {
LOG.info("getCompanyInfo");
Company company = tmdb.getCompanyInfo(ID_COMPANY_LUCASFILM);
Company company = tmdb.getCompanyInfo(ID_COMPANY);
assertTrue("No company information found", company.getCompanyId() > 0);
assertNotNull("No parent company found", company.getParentCompany());
}
/**
@ -423,7 +424,7 @@ public class TheMovieDbApiTest {
@Test
public void testGetCompanyMovies() throws MovieDbException {
LOG.info("getCompanyMovies");
TmdbResultsList<MovieDb> result = tmdb.getCompanyMovies(ID_COMPANY_LUCASFILM, LANGUAGE_DEFAULT, 0);
TmdbResultsList<MovieDb> result = tmdb.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0);
assertTrue("No company movies found", !result.getResults().isEmpty());
}

Loading…
Cancel
Save