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