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.LanguageContentActionEvent;
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.Language;
14  import com.hack23.cia.model.application.impl.common.LanguageContent;
15  import com.hack23.cia.model.application.impl.common.UserSession;
16  import com.hack23.cia.service.api.admin.LanguageContentRequest;
17  import com.hack23.cia.service.api.admin.LanguageContentResponse;
18  import com.hack23.cia.service.api.common.ServiceResponse;
19  import com.hack23.cia.service.impl.common.UserSessionService;
20  
21  /***
22   * The Class LanguageContentRequestService.
23   */
24  public class LanguageContentRequestService extends
25          AbstractAdminRequestService<LanguageContentRequest> {
26  
27      /***
28       * Instantiates a new language content request service.
29       *
30       * @param userSessionService the user session service
31       * @param adminService the admin service
32       */
33      public LanguageContentRequestService(final UserSessionService userSessionService,
34              final AdminService adminService) {
35          super(userSessionService, adminService);
36      }
37  
38      /*
39       * (non-Javadoc)
40       * 
41       * @see
42       * com.hack23.cia.service.impl.common.AbstractGenericService#createActionEvent
43       * (com.hack23.cia.service.api.common.AbstractServiceRequest,
44       * com.hack23.cia.model.application.UserSession)
45       */
46      @Override
47      public final ActionEvent createActionEvent(final LanguageContentRequest request,
48              final UserSession userSession) {
49          return new LanguageContentActionEvent(new Date(), userSession, request
50                  .getAgency().getId(), request.getLanguageContent().getId(), request
51                  .getOperation());
52      }
53  
54      /*
55       * (non-Javadoc)
56       * 
57       * @see com.hack23.cia.service.common.ServiceHandler#getSupportedService()
58       */
59      @SuppressWarnings("unchecked")
60      @Override
61      public final Class getSupportedService() {
62          return LanguageContentRequest.class;
63      }
64  
65      /*
66       * (non-Javadoc)
67       * 
68       * @seecom.hack23.cia.service.common.AbstractGenericServiceHandler#
69       * handleServiceRequest(com.hack23.cia.service.api.AbstractServiceRequest)
70       */
71      @Override
72      public final ServiceResponse handleServiceRequest(
73              final LanguageContentRequest request, final UserSessionDTO userSession) {
74          LanguageContentResponse languageResponse = null;
75  
76          switch (request.getOperation()) {
77          case Update:
78              final Agency updatedAgency = this.getAdminService().updateLanguageContent(
79                      request.getAgency(), request.getLanguageContent());
80              final LanguageContent updatedLanguageContent = updatedAgency.findLanguageContent(request
81                      .getLanguageContent().getId());
82              languageResponse = new LanguageContentResponse(userSession, updatedAgency,
83                      updatedLanguageContent);
84              break;
85          case Delete:
86              Language language = request.getLanguageContent().getLanguage();
87              final Agency agency = this.getAdminService().deleteLanguageContent(
88                      request.getAgency(), request.getLanguageContent());
89              language = agency.findLanguage(language.getId());
90              languageResponse = new LanguageContentResponse(userSession, agency,language);
91              break;            
92          default:
93              break;
94          }
95          return languageResponse;
96      }
97  }