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.UserRequest;
9   import com.hack23.cia.service.api.user.UserResponse;
10  import com.hack23.cia.web.action.user.UserAction;
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.UserModelAndView;
14  import com.hack23.cia.web.viewfactory.api.user.UserModelAndView.UserViewSpecification;
15  
16  /***
17   * The Class UserActionHandler.
18   */
19  public class UserActionHandler extends
20          AbstractUserActionHandler<UserAction, UserRequest, UserResponse> {
21  
22      /***
23       * Instantiates a new user action handler.
24       *
25       * @param viewFactoryService the view factory service
26       * @param applicationManager the application manager
27       */
28      public UserActionHandler(final ViewFactoryService viewFactoryService,
29              final ApplicationManager applicationManager) {
30          super(viewFactoryService, applicationManager);
31      }
32  
33      /*
34       * (non-Javadoc)
35       * 
36       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
37       * createServiceRequest(com.hack23.cia.web.action.common.AbstractAction)
38       */
39      @Override
40      public final UserRequest createServiceRequest(final UserAction action) {
41          return new UserRequest(getUserStateService().getUserSessionId(), action
42                  .getOperation());
43      }
44  
45      /*
46       * (non-Javadoc)
47       * 
48       * @see com.hack23.cia.web.controller.ActionHandler#getSupportedAction()
49       */
50      @SuppressWarnings("unchecked")
51      @Override
52      public final Class getSupportedAction() {
53          return UserAction.class;
54      }
55  
56      /*
57       * (non-Javadoc)
58       * 
59       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
60       * handleSuccessResponse(com.hack23.cia.web.action.common.AbstractAction,
61       * com.hack23.cia.service.api.common.AbstractServiceResponse)
62       */
63      @Override
64      public final ModelAndView handleSuccessResponse(final UserAction action,
65              final UserResponse response) {
66  
67          ModelAndView modelAndView = null;
68          switch (action.getOperation()) {
69          case StartPage:
70              modelAndView = new UserModelAndView(response.getUserSessionDTO(),response.getPoliticalParties(),
71                      action, UserViewSpecification.WelcomePageView);
72              break;
73          case UserHistory:
74              modelAndView = new UserModelAndView(response.getUserSessionDTO(),response.getPoliticalParties(),
75                      action, UserViewSpecification.UserHistoryView);
76              break;
77          default:
78              break;
79          }
80  
81          return modelAndView;
82      }
83  
84  }