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.component.agent.impl.worldbank.workgenerator;
20  
21  import java.util.List;
22  import java.util.Map;
23  
24  import javax.jms.Destination;
25  import javax.jms.JMSException;
26  
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.springframework.beans.factory.annotation.Autowired;
30  import org.springframework.beans.factory.annotation.Qualifier;
31  import org.springframework.stereotype.Service;
32  
33  import com.hack23.cia.model.external.worldbank.countries.impl.CountryElement;
34  import com.hack23.cia.model.internal.application.data.impl.WorldBankDataSources;
35  import com.hack23.cia.service.external.worldbank.api.DataFailureException;
36  import com.hack23.cia.service.external.worldbank.api.WorldBankCountryApi;
37  
38  /**
39   * The Class WorldBankCountryWorkGeneratorImpl.
40   */
41  @Service("WorldBankCountryWorkGeneratorImpl")
42  final class WorldBankCountryWorkGeneratorImpl extends AbstractWorldBankDataSourcesWorkGenerator {
43  
44  	/** The Constant LOGGER. */
45  	private static final Logger LOGGER = LoggerFactory
46  			.getLogger(WorldBankCountryWorkGeneratorImpl.class);
47  
48  	/** The country element workdestination. */
49  	@Autowired
50  	@Qualifier("com.hack23.cia.model.external.worldbank.countries.impl.CountryElement")
51  	private Destination countryElementWorkdestination;
52  
53  	/** The worldbank country api. */
54  	@Autowired
55  	private WorldBankCountryApi worldbankCountryApi;
56  
57  	/**
58  	 * Instantiates a new world bank country work generator impl.
59  	 */
60  	public WorldBankCountryWorkGeneratorImpl() {
61  		super(WorldBankDataSources.COUNTRIES);
62  	}
63  
64  	@Override
65  	public void generateWorkOrders() {
66  		try {
67  			final List<CountryElement> countryList = worldbankCountryApi.getCountries();
68  			final Map<String, String> currentSaved = getImportService().getWorldBankCountryMap();
69  
70  			for (final CountryElement countryElement : countryList) {
71  				if (countryElement.getCapitalCity() != null && countryElement.getCapitalCity().length() > 0 && !currentSaved.containsKey(countryElement.getIso2Code())) {
72  					getJmsSender().send(countryElementWorkdestination,
73  							countryElement);
74  				}
75  			}
76  		} catch (final JMSException | DataFailureException exception) {
77  			LOGGER.warn("jms", exception);
78  		}
79  	}
80  
81  }