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.text.ParseException;
22  import java.text.SimpleDateFormat;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.Locale;
26  import java.util.Map;
27  import java.util.Set;
28  
29  import javax.jms.Destination;
30  import javax.jms.JMSException;
31  
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.beans.factory.annotation.Qualifier;
36  import org.springframework.jms.JmsException;
37  import org.springframework.stereotype.Service;
38  
39  import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentType;
40  import com.hack23.cia.model.internal.application.data.impl.RiksdagenDataSources;
41  
42  /**
43   * The Class RiksdagenDocumentStatusWorkGeneratorImpl.
44   */
45  @Service("RiksdagenDocumentStatusWorkGeneratorImpl")
46  final class RiksdagenDocumentStatusWorkGeneratorImpl extends AbstractRiksdagenDataSourcesWorkGenerator {
47  
48  	/** The Constant LOGGER. */
49  	private static final Logger LOGGER = LoggerFactory.getLogger(RiksdagenDocumentStatusWorkGeneratorImpl.class);
50  
51  	/** The Constant RIKSDAGEN_JAVA_SIMPLE_DATE_FORMAT. */
52  	private static final String RIKSDAGEN_JAVA_SIMPLE_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
53  
54  	/** The document status container workdestination. */
55  	@Autowired
56  	@Qualifier("com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer")
57  	private Destination documentStatusContainerWorkdestination;
58  
59  
60  	/**
61  	 * Instantiates a new riksdagen document status work generator impl.
62  	 */
63  	public RiksdagenDocumentStatusWorkGeneratorImpl() {
64  		super(RiksdagenDataSources.DOCUMENT_STATUS);
65  	}
66  
67  	@Override
68  	public void generateWorkOrders() {
69  		try {
70  			final Map<String, String> documentStatusContainerMap = getImportService()
71  					.getDocumentStatusContainerMap();
72  
73  
74  			final List<DocumentType> selectedDocumentTypes = new ArrayList<>();
75  			selectedDocumentTypes.add(DocumentType.BET);
76  			selectedDocumentTypes.add(DocumentType.PROP);
77  			selectedDocumentTypes.add(DocumentType.MOT);
78  
79  
80  
81  			final Map<String, String> documentElementMap = getImportService()
82  					.getDocumentElementMap(
83  							new SimpleDateFormat(
84  									RIKSDAGEN_JAVA_SIMPLE_DATE_FORMAT,Locale.ENGLISH).parse("1999-12-30 00:00:00"),
85  							selectedDocumentTypes, false);
86  
87  			final Set<String> avaibleDocumentStatus = documentElementMap
88  					.keySet();
89  
90  			for (final String id : avaibleDocumentStatus) {
91  				if (!documentStatusContainerMap.containsKey(id)) {
92  					getJmsSender().send(documentStatusContainerWorkdestination,
93  							id);
94  				}
95  			}
96  
97  		} catch (final JmsException | ParseException | JMSException e) {
98  			LOGGER.warn("Loading document status ", e);
99  		}
100 	}
101 
102 }