1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.external.riksdagen.impl;
20
21 import javax.xml.bind.JAXBElement;
22
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.beans.factory.annotation.Qualifier;
27 import org.springframework.oxm.Unmarshaller;
28 import org.springframework.stereotype.Component;
29
30 import com.hack23.cia.model.external.riksdagen.utskottsforslag.impl.CommitteeProposalComponentData;
31 import com.hack23.cia.service.external.common.api.XmlAgent;
32 import com.hack23.cia.service.external.riksdagen.api.DataFailureException;
33 import com.hack23.cia.service.external.riksdagen.api.RiksdagenCommitteeProposalApi;
34
35
36
37
38 @Component
39 final class RiksdagenCommitteeProposalApiImpl implements RiksdagenCommitteeProposalApi {
40
41
42 private static final String COMMITTE_PROPOSAL = "http://data.riksdagen.se/utskottsforslag/${ID_KEY}/xml";
43
44
45
46
47
48 private static final String HTTP_UTSKOTTSFORSLAG_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL = "http://utskottsforslag.riksdagen.external.model.cia.hack23.com/impl";
49
50
51 private static final String ID_KEY = "${ID_KEY}";
52
53
54 private static final Logger LOGGER = LoggerFactory.getLogger(RiksdagenCommitteeProposalApiImpl.class);
55
56
57
58
59
60 private static final String PROBLEM_GETTING_COMMITTEE_PROPOSAL_FOR_ID_S_FROM_DATA_RIKSDAGEN_SE = "Problem getting committee proposal for id:{} from data.riksdagen.se";
61
62
63 @Autowired
64 @Qualifier("riksdagenCommitteeProposalMarshaller")
65 private Unmarshaller riksdagenCommitteeProposalMarshaller;
66
67
68 @Autowired
69 private XmlAgent xmlAgent;
70
71
72
73
74 public RiksdagenCommitteeProposalApiImpl() {
75 super();
76 }
77
78 @Override
79 public CommitteeProposalComponentData getCommitteeProposal(final String id) throws DataFailureException {
80 try {
81 final String url = COMMITTE_PROPOSAL.replace(ID_KEY, id);
82 return ((JAXBElement<CommitteeProposalComponentData>) xmlAgent.unmarshallXml(
83 riksdagenCommitteeProposalMarshaller, url,
84 HTTP_UTSKOTTSFORSLAG_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL, null, null)).getValue();
85 } catch (final Exception e) {
86 LOGGER.warn(PROBLEM_GETTING_COMMITTEE_PROPOSAL_FOR_ID_S_FROM_DATA_RIKSDAGEN_SE, id);
87 throw new DataFailureException(e);
88 }
89 }
90
91 }