Added wrapper class for config to remove dependency on runtime settings

master
Omertron 14 years ago
parent 20422642d0
commit bbcecbc85f

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
/**
@ -74,9 +73,8 @@ public class TheMovieDb {
public TheMovieDb(String apiKey) throws IOException {
this.apiKey = apiKey;
URL configUrl = tmdbConfigUrl.getQueryUrl("");
mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
tmdbConfig = mapper.readValue(configUrl, TmdbConfiguration.class);
mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, false);
WrapperConfig wc = mapper.readValue(configUrl, WrapperConfig.class);
tmdbConfig = wc.getTmdbConfiguration();
FilteringLayout.addApiKey(apiKey);
}

@ -17,13 +17,11 @@ import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.jackson.annotate.JsonAnySetter;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;
/**
*
* @author stuart.boston
*/
@JsonRootName("images")
public class TmdbConfiguration {
/*
@ -80,6 +78,7 @@ public class TmdbConfiguration {
/**
* Copy the data from the passed object to this one
*
* @param config
*/
public void clone(TmdbConfiguration config) {
@ -91,11 +90,12 @@ public class TmdbConfiguration {
/**
* Check that the poster size is valid
*
* @param posterSize
* @return
*/
public boolean isValidPosterSize(String posterSize) {
if (StringUtils.isBlank(posterSize)) {
if (StringUtils.isBlank(posterSize) || posterSizes.isEmpty()) {
return false;
}
return posterSizes.contains(posterSize);
@ -103,11 +103,12 @@ public class TmdbConfiguration {
/**
* Check that the backdrop size is valid
*
* @param backdropSize
* @return
*/
public boolean isValidBackdropSize(String backdropSize) {
if (StringUtils.isBlank(backdropSize)) {
if (StringUtils.isBlank(backdropSize) || backdropSizes.isEmpty()) {
return false;
}
return backdropSizes.contains(backdropSize);
@ -115,11 +116,12 @@ public class TmdbConfiguration {
/**
* Check that the profile size is valid
*
* @param profileSize
* @return
*/
public boolean isValidProfileSize(String profileSize) {
if (StringUtils.isBlank(profileSize)) {
if (StringUtils.isBlank(profileSize) || profileSizes.isEmpty()) {
return false;
}
return profileSizes.contains(profileSize);
@ -127,6 +129,7 @@ public class TmdbConfiguration {
/**
* Check to see if the size is valid for any of the images types
*
* @param sizeToCheck
* @return
*/
@ -136,6 +139,7 @@ public class TmdbConfiguration {
/**
* Handle unknown properties and print a message
*
* @param key
* @param value
*/

@ -0,0 +1,57 @@
/*
* Copyright (c) 2004-2012 YAMJ Members
* http://code.google.com/p/moviejukebox/people/list
*
* Web: http://code.google.com/p/moviejukebox/
*
* This software is licensed under a Creative Commons License
* See this page: http://code.google.com/p/moviejukebox/wiki/License
*
* For any reuse or distribution, you must make clear to others the
* license terms of this work.
*/
package com.moviejukebox.themoviedb.wrapper;
import com.moviejukebox.themoviedb.model.TmdbConfiguration;
import org.apache.log4j.Logger;
import org.codehaus.jackson.annotate.JsonAnySetter;
import org.codehaus.jackson.annotate.JsonProperty;
/**
*
* @author Stuart
*/
public class WrapperConfig {
/*
* Logger
*/
private static final Logger LOGGER = Logger.getLogger(WrapperConfig.class);
/*
* Properties
*/
@JsonProperty("images")
private TmdbConfiguration tmdbConfiguration;
public TmdbConfiguration getTmdbConfiguration() {
return tmdbConfiguration;
}
public void setTmdbConfiguration(TmdbConfiguration tmdbConfiguration) {
this.tmdbConfiguration = tmdbConfiguration;
}
/**
* 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.warn(sb.toString());
}
}
Loading…
Cancel
Save