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.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   * This class //TODO ...
43   *
44   * @author Kuali Student Team
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  //        String courseName = fieldValues.get("longName");
58  //        String containsSet = fieldValues.get("containsSet");
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  //        else if (StringUtils.isNotBlank(courseName) && !courseName.isEmpty()){
72  //            SearchParamInfo courseNameParam = new SearchParamInfo();
73  //            courseNameParam.setKey("cluset.queryParam.luOptionalLongName");
74  //            courseNameParam.getValues().add(courseName);
75  //            queryParamValueList.add(courseNameParam);
76  //        }
77  //        else if (StringUtils.isNotBlank(containsSet) && !containsSet.isEmpty()){
78  //            SearchParamInfo containsSetParam = new SearchParamInfo();
79  //            containsSetParam.setKey("cluset.queryParam.optionalSubCluSetName");
80  //            containsSetParam.getValues().add(containsSet);
81  //            queryParamValueList.add(containsSetParam);
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             //TODO - get real ContextInfo
133             contextInfo = TestHelper.getContext1();
134         }
135         return contextInfo;
136     }
137 }