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.TopListActionEvent;
14 import com.hack23.cia.model.sweden.impl.ParliamentMember;
15 import com.hack23.cia.service.api.common.ServiceResponse;
16 import com.hack23.cia.service.api.user.TopListRequest;
17 import com.hack23.cia.service.api.user.TopListResponse;
18 import com.hack23.cia.service.impl.common.ParliamentService;
19 import com.hack23.cia.service.impl.common.UserSessionService;
20
21 /***
22 * The Class TopListRequestService.
23 */
24 public class TopListRequestService extends
25 AbstractUserRequestService<TopListRequest> {
26
27 /*** The number in top list. */
28 private final int numberInTopList;
29
30 /*** The parliament service. */
31 private final ParliamentService parliamentService;
32
33 /***
34 * Instantiates a new top list request service.
35 *
36 * @param userSessionService the user session service
37 * @param parliamentService the parliament service
38 * @param numberInTopList the number in top list
39 */
40 public TopListRequestService(final UserSessionService userSessionService,
41 final ParliamentService parliamentService, final int numberInTopList) {
42 super(userSessionService);
43 this.parliamentService = parliamentService;
44 this.numberInTopList = numberInTopList;
45 }
46
47
48
49
50
51
52
53
54
55 @Override
56 public final ActionEvent createActionEvent(final TopListRequest request,
57 final UserSession userSession) {
58 return new TopListActionEvent(new Date(), userSession, request
59 .getOperation());
60 }
61
62
63
64
65
66
67 @SuppressWarnings("unchecked")
68 @Override
69 public final Class getSupportedService() {
70 return TopListRequest.class;
71 }
72
73
74
75
76
77
78
79 @Override
80 public final ServiceResponse handleServiceRequest(
81 final TopListRequest request, final UserSessionDTO userSession) {
82 List<ParliamentMember> members = null;
83
84 switch (request.getOperation()) {
85 case TopAbsent:
86 members = parliamentService
87 .getCurrentTopListAbsent(numberInTopList);
88 break;
89 case TopPresent:
90 members = parliamentService
91 .getCurrentTopListPresent(numberInTopList);
92 break;
93 case TopWinners:
94 members = parliamentService
95 .getCurrentTopListWinners(numberInTopList);
96 break;
97 case TopLosers:
98 members = parliamentService
99 .getCurrentTopListLosers(numberInTopList);
100 break;
101 case TopLoyals:
102 members = parliamentService.getCurrentTopListLoyal(numberInTopList);
103 break;
104 case TopRebels:
105 members = parliamentService
106 .getCurrentTopListRebels(numberInTopList);
107 break;
108 default:
109 break;
110 }
111
112 final TopListResponse partyResponse = new TopListResponse(userSession,
113 members);
114 return partyResponse;
115 }
116 }