RiksdagenBallotListWorkGeneratorImpl.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.workgenerator;

  20. import java.util.List;
  21. import java.util.Map;

  22. import javax.jms.Destination;

  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.stereotype.Service;

  28. import com.hack23.cia.model.external.riksdagen.voteringlista.impl.BallotDocumentElement;
  29. import com.hack23.cia.model.internal.application.data.impl.RiksdagenDataSources;
  30. import com.hack23.cia.service.external.riksdagen.api.DataFailureException;
  31. import com.hack23.cia.service.external.riksdagen.api.RiksdagenBallotApi;

  32. /**
  33.  * The Class RiksdagenBallotListWorkGeneratorImpl.
  34.  */
  35. @Service("RiksdagenBallotListWorkGeneratorImpl")
  36. final class RiksdagenBallotListWorkGeneratorImpl extends AbstractRiksdagenDataSourcesWorkGenerator {

  37.     /** The Constant LOADING_BALLOTS. */
  38.     private static final String LOADING_BALLOTS = "Loading ballots";


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


  41.     /** The vote data workdestination. */
  42.     @Autowired
  43.     @Qualifier("com.hack23.cia.model.external.riksdagen.votering.impl.VoteData")
  44.     private Destination voteDataWorkdestination;

  45.     /** The riksdagen api. */
  46.     @Autowired
  47.     private RiksdagenBallotApi riksdagenApi;

  48.     /**
  49.      * Instantiates a new riksdagen ballot list work generator impl.
  50.      */
  51.     public RiksdagenBallotListWorkGeneratorImpl() {
  52.         super(RiksdagenDataSources.BALLOT_LIST);
  53.     }

  54.     @Override
  55.     public void generateWorkOrders() {
  56.         try {
  57.             final List<BallotDocumentElement> ballotList = riksdagenApi.getBallotList();
  58.             final Map<String, String> alreadySavedIdMap = getImportService()
  59.                     .getLoadedBallotIdMap();

  60.             for (final BallotDocumentElement ballotDocument : ballotList) {
  61.                 if (!alreadySavedIdMap.containsKey(ballotDocument.getBallotId())) {
  62.                     getJmsSender().send(voteDataWorkdestination,
  63.                             ballotDocument.getBallotId());
  64.                     LOGGER.info("Load : https://data.riksdagen.se/votering/{}", ballotDocument.getBallotId());
  65.                 }
  66.             }
  67.         } catch (final DataFailureException e) {
  68.             LOGGER.warn(LOADING_BALLOTS, e);
  69.         }
  70.     }

  71. }