View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   
6   package com.hack23.cia.service.impl.admin;
7   
8   import gnu.trove.THashMap;
9   
10  import java.util.ArrayList;
11  import java.util.Date;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Map.Entry;
15  
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  import org.springframework.transaction.annotation.Propagation;
19  import org.springframework.transaction.annotation.Transactional;
20  
21  import com.hack23.cia.model.application.impl.common.Agency;
22  import com.hack23.cia.model.application.impl.common.ImageContent;
23  import com.hack23.cia.model.application.impl.common.Language;
24  import com.hack23.cia.model.sweden.impl.Ballot;
25  import com.hack23.cia.model.sweden.impl.BallotResult;
26  import com.hack23.cia.model.sweden.impl.CommitteeReport;
27  import com.hack23.cia.model.sweden.impl.ParliamentMember;
28  import com.hack23.cia.model.sweden.impl.ParliamentMemberBallotRecord;
29  import com.hack23.cia.model.sweden.impl.ParliamentMemberVoteCompareResult;
30  import com.hack23.cia.model.sweden.impl.PartyBallotResult;
31  import com.hack23.cia.model.sweden.impl.PoliticalParty;
32  import com.hack23.cia.model.sweden.impl.Vote;
33  import com.hack23.cia.model.sweden.impl.VoteMetaData;
34  import com.hack23.cia.model.sweden.impl.CommitteeReport.ImportStatus;
35  import com.hack23.cia.model.sweden.impl.Vote.Position;
36  import com.hack23.cia.model.sweden.impl.VoteMetaData.Outcome;
37  import com.hack23.cia.model.sweden.impl.VoteMetaData.PoliticalPartyBehavior;
38  import com.hack23.cia.model.sweden.impl.VoteMetaData.ProffessionalBehavior;
39  import com.hack23.cia.service.dao.AgencyDAO;
40  import com.hack23.cia.service.dao.BallotDAO;
41  import com.hack23.cia.service.dao.CommitteeReportDAO;
42  import com.hack23.cia.service.dao.ParliamentMemberDAO;
43  import com.hack23.cia.service.dao.PoliticalPartyDAO;
44  import com.hack23.cia.service.dao.ResourceDAO;
45  import com.hack23.cia.service.impl.common.ChartService;
46  
47  /***
48   * The Class LoaderServiceImpl.
49   */
50  @Transactional(propagation = Propagation.REQUIRED)
51  public class LoaderServiceImpl implements LoaderService {
52  
53  	/*** The Constant LOGGER. */
54  	private static final Log LOGGER = LogFactory
55  			.getLog(LoaderServiceImpl.class);
56  
57  	/*** The agency dao. */
58  	private final AgencyDAO agencyDAO;
59  
60  	/*** The ballot dao. */
61  	private final BallotDAO ballotDAO;
62  
63  	/*** The chart service. */
64  	private final ChartService chartService;
65  
66  	/*** The commitee report dao. */
67  	private final CommitteeReportDAO commiteeReportDAO;
68  	
69  	/*** The parliament member dao. */
70  	private final ParliamentMemberDAO parliamentMemberDAO;
71  	
72  	/*** The political party dao. */
73  	private final PoliticalPartyDAO politicalPartyDAO;
74  	
75  	/*** The resource dao. */
76  	private final ResourceDAO resourceDAO;
77  
78  	/***
79  	 * Instantiates a new loader service impl.
80  	 *
81  	 * @param commiteeReportDAO the commitee report dao
82  	 * @param ballotDAO the ballot dao
83  	 * @param parliamentMemberDAO the parliament member dao
84  	 * @param politicalPartyDAO the political party dao
85  	 * @param resourceDAO the resource dao
86  	 * @param agencyDAO the agency dao
87  	 * @param chartService the chart service
88  	 */
89  	public LoaderServiceImpl(final CommitteeReportDAO commiteeReportDAO,
90  			final BallotDAO ballotDAO,
91  			final ParliamentMemberDAO parliamentMemberDAO,
92  			final PoliticalPartyDAO politicalPartyDAO,final ResourceDAO resourceDAO,final AgencyDAO agencyDAO,final ChartService chartService) {
93  		super();
94  		this.commiteeReportDAO = commiteeReportDAO;
95  		this.ballotDAO = ballotDAO;
96  		this.parliamentMemberDAO = parliamentMemberDAO;
97  		this.politicalPartyDAO = politicalPartyDAO;
98  		this.resourceDAO = resourceDAO;
99  		this.agencyDAO = agencyDAO;
100 		this.chartService = chartService;
101 	}
102 
103 	/*
104 	 * (non-Javadoc)
105 	 * 
106 	 * @see
107 	 * com.hack23.cia.service.InformationService#addBallotInformation(java.lang
108 	 * .Long, java.util.Set)
109 	 */
110 	@Override
111 	public final void addBallotInformation(final Long ballotId,
112 			final List<Vote> voteResult) {
113 		final Ballot ballot = ballotDAO.load(ballotId);
114 
115 		if (voteResult.size() == Ballot.TOTAL_VOTES) {
116 
117 			final Map<String, ParliamentMember> allMap = createMap(parliamentMemberDAO
118 					.getAll());
119 
120 			final BallotResult ballotResult = new BallotResult();
121 			final Map<String, PartyBallotResult> partyPartyBallotResultMap = new THashMap<String, PartyBallotResult>();
122 
123 			for (final Vote vote : voteResult) {
124 				ballotResult.newVote(vote);
125 
126 				PartyBallotResult partyBallotResult = partyPartyBallotResultMap
127 						.get(vote.getParliamentMember().getParty());
128 
129 				if (partyBallotResult == null) {
130 					partyBallotResult = new PartyBallotResult();
131 					final PoliticalParty politicalParty = politicalPartyDAO
132 							.findByShortCode(vote.getParliamentMember()
133 									.getParty());
134 					partyBallotResult.setPoliticalParty(politicalParty);
135 					partyPartyBallotResultMap.put(politicalParty.getShortCode(), partyBallotResult);
136 				}
137 				partyBallotResult.newVote(vote);
138 			}
139 
140 			ballotResult.calcWinningPosition();
141 
142 			ballot.setBallotResult(ballotResult);
143 			for (final PartyBallotResult partyBallotResult : partyPartyBallotResultMap
144 					.values()) {
145 				partyBallotResult.calcWinningPosition();
146 				ballot.getPartyBallotResult().add(partyBallotResult);
147 			}
148 
149 			for (final Vote vote : voteResult) {
150 				vote.setDatum(ballot.getCommiteeReport().getDecisionDate());
151 				ParliamentMember parliamentMember = allMap.get(vote
152 						.getParliamentMember().getFuzzyKey());
153 
154 				if (parliamentMember == null) {
155 					final PoliticalParty politicalParty = politicalPartyDAO
156 							.findByShortCode(vote.getParliamentMember()
157 									.getParty());
158 					vote.getParliamentMember()
159 							.setPoliticalParty(politicalParty);
160 
161 					vote.getParliamentMember().setParliamentMemberBallotRecord(new ParliamentMemberBallotRecord());
162 					parliamentMember = parliamentMemberDAO.save(vote
163 							.getParliamentMember());
164 					politicalParty.getParliamentMembers().add(parliamentMember);
165 					politicalPartyDAO.save(politicalParty);
166 
167 					allMap
168 							.put(parliamentMember.getFuzzyKey(),
169 									parliamentMember);
170 				}
171 				vote.setParliamentMember(parliamentMember);
172 				parliamentMember.getParliamentMemberBallotRecord().newVote(vote);
173 				final VoteMetaData voteMetaData = new VoteMetaData();
174 				vote.setVoteMetaData(voteMetaData);
175 				
176 					if (ballot.getBallotResult().isLosingVote(vote)) {
177 						parliamentMember.getParliamentMemberBallotRecord()
178 								.setOpponent(parliamentMember.getParliamentMemberBallotRecord().getOpponent() + 1);
179 						voteMetaData.setOutcome(Outcome.Lost);
180 					} else {
181 						voteMetaData.setOutcome(Outcome.Won);
182 					}
183 				
184 					final PartyBallotResult partyBallotResult = partyPartyBallotResultMap.get(parliamentMember.getParty());
185 		
186 					if (partyBallotResult.isRebelVote(vote) ) {
187 						parliamentMember.getParliamentMemberBallotRecord().setRebel(parliamentMember.getParliamentMemberBallotRecord().getRebel() + 1);
188 						voteMetaData.setPoliticalPartyBehavior(PoliticalPartyBehavior.Rebel);
189 					} else {
190 						voteMetaData.setPoliticalPartyBehavior(PoliticalPartyBehavior.Loyal);
191 					}
192 				
193 					if (vote.getPosition().equals(Position.Absent)) {
194 						voteMetaData.setProffessionalBehavior(ProffessionalBehavior.Absent);
195 					} else {
196 						voteMetaData.setProffessionalBehavior(ProffessionalBehavior.Present);
197 					}
198 
199 				vote.setBallot(ballot);
200 				ballot.getVotes().add(vote);
201 				parliamentMemberDAO.save(parliamentMember);
202 			}
203 			ballot.setImportStatus(Ballot.ImportStatus.Completed);
204 			ballotDAO.save(ballot);
205 			LOGGER.info("Ballot saved " + ballot.getDescription()); //$NON-NLS-1$
206 		} else {
207 			
208 			LOGGER.info("Ballot data Missing " + ballot.getDescription()); //$NON-NLS-1$
209 		}
210 	}
211 
212 	/*
213 	 * (non-Javadoc)
214 	 * 
215 	 * @see
216 	 * com.hack23.cia.service.InformationService#addBetankandeInformation(java
217 	 * .lang.Long, java.util.Date, java.util.List)
218 	 */
219 	@Override
220 	public final void addCommitteeReportInformation(final Long id,
221 			final Date decidedDateIfAny, final List<Ballot> findVotedballot) {
222 		final CommitteeReport commiteeReport = commiteeReportDAO.load(id);
223 
224 		commiteeReport.setImportStatus(ImportStatus.Completed);
225 		commiteeReport.setDecisionDate(decidedDateIfAny);
226 
227 		if (findVotedballot != null) {
228 			for (final Ballot ballot : findVotedballot) {
229 				ballot.setDatum(decidedDateIfAny);
230 				ballot.setCommiteeReport(commiteeReport);
231 				commiteeReport.getBallots().add(ballot);
232 			}
233 		}
234 		commiteeReportDAO.save(commiteeReport);
235 		LOGGER
236 				.info("CommiteeReport updated " + commiteeReport.getDecisionDate() //$NON-NLS-1$
237 						+ "  ballots : " + commiteeReport.getBallots().size()); //$NON-NLS-1$
238 	}
239 
240 	/*
241 	 * (non-Javadoc)
242 	 * 
243 	 * @see
244 	 * com.hack23.cia.service.InformationService#addIfNotExist(com.hack23.cia
245 	 * .model.sweden.CommiteeReport)
246 	 */
247 	@Override
248 	public final void addIfNotExist(final CommitteeReport commiteeReport) {
249 		final CommitteeReport exist = commiteeReportDAO.findByName(commiteeReport
250 				.getName());
251 
252 		if (exist == null) {
253 			commiteeReportDAO.save(commiteeReport);
254 			LOGGER.info("CommiteeReport saved " + commiteeReport.getName()); //$NON-NLS-1$
255 		}
256 	}
257 
258 	/*
259 	 * (non-Javadoc)
260 	 * 
261 	 * @see
262 	 * com.hack23.cia.service.impl.admin.LoaderService#addIfNotExist(com.hack23
263 	 * .cia.model.sweden.impl.PoliticalParty)
264 	 */
265 	@Override
266 	public final void addIfNotExist(final PoliticalParty politcalParty) {
267 		final PoliticalParty exist = politicalPartyDAO.findByName(politcalParty
268 				.getName());
269 
270 		if (exist == null) {
271 			politicalPartyDAO.save(politcalParty);
272 			LOGGER.info("PoliticalParty saved " + politcalParty.getName()); //$NON-NLS-1$
273 		}
274 	}
275 
276 
277 	/***
278 	 * Calc friends.
279 	 *
280 	 * @param first the first
281 	 * @param parliamentMember the parliament member
282 	 * @param parliamentMember2 the parliament member2
283 	 * @return the parliament member vote compare result
284 	 */
285 
286 	private ParliamentMemberVoteCompareResult calcFriends(
287 			final List<Vote> first, final ParliamentMember parliamentMember,
288 			final ParliamentMember parliamentMember2) {
289 
290 		int total = 0;
291 		int with = 0;
292 
293 		for (final Vote vote : first) {
294 			final Position position = vote.getPosition();
295 
296 			final Vote vote2 = vote.getBallot().getVoteForParliamentMember(
297 					parliamentMember2);
298 
299 			if (vote2 != null) {
300 				final Position position2 = vote2.getPosition();
301 
302 				// Only compare when both parties are present and vote yes or no
303 				if (!((Position.Absent.equals(position))
304 						|| (Position.Absent.equals(position2))
305 						|| (Position.Neutral.equals(position)) || (Position.Neutral
306 						.equals(position2)))) {
307 					if (position.equals(position2)) {
308 						with++;
309 					}
310 					total++;
311 				}
312 			}
313 		}
314 
315 		float result = -1f;
316 		if (total != 0) {
317 			result = (with * 100f) / total;
318 		} else {
319 			result = -1;
320 		}
321 		return new ParliamentMemberVoteCompareResult(new Date(), total, result,
322 				parliamentMember, parliamentMember2);
323 	}
324 
325 	/***
326 	 * Creates the map.
327 	 *
328 	 * @param all the all
329 	 * @return the map
330 	 */
331 	private Map<String, ParliamentMember> createMap(
332 			final List<ParliamentMember> all) {
333 		final Map<String, ParliamentMember> map = new THashMap<String, ParliamentMember>();
334 		for (final ParliamentMember parliamentMember : all) {
335 			map.put(parliamentMember.getFuzzyKey(), parliamentMember);
336 		}
337 		return map;
338 	}
339 
340 	/*
341 	 * (non-Javadoc)
342 	 * 
343 	 * @seecom.hack23.cia.service.InformationService#
344 	 * createParliamentMemberVoteCompareResults()
345 	 */
346 	@Override
347 	public final void createParliamentMemberVoteCompareResults() {
348 		final List<ParliamentMemberVoteCompareResult> result = new ArrayList<ParliamentMemberVoteCompareResult>();
349 		final List<ParliamentMember> list = parliamentMemberDAO.getCurrentList();
350 		for (final ParliamentMember parliamentMember : list) {
351 			final List<Vote> position = parliamentMemberDAO
352 					.findVotes(parliamentMember.getId());
353 			for (final ParliamentMember parliamentMember2 : list) {
354 				if (!parliamentMember.getId().equals(parliamentMember2.getId())) {
355 					result.add(calcFriends(position, parliamentMember,
356 							parliamentMember2));
357 				}
358 			}
359 			LOGGER
360 					.info("Generated friends " + parliamentMember.getName() + " " + parliamentMember.getParty()); //$NON-NLS-1$ //$NON-NLS-2$
361 		}
362 		parliamentMemberDAO.saveParliamentMemberVoteCompareResult(result);
363 	}
364 
365 
366 	/*
367 	 * (non-Javadoc)
368 	 * 
369 	 * @seecom.hack23.cia.service.InformationService#
370 	 * deleteParliamentMemberVoteCompareResults()
371 	 */
372 	@Override
373 	public final void deleteParliamentMemberVoteCompareResults() {
374 		this.parliamentMemberDAO.deleteAllParliamentMemberVoteCompareResults();
375 	}
376 
377 	/* (non-Javadoc)
378 	 * @see com.hack23.cia.service.impl.admin.LoaderService#generateBallotCharts()
379 	 */
380 	@Override
381 	public final void generateBallotCharts(final Long ballotId) {
382 		final long agencyId =1;
383 		final Agency agency = agencyDAO.load(agencyId);
384 		final Ballot ballot = this.ballotDAO.load(ballotId);
385 		final List<PoliticalParty> allPoliticalParties = politicalPartyDAO.getAll();
386 		for (final Language language : agency.getLanguages()) {
387 			
388 			final List<ImageContent> parliamentCharts = this.chartService.generateBallotCharts(agency,ballot,allPoliticalParties,language);
389 			
390 			for (final ImageContent imageContent : parliamentCharts) {
391 				final ImageContent oldImageContentIfExist = this.resourceDAO.getImageContentByFileName(imageContent.getFileName());
392 				if (oldImageContentIfExist !=null) {
393 					this.resourceDAO.delete(oldImageContentIfExist);
394 				}
395 				this.resourceDAO.save(imageContent);
396 			}
397 		}
398 	}
399 
400 	/* (non-Javadoc)
401 	 * @see com.hack23.cia.service.impl.admin.LoaderService#generateCommitteeReportCharts()
402 	 */
403 	@Override
404 	public final void generateCommitteeReportCharts() {
405 		final long agencyId =1;
406 		final Agency agency = agencyDAO.load(agencyId);
407 		final List<Ballot> allBallots = this.ballotDAO.getAll();
408 		final List<PoliticalParty> allPoliticalParties = politicalPartyDAO.getAll();
409 		for (final Language language : agency.getLanguages()) {
410 			
411 			final List<ImageContent> parliamentCharts = this.chartService.generateCommitteeReportCharts(agency, allBallots,allPoliticalParties,language);
412 			
413 			for (final ImageContent imageContent : parliamentCharts) {
414 				final ImageContent oldImageContentIfExist = this.resourceDAO.getImageContentByFileName(imageContent.getFileName());
415 				if (oldImageContentIfExist !=null) {
416 					this.resourceDAO.delete(oldImageContentIfExist);
417 				}
418 				this.resourceDAO.save(imageContent);
419 			}
420 		}
421 	}
422 
423 	/* (non-Javadoc)
424 	 * @see com.hack23.cia.service.impl.admin.LoaderService#generateCharts()
425 	 */
426 	@Override
427 	public final void generateParliamentCharts() {
428 		final long agencyId =1;
429 		final Agency agency = agencyDAO.load(agencyId);
430 		final List<Ballot> allBallots = this.ballotDAO.getAll();
431 		final List<PoliticalParty> allPoliticalParties = politicalPartyDAO.getAll();
432 		for (final Language language : agency.getLanguages()) {
433 			
434 			final List<ImageContent> parliamentCharts = this.chartService.generateParliamentCharts(agency, allBallots,allPoliticalParties,language);
435 			
436 			for (final ImageContent imageContent : parliamentCharts) {
437 				final ImageContent oldImageContentIfExist = this.resourceDAO.getImageContentByFileName(imageContent.getFileName());
438 				if (oldImageContentIfExist !=null) {
439 					this.resourceDAO.delete(oldImageContentIfExist);
440 				}
441 				this.resourceDAO.save(imageContent);
442 			}
443 		}
444 	}
445 
446 	/* (non-Javadoc)
447 	 * @see com.hack23.cia.service.impl.admin.LoaderService#generateParliamentMemberCharts()
448 	 */
449 	@Override
450 	public final void generateParliamentMemberCharts(final Long memberId) {
451 		final ParliamentMember parliamentMember = parliamentMemberDAO.load(memberId);
452 		final long agencyId =1;
453 		final Agency agency = agencyDAO.load(agencyId);
454 		final List<Ballot> allBallots = this.ballotDAO.getAll();
455 		final List<PoliticalParty> allPoliticalParties = politicalPartyDAO.getAll();
456 		for (final Language language : agency.getLanguages()) {
457 			
458 			final List<ImageContent> parliamentCharts = this.chartService.generateParliamentMemberCharts(agency, allBallots,parliamentMember,allPoliticalParties,language);
459 			
460 			for (final ImageContent imageContent : parliamentCharts) {
461 				LOGGER.info("Saving Chart " + imageContent.getFileName());
462 				final ImageContent oldImageContentIfExist = this.resourceDAO.getImageContentByFileName(imageContent.getFileName());
463 				if (oldImageContentIfExist !=null) {
464 					this.resourceDAO.delete(oldImageContentIfExist);
465 				}
466 				this.resourceDAO.save(imageContent);
467 			}
468 		}		
469 	}
470 
471 	/* (non-Javadoc)
472 	 * @see com.hack23.cia.service.impl.admin.LoaderService#generatePoliticalPartyCharts()
473 	 */
474 	@Override
475 	public final void generatePoliticalPartyCharts(final Long politicalPartyId) {
476 		final long agencyId =1;
477 		final Agency agency = agencyDAO.load(agencyId);
478 		final List<Ballot> allBallots = this.ballotDAO.getAll();
479 		final PoliticalParty politicalParty = this.politicalPartyDAO.load(politicalPartyId);
480 		for (final Language language : agency.getLanguages()) {
481 			
482 			final List<ImageContent> parliamentCharts = this.chartService.generatePoliticalPartyCharts(agency, allBallots,politicalParty,language);
483 			
484 			for (final ImageContent imageContent : parliamentCharts) {
485 				final ImageContent oldImageContentIfExist = this.resourceDAO.getImageContentByFileName(imageContent.getFileName());
486 				if (oldImageContentIfExist !=null) {
487 					this.resourceDAO.delete(oldImageContentIfExist);
488 				}
489 				this.resourceDAO.save(imageContent);
490 			}
491 		}		
492 	}
493 
494 	/* (non-Javadoc)
495 	 * @see com.hack23.cia.service.impl.admin.LoaderService#getAllBallots()
496 	 */
497 	@Override
498 	public final List<Ballot> getAllBallots() {
499 		return ballotDAO.getAll();
500 	}
501 
502 	/*
503 	 * (non-Javadoc)
504 	 * 
505 	 * @see com.hack23.cia.service.InformationService#getAllCompletedBallotar()
506 	 */
507 	@Override
508 	public final List<Ballot> getAllCompletedBallotar() {
509 		return ballotDAO.getAllCompleted();
510 	}
511 
512 	/*
513 	 * (non-Javadoc)
514 	 * 
515 	 * @see com.hack23.cia.service.InformationService#getAllCreatedBallotar()
516 	 */
517 	@Override
518 	public final List<Ballot> getAllCreatedBallotar() {
519 		return ballotDAO.getAllCreated();
520 	}
521 
522 	/*
523 	 * (non-Javadoc)
524 	 * 
525 	 * @see com.hack23.cia.service.InformationService#getAllCreatedBetankanden()
526 	 */
527 	@Override
528 	public final List<CommitteeReport> getAllCreatedCommitteeReports() {
529 		return commiteeReportDAO.getAllCreated();
530 	}
531 
532 	/* (non-Javadoc)
533 	 * @see com.hack23.cia.service.impl.admin.LoaderService#getAllPoliticalParties()
534 	 */
535 	@Override
536 	public final List<PoliticalParty> getAllPoliticalParties() {
537 		return politicalPartyDAO.getAll();
538 	}
539 
540 	/*
541 	 * (non-Javadoc)
542 	 * 
543 	 * @see com.hack23.cia.service.InformationService#getCurrentList()
544 	 */
545 	@Override
546 	public final List<ParliamentMember> getCurrentList() {
547 		return parliamentMemberDAO.getCurrentList();
548 	}
549 
550 	/*
551 	 * (non-Javadoc)
552 	 * 
553 	 * @see
554 	 * com.hack23.cia.service.LoaderService#updateParliamentMembersEnglishWikiHref
555 	 * (java.util.Map)
556 	 */
557 	@Override
558 	public final void updateParliamentMembersEnglishWikiHref(
559 			final Map<Long, String> updates) {
560 		final List<ParliamentMember> list = new ArrayList<ParliamentMember>();
561 		for (final Entry<Long, String> entry : updates.entrySet()) {
562 			final ParliamentMember parliamentMember = this.parliamentMemberDAO
563 					.load(entry.getKey());
564 
565 			if (parliamentMember != null) {
566 				parliamentMember.setEnglishWikiHref(entry.getValue());
567 				list.add(parliamentMember);
568 			}
569 		}
570 		this.parliamentMemberDAO.saveAll(list);
571 	}
572 	
573 	/*
574 	 * (non-Javadoc)
575 	 * 
576 	 * @see
577 	 * com.hack23.cia.service.InformationService#updateParliamentMembersHref
578 	 * (java.util.Map)
579 	 */
580 	@Override
581 	public final void updateParliamentMembersHref(
582 			final Map<Long, String> updates) {
583 		final List<ParliamentMember> list = new ArrayList<ParliamentMember>();
584 		for (final Entry<Long, String> entry : updates.entrySet()) {
585 			final ParliamentMember parliamentMember = this.parliamentMemberDAO
586 					.load(entry.getKey());
587 
588 			if (parliamentMember != null) {
589 				parliamentMember.setHref(entry.getValue());
590 				list.add(parliamentMember);
591 			}
592 		}
593 		this.parliamentMemberDAO.saveAll(list);
594 	}
595 	
596 	/*
597 	 * (non-Javadoc)
598 	 * 
599 	 * @see
600 	 * com.hack23.cia.service.LoaderService#updateParliamentMembersWikiHref(
601 	 * java.util.Map)
602 	 */
603 	@Override
604 	public final void updateParliamentMembersWikiHref(
605 			final Map<Long, String> updates) {
606 		final List<ParliamentMember> list = new ArrayList<ParliamentMember>();
607 		for (final Entry<Long, String> entry : updates.entrySet()) {
608 			final ParliamentMember parliamentMember = this.parliamentMemberDAO
609 					.load(entry.getKey());
610 
611 			if (parliamentMember != null) {
612 				parliamentMember.setWikiHref(entry.getValue());
613 				list.add(parliamentMember);
614 			}
615 		}
616 		this.parliamentMemberDAO.saveAll(list);
617 	}
618 	
619 }