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.application;
6   
7   import gnu.trove.THashMap;
8   
9   import java.util.Map;
10  
11  import com.hack23.cia.service.api.application.ApplicationManager;
12  import com.hack23.cia.service.api.application.ApplicationRequest;
13  import com.hack23.cia.service.api.application.ApplicationResponse;
14  import com.hack23.cia.web.action.application.ApplicationAction;
15  import com.hack23.cia.web.controller.common.AbstractGenericHandler;
16  import com.hack23.cia.web.viewfactory.api.application.ApplicationModelAndView;
17  import com.hack23.cia.web.viewfactory.api.application.ApplicationModelAndView.ApplicationViewSpecification;
18  import com.hack23.cia.web.viewfactory.api.common.ModelAndView;
19  import com.hack23.cia.web.viewfactory.api.common.ViewFactoryService;
20  
21  /***
22   * The Class ApplicationActionHandler.
23   */
24  public class ApplicationActionHandler
25          extends
26          AbstractGenericHandler<ApplicationAction, ApplicationRequest, ApplicationResponse> {
27  
28      /***
29       * Instantiates a new application action handler.
30       *
31       * @param viewFactoryService the view factory service
32       * @param applicationManager the application manager
33       */
34      public ApplicationActionHandler(
35              final ViewFactoryService viewFactoryService,
36              final ApplicationManager applicationManager) {
37          super(viewFactoryService, applicationManager);
38      }
39  
40      /*
41       * (non-Javadoc)
42       * 
43       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
44       * createServiceRequest(com.hack23.cia.web.action.common.AbstractAction)
45       */
46      @Override
47      public final ApplicationRequest createServiceRequest(
48              final ApplicationAction action) {
49          return new ApplicationRequest(createUserSettingMap(action.getArgs()));
50      }
51  
52      /***
53       * Creates the user setting map.
54       *
55       * @param args the args
56       * @return the map
57       */
58      private Map<String, String> createUserSettingMap(final String[] args) {
59          final Map<String, String> userSetting = new THashMap<String, String>();
60  
61          for (final String arg : args) {
62              final String[] split = arg.split("=", 2); //$NON-NLS-1$
63  
64              final String key = split[0];
65              final String value = split[1];
66  
67              userSetting.put(key, value);
68          }
69          return userSetting;
70      }
71  
72      /*
73       * (non-Javadoc)
74       * 
75       * @see com.hack23.cia.web.controller.ActionHandler#getSupportedAction()
76       */
77      @SuppressWarnings("unchecked")
78      @Override
79      public final Class getSupportedAction() {
80          return ApplicationAction.class;
81      }
82  
83      /*
84       * (non-Javadoc)
85       * 
86       * @seecom.hack23.cia.web.controller.common.AbstractGenericHandler#
87       * handleSuccessResponse(com.hack23.cia.web.action.common.AbstractAction,
88       * com.hack23.cia.service.api.common.AbstractServiceResponse)
89       */
90      @Override
91      public final ModelAndView handleSuccessResponse(
92              final ApplicationAction action, final ApplicationResponse response) {
93          final ApplicationResponse applicationResponse = response;
94          return new ApplicationModelAndView(
95                  applicationResponse.getUserSessionDTO(), action,
96                  ApplicationViewSpecification.ApplicationView,
97                  applicationResponse.getAgency(), applicationResponse
98                          .getLastDecidedCommiteeReports(),applicationResponse.getPoliticalParties());
99      }
100 
101 }