RiksdagenPersonElementWorkConsumerImpl.java

  1. /*
  2.  * Copyright 2010-2024 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.personlista.impl.PersonElement;
  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. import com.hack23.cia.service.external.riksdagen.api.DataFailureException;
  32. import com.hack23.cia.service.external.riksdagen.api.RiksdagenPersonApi;

  33. /**
  34.  * The Class RiksdagenPersonElementWorkConsumerImpl.
  35.  */
  36. @Service("riksdagenPersonElementWorkConsumerImpl")
  37. final class RiksdagenPersonElementWorkConsumerImpl extends AbstractMessageListener implements MessageListener {

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

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

  43.     /** The riksdagen api. */
  44.     private final RiksdagenPersonApi riksdagenApi;

  45.     /**
  46.      * Instantiates a new riksdagen person element work consumer impl.
  47.      *
  48.      * @param updateService
  49.      *            the update service
  50.      * @param riksdagenApi
  51.      *            the riksdagen api
  52.      */
  53.     @Autowired
  54.     public RiksdagenPersonElementWorkConsumerImpl(final RiksdagenUpdateService updateService,
  55.             final RiksdagenPersonApi riksdagenApi) {
  56.         super();
  57.         this.updateService = updateService;
  58.         this.riksdagenApi = riksdagenApi;
  59.     }

  60.     @Override
  61.     public void onMessage(final Message message) {
  62.         try {
  63.             configureAuthentication();
  64.             updateService.update(riksdagenApi
  65.                     .getPerson(((PersonElement) ((ObjectMessage) message)
  66.                             .getObject()).getId()));
  67.         } catch (final DataFailureException | JMSException e) {
  68.             LOGGER.warn("Error loading PersonElement",e);
  69.         } finally {
  70.             clearAuthentication();
  71.         }
  72.     }
  73. }