WorldBankIndicatorWorkGeneratorImpl.java

  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. import java.util.List;
  21. import java.util.Map;

  22. import javax.jms.Destination;
  23. import javax.jms.JMSException;

  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.beans.factory.annotation.Qualifier;
  28. import org.springframework.stereotype.Service;

  29. import com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement;
  30. import com.hack23.cia.model.internal.application.data.impl.WorldBankDataSources;
  31. import com.hack23.cia.service.external.worldbank.api.DataFailureException;
  32. import com.hack23.cia.service.external.worldbank.api.WorldBankIndicatorApi;

  33. /**
  34.  * The Class WorldBankIndicatorWorkGeneratorImpl.
  35.  */
  36. @Service("WorldBankIndicatorWorkGeneratorImpl")
  37. final class WorldBankIndicatorWorkGeneratorImpl extends AbstractWorldBankDataSourcesWorkGenerator {

  38.     /** The Constant LOGGER. */
  39.     private static final Logger LOGGER = LoggerFactory
  40.             .getLogger(WorldBankIndicatorWorkGeneratorImpl.class);

  41.     /** The indicator element workdestination. */
  42.     @Autowired
  43.     @Qualifier("com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement")
  44.     private Destination indicatorElementWorkdestination;

  45.     /** The worldbank indicator api. */
  46.     @Autowired
  47.     private WorldBankIndicatorApi worldbankIndicatorApi;


  48.     /**
  49.      * Instantiates a new world bank indicator work generator impl.
  50.      *
  51.      * @param datasource
  52.      *            the datasource
  53.      */
  54.     public WorldBankIndicatorWorkGeneratorImpl() {
  55.         super(WorldBankDataSources.INDICATORS);
  56.     }

  57.     @Override
  58.     public void generateWorkOrders() {
  59.         try {
  60.             final List<IndicatorElement> list =worldbankIndicatorApi.getIndicators();

  61.             final Map<String, String> currentSaved = getImportService()
  62.                     .getWorldBankIndicatorElementMap();

  63.             for (final IndicatorElement element : list) {
  64.                 if (!currentSaved.containsKey(element.getId())) {
  65.                     getJmsSender().send(indicatorElementWorkdestination,
  66.                             element);
  67.                 }
  68.             }
  69.         } catch (final JMSException | DataFailureException exception) {
  70.             LOGGER.warn("jms", exception);
  71.         }
  72.     }

  73. }