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.courseoffering.service.impl;
18  
19  import org.apache.commons.lang.StringUtils;
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.LookupForm;
23  import org.kuali.rice.krad.lookup.LookupableImpl;
24  import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
25  import org.kuali.student.common.util.security.ContextUtils;
26  import org.kuali.student.r2.core.organization.dto.OrgInfo;
27  
28  import java.util.ArrayList;
29  import java.util.List;
30  import java.util.Map;
31  
32  
33  /**
34   * This class provides a Lookupable implementation for Organizations
35   *
36   * @author Kuali Student Team
37   */
38  public class OrganizationInfoLookupableImpl extends LookupableImpl {
39  
40      @Override
41      public List<?> performSearch(LookupForm lookupForm, Map<String, String> searchCriteria, boolean bounded) {
42          List<OrgInfo> results = new ArrayList<OrgInfo>();
43  
44  
45          String shortName = searchCriteria.get("shortName");
46          String longName = searchCriteria.get("longName");
47  
48          QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
49          if (StringUtils.isNotBlank(longName) && !longName.isEmpty()) {
50              if (StringUtils.isNotBlank(shortName) && !shortName.isEmpty()){
51                  qBuilder.setPredicates(PredicateFactory.or(
52                          PredicateFactory.like("longName","*"+ searchCriteria.get("longName")+ "*"),
53                          PredicateFactory.like("shortName","*" + searchCriteria.get("shortName") + "*")));
54              }
55              else {
56                  qBuilder.setPredicates(PredicateFactory.like("longName","*"+ searchCriteria.get("longName")+ "*"));
57              }
58          }else if (StringUtils.isNotBlank(shortName) && !shortName.isEmpty()){
59              qBuilder.setPredicates(PredicateFactory.like("shortName","*" + searchCriteria.get("shortName") + "*"));
60          }
61          try {
62              QueryByCriteria query = qBuilder.build();
63  
64              List<OrgInfo> orgInfos = CourseOfferingManagementUtil.getOrganizationService().searchForOrgs(query, ContextUtils.createDefaultContextInfo());
65              if (!orgInfos.isEmpty()){
66                  results.addAll(orgInfos);
67              }
68          } catch (Exception e) {
69              throw new RuntimeException("Error Performing Search", e); //To change body of catch statement use File | Settings | File Templates.
70          }
71          return results;
72      }
73  }