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.courseoffering.service.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.criteria.Predicate;
20  import org.kuali.rice.core.api.criteria.PredicateFactory;
21  import org.kuali.rice.core.api.criteria.QueryByCriteria;
22  import org.kuali.rice.krad.lookup.LookupableImpl;
23  import org.kuali.rice.krad.web.form.LookupForm;
24  import org.kuali.student.enrollment.class2.courseoffering.util.ActivityOfferingConstants;
25  import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
26  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
27  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
28  import org.kuali.student.r2.common.util.ContextUtils;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * This class //TODO ...
36   *
37   * @author Kuali Student Team
38   */
39  public class ActivityOfferingLookupableImpl extends LookupableImpl {
40  
41      @Override
42      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
43          List<ActivityOfferingInfo> activityOfferingInfos = new ArrayList<ActivityOfferingInfo>();
44  
45          try {
46              if(hasCriteria(fieldValues)){
47                  QueryByCriteria qbc = buildQueryByCriteria(fieldValues);
48                  activityOfferingInfos = getCourseOfferingService().searchForActivityOfferings(qbc, ContextUtils.createDefaultContextInfo());
49              }
50          } catch (Exception e) {
51             throw new RuntimeException(e);
52          }
53  
54          return activityOfferingInfos;
55      }
56  
57      private QueryByCriteria buildQueryByCriteria(Map<String, String> fieldValues){
58          String aoId = fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID);
59  
60          List<Predicate> predicates = new ArrayList<Predicate>();
61          if (StringUtils.isNotBlank(aoId)) {
62              predicates.add(PredicateFactory.equalIgnoreCase("id", aoId));
63          }
64  
65          QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
66          qbcBuilder.setPredicates(predicates.toArray(new Predicate[predicates.size()]));
67          QueryByCriteria qbc = qbcBuilder.build();
68  
69          return qbc;
70      }
71  
72      private boolean hasCriteria(Map<String, String> fieldValues){
73          return StringUtils.isNotBlank(fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID));
74      }
75  
76      public CourseOfferingService getCourseOfferingService() {
77          return CourseOfferingResourceLoader.loadCourseOfferingService();
78      }
79  }