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 Adi Rajesh on 6/7/12
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.constants.CommonServiceConstants;
25  import org.kuali.student.r2.common.dto.ContextInfo;
26  import org.kuali.student.r2.common.dto.RichTextInfo;
27  import org.kuali.student.r2.lum.clu.dto.CluSetInfo;
28  import org.kuali.student.r2.core.search.dto.SearchParamInfo;
29  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
30  import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
31  import org.kuali.student.r2.core.search.dto.SearchResultInfo;
32  import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
33  import org.kuali.student.r2.lum.clu.service.CluService;
34  import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
35  
36  import javax.xml.namespace.QName;
37  import java.util.ArrayList;
38  import java.util.List;
39  import java.util.Map;
40  
41  
42  /**
43   * This class //TODO ...
44   *
45   * @author Kuali Student Team
46   */
47  public class TestSetLookupableImpl extends LookupableImpl {
48  
49      private ContextInfo contextInfo;
50  
51      private CluService cluService;
52      @Override
53      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
54          List<CluSetInfo> cluSetInfos = new ArrayList<CluSetInfo>();
55          List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
56          String name = fieldValues.get("name");
57          String description = fieldValues.get("descr");
58          String standardizedTestName = fieldValues.get("longName");
59          String containsSet = fieldValues.get("containsSet");
60          if (StringUtils.isNotBlank(name) && !name.isEmpty()) {
61              SearchParamInfo testNameParam = new SearchParamInfo();
62              testNameParam.setKey("cluset.queryParam.optionalName");
63              testNameParam.getValues().add(name);
64              queryParamValueList.add(testNameParam);
65          }
66          else if (StringUtils.isNotBlank(description) && !description.isEmpty()){
67              SearchParamInfo descriptionParam = new SearchParamInfo();
68              descriptionParam.setKey("cluset.queryParam.optionalDescription");
69              descriptionParam.getValues().add(description);
70              queryParamValueList.add(descriptionParam);
71          }
72          else if (StringUtils.isNotBlank(standardizedTestName) && !standardizedTestName.isEmpty()){
73              SearchParamInfo standardizedTestNameParam = new SearchParamInfo();
74              standardizedTestNameParam.setKey("cluset.queryParam.luOptionalLongName");
75              standardizedTestNameParam.getValues().add(standardizedTestName);
76              queryParamValueList.add(standardizedTestNameParam);
77          }
78          else if (StringUtils.isNotBlank(containsSet) && !containsSet.isEmpty()){
79              SearchParamInfo containsSetParam = new SearchParamInfo();
80              containsSetParam.setKey("cluset.queryParam.optionalSubCluSetName");
81              containsSetParam.getValues().add(containsSet);
82              queryParamValueList.add(containsSetParam);
83          }
84  
85          SearchParamInfo reusableParam = new SearchParamInfo();
86          reusableParam.setKey("cluset.queryParam.optionalReusable");
87          reusableParam.getValues().add(Boolean.TRUE.toString());
88          queryParamValueList.add(reusableParam);
89          SearchParamInfo cluSetTypeParam = new SearchParamInfo();
90          cluSetTypeParam.setKey("cluset.queryParam.optionalType");
91          cluSetTypeParam.getValues().add("kuali.cluSet.type.Test");
92          queryParamValueList.add(cluSetTypeParam);
93          SearchRequestInfo searchRequest = new SearchRequestInfo();
94          searchRequest.setSearchKey("cluset.search.generic");
95          searchRequest.setParams(queryParamValueList);
96          SearchResultInfo clus = null;
97          try {
98              clus = getCluService().search(searchRequest, getContextInfo());
99              for (SearchResultRowInfo result : clus.getRows()) {
100                 List<SearchResultCellInfo> cells = result.getCells();
101                 CluSetInfo cluSetInfo = new CluSetInfo();
102                 for (SearchResultCellInfo cell : cells) {
103                     if ("cluset.resultColumn.cluSetId".equals(cell.getKey())) {
104                         cluSetInfo.setId(cell.getValue());
105                     } else if ("cluset.resultColumn.name".equals(cell.getKey())) {
106                         cluSetInfo.setName(cell.getValue());
107                     } else if ("cluset.resultColumn.description".equals(cell.getKey())) {
108                         RichTextInfo richTextInfo = new RichTextInfo();
109                         richTextInfo.setPlain(cell.getValue());
110                         cluSetInfo.setDescr(richTextInfo);
111                     }
112                     else if ("cluset.resultColumn.type".equals(cell.getKey())) {
113                         cluSetInfo.setTypeKey(cell.getValue());
114                     }
115                 }
116                 cluSetInfos.add(cluSetInfo);
117             }
118         } catch (Exception e) {
119 
120         }
121         return cluSetInfos;
122     }
123 
124     private CluService getCluService() {
125         if (cluService == null) {
126             cluService = (CluService) GlobalResourceLoader.getService(new QName(CluServiceConstants.CLU_NAMESPACE, CluServiceConstants.SERVICE_NAME_LOCAL_PART));
127         }
128         return cluService;
129     }
130 
131     private ContextInfo getContextInfo() {
132         if (null == contextInfo) {
133             //TODO - get real ContextInfo
134             contextInfo = TestHelper.getContext1();
135         }
136         return contextInfo;
137     }
138 }