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.workgenerator;
20  
21  import java.util.List;
22  import java.util.Map;
23  
24  import javax.jms.Destination;
25  import javax.jms.JMSException;
26  
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.springframework.beans.factory.annotation.Autowired;
30  import org.springframework.beans.factory.annotation.Qualifier;
31  import org.springframework.stereotype.Service;
32  
33  import com.hack23.cia.model.internal.application.data.impl.RiksdagenDataSources;
34  
35  /**
36   * The Class RiksdagenCommitteeProposalWorkGeneratorImpl.
37   */
38  @Service("RiksdagenCommitteeProposalWorkGeneratorImpl")
39  final class RiksdagenCommitteeProposalWorkGeneratorImpl extends AbstractRiksdagenDataSourcesWorkGenerator {
40  
41  	/** The Constant LOGGER. */
42  	private static final Logger LOGGER = LoggerFactory.getLogger(RiksdagenCommitteeProposalWorkGeneratorImpl.class);
43  
44  
45  	/** The committee proposal component data workdestination. */
46  	@Autowired
47  	@Qualifier("com.hack23.cia.model.external.riksdagen.utskottsforslag.impl.CommitteeProposalComponentData")
48  	private Destination committeeProposalComponentDataWorkdestination;
49  
50  
51  	/**
52  	 * Instantiates a new riksdagen committee proposal work generator impl.
53  	 */
54  	public RiksdagenCommitteeProposalWorkGeneratorImpl() {
55  		super(RiksdagenDataSources.COMMITTEE_PROPOSALS);
56  	}
57  
58  	@Override
59  	public void generateWorkOrders() {
60  		try {
61  			final List<String> avaibleCommitteeProposal = getImportService()
62  					.getAvaibleCommitteeProposal();
63  			final Map<String, String> committeeProposalComponentDataMap = getImportService()
64  					.getCommitteeProposalComponentDataMap();
65  
66  			LOGGER.info("getAvaibleCommitteeProposal()={}",avaibleCommitteeProposal.size());
67  			LOGGER.info("getCommitteeProposalComponentDataMap()={}",committeeProposalComponentDataMap.keySet().size());
68  
69  			for (final String id : avaibleCommitteeProposal) {
70  				if (!committeeProposalComponentDataMap.containsKey(id)) {
71  					getJmsSender().send(
72  							committeeProposalComponentDataWorkdestination,
73  							id);
74  
75  					LOGGER.info("load http://data.riksdagen.se/utskottsforslag/{}", id);
76  				}
77  			}
78  		} catch (final JMSException exception) {
79  			LOGGER.warn("Loading avaibleCommitteeProposal", exception);
80  		}
81  	}
82  
83  }