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.command;
20
21 import javax.jms.Destination;
22 import javax.jms.JMSException;
23
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Qualifier;
28 import org.springframework.stereotype.Service;
29 import org.springframework.transaction.annotation.Propagation;
30 import org.springframework.transaction.annotation.Transactional;
31
32 import com.hack23.cia.model.internal.application.data.impl.DataAgentWorkOrder;
33 import com.hack23.cia.model.internal.application.data.impl.RiksdagenDataSources;
34 import com.hack23.cia.model.internal.application.data.impl.WorldBankDataSources;
35 import com.hack23.cia.service.component.agent.api.DataAgentApi;
36 import com.hack23.cia.service.component.agent.impl.common.jms.JmsSender;
37
38
39
40
41 @Service
42 @Transactional(propagation=Propagation.REQUIRED)
43 final class DataAgentApiImpl implements DataAgentApi {
44
45
46 private static final Logger LOGGER = LoggerFactory
47 .getLogger(DataAgentApiImpl.class);
48
49
50 @Autowired
51 private JmsSender jmsSender;
52
53
54 @Autowired
55 @Qualifier("riksdagenApiAgentWorkQueue")
56 private Destination riksdagenApiDestination;
57
58
59 @Autowired
60 @Qualifier("worldbankApiAgentWorkQueue")
61 private Destination worldBankApiDestination;
62
63
64
65
66 public DataAgentApiImpl() {
67 super();
68 }
69
70 @Override
71 public void execute(final DataAgentWorkOrder workOrder) {
72 try {
73 sendMessage(workOrder);
74 } catch (final JMSException e) {
75 LOGGER.error("Jms exception:", e);
76 }
77 }
78
79
80
81
82
83
84
85
86
87 public void sendMessage(final DataAgentWorkOrder workOrder)
88 throws JMSException {
89
90 switch (workOrder.getTarget()) {
91 case MODEL_EXTERNAL_RIKSDAGEN:
92 for (final RiksdagenDataSources datasource :RiksdagenDataSources.values()) {
93 jmsSender.send(riksdagenApiDestination, datasource);
94 }
95 break;
96 case MODEL_EXTERNAL_WORLDBANK:
97 for (final WorldBankDataSources datasource :WorldBankDataSources.values()) {
98 jmsSender.send(worldBankApiDestination,datasource);
99 }
100 break;
101 default:
102 break;
103 }
104 }
105
106 }