View Javadoc
1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
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   * The Class RiksdagenPersonElementWorkConsumerImpl.
38   */
39  @Service("riksdagenPersonElementWorkConsumerImpl")
40  final class RiksdagenPersonElementWorkConsumerImpl implements MessageListener {
41  
42  	/** The Constant LOGGER. */
43  	private static final Logger LOGGER = LoggerFactory
44  			.getLogger(RiksdagenPersonElementWorkConsumerImpl.class);
45  
46  	/** The import service. */
47  	@Autowired
48  	private RiksdagenUpdateService updateService;
49  
50  	/** The riksdagen api. */
51  	@Autowired
52  	private RiksdagenPersonApi riksdagenApi;
53  
54  	/**
55  	 * Instantiates a new riksdagen person element work consumer impl.
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  }