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 Adi Rajesh on 6/7/12
16   */
17  package org.kuali.student.enrollment.class2.acal.service.impl;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.criteria.Predicate;
21  import org.kuali.rice.core.api.criteria.QueryByCriteria;
22  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
23  import org.kuali.rice.krad.lookup.LookupableImpl;
24  import org.kuali.rice.krad.web.form.LookupForm;
25  import org.kuali.student.common.util.ContextBuilder;
26  import org.kuali.student.r2.core.acal.dto.AcalEventInfo;
27  import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
28  import org.kuali.student.r2.common.dto.ContextInfo;
29  import javax.xml.namespace.QName;
30  import java.util.ArrayList;
31  import java.util.List;
32  import java.util.Map;
33  
34  import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
35  import static org.kuali.rice.core.api.criteria.PredicateFactory.like;
36  
37  
38  /**
39   * This class provides a Lookupable implementation for AcalEvent objects
40   *
41   * @author Kuali Student Team
42   */
43  public class AcalEventInfoLookupableImpl extends LookupableImpl {
44      private AcademicCalendarService academicCalendarService;
45      ContextInfo contextInfo = new ContextInfo();
46  
47      @Override
48      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
49          List<AcalEventInfo> results = new ArrayList<AcalEventInfo>();
50          QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
51          List<Predicate> pList = new ArrayList<Predicate>();
52          Predicate p;
53  
54          String name = fieldValues.get("name");
55  
56          qBuilder.setPredicates();
57          if (StringUtils.isNotBlank(name)){
58              p = like("name", "%" + name + "%");
59              pList.add(p);
60          }
61  
62          if (!pList.isEmpty()){
63              Predicate[] preds = new Predicate[pList.size()];
64              pList.toArray(preds);
65              qBuilder.setPredicates(and(preds));
66          }
67  
68          try {
69              QueryByCriteria query = qBuilder.build();
70  
71              academicCalendarService= getAcademicCalendarService();
72  
73  
74              List<AcalEventInfo> acalEventInfos = academicCalendarService.searchForAcalEvents(query, getContextInfo());
75              if (!acalEventInfos.isEmpty()){
76                  results.addAll(acalEventInfos);
77              }
78          } catch (Exception e) {
79              e.printStackTrace();
80              throw new RuntimeException("Error Performing Search",e); //To change body of catch statement use File | Settings | File Templates.
81          }
82          return results;
83      }
84  
85      protected AcademicCalendarService getAcademicCalendarService() {
86          if(academicCalendarService == null) {
87              academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService"));
88          }
89          return academicCalendarService;
90      }
91  
92      public ContextInfo getContextInfo() {
93          if (contextInfo == null){
94              contextInfo =  ContextBuilder.loadContextInfo();
95          }
96          return contextInfo;
97      }
98  }