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/31/12
16   */
17  package org.kuali.student.common.kitchensink;
18  
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.core.api.resourceloader.GlobalResourceLoader;
23  import org.kuali.rice.krad.lookup.LookupForm;
24  import org.kuali.rice.krad.lookup.LookupableImpl;
25  import org.kuali.student.common.util.security.ContextUtils;
26  import org.kuali.student.r2.core.constants.PopulationServiceConstants;
27  import org.kuali.student.r2.core.population.dto.PopulationInfo;
28  import org.kuali.student.r2.core.population.service.PopulationService;
29  
30  import javax.xml.namespace.QName;
31  import java.util.ArrayList;
32  import java.util.List;
33  import java.util.Map;
34  
35  /**
36   * This class performs a search on the name & description properties in Populations
37   *
38   * @author Kuali Student Team
39   */
40  public class KitchenSinkPopulationInfoLookupableImpl extends LookupableImpl {
41  
42      private transient PopulationService populationService;
43  
44      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
45          // build query criteria
46          String keyword = fieldValues.get("keyword");
47          keyword = keyword.isEmpty() ? "*" : keyword; //search for all if empty
48          List<Predicate> predicates = new ArrayList<Predicate>();
49          predicates.add(PredicateFactory.or(PredicateFactory.like("name", "%" + keyword + "%"),
50                  PredicateFactory.like("descrPlain", "%" + keyword + "%")));
51          QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
52          qbcBuilder.setPredicates(predicates.toArray(new Predicate[predicates.size()]));
53          QueryByCriteria qbc = qbcBuilder.build();
54  
55          // perform population search using criteria
56          List<PopulationInfo> populationInfoList;
57          try {
58              populationInfoList =
59                      getPopulationService().searchForPopulations(qbc, ContextUtils.createDefaultContextInfo());
60          }
61          catch (Exception e) {
62              throw new RuntimeException(e);
63          }
64  
65          return populationInfoList;
66      }
67  
68  
69      private PopulationService getPopulationService() {
70          if (populationService == null) {
71              populationService = (PopulationService)GlobalResourceLoader
72                      .getService(new QName(PopulationServiceConstants.NAMESPACE, "PopulationService"));
73          }
74          return populationService;
75      }
76  
77      /**
78       * Determines if given data object has associated maintenance document that allows new or copy
79       * maintenance
80       * actions
81       *
82       * @return boolean true if the maintenance new or copy action is allowed for the data object instance, false
83       *         otherwise
84       */
85      @Override
86      public boolean allowsMaintenanceNewOrCopyAction() {
87          // maintenance new or copy action not allowed
88          return false;
89      }
90  
91      /**
92       * Determines if given data object has associated maintenance document that allows delete maintenance
93       * actions.
94       *
95       * @return boolean true if the maintenance delete action is allowed for the data object instance, false otherwise
96       */
97      @Override
98      public boolean allowsMaintenanceDeleteAction(Object dataObject) {
99          // maintenance delete action not allowed
100         return false;
101     }
102 }