View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.ui.server.gwt;
17  
18  import com.google.gwt.user.server.rpc.RemoteServiceServlet;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.kim.api.permission.PermissionService;
21  import org.kuali.student.common.ui.client.service.BaseRpcService;
22  import org.kuali.student.common.util.security.SecurityUtils;
23  import org.kuali.student.r1.common.dictionary.old.dto.ObjectStructure;
24  import org.kuali.student.r1.common.dictionary.service.old.DictionaryService;
25  import org.kuali.student.r2.common.exceptions.*;
26  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
27  import org.kuali.student.r2.core.search.dto.SearchResultInfo;
28  import org.kuali.student.r2.core.search.service.SearchService;
29  import org.kuali.student.r2.common.util.ContextUtils;
30  import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
31  
32  import java.util.List;
33  
34  /**
35   * This abstract service delegates search & dictionary operations to the web service being
36   * remoted. Extend this class for gwt servlets only if you the service being remoted has
37   * dictionary and search operations
38   * 
39   * @author Kuali Student Team
40   * 
41   */
42  public abstract class BaseRpcGwtServletAbstract<SEI> extends RemoteServiceServlet implements BaseRpcService {
43      final Logger LOG = Logger.getLogger(BaseRpcGwtServletAbstract.class);
44      private static final long serialVersionUID = 1L;
45  
46      protected SEI service;
47      protected PermissionService permissionService;
48  
49      public SEI getService() {
50          return this.service;
51      }
52  
53      public void setService(SEI service) {
54          this.service = service;
55      };
56  
57      public PermissionService getPermissionService() {
58          return permissionService;
59      }
60  
61      public void setPermissionService(PermissionService permissionService) {
62          this.permissionService = permissionService;
63      }
64  
65      /**
66       * @see org.kuali.student.common.dictionary.service.old.DictionaryService#getObjectStructure(java.lang.String)
67       */
68      @Override
69      public ObjectStructure getObjectStructure(String objectTypeKey) {
70          return ((DictionaryService) getService()).getObjectStructure(objectTypeKey);
71      }
72  
73      /**
74       * @see org.kuali.student.common.dictionary.service.old.DictionaryService#getObjectTypes()
75       */
76      @Override
77      public List<String> getObjectTypes() {
78          return ((DictionaryService) getService()).getObjectTypes();
79      }
80  
81  
82  
83      /**
84       * @see org.kuali.student.common.search.service.SearchService#getSearchType(java.lang.String)
85       */
86  
87      @Override
88      public TypeInfo getSearchType(String searchTypeKey) {
89          try {
90              return ((SearchService) getService()).getSearchType(searchTypeKey, ContextUtils.getContextInfo());
91          } catch (DoesNotExistException e) {
92              LOG.error(e);
93          } catch (InvalidParameterException e) {
94              LOG.error(e);
95          } catch (MissingParameterException e) {
96              LOG.error(e);
97          } catch (OperationFailedException e) {
98              LOG.error(e);
99          }
100         return null;
101     }
102 
103     /**
104      * @see org.kuali.student.common.search.service.SearchService#getSearchTypes()
105      */
106 
107     @Override
108     public List<TypeInfo> getSearchTypes() {
109         try {
110             return ((SearchService) getService()).getSearchTypes(ContextUtils.getContextInfo());
111         } catch (InvalidParameterException e) {
112             LOG.error(e);
113         } catch (MissingParameterException e) {
114             LOG.error(e);
115         } catch (OperationFailedException e) {
116             LOG.error(e);
117         }
118         return null;
119     }
120 
121     /**
122      * @see org.kuali.student.common.search.service.SearchService#search(org.kuali.student.common.search.dto.SearchRequest)
123      */
124 
125     @Override
126     public SearchResultInfo search(SearchRequestInfo searchRequest) {
127         try {
128             return ((SearchService) getService()).search(searchRequest, ContextUtils.getContextInfo());
129         } catch (OperationFailedException e) {
130             LOG.error(e);
131         } catch (InvalidParameterException e) {
132             LOG.error(e);
133         } catch (PermissionDeniedException e) {
134             LOG.error(e);
135         } catch (MissingParameterException e) {
136             LOG.error(e);
137         }
138         return null;
139     }
140 
141     protected String getCurrentUser() {
142         String username = SecurityUtils.getCurrentUserId();
143         //backdoorId is only for convenience
144         if (username == null && this.getThreadLocalRequest().getSession().getAttribute("backdoorId") != null) {
145             username = (String) this.getThreadLocalRequest().getSession().getAttribute("backdoorId");
146         }
147         return username;
148     }
149 }