1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class1.krms.service.impl;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21 import org.kuali.rice.krad.lookup.LookupableImpl;
22 import org.kuali.rice.krad.web.form.LookupForm;
23 import org.kuali.student.mock.utilities.TestHelper;
24 import org.kuali.student.r2.common.dto.ContextInfo;
25 import org.kuali.student.r2.common.dto.RichTextInfo;
26 import org.kuali.student.r2.core.search.dto.SearchParamInfo;
27 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
28 import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
29 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
30 import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
31 import org.kuali.student.r2.lum.clu.dto.CluSetInfo;
32 import org.kuali.student.r2.lum.clu.service.CluService;
33 import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
34
35 import javax.xml.namespace.QName;
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Map;
39
40
41
42
43
44
45
46 public class CourseSetsLookupableImpl extends LookupableImpl {
47
48 private ContextInfo contextInfo;
49
50 private CluService cluService;
51 @Override
52 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
53 List<CluSetInfo> cluSetInfos = new ArrayList<CluSetInfo>();
54 List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
55 String name = fieldValues.get("name");
56 String description = fieldValues.get("descr");
57
58
59 if (StringUtils.isNotBlank(name) && !name.isEmpty()) {
60 SearchParamInfo nameParam = new SearchParamInfo();
61 nameParam.setKey("cluset.queryParam.optionalName");
62 nameParam.getValues().add(name);
63 queryParamValueList.add(nameParam);
64 }
65 else if (StringUtils.isNotBlank(description) && !description.isEmpty()){
66 SearchParamInfo descriptionParam = new SearchParamInfo();
67 descriptionParam.setKey("cluset.queryParam.optionalDescription");
68 descriptionParam.getValues().add(description);
69 queryParamValueList.add(descriptionParam);
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84 SearchParamInfo reusableParam = new SearchParamInfo();
85 reusableParam.setKey("cluset.queryParam.optionalReusable");
86 reusableParam.getValues().add(Boolean.TRUE.toString());
87 queryParamValueList.add(reusableParam);
88 SearchParamInfo cluSetTypeParam = new SearchParamInfo();
89 cluSetTypeParam.setKey("cluset.queryParam.optionalType");
90 cluSetTypeParam.getValues().add("kuali.cluSet.type.CreditCourse");
91 queryParamValueList.add(cluSetTypeParam);
92 SearchRequestInfo searchRequest = new SearchRequestInfo();
93 searchRequest.setSearchKey("cluset.search.generic");
94 searchRequest.setParams(queryParamValueList);
95 SearchResultInfo clus = null;
96 try {
97 clus = getCluService().search(searchRequest, getContextInfo());
98 for (SearchResultRowInfo result : clus.getRows()) {
99 List<SearchResultCellInfo> cells = result.getCells();
100 CluSetInfo cluSetInfo = new CluSetInfo();
101 for (SearchResultCellInfo cell : cells) {
102 if ("cluset.resultColumn.cluSetId".equals(cell.getKey())) {
103 cluSetInfo.setId(cell.getValue());
104 } else if ("cluset.resultColumn.name".equals(cell.getKey())) {
105 cluSetInfo.setName(cell.getValue());
106 } else if ("cluset.resultColumn.description".equals(cell.getKey())) {
107 RichTextInfo richTextInfo = new RichTextInfo();
108 richTextInfo.setPlain(cell.getValue());
109 cluSetInfo.setDescr(richTextInfo);
110 }
111 else if ("cluset.resultColumn.type".equals(cell.getKey())) {
112 cluSetInfo.setTypeKey(cell.getValue());
113 }
114 }
115 cluSetInfos.add(cluSetInfo);
116 }
117 } catch (Exception e) {
118
119 }
120 return cluSetInfos;
121 }
122
123 private CluService getCluService() {
124 if (cluService == null) {
125 cluService = (CluService) GlobalResourceLoader.getService(new QName(CluServiceConstants.CLU_NAMESPACE, CluServiceConstants.SERVICE_NAME_LOCAL_PART));
126 }
127 return cluService;
128 }
129
130 private ContextInfo getContextInfo() {
131 if (null == contextInfo) {
132
133 contextInfo = TestHelper.getContext1();
134 }
135 return contextInfo;
136 }
137 }