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;
20
21 import java.util.Collection;
22 import java.util.Map;
23
24 import javax.jms.JMSException;
25 import javax.jms.Message;
26 import javax.jms.ObjectMessage;
27
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.stereotype.Service;
32
33 import com.hack23.cia.model.internal.application.data.impl.RiksdagenDataSources;
34 import com.hack23.cia.service.component.agent.impl.common.AbstractAgentWorkConsumerImpl;
35 import com.hack23.cia.service.component.agent.impl.riksdagen.workgenerator.RiksdagenDataSourcesWorkGenerator;
36
37
38
39
40 @Service("RiksdagenApiAgentWorkConsumer")
41 final class RiksdagenApiAgentWorkConsumerImpl extends AbstractAgentWorkConsumerImpl {
42
43
44 private static final Logger LOGGER = LoggerFactory.getLogger(RiksdagenApiAgentWorkConsumerImpl.class);
45
46 private final Map<String, RiksdagenDataSourcesWorkGenerator> beansOfType;
47
48
49
50
51 public RiksdagenApiAgentWorkConsumerImpl(final ApplicationContext context) {
52 super();
53 beansOfType = context.getBeansOfType(RiksdagenDataSourcesWorkGenerator.class);
54 }
55
56 @Override
57 public void onMessage(final Message message) {
58 final ObjectMessage msg = (ObjectMessage) message;
59
60 try {
61 LOGGER.info("Consumed message:{}", msg.getObject());
62 final RiksdagenDataSources dataSource = (RiksdagenDataSources) msg.getObject();
63
64 final Collection<RiksdagenDataSourcesWorkGenerator> values = beansOfType.values();
65
66 for (final RiksdagenDataSourcesWorkGenerator riksdagenDataSourcesWorkGenerator : values) {
67 if (riksdagenDataSourcesWorkGenerator.matches(dataSource)) {
68 riksdagenDataSourcesWorkGenerator.generateWorkOrders();
69 return;
70 }
71 }
72 LOGGER.warn("Missing import for :{}", dataSource);
73
74 } catch (final JMSException exception) {
75 LOGGER.warn("jms", exception);
76 }
77 }
78
79 }