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.service.impl.admin;
6   
7   import java.util.Date;
8   
9   import com.hack23.cia.model.application.dto.common.UserSessionDTO;
10  import com.hack23.cia.model.application.impl.admin.AgencyActionEvent;
11  import com.hack23.cia.model.application.impl.common.ActionEvent;
12  import com.hack23.cia.model.application.impl.common.Agency;
13  import com.hack23.cia.model.application.impl.common.UserSession;
14  import com.hack23.cia.service.api.admin.AgencyRequest;
15  import com.hack23.cia.service.api.admin.AgencyResponse;
16  import com.hack23.cia.service.api.common.ServiceResponse;
17  import com.hack23.cia.service.impl.common.UserSessionService;
18  
19  /***
20   * The Class AgencyRequestService.
21   */
22  public class AgencyRequestService extends
23          AbstractAdminRequestService<AgencyRequest> {
24  
25      /***
26       * Instantiates a new agency request service.
27       *
28       * @param userSessionService the user session service
29       * @param adminService the admin service
30       */
31      public AgencyRequestService(final UserSessionService userSessionService,
32              final AdminService adminService) {
33          super(userSessionService, adminService);
34      }
35  
36      /*
37       * (non-Javadoc)
38       * 
39       * @see
40       * com.hack23.cia.service.impl.common.AbstractGenericService#createActionEvent
41       * (com.hack23.cia.service.api.common.AbstractServiceRequest,
42       * com.hack23.cia.model.application.UserSession)
43       */
44      @Override
45      public final ActionEvent createActionEvent(final AgencyRequest request,
46              final UserSession userSession) {
47          return new AgencyActionEvent(new Date(), userSession, request
48                  .getOperation(), request.getAgencyId());
49      }
50  
51      /*
52       * (non-Javadoc)
53       * 
54       * @see com.hack23.cia.service.common.ServiceHandler#getSupportedService()
55       */
56      @SuppressWarnings("unchecked")
57      @Override
58      public final Class getSupportedService() {
59          return AgencyRequest.class;
60      }
61  
62      /*
63       * (non-Javadoc)
64       * 
65       * @seecom.hack23.cia.service.common.AbstractGenericServiceHandler#
66       * handleServiceRequest(com.hack23.cia.service.api.AbstractServiceRequest)
67       */
68      @Override
69      public final ServiceResponse handleServiceRequest(
70              final AgencyRequest request, final UserSessionDTO userSession) {
71          AgencyResponse agencyResponse = null;
72          Agency agency = null;
73          
74          if (request.getAgencyId() != null) {
75              agency = this.getAdminService().loadAgency(request.getAgencyId());
76          } else {
77              agency = this.getAdminService().loadAgency();
78          }
79  
80  
81          switch (request.getOperation()) {
82          case UpdateAgency:
83              agencyResponse = new AgencyResponse(userSession, this
84                      .getAdminService().updateAgency(request.getAgency()));
85              break;
86          case AddPortal:
87              agencyResponse = new AgencyResponse(userSession, this
88                      .getAdminService().addPortal(agency));
89              break;
90          case AddLanguage:
91              agencyResponse = new AgencyResponse(userSession, this
92                      .getAdminService().addLanguage(agency));
93              break;
94          case ConfigureAgency:
95              agencyResponse = new AgencyResponse(userSession, agency);
96              break;
97          default:
98              break;
99          }
100 
101         return agencyResponse;
102     }
103 }