RiksdagenDocumentElementWorkConsumerImpl.java

  1. /*
  2.  * Copyright 2010-2019 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 com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
  29. import com.hack23.cia.service.component.agent.impl.common.jms.AbstractMessageListener;
  30. import com.hack23.cia.service.component.agent.impl.riksdagen.workers.data.RiksdagenUpdateService;

  31. /**
  32.  * The Class RiksdagenDocumentElementWorkConsumerImpl.
  33.  */
  34. @Service("riksdagenDocumentElementWorkConsumerImpl")
  35. final class RiksdagenDocumentElementWorkConsumerImpl extends AbstractMessageListener implements
  36. MessageListener {

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

  40.     /** The update service. */
  41.     private final RiksdagenUpdateService updateService;

  42.     /**
  43.      * Instantiates a new riksdagen document element work consumer impl.
  44.      *
  45.      * @param updateService
  46.      *            the update service
  47.      */
  48.     @Autowired
  49.     public RiksdagenDocumentElementWorkConsumerImpl(final RiksdagenUpdateService updateService) {
  50.         super();
  51.         this.updateService = updateService;
  52.     }

  53.     @Override
  54.     public void onMessage(final Message message) {
  55.         try {
  56.             configureAuthentication();
  57.             updateService.updateDocumentElement((DocumentElement) ((ObjectMessage) message).getObject());
  58.         } catch (final JMSException e) {
  59.             LOGGER.warn("Error loading riksdagen document" , e);
  60.         } finally {
  61.             clearAuthentication();          
  62.         }
  63.     }
  64. }