1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
34
35 @Component("ValImportService")
36 @Transactional(propagation = Propagation.REQUIRED)
37 final class ValImportServiceImpl implements ValImportService {
38
39
40 private static final Logger LOGGER = LoggerFactory
41 .getLogger(ValImportServiceImpl.class);
42
43
44 @Autowired
45 private SwedenPoliticalPartyDAO swedenPoliticalPartyDAO;
46
47
48 @Autowired
49 private ValApi valApi;
50
51
52
53
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 }