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.indicators.impl.IndicatorElement;
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.WorldBankIndicatorApi;
37  
38  /**
39   * The Class WorldBankIndicatorWorkGeneratorImpl.
40   */
41  @Service("WorldBankIndicatorWorkGeneratorImpl")
42  final class WorldBankIndicatorWorkGeneratorImpl extends AbstractWorldBankDataSourcesWorkGenerator {
43  
44  	/** The Constant LOGGER. */
45  	private static final Logger LOGGER = LoggerFactory
46  			.getLogger(WorldBankIndicatorWorkGeneratorImpl.class);
47  
48  	/** The indicator element workdestination. */
49  	@Autowired
50  	@Qualifier("com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement")
51  	private Destination indicatorElementWorkdestination;
52  
53  	/** The worldbank indicator api. */
54  	@Autowired
55  	private WorldBankIndicatorApi worldbankIndicatorApi;
56  
57  
58  	/**
59  	 * Instantiates a new world bank indicator work generator impl.
60  	 *
61  	 * @param datasource
62  	 *            the datasource
63  	 */
64  	public WorldBankIndicatorWorkGeneratorImpl() {
65  		super(WorldBankDataSources.INDICATORS);
66  	}
67  
68  	@Override
69  	public void generateWorkOrders() {
70  		try {
71  			final List<IndicatorElement> list =worldbankIndicatorApi.getIndicators();
72  
73  			final Map<String, String> currentSaved = getImportService()
74  					.getWorldBankIndicatorElementMap();
75  
76  			for (final IndicatorElement element : list) {
77  				if (!currentSaved.containsKey(element.getId())) {
78  					getJmsSender().send(indicatorElementWorkdestination,
79  							element);
80  				}
81  			}
82  		} catch (final JMSException | DataFailureException exception) {
83  			LOGGER.warn("jms", exception);
84  		}
85  	}
86  
87  }