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.Destination;
22 import javax.jms.JMSException;
23 import javax.jms.Message;
24 import javax.jms.MessageListener;
25 import javax.jms.ObjectMessage;
26
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.beans.factory.annotation.Qualifier;
31 import org.springframework.stereotype.Service;
32 import org.springframework.transaction.annotation.Transactional;
33
34 import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
35 import com.hack23.cia.service.component.agent.impl.common.jms.JmsSender;
36 import com.hack23.cia.service.external.common.api.ProcessDataStrategy;
37 import com.hack23.cia.service.external.riksdagen.api.DataFailureException;
38 import com.hack23.cia.service.external.riksdagen.api.RiksdagenDocumentApi;
39
40
41
42
43 @Service("riksdagenLoadDocumentWorkConsumerImpl")
44 @Transactional
45 final class RiksdagenLoadDocumentWorkConsumerImpl implements
46 MessageListener {
47
48
49 private static final Logger LOGGER = LoggerFactory
50 .getLogger(RiksdagenLoadDocumentWorkConsumerImpl.class);
51
52
53
54 @Autowired
55 @Qualifier("com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement")
56 private Destination documentElementWorkdestination;
57
58
59 @Autowired
60 private RiksdagenDocumentApi riksdagenApi;
61
62
63 @Autowired
64 private JmsSender jmsSender;
65
66
67
68
69
70 public RiksdagenLoadDocumentWorkConsumerImpl() {
71 super();
72 }
73
74 @Override
75 public void onMessage(final Message message) {
76 try {
77 final LoadDocumentWork work = (LoadDocumentWork) ((ObjectMessage) message).getObject();
78
79 riksdagenApi.processDocumentList(work.getFromDate(),work.getToDate(),new DocumentElementWorkProducer());
80
81 } catch (final DataFailureException | RuntimeException | JMSException e) {
82 LOGGER.warn("Error loading riksdagen document" , e);
83 }
84 }
85
86
87
88
89
90 private class DocumentElementWorkProducer implements ProcessDataStrategy<DocumentElement> {
91
92 @Override
93 public void process(final DocumentElement t) {
94 try {
95 jmsSender.send(documentElementWorkdestination, t);
96 } catch (final JMSException e) {
97 LOGGER.warn("Error proccessing documentElement",e);
98 }
99 }
100 }
101
102 }