1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.countries.impl.CountriesElement;
31 import com.hack23.cia.model.external.worldbank.countries.impl.CountryElement;
32 import com.hack23.cia.service.external.worldbank.api.DataFailureException;
33 import com.hack23.cia.service.external.worldbank.api.WorldBankCountryApi;
34
35
36
37
38 @Component
39 final class WorldbankCountryApiImpl extends AbstractWorldBankApiImpl implements WorldBankCountryApi {
40
41
42 private static final Logger LOGGER = LoggerFactory.getLogger(WorldbankCountryApiImpl.class);
43
44
45 private static final String COUNTRIES = "http://api.worldbank.org/country?per_page=300";
46
47
48 private static final String PROBLEM_GETTING_WORLDBANK_COUNTRY_LIST = "Problem getting worldbank country list";
49
50
51
52
53
54 private static final String XMLNS_WB_HTTP_COUNTRIES_WORLDBANK_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL = "xmlns:wb=\"http://countries.worldbank.external.model.cia.hack23.com/impl\"";
55
56
57 @Autowired
58 @Qualifier("worldbankOrgCountriesMarshaller")
59 private Unmarshaller countriesUnmarshaller;
60
61
62
63
64 public WorldbankCountryApiImpl() {
65 super();
66 }
67
68 @Override
69 public List<CountryElement> getCountries() throws DataFailureException {
70 try {
71 return ((CountriesElement) getXmlAgent().unmarshallXml(countriesUnmarshaller, COUNTRIES, null,
72 XMLNS_WB_HTTP_WWW_WORLDBANK_ORG,
73 XMLNS_WB_HTTP_COUNTRIES_WORLDBANK_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL)).getCountry();
74 } catch (final Exception e) {
75 LOGGER.warn(PROBLEM_GETTING_WORLDBANK_COUNTRY_LIST);
76 throw new DataFailureException(e);
77 }
78 }
79
80 }