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.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20 import org.kuali.rice.krad.lookup.LookupableImpl;
21 import org.kuali.rice.krad.web.form.LookupForm;
22 import org.kuali.student.r2.common.constants.CommonServiceConstants;
23 import org.kuali.student.r2.common.dto.ContextInfo;
24 import org.kuali.student.r2.common.dto.RichTextInfo;
25 import org.kuali.student.r2.common.util.ContextUtils;
26 import org.kuali.student.r2.lum.clu.dto.CluSetInfo;
27 import org.kuali.student.r2.core.search.dto.SearchParamInfo;
28 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
29 import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
30 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
31 import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
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 public class TestSetLookupableImpl extends LookupableImpl {
46
47 private CluService cluService;
48
49 @Override
50 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
51 List<CluSetInfo> cluSetInfos = new ArrayList<CluSetInfo>();
52 List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
53 String name = fieldValues.get("name");
54 String description = fieldValues.get("descr");
55 String standardizedTestName = fieldValues.get("longName");
56 String containsSet = fieldValues.get("containsSet");
57 if (StringUtils.isNotBlank(name) && !name.isEmpty()) {
58 SearchParamInfo testNameParam = new SearchParamInfo();
59 testNameParam.setKey("cluset.queryParam.optionalName");
60 testNameParam.getValues().add(name);
61 queryParamValueList.add(testNameParam);
62 }
63 else if (StringUtils.isNotBlank(description) && !description.isEmpty()){
64 SearchParamInfo descriptionParam = new SearchParamInfo();
65 descriptionParam.setKey("cluset.queryParam.optionalDescription");
66 descriptionParam.getValues().add(description);
67 queryParamValueList.add(descriptionParam);
68 }
69 else if (StringUtils.isNotBlank(standardizedTestName) && !standardizedTestName.isEmpty()){
70 SearchParamInfo standardizedTestNameParam = new SearchParamInfo();
71 standardizedTestNameParam.setKey("cluset.queryParam.luOptionalLongName");
72 standardizedTestNameParam.getValues().add(standardizedTestName);
73 queryParamValueList.add(standardizedTestNameParam);
74 }
75 else if (StringUtils.isNotBlank(containsSet) && !containsSet.isEmpty()){
76 SearchParamInfo containsSetParam = new SearchParamInfo();
77 containsSetParam.setKey("cluset.queryParam.optionalSubCluSetName");
78 containsSetParam.getValues().add(containsSet);
79 queryParamValueList.add(containsSetParam);
80 }
81
82 SearchParamInfo reusableParam = new SearchParamInfo();
83 reusableParam.setKey("cluset.queryParam.optionalReusable");
84 reusableParam.getValues().add(Boolean.TRUE.toString());
85 queryParamValueList.add(reusableParam);
86 SearchParamInfo cluSetTypeParam = new SearchParamInfo();
87 cluSetTypeParam.setKey("cluset.queryParam.optionalType");
88 cluSetTypeParam.getValues().add(CluServiceConstants.CLUSET_TYPE_TEST);
89 queryParamValueList.add(cluSetTypeParam);
90 SearchRequestInfo searchRequest = new SearchRequestInfo();
91 searchRequest.setSearchKey("cluset.search.generic");
92 searchRequest.setParams(queryParamValueList);
93
94 try {
95 SearchResultInfo clus = getCluService().search(searchRequest, ContextUtils.createDefaultContextInfo());
96 for (SearchResultRowInfo result : clus.getRows()) {
97 List<SearchResultCellInfo> cells = result.getCells();
98 CluSetInfo cluSetInfo = new CluSetInfo();
99 for (SearchResultCellInfo cell : cells) {
100 if ("cluset.resultColumn.cluSetId".equals(cell.getKey())) {
101 cluSetInfo.setId(cell.getValue());
102 } else if ("cluset.resultColumn.name".equals(cell.getKey())) {
103 cluSetInfo.setName(cell.getValue());
104 } else if ("cluset.resultColumn.description".equals(cell.getKey())) {
105 RichTextInfo richTextInfo = new RichTextInfo();
106 richTextInfo.setPlain(cell.getValue());
107 cluSetInfo.setDescr(richTextInfo);
108 }
109 else if ("cluset.resultColumn.type".equals(cell.getKey())) {
110 cluSetInfo.setTypeKey(cell.getValue());
111 }
112 }
113 cluSetInfos.add(cluSetInfo);
114 }
115 } catch (Exception e) {
116
117 }
118 return cluSetInfos;
119 }
120
121 private CluService getCluService() {
122 if (cluService == null) {
123 cluService = GlobalResourceLoader.getService(new QName(CluServiceConstants.CLU_NAMESPACE, CluServiceConstants.SERVICE_NAME_LOCAL_PART));
124 }
125 return cluService;
126 }
127
128 }