1
2
3
4
5 package com.hack23.cia.service.impl.user;
6
7 import java.util.Date;
8 import java.util.List;
9
10 import com.hack23.cia.model.application.dto.common.UserSessionDTO;
11 import com.hack23.cia.model.application.impl.common.ActionEvent;
12 import com.hack23.cia.model.application.impl.common.UserSession;
13 import com.hack23.cia.model.application.impl.user.PartyActionEvent;
14 import com.hack23.cia.model.sweden.impl.ParliamentMember;
15 import com.hack23.cia.model.sweden.impl.PoliticalParty;
16 import com.hack23.cia.service.api.common.ServiceResponse;
17 import com.hack23.cia.service.api.user.PartyRequest;
18 import com.hack23.cia.service.api.user.TopListResponse;
19 import com.hack23.cia.service.impl.common.ParliamentService;
20 import com.hack23.cia.service.impl.common.UserSessionService;
21
22 /***
23 * The Class PartyRequestService.
24 */
25 public class PartyRequestService extends
26 AbstractParliamentRequestService<PartyRequest> {
27
28 /*** The number in top list. */
29 private final int numberInTopList;
30
31 /***
32 * Instantiates a new party request service.
33 *
34 * @param userSessionService the user session service
35 * @param parliamentService the parliament service
36 * @param numberInTopList the number in top list
37 */
38 public PartyRequestService(final UserSessionService userSessionService,
39 final ParliamentService parliamentService, final int numberInTopList) {
40 super(userSessionService, parliamentService);
41 this.numberInTopList = numberInTopList;
42 }
43
44
45
46
47
48
49
50
51
52 @Override
53 public final ActionEvent createActionEvent(final PartyRequest request,
54 final UserSession userSession) {
55 return new PartyActionEvent(new Date(), userSession,
56 request.getParty(), request.getOperation());
57 }
58
59
60
61
62
63
64 @SuppressWarnings("unchecked")
65 @Override
66 public final Class getSupportedService() {
67 return PartyRequest.class;
68 }
69
70
71
72
73
74
75
76 @Override
77 public final ServiceResponse handleServiceRequest(
78 final PartyRequest request, final UserSessionDTO userSession) {
79 List<ParliamentMember> members = null;
80
81 final PoliticalParty politicalParty = getParliamentService().findPoliticalPartyByShortCode(request.getParty());
82
83 switch (request.getOperation()) {
84 case TopAbsent:
85 members = getParliamentService().getCurrentTopListAbsentInParty(
86 numberInTopList, politicalParty.getShortCode());
87 break;
88 case TopPresent:
89 members = getParliamentService().getCurrentTopListPresentInParty(
90 numberInTopList, politicalParty.getShortCode());
91 break;
92 case TopWinners:
93 members = getParliamentService().getCurrentTopListWinnersInParty(
94 numberInTopList, politicalParty.getShortCode());
95 break;
96 case TopLosers:
97 members = getParliamentService().getCurrentTopListLosersInParty(
98 numberInTopList, politicalParty.getShortCode());
99 break;
100 case TopLoyals:
101 members = getParliamentService().getCurrentTopListLoyalInParty(
102 numberInTopList, politicalParty.getShortCode());
103 break;
104 case TopRebels:
105 members = getParliamentService().getCurrentTopListRebelsInParty(
106 numberInTopList, politicalParty.getShortCode());
107 break;
108 default:
109 break;
110 }
111
112 final TopListResponse partyResponse = new TopListResponse(userSession,
113 members);
114 return partyResponse;
115 }
116 }