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.workers.data;
20  
21  import java.util.List;
22  
23  import org.springframework.beans.factory.annotation.Autowired;
24  import org.springframework.stereotype.Component;
25  import org.springframework.transaction.annotation.Propagation;
26  import org.springframework.transaction.annotation.Transactional;
27  
28  import com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData;
29  import com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData_;
30  import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
31  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer;
32  import com.hack23.cia.model.external.riksdagen.person.impl.PersonData;
33  import com.hack23.cia.model.external.riksdagen.utskottsforslag.impl.CommitteeProposalComponentData;
34  import com.hack23.cia.model.external.riksdagen.utskottsforslag.impl.CommitteeProposalComponentData_;
35  import com.hack23.cia.model.external.riksdagen.votering.impl.VoteData;
36  import com.hack23.cia.service.data.api.CommitteeProposalComponentDataDAO;
37  import com.hack23.cia.service.data.api.DocumentContentDataDAO;
38  import com.hack23.cia.service.data.api.DocumentElementDAO;
39  import com.hack23.cia.service.data.api.DocumentStatusContainerDAO;
40  import com.hack23.cia.service.data.api.PersonDataDAO;
41  import com.hack23.cia.service.data.api.VoteDataDAO;
42  
43  /**
44   * The Class RiksdagenUpdateServiceImpl.
45   */
46  @Component("RiksdagenUpdateService")
47  @Transactional(propagation = Propagation.MANDATORY)
48  final class RiksdagenUpdateServiceImpl implements RiksdagenUpdateService {
49  
50  	/** The committee proposal component data dao. */
51  	@Autowired
52  	private CommitteeProposalComponentDataDAO committeeProposalComponentDataDAO;
53  
54  	/** The document content data dao. */
55  	@Autowired
56  	private DocumentContentDataDAO documentContentDataDAO;
57  
58  	/** The document element dao. */
59  	@Autowired
60  	private DocumentElementDAO documentElementDAO;
61  
62  	/** The document status container dao. */
63  	@Autowired
64  	private DocumentStatusContainerDAO documentStatusContainerDAO;
65  
66  	/** The person data dao. */
67  	@Autowired
68  	private PersonDataDAO personDataDAO;
69  
70  	/** The vote data dao. */
71  	@Autowired
72  	private VoteDataDAO voteDataDAO;
73  
74  	/**
75  	 * Instantiates a new riksdagen update service impl.
76  	 */
77  	public RiksdagenUpdateServiceImpl() {
78  		super();
79  	}
80  
81  	@Override
82  	public void update(final PersonData personData) {
83  		if (personDataDAO.load(personData.getId()) != null) {
84  			//personDataDAO.merge(personData);
85  		} else {
86  			personDataDAO.persist(personData);
87  		}
88  	}
89  
90  	@Override
91  	public void updateCommitteeProposalComponentData(final CommitteeProposalComponentData committeeProposal) {
92  		if (committeeProposalComponentDataDAO.findFirstByProperty(CommitteeProposalComponentData_.document,
93  				committeeProposal.getDocument()) != null) {
94  			//committeeProposalComponentDataDAO.merge(committeeProposal);
95  		} else {
96  			committeeProposalComponentDataDAO.persist(committeeProposal);
97  		}
98  	}
99  
100 	@Override
101 	public void updateDocumentContentData(final DocumentContentData documentData) {
102 		if (documentContentDataDAO.findFirstByProperty(DocumentContentData_.id, documentData.getId()) != null) {
103 			// documentContentDataDAO.merge(documentData);
104 		} else {
105 			documentContentDataDAO.persist(documentData);
106 		}
107 	}
108 
109 	@Override
110 	public void updateDocumentData(final DocumentStatusContainer documentData) {
111 		documentStatusContainerDAO.persist(documentData);
112 	}
113 
114 	@Override
115 	public void updateDocumentElement(final DocumentElement documentData) {
116 		if (documentElementDAO.checkDocumentElement(documentData.getId())) {
117 			//documentElementDAO.merge(documentData);
118 		} else {
119 			documentElementDAO.persist(documentData);
120 		}
121 
122 	}
123 
124 	@Override
125 	public void updateVoteDataData(final List<VoteData> list) {
126 		if (list != null && !list.isEmpty()) {
127 			voteDataDAO.persist(list);
128 		}
129 	}
130 
131 }