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   package com.hack23.cia.web.controller.user;
6   
7   import com.hack23.cia.service.api.application.ApplicationManager;
8   import com.hack23.cia.service.api.user.PartyRequest;
9   import com.hack23.cia.service.api.user.TopListResponse;
10  import com.hack23.cia.web.action.user.PartyAction;
11  import com.hack23.cia.web.viewfactory.api.common.ModelAndView;
12  import com.hack23.cia.web.viewfactory.api.common.ViewFactoryService;
13  import com.hack23.cia.web.viewfactory.api.user.ParliamentMemberListModelAndView;
14  import com.hack23.cia.web.viewfactory.api.user.ParliamentMemberListModelAndView.ParliamentMemberListViewSpecification;
15  
16  /***
17   * The Class PartyActionHandler.
18   */
19  public class PartyActionHandler
20          extends
21          AbstractTopListActionHandler<PartyAction, PartyRequest, TopListResponse> {
22  
23      /***
24       * Instantiates a new party action handler.
25       *
26       * @param viewFactoryService the view factory service
27       * @param applicationManager the application manager
28       */
29      public PartyActionHandler(final ViewFactoryService viewFactoryService,
30              final ApplicationManager applicationManager) {
31          super(viewFactoryService, applicationManager);
32      }
33  
34      /*
35       * (non-Javadoc)
36       * 
37       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
38       * createServiceRequest(com.hack23.cia.web.action.common.AbstractAction)
39       */
40      @Override
41      public final PartyRequest createServiceRequest(final PartyAction action) {
42  
43          return new PartyRequest(getUserStateService().getUserSessionId(),
44                  action.getParty(), action.getOperation());
45      }
46  
47      /*
48       * (non-Javadoc)
49       * 
50       * @see com.hack23.cia.web.controller.ActionHandler#getSupportedAction()
51       */
52      @SuppressWarnings("unchecked")
53      @Override
54      public final Class getSupportedAction() {
55          return PartyAction.class;
56      }
57  
58      /*
59       * (non-Javadoc)
60       * 
61       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
62       * handleSuccessResponse(com.hack23.cia.web.action.common.AbstractAction,
63       * com.hack23.cia.service.api.common.AbstractServiceResponse)
64       */
65      @Override
66      public final ModelAndView handleSuccessResponse(final PartyAction action,
67              final TopListResponse response) {
68          ModelAndView modelAndView = null;
69  
70          switch (action.getOperation()) {
71          case TopAbsent:
72              modelAndView = new ParliamentMemberListModelAndView(response
73                      .getUserSessionDTO(), action,
74                      ParliamentMemberListViewSpecification.TopAbsentInPartyView,
75                      response.getParliamentMembers());
76              break;
77          case TopPresent:
78              modelAndView = new ParliamentMemberListModelAndView(
79                      response.getUserSessionDTO(),
80                      action,
81                      ParliamentMemberListViewSpecification.TopPresentInPartyView,
82                      response.getParliamentMembers());
83              break;
84          case TopWinners:
85              modelAndView = new ParliamentMemberListModelAndView(
86                      response.getUserSessionDTO(),
87                      action,
88                      ParliamentMemberListViewSpecification.TopWinnersInPartyView,
89                      response.getParliamentMembers());
90              break;
91          case TopLosers:
92              modelAndView = new ParliamentMemberListModelAndView(response
93                      .getUserSessionDTO(), action,
94                      ParliamentMemberListViewSpecification.TopLosersInPartyView,
95                      response.getParliamentMembers());
96              break;
97          case TopRebels:
98              modelAndView = new ParliamentMemberListModelAndView(response
99                      .getUserSessionDTO(), action,
100                     ParliamentMemberListViewSpecification.TopRebelsInPartyView,
101                     response.getParliamentMembers());
102             break;
103         case TopLoyals:
104             modelAndView = new ParliamentMemberListModelAndView(response
105                     .getUserSessionDTO(), action,
106                     ParliamentMemberListViewSpecification.TopLoyalsInPartyView,
107                     response.getParliamentMembers());
108             break;
109         default:
110             break;
111         }
112         return modelAndView;
113 
114     }
115 
116 }