View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.LookupableImpl;
20  import org.kuali.rice.krad.web.form.LookupForm;
21  import org.kuali.student.lum.lu.ui.krms.dto.CluInformation;
22  import org.kuali.student.r2.common.dto.RichTextInfo;
23  import org.kuali.student.r2.common.util.ContextUtils;
24  import org.kuali.student.r2.common.util.constants.ProgramServiceConstants;
25  import org.kuali.student.r2.core.search.dto.SearchParamInfo;
26  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
27  import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
28  import org.kuali.student.r2.core.search.dto.SearchResultInfo;
29  import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
30  import org.kuali.student.r2.lum.clu.service.CluService;
31  import org.kuali.student.r2.lum.program.service.ProgramService;
32  import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
33  
34  import javax.xml.namespace.QName;
35  import java.util.ArrayList;
36  import java.util.List;
37  import java.util.Map;
38  
39  import static org.apache.commons.lang.StringUtils.isEmpty;
40  
41  /**
42   * Lookupable Implementation for Programs
43   *
44   * @author Kuali Student Team
45   */
46  public class ProgramInfoLookupableImpl extends LookupableImpl {
47  	private static final long serialVersionUID = 1L;	
48  	
49      private transient CluService cluService;
50      private ProgramService programService;
51  
52      public enum QueryParamEnum {
53          ID("lu.queryParam.luOptionalId","id"),
54          TITLE("lu.queryParam.luOptionalLongName", "title"),
55          CODE("lu.queryParam.luOptionalCode", "code"),
56          DESCRIPTION("lu.queryParam.luOptionalDescr", "description");
57  
58          private final String fieldValue;
59          private final String queryKey;
60  
61          QueryParamEnum(String qKey, String fValue) {
62              this.queryKey = qKey;
63              this.fieldValue = fValue;
64          }
65  
66          public String getFieldValue() {
67              return fieldValue;
68          }
69  
70          public String getQueryKey() {
71              return queryKey;
72          }
73      }
74  
75      @Override
76      protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
77          List <CluInformation> programInfoList = new ArrayList<CluInformation>();
78          List<SearchParamInfo> searchParams = new ArrayList<SearchParamInfo>();
79          SearchParamInfo qpv1 = new SearchParamInfo();
80          qpv1.setKey("lu.queryParam.luOptionalType");
81  //        qpv1.getValues().add("kuali.lu.type.CreditCourse");
82          qpv1.getValues().add("kuali.lu.type.credential.Baccalaureate");
83          qpv1.getValues().add("kuali.lu.type.credential.Masters");
84          qpv1.getValues().add("kuali.lu.type.credential.Professional");
85          qpv1.getValues().add("kuali.lu.type.credential.Doctoral");
86          qpv1.getValues().add("kuali.lu.type.credential.UndergraduateCertificate");
87          qpv1.getValues().add("kuali.lu.type.credential.GraduateCertificate");
88          qpv1.getValues().add("kuali.lu.type.credential.ContinuingEd");
89          qpv1.getValues().add("kuali.lu.type.MajorDiscipline");
90          qpv1.getValues().add("kuali.lu.type.Variation");
91          qpv1.getValues().add("kuali.lu.type.MinorDiscipline");
92          qpv1.getValues().add("kuali.lu.type.CoreProgram");
93          qpv1.getValues().add("kuali.lu.type.Honors");
94          qpv1.getValues().add("kuali.lu.type.LivingLearning");
95          searchParams.add(qpv1);
96          SearchParamInfo qpv2 = new SearchParamInfo();
97          qpv2.setKey("lu.queryParam.luOptionalState");
98          qpv2.getValues().add("Approved");
99          qpv2.getValues().add("Active");
100         qpv2.getValues().add("Retired");
101         qpv2.getValues().add("Suspended");
102         searchParams.add(qpv2);
103         for (QueryParamEnum qpEnum : QueryParamEnum.values()) {
104             String fieldValue = fieldValues.get(qpEnum.getFieldValue());
105             if ( ! isEmpty(fieldValue) ) {
106                 SearchParamInfo qpv = new SearchParamInfo();
107                 qpv.setKey(qpEnum.getQueryKey());
108                 qpv.getValues().add(fieldValue);
109                 searchParams.add(qpv);
110             }
111         }
112 
113         SearchRequestInfo searchRequest = new SearchRequestInfo();
114         searchRequest.setParams(searchParams);
115         searchRequest.setSearchKey("lu.search.current");
116 
117         try {
118             SearchResultInfo searchResult = getCluService().search(searchRequest, ContextUtils.getContextInfo());
119             CluInformation clu  = null;
120             if (searchResult.getRows().size() > 0) {
121                 for(SearchResultRowInfo srrow : searchResult.getRows()){
122                     clu = new CluInformation();
123                     List<SearchResultCellInfo> srCells = srrow.getCells();
124                     if(srCells != null && srCells.size() > 0){
125                         for(SearchResultCellInfo srcell : srCells){
126                             if (srcell.getKey().equals("lu.resultColumn.cluId")) {
127                                 clu.setCluId(srcell.getValue());
128                             }
129                             else if(srcell.getKey().equals("lu.resultColumn.luOptionalLongName")) {
130                                 clu.setTitle(srcell.getValue());
131                             }
132                              else if (srcell.getKey().equals("lu.resultColumn.luOptionalVersionIndId")){
133                             clu.setVerIndependentId(srcell.getValue());
134                              }
135                             else if(srcell.getKey().equals("lu.resultColumn.luOptionalDescr")) {
136                                 RichTextInfo richTextInfo = new RichTextInfo();
137                                 richTextInfo.setPlain(srcell.getValue());
138                                 clu.setDescription(srcell.getValue());
139                             }
140                             else if(srcell.getKey().equals("lu.resultColumn.luOptionalState")) {
141                                 clu.setState(srcell.getValue());
142                             }
143                             else if(srcell.getKey().equals("lu.resultColumn.luOptionalCode")) {
144                                 clu.setCode(srcell.getValue());
145                             }
146 
147                         }
148                     }
149                     programInfoList.add(clu);
150                 }
151 
152             }
153 
154             return programInfoList;
155         } catch (Exception e) {
156             throw new RuntimeException(e);
157         }
158     }
159 
160     //Note: here I am using r1 CluService implementation!!!
161     protected CluService getCluService() {
162         if(cluService == null) {
163             cluService = (CluService)GlobalResourceLoader.getService(new QName(CluServiceConstants.CLU_NAMESPACE,CluServiceConstants.SERVICE_NAME_LOCAL_PART));
164         }
165         return this.cluService;
166     }
167 
168 
169     protected ProgramService getProgramService() {
170         if(programService == null) {
171             programService = (ProgramService)GlobalResourceLoader.getService(new QName(ProgramServiceConstants.PROGRAM_NAMESPACE,"ProgramService"));
172         }
173         return this.programService;
174     }
175 }