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   * Created by bobhurt on 10/29/12
16   */
17  package org.kuali.student.enrollment.kitchensink;
18  
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.core.acal.dto.TermInfo;
23  import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
24  import org.kuali.student.enrollment.class2.acal.util.CalendarSearchViewHelperUtil;
25  import org.kuali.student.enrollment.common.util.ContextBuilder;
26  import org.kuali.student.r2.common.dto.ContextInfo;
27  import org.kuali.student.r2.core.constants.AcademicCalendarServiceConstants;
28  
29  import javax.xml.namespace.QName;
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * This class replaces org.kuali.student.enrollment.class2.acal.service.AcademicTermLookupableImpl
35   * which was removed after being used by ks-ksink as a convenient example.
36   *
37   * @author Kuali Student Team
38   */
39  public class KitchenSinkTermInfoLookupableImpl extends LookupableImpl {
40  
41      private transient AcademicCalendarService academicCalendarService;
42      private ContextInfo contextInfo;
43  
44      @Override
45      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
46          List<TermInfo> rList = null;
47          String name = fieldValues.get("code");
48          String year = fieldValues.get("startDate");
49  
50          try {
51              rList = CalendarSearchViewHelperUtil.searchForTerms(name, year, getContextInfo(), getAcademicCalendarService());
52          }
53          catch (Exception ex){
54              throw new RuntimeException("Error in AcademicTermLookupableImpl searching for term. name[" + name +"] year["+year +"]", ex);
55          }
56  
57          return rList;
58      }
59  
60      protected AcademicCalendarService getAcademicCalendarService() {
61          if (academicCalendarService == null) {
62              academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
63          }
64          return this.academicCalendarService;
65      }
66  
67      public ContextInfo getContextInfo() {
68          if (null == contextInfo) {
69              contextInfo = ContextBuilder.loadContextInfo();
70          }
71          return contextInfo;
72      }
73  
74  }