View Javadoc
1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.service.external.worldbank.impl;
20  
21  import java.util.List;
22  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.springframework.beans.factory.annotation.Autowired;
26  import org.springframework.beans.factory.annotation.Qualifier;
27  import org.springframework.oxm.Unmarshaller;
28  import org.springframework.stereotype.Component;
29  
30  import com.hack23.cia.model.external.worldbank.topic.impl.TopicElement;
31  import com.hack23.cia.model.external.worldbank.topic.impl.TopicsElement;
32  import com.hack23.cia.service.external.worldbank.api.DataFailureException;
33  import com.hack23.cia.service.external.worldbank.api.WorldBankTopicApi;
34  
35  /**
36   * The Class WorldbankTopicApiImpl.
37   */
38  @Component
39  final class WorldbankTopicApiImpl extends AbstractWorldBankApiImpl implements WorldBankTopicApi {
40  
41  	/** The Constant LOGGER. */
42  	private static final Logger LOGGER = LoggerFactory.getLogger(WorldbankTopicApiImpl.class);
43  
44  	/** The Constant PROBLEM_GETTING_WORLDBANK_TOPIC_LIST. */
45  	private static final String PROBLEM_GETTING_WORLDBANK_TOPIC_LIST = "Problem getting worldbank topic list";
46  
47  	/** The Constant TOPICS. */
48  	private static final String TOPICS = "http://api.worldbank.org/topics?per_page=3000";
49  
50  	/**
51  	 * The Constant
52  	 * XMLNS_WB_HTTP_TOPIC_WORLDBANK_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL.
53  	 */
54  	private static final String XMLNS_WB_HTTP_TOPIC_WORLDBANK_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL = "xmlns:wb=\"http://topic.worldbank.external.model.cia.hack23.com/impl\"";
55  
56  	/** The topics unmarshaller. */
57  	@Autowired
58  	@Qualifier("worldbankOrgTopicsMarshaller")
59  	private Unmarshaller topicsUnmarshaller;
60  
61  	/**
62  	 * Instantiates a new worldbank topic api impl.
63  	 */
64  	public WorldbankTopicApiImpl() {
65  		super();
66  	}
67  
68  	@Override
69  	public List<TopicElement> getTopics() throws DataFailureException {
70  		try {
71  			return ((TopicsElement) getXmlAgent().unmarshallXml(topicsUnmarshaller, TOPICS, null,
72  					XMLNS_WB_HTTP_WWW_WORLDBANK_ORG, XMLNS_WB_HTTP_TOPIC_WORLDBANK_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL))
73  							.getTopic();
74  		} catch (final Exception e) {
75  			LOGGER.warn(PROBLEM_GETTING_WORLDBANK_TOPIC_LIST);
76  			throw new DataFailureException(e);
77  		}
78  	}
79  
80  }