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.TopListRequest;
9   import com.hack23.cia.service.api.user.TopListResponse;
10  import com.hack23.cia.web.action.user.TopListAction;
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 TopListActionHandler.
18   */
19  public class TopListActionHandler
20          extends
21          AbstractTopListActionHandler<TopListAction, TopListRequest, TopListResponse> {
22  
23      /***
24       * Instantiates a new top list action handler.
25       *
26       * @param viewFactoryService the view factory service
27       * @param applicationManager the application manager
28       */
29      public TopListActionHandler(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 TopListRequest createServiceRequest(final TopListAction action) {
42          return new TopListRequest(getUserStateService().getUserSessionId(),
43                  action.getOperation());
44      }
45  
46      /*
47       * (non-Javadoc)
48       * 
49       * @see com.hack23.cia.web.controller.ActionHandler#getSupportedAction()
50       */
51      @SuppressWarnings("unchecked")
52      @Override
53      public final Class getSupportedAction() {
54          return TopListAction.class;
55      }
56  
57      /*
58       * (non-Javadoc)
59       * 
60       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
61       * handleSuccessResponse(com.hack23.cia.web.action.common.AbstractAction,
62       * com.hack23.cia.service.api.common.AbstractServiceResponse)
63       */
64      @Override
65      public final ModelAndView handleSuccessResponse(final TopListAction action,
66              final TopListResponse response) {
67          ModelAndView modelAndView = null;
68  
69          switch (action.getOperation()) {
70          case TopAbsent:
71              modelAndView = new ParliamentMemberListModelAndView(response
72                      .getUserSessionDTO(), action,
73                      ParliamentMemberListViewSpecification.TopAbsentView,
74                      response.getParliamentMembers());
75              break;
76          case TopPresent:
77              modelAndView = new ParliamentMemberListModelAndView(response
78                      .getUserSessionDTO(), action,
79                      ParliamentMemberListViewSpecification.TopPresentView,
80                      response.getParliamentMembers());
81              break;
82          case TopWinners:
83              modelAndView = new ParliamentMemberListModelAndView(response
84                      .getUserSessionDTO(), action,
85                      ParliamentMemberListViewSpecification.TopWinnersView,
86                      response.getParliamentMembers());
87              break;
88          case TopLosers:
89              modelAndView = new ParliamentMemberListModelAndView(response
90                      .getUserSessionDTO(), action,
91                      ParliamentMemberListViewSpecification.TopLosersView,
92                      response.getParliamentMembers());
93              break;
94          case TopRebels:
95              modelAndView = new ParliamentMemberListModelAndView(response
96                      .getUserSessionDTO(), action,
97                      ParliamentMemberListViewSpecification.TopRebelsView,
98                      response.getParliamentMembers());
99              break;
100         case TopLoyals:
101             modelAndView = new ParliamentMemberListModelAndView(response
102                     .getUserSessionDTO(), action,
103                     ParliamentMemberListViewSpecification.TopLoyalsView,
104                     response.getParliamentMembers());
105             break;
106         default:
107             break;
108         }
109         return modelAndView;
110     }
111 
112 }