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.apache.log4j.Logger;
19  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20  import org.kuali.rice.krad.lookup.LookupableImpl;
21  import org.kuali.rice.krad.web.form.LookupForm;
22  import org.kuali.student.r2.common.util.constants.AcademicCalendarServiceConstants;
23  import org.kuali.student.enrollment.acal.dto.TermInfo;
24  import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
25  import org.kuali.student.enrollment.class2.acal.util.CalendarSearchViewHelperUtil;
26  import org.kuali.student.enrollment.common.util.ContextBuilder;
27  import org.kuali.student.r2.common.dto.ContextInfo;
28  
29  import javax.xml.namespace.QName;
30  import java.util.List;
31  import java.util.Map;
32  
33  
34  public class AcademicTermLookupableImpl  extends LookupableImpl {
35      private static final long serialVersionUID = 1L;
36      private transient AcademicCalendarService academicCalendarService;
37      private ContextInfo contextInfo;
38      private final static Logger LOG = Logger.getLogger(AcademicTermLookupableImpl.class);
39  
40      @Override
41      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
42  
43          List<TermInfo> rList = null;
44          String name = fieldValues.get("code");
45          String year = fieldValues.get("startDate");
46  
47          try{
48              rList = CalendarSearchViewHelperUtil.searchForTerms(name, year, getContextInfo(), getAcademicCalendarService());
49          }   catch (Exception ex){
50              LOG.error(ex);
51              throw new RuntimeException("Error in AcademicTermLookupableImpl searching for term. name[" + name +"] year["+year +"]", ex);
52          }
53  
54          return rList;
55      }
56  
57      protected AcademicCalendarService getAcademicCalendarService() {
58           if(academicCalendarService == null) {
59               academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
60          }
61          return this.academicCalendarService;
62      }
63  
64      public ContextInfo getContextInfo() {
65          if (null == contextInfo) {
66              contextInfo = ContextBuilder.loadContextInfo();
67          }
68          return contextInfo;
69      }
70  
71  }
72