WorldbankImportServiceImpl.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.data;

  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.concurrent.ConcurrentHashMap;

  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Component;
  26. import org.springframework.transaction.annotation.Propagation;
  27. import org.springframework.transaction.annotation.Transactional;

  28. import com.hack23.cia.model.external.worldbank.countries.impl.CountryElement;
  29. import com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement;
  30. import com.hack23.cia.service.data.api.CountryElementDAO;
  31. import com.hack23.cia.service.data.api.DataDAO;
  32. import com.hack23.cia.service.data.api.IndicatorElementDAO;

  33. /**
  34.  * The Class WorldbankImportServiceImpl.
  35.  */
  36. @Component("WorldbankImportService")
  37. @Transactional(propagation = Propagation.MANDATORY)
  38. final class WorldbankImportServiceImpl implements WorldbankImportService {

  39.     /** The country element dao. */
  40.     @Autowired
  41.     private CountryElementDAO countryElementDAO;

  42.     /** The data dao. */
  43.     @Autowired
  44.     private DataDAO dataDAO;

  45.     /** The indicator element dao. */
  46.     @Autowired
  47.     private IndicatorElementDAO indicatorElementDAO;

  48.     /**
  49.      * Instantiates a new worldbank import service impl.
  50.      */
  51.     public WorldbankImportServiceImpl() {
  52.         super();
  53.     }

  54.     /**
  55.      * Creates the map from list.
  56.      *
  57.      * @param all
  58.      *            the all
  59.      * @return the map
  60.      */
  61.     private static Map<String, String> createMapFromList(final List<String> all) {
  62.         final Map<String, String> map = new ConcurrentHashMap<>();

  63.         for (final String documentElement : all) {
  64.             if (documentElement != null) {
  65.                 map.put(documentElement, documentElement);
  66.             }
  67.         }
  68.         return map;
  69.     }

  70.     @Override
  71.     public List<IndicatorElement> getAllIndicators() {
  72.         return indicatorElementDAO.getAll();
  73.     }

  74.     @Override
  75.     public Map<String, String> getWorldBankCountryMap() {
  76.         final List<String> list = new ArrayList<>();
  77.         for (final CountryElement countryElement : countryElementDAO.getAll()) {
  78.             list.add(countryElement.getIso2Code());
  79.         }
  80.         return createMapFromList(list);
  81.     }

  82.     @Override
  83.     public Map<String, String> getWorldBankDataMap() {
  84.         return createMapFromList(dataDAO.getIdList());
  85.     }

  86.     @Override
  87.     public Map<String, String> getWorldBankIndicatorElementMap() {
  88.         final List<String> list = new ArrayList<>();
  89.         for (final IndicatorElement element : indicatorElementDAO.getAll()) {
  90.             list.add(element.getId());
  91.         }
  92.         return createMapFromList(list);
  93.     }

  94. }