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.val;
20  
21  import org.slf4j.Logger;
22  import org.slf4j.LoggerFactory;
23  import org.springframework.beans.factory.annotation.Autowired;
24  import org.springframework.stereotype.Component;
25  import org.springframework.transaction.annotation.Propagation;
26  import org.springframework.transaction.annotation.Transactional;
27  
28  import com.hack23.cia.service.data.api.SwedenPoliticalPartyDAO;
29  import com.hack23.cia.service.external.val.api.ValApi;
30  import com.hack23.cia.service.external.val.api.ValApiException;
31  
32  /**
33   * The Class ValImportServiceImpl.
34   */
35  @Component("ValImportService")
36  @Transactional(propagation = Propagation.REQUIRED)
37  final class ValImportServiceImpl implements ValImportService {
38  
39  	/** The Constant LOGGER. */
40  	private static final Logger LOGGER = LoggerFactory
41  			.getLogger(ValImportServiceImpl.class);
42  
43  	/** The sweden political party dao. */
44  	@Autowired
45  	private SwedenPoliticalPartyDAO swedenPoliticalPartyDAO;
46  
47  	/** The val api. */
48  	@Autowired
49  	private ValApi valApi;
50  
51  
52  	/**
53  	 * Instantiates a new val import service impl.
54  	 */
55  	public ValImportServiceImpl() {
56  		super();
57  	}
58  
59  
60  	@Override
61  	public void loadPoliticalParties() {
62  		if (swedenPoliticalPartyDAO.getSize() ==0) {
63  			try {
64  				swedenPoliticalPartyDAO.persist(valApi.getSwedenPoliticalParties());
65  			} catch (final ValApiException e) {
66  				LOGGER.warn("Problem loading Sweden political parties",e);
67  			}
68  			LOGGER.info("Sweden political persisted to database");
69  		} else {
70  			LOGGER.info("Sweden political parties already in database");
71  		}
72  
73  	}
74  
75  }