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 Daniel on 3/30/12
16   */
17  package org.kuali.student.enrollment.class2.appointment.service.impl;
18  
19  import org.kuali.rice.core.api.criteria.Predicate;
20  import org.kuali.rice.core.api.criteria.QueryByCriteria;
21  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22  import org.kuali.rice.krad.lookup.LookupableImpl;
23  import org.kuali.rice.krad.web.form.LookupForm;
24  import org.kuali.student.enrollment.class2.appointment.dto.StudentGroupWrapper;
25  import org.kuali.student.r2.common.constants.CommonServiceConstants;
26  import org.kuali.student.r2.common.dto.ContextInfo;
27  import org.kuali.student.r2.core.constants.PopulationServiceConstants;
28  import org.kuali.student.r2.core.population.dto.PopulationInfo;
29  import org.kuali.student.r2.core.population.service.PopulationService;
30  
31  import javax.xml.namespace.QName;
32  import java.util.ArrayList;
33  import java.util.List;
34  import java.util.Map;
35  
36  import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
37  import static org.kuali.rice.core.api.criteria.PredicateFactory.like;
38  
39  /**
40   * This class //TODO ...
41   *
42   * @author Kuali Student Team
43   */
44  public class StudentGroupWrapperLookupableImpl extends LookupableImpl {
45      private transient PopulationService populationService;
46      private static final long serialVersionUID = 1L;
47      @Override
48      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
49          List<StudentGroupWrapper> results = new ArrayList<StudentGroupWrapper>();
50          ContextInfo context = new ContextInfo();
51  
52          QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
53          List<Predicate> pList = new ArrayList<Predicate>();
54          qBuilder.setPredicates();
55          // create predicates for search parameters
56          for(String key : fieldValues.keySet()){
57              Predicate words = like(key,fieldValues.get(key));
58              pList.add(words);
59          }
60          if (!pList.isEmpty()){
61              Predicate[] preds = new Predicate[pList.size()];
62              pList.toArray(preds);
63              qBuilder.setPredicates(and(preds));
64          }
65  
66          try {
67              // method returns list of populationinfos.
68              java.util.List<PopulationInfo> populationInfos = getPopulationService().searchForPopulations(qBuilder.build(), context);
69              for(PopulationInfo populationInfo:populationInfos){
70                  StudentGroupWrapper studentGroupWrapper = new StudentGroupWrapper();
71                  studentGroupWrapper.setId(populationInfo.getId());
72                  studentGroupWrapper.setName(populationInfo.getName());
73                  studentGroupWrapper.setDescription(populationInfo.getDescr().getPlain());
74                  results.add(studentGroupWrapper);
75              }
76          } catch (Exception e) {
77              throw new RuntimeException("Error Performing Search", e); //To change body of catch statement use File | Settings | File Templates.
78          }
79          return results;
80      }
81  
82      protected PopulationService getPopulationService() {
83          // populationService is retrieved using global resource loader which is wired in ks-enroll-context.xml
84          if (populationService == null) {
85              // TODO: Fix with real service later on
86              populationService = (PopulationService) GlobalResourceLoader.getService(new QName(PopulationServiceConstants.NAMESPACE, "PopulationMockService"));
87  
88          }
89          return populationService;
90      }
91  
92  }