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.data;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.concurrent.ConcurrentHashMap;
25  
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.stereotype.Component;
28  import org.springframework.transaction.annotation.Propagation;
29  import org.springframework.transaction.annotation.Transactional;
30  
31  import com.hack23.cia.model.external.worldbank.countries.impl.CountryElement;
32  import com.hack23.cia.model.external.worldbank.indicators.impl.IndicatorElement;
33  import com.hack23.cia.service.data.api.CountryElementDAO;
34  import com.hack23.cia.service.data.api.DataDAO;
35  import com.hack23.cia.service.data.api.IndicatorElementDAO;
36  
37  /**
38   * The Class WorldbankImportServiceImpl.
39   */
40  @Component("WorldbankImportService")
41  @Transactional(propagation = Propagation.MANDATORY)
42  final class WorldbankImportServiceImpl implements WorldbankImportService {
43  
44  	/** The country element dao. */
45  	@Autowired
46  	private CountryElementDAO countryElementDAO;
47  
48  	/** The data dao. */
49  	@Autowired
50  	private DataDAO dataDAO;
51  
52  	/** The indicator element dao. */
53  	@Autowired
54  	private IndicatorElementDAO indicatorElementDAO;
55  
56  	/**
57  	 * Instantiates a new worldbank import service impl.
58  	 */
59  	public WorldbankImportServiceImpl() {
60  		super();
61  	}
62  
63  	/**
64  	 * Creates the map from list.
65  	 *
66  	 * @param all
67  	 *            the all
68  	 * @return the map
69  	 */
70  	private static Map<String, String> createMapFromList(final List<String> all) {
71  		final Map<String, String> map = new ConcurrentHashMap<>();
72  
73  		for (final String documentElement : all) {
74  			if (documentElement != null) {
75  				map.put(documentElement, documentElement);
76  			}
77  		}
78  		return map;
79  	}
80  
81  	@Override
82  	public List<IndicatorElement> getAllIndicators() {
83  		return indicatorElementDAO.getAll();
84  	}
85  
86  	@Override
87  	public Map<String, String> getWorldBankCountryMap() {
88  		final List<String> list = new ArrayList<>();
89  		for (final CountryElement countryElement : countryElementDAO.getAll()) {
90  			list.add(countryElement.getIso2Code());
91  		}
92  		return createMapFromList(list);
93  	}
94  
95  	@Override
96  	public Map<String, String> getWorldBankDataMap() {
97  		return createMapFromList(dataDAO.getIdList());
98  	}
99  
100 	@Override
101 	public Map<String, String> getWorldBankIndicatorElementMap() {
102 		final List<String> list = new ArrayList<>();
103 		for (final IndicatorElement element : indicatorElementDAO.getAll()) {
104 			list.add(element.getId());
105 		}
106 		return createMapFromList(list);
107 	}
108 
109 }