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.riksdagen.workers;
20
21 import javax.jms.JMSException;
22 import javax.jms.Message;
23 import javax.jms.MessageListener;
24 import javax.jms.ObjectMessage;
25
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Service;
30 import org.springframework.transaction.annotation.Transactional;
31
32 import com.hack23.cia.service.component.agent.impl.riksdagen.workers.data.RiksdagenUpdateService;
33 import com.hack23.cia.service.external.riksdagen.api.DataFailureException;
34 import com.hack23.cia.service.external.riksdagen.api.RiksdagenBallotApi;
35
36
37
38
39 @Service("riksdagenVoteDataWorkConsumerImpl")
40 @Transactional
41 final class RiksdagenVoteDataWorkConsumerImpl implements MessageListener {
42
43
44 private static final Logger LOGGER = LoggerFactory.getLogger(RiksdagenVoteDataWorkConsumerImpl.class);
45
46
47 @Autowired
48 private RiksdagenUpdateService updateService;
49
50
51 @Autowired
52 private RiksdagenBallotApi riksdagenApi;
53
54
55
56
57 public RiksdagenVoteDataWorkConsumerImpl() {
58 super();
59 }
60
61 @Override
62 public void onMessage(final Message message) {
63 final String ballotId;
64 try {
65 ballotId = (String) ((ObjectMessage) message).getObject();
66 try {
67 updateService.updateVoteDataData(riksdagenApi.getBallot(ballotId));
68 } catch (final DataFailureException | RuntimeException e) {
69 LOGGER.warn("Eror loading riksdagen voteData:" + ballotId + " errorMessage:", e);
70 }
71 } catch (final JMSException e) {
72 LOGGER.warn("No Valid input", e);
73 }
74 }
75 }