1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
40
41 @Service("WorldBankCountryWorkGeneratorImpl")
42 final class WorldBankCountryWorkGeneratorImpl extends AbstractWorldBankDataSourcesWorkGenerator {
43
44
45 private static final Logger LOGGER = LoggerFactory
46 .getLogger(WorldBankCountryWorkGeneratorImpl.class);
47
48
49 @Autowired
50 @Qualifier("com.hack23.cia.model.external.worldbank.countries.impl.CountryElement")
51 private Destination countryElementWorkdestination;
52
53
54 @Autowired
55 private WorldBankCountryApi worldbankCountryApi;
56
57
58
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 }