View Javadoc
1   /**
2    * Copyright 2012 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.enrollment.class2.acal.service.impl;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.krad.lookup.LookupForm;
20  import org.kuali.rice.krad.lookup.LookupableImpl;
21  import org.kuali.student.common.util.CalendarSearchViewHelperUtil;
22  import org.kuali.student.common.util.security.ContextUtils;
23  import org.kuali.student.r2.core.acal.dto.TermInfo;
24  import org.kuali.student.r2.core.atp.service.AtpService;
25  import org.kuali.student.r2.core.class1.type.service.TypeService;
26  import org.kuali.student.r2.core.constants.AtpServiceConstants;
27  import org.kuali.student.r2.core.constants.TypeServiceConstants;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  import javax.xml.namespace.QName;
32  import java.util.List;
33  import java.util.Map;
34  
35  
36  public class AcademicTermLookupableImpl  extends LookupableImpl {
37      private static final long serialVersionUID = 1L;
38  
39      private transient AtpService atpService;
40      private transient TypeService typeService;
41  
42      private static final Logger LOG = LoggerFactory.getLogger(AcademicTermLookupableImpl.class);
43  
44      @Override
45      public List<?> performSearch(LookupForm lookupForm, Map<String, String> searchCriteria, boolean bounded) {
46  
47          List<TermInfo> rList;
48          String name = searchCriteria.get("code");
49          String year = searchCriteria.get("startDate");
50  
51          try{
52              rList = CalendarSearchViewHelperUtil.searchForTerms(name, year, ContextUtils.createDefaultContextInfo(), getAtpService(), getTypeService());
53          }   catch (Exception ex){
54              LOG.error("Exception occurred", ex);
55              throw new RuntimeException("Error in AcademicTermLookupableImpl searching for term. name[" + name +"] year["+year +"]", ex);
56          }
57  
58          return rList;
59      }
60  
61      protected AtpService getAtpService() {
62           if(atpService == null) {
63               atpService = (AtpService) GlobalResourceLoader.getService(new QName(AtpServiceConstants.NAMESPACE, AtpServiceConstants.SERVICE_NAME_LOCAL_PART));
64          }
65          return this.atpService;
66      }
67  
68      protected TypeService getTypeService(){
69          if (typeService == null){
70              typeService = GlobalResourceLoader.getService(new QName(TypeServiceConstants.NAMESPACE, TypeServiceConstants.SERVICE_NAME_LOCAL_PART));
71          }
72          return typeService;
73      }
74  }
75