1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
38
39
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 }