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.AbstractUserAccountRequest;
9   import com.hack23.cia.service.api.user.AbstractUserAccountResponse;
10  import com.hack23.cia.service.api.user.LoginRequest;
11  import com.hack23.cia.service.api.user.LogoutRequest;
12  import com.hack23.cia.web.action.user.UserAccountAction;
13  import com.hack23.cia.web.viewfactory.api.common.ModelAndView;
14  import com.hack23.cia.web.viewfactory.api.common.ViewFactoryService;
15  import com.hack23.cia.web.viewfactory.api.user.UserModelAndView;
16  import com.hack23.cia.web.viewfactory.api.user.UserModelAndView.UserViewSpecification;
17  
18  /***
19   * The Class UserAccountActionHandler.
20   */
21  public class UserAccountActionHandler
22          extends
23          AbstractUserActionHandler<UserAccountAction, AbstractUserAccountRequest, AbstractUserAccountResponse> {
24  
25      /***
26       * Instantiates a new user account action handler.
27       *
28       * @param viewFactoryService the view factory service
29       * @param applicationManager the application manager
30       */
31      public UserAccountActionHandler(
32              final ViewFactoryService viewFactoryService,
33              final ApplicationManager applicationManager) {
34          super(viewFactoryService, applicationManager);
35      }
36  
37      /*
38       * (non-Javadoc)
39       * 
40       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
41       * createServiceRequest(com.hack23.cia.web.action.common.AbstractAction)
42       */
43      @Override
44      public final AbstractUserAccountRequest createServiceRequest(
45              final UserAccountAction action) {
46          AbstractUserAccountRequest userRequest = null;
47  
48          switch (action.getOperation()) {
49          case Login:
50                  userRequest = new LoginRequest(getUserStateService()
51                          .getUserSessionId(),action.getOperation(),null,null);            
52              break;
53          case Process_login:
54              userRequest = new LoginRequest(getUserStateService()
55                      .getUserSessionId(),action.getOperation(), action.getUsername(),
56                      action.getEncodedPassword());
57  
58              break;            
59          case Logout:
60              userRequest = new LogoutRequest(getUserStateService()
61                      .getUserSessionId(),action.getOperation());
62              break;
63          case Register:
64  
65              break;
66          default:
67              break;
68          }
69  
70          return userRequest;
71      }
72  
73      /*
74       * (non-Javadoc)
75       * 
76       * @see com.hack23.cia.web.controller.ActionHandler#getSupportedAction()
77       */
78      @SuppressWarnings("unchecked")
79      @Override
80      public final Class getSupportedAction() {
81          return UserAccountAction.class;
82      }
83  
84      /*
85       * (non-Javadoc)
86       * 
87       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
88       * handleSuccessResponse(com.hack23.cia.web.action.common.AbstractAction,
89       * com.hack23.cia.service.api.common.AbstractServiceResponse)
90       */
91      @Override
92      public final ModelAndView handleSuccessResponse(
93              final UserAccountAction action,
94              final AbstractUserAccountResponse response) {
95  
96          ModelAndView modelAndView = null;
97          switch (action.getOperation()) {
98          case Login:
99              modelAndView = new UserModelAndView(response.getUserSessionDTO(),response.getPoliticalParties(),
100                     action, UserViewSpecification.LoginView);
101             break;
102         case Process_login:
103             modelAndView = new UserModelAndView(response.getUserSessionDTO(),response.getPoliticalParties(),
104                     action, UserViewSpecification.UserHomeView);            
105             break;
106         case Logout:
107             modelAndView = new UserModelAndView(response.getUserSessionDTO(),response.getPoliticalParties(),
108                     action, UserViewSpecification.LogoutView);
109             break;
110         case Register:
111 
112             break;
113         default:
114             break;
115         }
116 
117         return modelAndView;
118     }
119 
120 }