RiksdagenCommitteeProposalComponentDataWorkConsumerImpl.java

  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. import javax.jms.JMSException;
  21. import javax.jms.Message;
  22. import javax.jms.MessageListener;
  23. import javax.jms.ObjectMessage;

  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;

  29. import com.hack23.cia.service.component.agent.impl.riksdagen.workers.data.RiksdagenUpdateService;
  30. import com.hack23.cia.service.external.riksdagen.api.DataFailureException;
  31. import com.hack23.cia.service.external.riksdagen.api.RiksdagenCommitteeProposalApi;

  32. /**
  33.  * The Class RiksdagenCommitteeProposalComponentDataWorkConsumerImpl.
  34.  */
  35. @Service("riksdagenCommitteeProposalComponentDataWorkConsumerImpl")
  36. @Transactional
  37. final class RiksdagenCommitteeProposalComponentDataWorkConsumerImpl implements MessageListener {

  38.     /** The Constant LOGGER. */
  39.     private static final Logger LOGGER = LoggerFactory
  40.             .getLogger(RiksdagenCommitteeProposalComponentDataWorkConsumerImpl.class);

  41.     /** The import service. */
  42.     @Autowired
  43.     private RiksdagenUpdateService updateService;

  44.     /** The riksdagen api. */
  45.     @Autowired
  46.     private RiksdagenCommitteeProposalApi riksdagenApi;


  47.     /**
  48.      * Instantiates a new riksdagen committee proposal component data work
  49.      * consumer impl.
  50.      */
  51.     public RiksdagenCommitteeProposalComponentDataWorkConsumerImpl() {
  52.         super();
  53.     }


  54.     @Override
  55.     public void onMessage(final Message message) {
  56.         try {
  57.             updateService.updateCommitteeProposalComponentData(riksdagenApi
  58.                     .getCommitteeProposal((String) ((ObjectMessage) message)
  59.                             .getObject()));
  60.         } catch (final DataFailureException | RuntimeException | JMSException e) {
  61.             LOGGER.warn("Error loading CommitteeProposalComponentData" , e);
  62.         }
  63.     }
  64. }