View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.lum.lu.ui.krms.service.impl;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.krad.lookup.LookupForm;
20  import org.kuali.student.common.uif.service.impl.KSLookupableImpl;
21  import org.kuali.student.lum.lu.ui.krms.util.CluSearchUtil;
22  import org.kuali.student.common.util.security.ContextUtils;
23  import org.kuali.student.r2.core.search.dto.SearchParamInfo;
24  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
25  import org.kuali.student.r2.core.search.dto.SearchResultInfo;
26  import org.kuali.student.r2.lum.clu.service.CluService;
27  import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
28  
29  import javax.xml.namespace.QName;
30  import java.util.ArrayList;
31  import java.util.List;
32  import java.util.Map;
33  
34  import static org.apache.commons.lang.StringUtils.isEmpty;
35  
36  /**
37   * Lookupable Implementation for Programs
38   *
39   * @author Kuali Student Team
40   */
41  public class ProgramInfoLookupableImpl extends KSLookupableImpl {
42  
43  	private static final long serialVersionUID = 1L;	
44  	
45      private transient CluService cluService;
46  
47      public enum QueryParamEnum {
48          ID("lu.queryParam.luOptionalId","id"),
49          TITLE("lu.queryParam.luOptionalLongName", "title"),
50          CODE("lu.queryParam.luOptionalCode", "code"),
51          DESCRIPTION("lu.queryParam.luOptionalDescr", "description");
52  
53          private final String fieldValue;
54          private final String queryKey;
55  
56          QueryParamEnum(String qKey, String fValue) {
57              this.queryKey = qKey;
58              this.fieldValue = fValue;
59          }
60  
61          public String getFieldValue() {
62              return fieldValue;
63          }
64  
65          public String getQueryKey() {
66              return queryKey;
67          }
68      }
69  
70      @Override
71      public List<?> performSearch(LookupForm lookupForm, Map<String, String> searchCriteria, boolean bounded) {
72  
73          List<SearchParamInfo> searchParams = new ArrayList<SearchParamInfo>();
74          searchParams.add(CluSearchUtil.getTypeSearchParamForProgram());
75          searchParams.add(CluSearchUtil.getApprovedStateSearchParam());
76          for (QueryParamEnum qpEnum : QueryParamEnum.values()) {
77              String fieldValue = searchCriteria.get(qpEnum.getFieldValue());
78              if ( ! isEmpty(fieldValue) ) {
79                  SearchParamInfo qpv = new SearchParamInfo();
80                  qpv.setKey(qpEnum.getQueryKey());
81                  qpv.getValues().add(fieldValue);
82                  searchParams.add(qpv);
83              }
84          }
85  
86          SearchRequestInfo searchRequest = new SearchRequestInfo();
87          searchRequest.setParams(searchParams);
88          searchRequest.setSearchKey("lu.search.current");
89          searchRequest.setSortColumn("lu.resultColumn.luOptionalCode");
90  
91          try {
92              SearchResultInfo searchResult = getCluService().search(searchRequest, ContextUtils.getContextInfo());
93              return CluSearchUtil.resolveCluSearchResultSet(searchResult);
94          } catch (Exception e) {
95              throw new RuntimeException(e);
96          }
97      }
98  
99      protected CluService getCluService() {
100         if(cluService == null) {
101             cluService = (CluService)GlobalResourceLoader.getService(new QName(CluServiceConstants.CLU_NAMESPACE,CluServiceConstants.SERVICE_NAME_LOCAL_PART));
102         }
103         return this.cluService;
104     }
105 
106 }