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.common.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.common.util.CalendarSearchViewHelperUtil;
23  import org.kuali.student.r2.common.util.ContextUtils;
24  import org.kuali.student.r2.core.acal.dto.TermInfo;
25  import org.kuali.student.r2.core.atp.service.AtpService;
26  import org.kuali.student.r2.core.class1.type.service.TypeService;
27  import org.kuali.student.r2.core.constants.AtpServiceConstants;
28  import org.kuali.student.r2.core.constants.TypeServiceConstants;
29  
30  import javax.xml.namespace.QName;
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * This class replaces org.kuali.student.enrollment.class2.acal.service.AcademicTermLookupableImpl
36   * which was removed after being used by ks-ksink as a convenient example.
37   *
38   * @author Kuali Student Team
39   */
40  public class KitchenSinkTermInfoLookupableImpl extends LookupableImpl {
41  
42      private transient AtpService atpService;
43      private transient TypeService typeService;
44  
45      @Override
46      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
47          List<TermInfo> rList;
48          String name = fieldValues.get("code");
49          String year = fieldValues.get("startDate");
50  
51          try {
52              rList = CalendarSearchViewHelperUtil.searchForTerms(name, year, ContextUtils.createDefaultContextInfo(), getAtpService(), getTypeService());
53          }
54          catch (Exception 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  }