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
31 import com.hack23.cia.model.external.riksdagen.personlista.impl.PersonElement;
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.RiksdagenPersonApi;
35
36
37
38
39 @Service("riksdagenPersonElementWorkConsumerImpl")
40 final class RiksdagenPersonElementWorkConsumerImpl implements MessageListener {
41
42
43 private static final Logger LOGGER = LoggerFactory
44 .getLogger(RiksdagenPersonElementWorkConsumerImpl.class);
45
46
47 @Autowired
48 private RiksdagenUpdateService updateService;
49
50
51 @Autowired
52 private RiksdagenPersonApi riksdagenApi;
53
54
55
56
57 public RiksdagenPersonElementWorkConsumerImpl() {
58 super();
59 }
60
61 @Override
62 public void onMessage(final Message message) {
63 try {
64 updateService.update(riksdagenApi
65 .getPerson(((PersonElement) ((ObjectMessage) message)
66 .getObject()).getId()));
67 } catch (final DataFailureException | RuntimeException | JMSException e) {
68 LOGGER.warn("Error loading PersonElement",e);
69 }
70 }
71 }