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.kim.api.identity.Person;
20  import org.kuali.rice.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.component.DataBinding;
22  import org.kuali.rice.krad.uif.container.CollectionGroup;
23  import org.kuali.rice.krad.uif.container.Group;
24  import org.kuali.rice.krad.uif.container.TreeGroup;
25  import org.kuali.rice.krad.uif.element.Action;
26  import org.kuali.rice.krad.uif.field.ActionField;
27  import org.kuali.rice.krad.uif.field.DataField;
28  import org.kuali.rice.krad.uif.field.Field;
29  import org.kuali.rice.krad.uif.util.ComponentUtils;
30  import org.kuali.rice.krad.uif.view.View;
31  import org.kuali.rice.krad.uif.view.ViewAuthorizer;
32  import org.kuali.rice.krad.uif.view.ViewModel;
33  import org.kuali.rice.krad.uif.view.ViewPresentationController;
34  import org.kuali.rice.krad.uif.widget.Widget;
35  import org.kuali.rice.krad.util.GlobalVariables;
36  import org.kuali.rice.krad.util.ObjectUtils;
37  import org.kuali.rice.krms.api.repository.LogicalOperator;
38  import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
39  import org.kuali.rice.krms.api.repository.proposition.PropositionType;
40  import org.kuali.rice.krms.dto.PropositionEditor;
41  import org.kuali.rice.krms.dto.RuleEditor;
42  import org.kuali.rice.krms.dto.TermEditor;
43  import org.kuali.rice.krms.dto.TermParameterEditor;
44  import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
45  import org.kuali.rice.krms.service.impl.RuleViewHelperServiceImpl;
46  import org.kuali.rice.krms.tree.RuleEditTreeBuilder;
47  import org.kuali.rice.krms.tree.RulePreviewTreeBuilder;
48  import org.kuali.rice.krms.tree.RuleViewTreeBuilder;
49  import org.kuali.rice.krms.util.PropositionTreeUtil;
50  import org.kuali.student.core.krms.dto.KSPropositionEditor;
51  import org.kuali.student.core.krms.tree.KSRuleEditTreeBuilder;
52  import org.kuali.student.core.krms.tree.KSRulePreviewTreeBuilder;
53  import org.kuali.student.core.krms.tree.KSRuleViewTreeBuilder;
54  import org.kuali.student.lum.lu.ui.krms.builder.MultiCourseComponentBuilder;
55  import org.kuali.student.lum.lu.ui.krms.builder.ProgramComponentBuilder;
56  import org.kuali.student.lum.lu.ui.krms.dto.LUPropositionEditor;
57  import org.kuali.student.lum.lu.ui.krms.dto.KrmsSuggestDisplay;
58  import org.kuali.student.lum.lu.ui.krms.tree.LURulePreviewTreeBuilder;
59  import org.kuali.student.lum.lu.ui.krms.tree.LURuleViewTreeBuilder;
60  import org.kuali.student.lum.lu.ui.krms.dto.CluInformation;
61  import org.kuali.student.lum.lu.ui.krms.dto.CluSetInformation;
62  import org.kuali.student.lum.lu.ui.krms.util.CluInformationHelper;
63  import org.kuali.student.lum.lu.ui.krms.util.LUKRMSConstants;
64  import org.kuali.student.r1.common.rice.StudentIdentityConstants;
65  import org.kuali.student.r2.common.dto.ContextInfo;
66  import org.kuali.student.r2.common.dto.DtoConstants;
67  import org.kuali.student.r2.common.util.ContextUtils;
68  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
69  import org.kuali.student.r2.core.constants.OrganizationServiceConstants;
70  import org.kuali.student.r2.core.organization.service.OrganizationService;
71  import org.kuali.student.r2.core.search.dto.SearchParamInfo;
72  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
73  import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
74  import org.kuali.student.r2.core.search.dto.SearchResultInfo;
75  import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
76  import org.kuali.student.r2.lum.clu.dto.MembershipQueryInfo;
77  import org.kuali.student.r2.lum.clu.service.CluService;
78  import org.kuali.student.r2.lum.lrc.service.LRCService;
79  import org.kuali.student.r2.lum.util.constants.CluServiceConstants;
80  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
81  
82  import javax.xml.namespace.QName;
83  import java.util.ArrayList;
84  import java.util.Collections;
85  import java.util.Comparator;
86  import java.util.List;
87  
88  /**
89   * Helpers Service with enrolment specific functions for the Rule Pages.
90   *
91   * @author Kuali Student Team
92   */
93  public class LURuleViewHelperServiceImpl extends RuleViewHelperServiceImpl {
94  
95      private CluService cluService;
96      private ContextInfo contextInfo;
97      private OrganizationService organizationService;
98  
99      private CluInformationHelper cluInfoHelper;
100 
101     private KSRulePreviewTreeBuilder previewTreeBuilder;
102     private KSRuleViewTreeBuilder viewTreeBuilder;
103     private KSRuleEditTreeBuilder editTreeBuilder;
104 
105     @Override
106     public Class<? extends PropositionEditor> getPropositionEditorClass() {
107         return KSPropositionEditor.class;
108     }
109 
110     @Override
111     public void applyAuthorizationAndPresentationLogic(View view, Component component, ViewModel model) {
112         super.applyAuthorizationAndPresentationLogic(view, component, model);
113 
114         if(component instanceof Group) {
115             Group group = (Group) component;
116 
117             if(group.isReadOnly()) {
118                 processGroupItems(group);
119             }
120         }
121     }
122 
123     protected void processGroupItems(Group group) {
124         List<Field> fields = ComponentUtils.getComponentsOfType(group.getItems(), Field.class);
125         for(Field field : fields) {
126             field.setReadOnly(true);
127         }
128 
129         List<Action> actions = ComponentUtils.getComponentsOfTypeDeep(group.getItems(), Action.class);
130         for(Action action : actions) {
131             action.setRender(false);
132         }
133     }
134 
135     @Override
136     public PropositionEditor copyProposition(PropositionEditor oldProposition) {
137         try {
138             LUPropositionEditor newProposition = (LUPropositionEditor) this.copyPropositionEditor(oldProposition);
139 
140             //Set the cluset to null to force the builder to create a new cluset.
141             nullifyCluSetInfo(newProposition);
142 
143             //Use a deepcopy to create new references to inner objects such as string.
144             return (PropositionEditor) ObjectUtils.deepCopy(newProposition);
145         } catch (Exception e) {
146             return null;
147         }
148     }
149 
150     @Override
151     public void setTypeForCompoundOpCode(PropositionEditor proposition, String compoundOpCode) {
152         super.setTypeForCompoundOpCode(proposition, compoundOpCode);
153         if (LogicalOperator.AND.getCode().equalsIgnoreCase(compoundOpCode)) {
154             proposition.setType(KSKRMSServiceConstants.PROPOSITION_TYPE_COMPOUND_AND);
155         } else if (LogicalOperator.OR.getCode().equalsIgnoreCase(compoundOpCode)) {
156             proposition.setType(KSKRMSServiceConstants.PROPOSITION_TYPE_COMPOUND_OR);
157         }
158         try {
159             KrmsTypeDefinition type = KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().getTypeByName(StudentIdentityConstants.KS_NAMESPACE_CD, proposition.getType());
160             proposition.setTypeId(type.getId());
161         } catch (Exception e) {
162             //ignore if service not available.
163         }
164 
165     }
166 
167     /**
168      * Method to recursively set proposition's cluSetInfo to null.
169      *
170      * @param propositionEditor
171      */
172     protected void nullifyCluSetInfo(LUPropositionEditor propositionEditor) {
173 
174         //Set cluSetInfo recursively to null to force builder to create new cluset.
175         if(propositionEditor.getCluSet()!=null){
176             propositionEditor.getCluSet().setCluSetInfo(null);
177         } else if(propositionEditor.getPropositionTypeCode().equals(PropositionType.COMPOUND.getCode())) {
178             for(int i = 0; i < propositionEditor.getCompoundEditors().size(); i++) {
179                 LUPropositionEditor prop = (LUPropositionEditor) propositionEditor.getCompoundEditors().get(i);
180                 if(prop.getCluSet() != null) {
181                     prop.getCluSet().setCluSetInfo(null);
182                 } else if(prop.getPropositionTypeCode().equals(PropositionType.COMPOUND.getCode())) {
183                     nullifyCluSetInfo(prop);
184                 }
185             }
186         }
187     }
188 
189     protected void checkNaturalLanguageForTree(RuleEditor ruleEditor) {
190         if ((ruleEditor !=null) && (ruleEditor.getProposition()!=null)){
191             PropositionEditor originalRoot = ruleEditor.getPropositionEditor();
192             if (!originalRoot.getNaturalLanguage().containsKey(this.getEditTreeBuilder().getNaturalLanguageUsageKey())) {
193                 this.getNaturalLanguageHelper().setNaturalLanguageTreeForUsage(originalRoot, this.getEditTreeBuilder().getNaturalLanguageUsageKey(), StudentIdentityConstants.KS_NAMESPACE_CD);
194             }
195         }
196     }
197 
198     /**
199      * Compares CO and CLU with each other for the display of a info message.
200      *
201      * @param original
202      * @param compare
203      * @return
204      */
205     @Override
206     public Boolean compareProposition(PropositionEditor original, PropositionEditor compare) {
207 
208         if(!super.compareProposition(original, compare)) {
209             return false;
210         } else if(!original.getPropositionTypeCode().equals("C")) {
211             LUPropositionEditor enrolOriginal = (LUPropositionEditor) original;
212 
213             //Populate compare proposition cluSetInformation for comparison
214             if(enrolOriginal.getCluSet() != null) {
215                 if(enrolOriginal.getCluSet().getParent() == null) {
216                     MultiCourseComponentBuilder builder = new MultiCourseComponentBuilder();
217                     TermEditor term = new TermEditor(PropositionTreeUtil.getTermParameter(compare.getParameters()).getTermValue());
218                     for(TermParameterEditor termParameterEditor : term.getEditorParameters()) {
219                         if(termParameterEditor.getName().equals(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLUSET_KEY)) {
220                             enrolOriginal.getCluSet().setParent(builder.getCluSetInformation(termParameterEditor.getValue()));
221                             break;
222                         }
223                     }
224                 }
225                 //If compare and original propositions are not null compare CluSetInformation
226                 if(enrolOriginal.getCluSet() != null && enrolOriginal.getCluSet().getParent() != null) {
227                     //Compare propositions CluSetInformation clu's
228                     if(!enrolOriginal.getCluSet().getCluDelimitedString().equals(enrolOriginal.getCluSet().getParent().getCluDelimitedString())) {
229                         return false;
230                     }
231                     //Compare propositions CluSetInformation cluSets
232                     if(!enrolOriginal.getCluSet().getCluSetDelimitedString().equals(enrolOriginal.getCluSet().getParent().getCluSetDelimitedString())) {
233                         return false;
234                     }
235                 }
236             }
237 
238             //Populate compare proposition ProgramCluSetInformation for comparison
239             if(enrolOriginal.getProgCluSet() != null) {
240                 if(enrolOriginal.getProgCluSet().getParent() == null) {
241                     ProgramComponentBuilder builder = new ProgramComponentBuilder();
242                     TermEditor term = new TermEditor(PropositionTreeUtil.getTermParameter(compare.getParameters()).getTermValue());
243                     for(TermParameterEditor termParameterEditor : term.getEditorParameters()) {
244                         if(termParameterEditor.getName().equals(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLUSET_KEY)) {
245                             enrolOriginal.getProgCluSet().setParent(builder.getProgramCluSetInformation(termParameterEditor.getValue()));
246                             break;
247                         }
248                     }
249                 }
250                 //If compare and original propositions are not null compare ProgramCluSetInformation
251                 if(enrolOriginal.getProgCluSet() != null && enrolOriginal.getProgCluSet().getParent() != null) {
252                     //Compare propositions ProgramCluSetInformation clu's
253                     if(!enrolOriginal.getProgCluSet().getCluDelimitedString().equals(enrolOriginal.getProgCluSet().getParent().getCluDelimitedString())) {
254                         return false;
255                     }
256                     //Compare propositions ProgramCluSetInformation cluSets
257                     if(!enrolOriginal.getProgCluSet().getCluSetDelimitedString().equals(enrolOriginal.getProgCluSet().getParent().getCluSetDelimitedString())) {
258                         return false;
259                     }
260                 }
261             }
262         }
263 
264         return true;
265     }
266 
267     protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model,
268                                                Object addLine) {
269         if(LUKRMSConstants.KSKRMS_PROPERTY_NAME_CLUS.equals(collectionGroup.getPropertyName())){
270             //Check if this is a valid clu.
271             CluInformation clu = (CluInformation) addLine;
272             if((clu.getCluId() == null)||(clu.getCluId().isEmpty())){
273                 collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true);
274                 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroup.getId(), LUKRMSConstants.KSKRMS_MSG_ERROR_APPROVED_COURSE_REQUIRED);
275                   return false;
276             }
277 
278             //Check if this clu is not already in the collection
279             RuleEditor ruleEditor = this.getRuleEditor(model);
280             LUPropositionEditor propEditor = (LUPropositionEditor)PropositionTreeUtil.getProposition(ruleEditor);
281             for(CluInformation cluInformation : propEditor.getCluSet().getClus()){
282                 if(cluInformation.getCluId().equals(clu.getCluId())){
283                     collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true);
284                     return false;
285                 }
286             }
287         } else if (LUKRMSConstants.KSKRMS_PROPERTY_NAME_CLUSETS.equals(collectionGroup.getPropertyName())){
288             //Check if this is a valid clu.
289             CluSetInformation cluSet = (CluSetInformation) addLine;
290             if((cluSet.getCluSetInfo().getId() == null)||(cluSet.getCluSetInfo().getId().isEmpty())){
291                 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroup.getId(), LUKRMSConstants.KSKRMS_MSG_ERROR_COURSESETS_REQUIRED);
292                 return false;
293             }
294 
295             //Check if this clu is not already in the collection
296             RuleEditor ruleEditor = this.getRuleEditor(model);
297             LUPropositionEditor propEditor = (LUPropositionEditor)PropositionTreeUtil.getProposition(ruleEditor);
298             for(CluSetInformation cluSetInfo : propEditor.getCluSet().getCluSets()){
299                 if(cluSetInfo.getCluSetInfo().getId().equals(cluSet.getCluSetInfo().getId())){
300                     return false;
301                 }
302             }
303         }
304         else if(LUKRMSConstants.KSKRMS_PROPERTY_NAME_PROG_CLUS.equals(collectionGroup.getPropertyName())){
305             //Check if this is a valid clu.
306             CluInformation clu = (CluInformation) addLine;
307             if((clu.getCluId() == null)||(clu.getCluId().isEmpty())){
308                 collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true);
309                 GlobalVariables.getMessageMap().putErrorForSectionId(collectionGroup.getId(), LUKRMSConstants.KSKRMS_MSG_ERROR_APPROVED_PROGRAM_REQUIRED);
310                 return false;
311             }
312 
313             //Check if this clu is not already in the collection
314             RuleEditor ruleEditor = this.getRuleEditor(model);
315             LUPropositionEditor propEditor = (LUPropositionEditor)PropositionTreeUtil.getProposition(ruleEditor);
316             for(CluInformation cluInformation : propEditor.getProgCluSet().getClus()){
317                 if(cluInformation.getCluId().equals(clu.getCluId())){
318                     collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true);
319                     return false;
320                 }
321             }
322         }
323 
324         return true;
325     }
326 
327     protected void processAfterAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine,
328                                        boolean isValidLine) {
329 
330         if(LUKRMSConstants.KSKRMS_PROPERTY_NAME_CLUS.equals(collectionGroup.getPropertyName())){
331             //Sort the clus.
332             RuleEditor ruleEditor = this.getRuleEditor(model);
333             LUPropositionEditor propEditor = (LUPropositionEditor)PropositionTreeUtil.getProposition(ruleEditor);
334 
335             CluInformation clu = (CluInformation) addLine;
336             if(clu.getCluId() != null){
337             clu.setCredits(this.getCluInfoHelper().getCreditInfo(clu.getCluId()));
338             Collections.sort(propEditor.getCluSet().getClus());
339 
340             }
341         } else if (LUKRMSConstants.KSKRMS_PROPERTY_NAME_CLUSETS.equals(collectionGroup.getPropertyName())){
342             //Set the clus on the wrapper object.
343             CluSetInformation cluSet = (CluSetInformation) addLine;
344             if(cluSet.getCluSetInfo().getId() != null) {
345             try {
346                 cluSet.getCluSetInfo().setCluIds(this.getCluService().getCluIdsFromCluSet(cluSet.getCluSetInfo().getId(), ContextUtils.getContextInfo()));
347             } catch (Exception e) {
348                 throw new RuntimeException(e);
349             }
350             cluSet.setClus(this.getCluInfoHelper().getCourseInfos(cluSet.getCluSetInfo().getCluIds()));
351 
352             //Sort the clus.
353             RuleEditor ruleEditor = this.getRuleEditor(model);
354                 LUPropositionEditor propEditor = (LUPropositionEditor)PropositionTreeUtil.getProposition(ruleEditor);
355             Collections.sort(propEditor.getCluSet().getCluSets(), new Comparator<CluSetInformation>(){
356 
357                 @Override
358                 public int compare(CluSetInformation o1, CluSetInformation o2) {
359                     return o1.getCluSetInfo().getName().compareTo(o2.getCluSetInfo().getName());
360                 }
361             });
362             }
363         }
364         else if(LUKRMSConstants.KSKRMS_PROPERTY_NAME_PROG_CLUS.equals(collectionGroup.getPropertyName())){
365             //Sort the clus.
366             RuleEditor ruleEditor = this.getRuleEditor(model);
367             LUPropositionEditor propEditor = (LUPropositionEditor)PropositionTreeUtil.getProposition(ruleEditor);
368 
369             CluInformation clu = (CluInformation) addLine;
370             if(clu.getCluId() != null){
371                 clu.setCredits(this.getCluInfoHelper().getCreditInfo(clu.getCluId()));
372                 Collections.sort(propEditor.getProgCluSet().getClus());
373             }
374         }
375     }
376 
377     public List<CluInformation> getCoursesInRange(MembershipQueryInfo membershipQuery) {
378         return this.getCluInfoHelper().getCluInfosWithDetailForQuery(membershipQuery);
379     }
380 
381     public List<KrmsSuggestDisplay> getCourseNamesForSuggest(String moduleName) {
382 
383         List<KrmsSuggestDisplay> displays = new ArrayList<KrmsSuggestDisplay>();
384         List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
385         SearchParamInfo stateKeyParam = new SearchParamInfo();
386         stateKeyParam.setKey("lu.queryParam.luOptionalState");
387 
388         List<String> stateValues = new ArrayList<String>();
389         stateValues.add(DtoConstants.STATE_ACTIVE);
390         stateValues.add(DtoConstants.STATE_APPROVED);
391         stateKeyParam.setValues(stateValues);
392         queryParamValueList.add(stateKeyParam);
393         SearchParamInfo cluCodeParam = new SearchParamInfo();
394         cluCodeParam.setKey("lu.queryParam.luOptionalCode");
395         cluCodeParam.getValues().add(moduleName);
396         queryParamValueList.add(cluCodeParam);
397 
398         SearchRequestInfo searchRequest = new SearchRequestInfo();
399         searchRequest.setSearchKey("lu.search.current.quick");
400         searchRequest.setParams(queryParamValueList);
401         SearchResultInfo clus = null;
402 
403         try {
404             clus = getCluService().search(searchRequest, getContextInfo());
405             for (SearchResultRowInfo result : clus.getRows()) {
406                 List<SearchResultCellInfo> cells = result.getCells();
407                 KrmsSuggestDisplay display = new KrmsSuggestDisplay();
408                 for (SearchResultCellInfo cell : cells) {
409                     if ("lu.resultColumn.cluId".equals(cell.getKey())) {
410                         display.setId(cell.getValue());
411                     } else if ("lu.resultColumn.luOptionalCode".equals(cell.getKey())) {
412                         display.setDisplayName(cell.getValue());
413                     }
414                 }
415                 displays.add(display);
416             }
417         } catch (Exception e) {
418             throw new RuntimeException(e);
419         }
420 
421         return displays;
422     }
423 
424     public List<KrmsSuggestDisplay> getOrgDepartmentForSuggest(String orgName) {
425 
426         List<KrmsSuggestDisplay> displays = new ArrayList<KrmsSuggestDisplay>();
427         List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
428         SearchParamInfo orgNameParam = new SearchParamInfo();
429         orgNameParam.setKey("org.queryParam.orgOptionalLongName");
430         orgNameParam.getValues().add(orgName);
431         queryParamValueList.add(orgNameParam);
432         SearchParamInfo orgTypeParam = new SearchParamInfo();
433         orgTypeParam.setKey("org.queryParam.orgOptionalType");
434         List<String> orgTypeValues = new ArrayList<String>();
435         orgTypeValues.add(OrganizationServiceConstants.ORGANIZATION_DEPARTMENT_TYPE_KEY);
436         orgTypeParam.setValues(orgTypeValues);
437         queryParamValueList.add(orgTypeParam);
438         SearchRequestInfo searchRequest = new SearchRequestInfo();
439         searchRequest.setSearchKey("org.search.generic");
440         searchRequest.setParams(queryParamValueList);
441 
442         try {
443             SearchResultInfo orgs = getOrganizationService().search(searchRequest, getContextInfo());
444             for (SearchResultRowInfo result : orgs.getRows()) {
445                 List<SearchResultCellInfo> cells = result.getCells();
446                 KrmsSuggestDisplay display = new KrmsSuggestDisplay();
447                 for (SearchResultCellInfo cell : cells) {
448                     if ("org.resultColumn.orgId".equals(cell.getKey())) {
449                         display.setId(cell.getValue());
450                     } else if ("org.resultColumn.orgOptionalLongName".equals(cell.getKey())) {
451                         display.setDisplayName(cell.getValue());
452                     }
453                 }
454                 displays.add(display);
455             }
456         } catch (Exception e) {
457             throw new RuntimeException(e);
458         }
459 
460         return displays;
461     }
462 
463     public List<KrmsSuggestDisplay> getTestNamesForSuggest(String testName) {
464 
465         List<KrmsSuggestDisplay> displays = new ArrayList<KrmsSuggestDisplay>();
466         List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
467         SearchParamInfo testNameParam = new SearchParamInfo();
468         testNameParam.setKey("cluset.queryParam.optionalName");
469         testNameParam.getValues().add(testName);
470         queryParamValueList.add(testNameParam);
471         SearchParamInfo reusableParam = new SearchParamInfo();
472         reusableParam.setKey("cluset.queryParam.optionalReusable");
473         reusableParam.getValues().add(Boolean.TRUE.toString());
474         queryParamValueList.add(reusableParam);
475         SearchParamInfo cluSetTypeParam = new SearchParamInfo();
476         cluSetTypeParam.setKey("cluset.queryParam.optionalType");
477         cluSetTypeParam.getValues().add(CluServiceConstants.CLUSET_TYPE_TEST);
478         queryParamValueList.add(cluSetTypeParam);
479 
480         SearchRequestInfo searchRequest = new SearchRequestInfo();
481         searchRequest.setSearchKey("cluset.search.generic");
482         searchRequest.setParams(queryParamValueList);
483 
484         try {
485             SearchResultInfo clus = getCluService().search(searchRequest, getContextInfo());
486             for (SearchResultRowInfo result : clus.getRows()) {
487                 List<SearchResultCellInfo> cells = result.getCells();
488                 KrmsSuggestDisplay display = new KrmsSuggestDisplay();
489                 for (SearchResultCellInfo cell : cells) {
490                     if ("cluset.resultColumn.cluSetId".equals(cell.getKey())) {
491                         display.setId(cell.getValue());
492                     } else if ("cluset.resultColumn.name".equals(cell.getKey())) {
493                         display.setDisplayName(cell.getValue());
494                     }
495                 }
496                 displays.add(display);
497             }
498         } catch (Exception e) {
499             throw new RuntimeException(e);
500         }
501         return displays;
502     }
503 
504     public List<KrmsSuggestDisplay> getCourseSetForSuggest(String cluSetName) {
505         List<KrmsSuggestDisplay> displays = new ArrayList<KrmsSuggestDisplay>();
506         List<SearchParamInfo> queryParamValueList = new ArrayList<SearchParamInfo>();
507         SearchParamInfo cluSetParam = new SearchParamInfo();
508         cluSetParam.setKey("cluset.queryParam.optionalName");
509         cluSetParam.getValues().add(cluSetName);
510         queryParamValueList.add(cluSetParam);
511         SearchParamInfo reusableCluSet = new SearchParamInfo();
512         reusableCluSet.setKey("cluset.queryParam.optionalReusable");
513         reusableCluSet.getValues().add(Boolean.TRUE.toString());
514         queryParamValueList.add(reusableCluSet);
515         SearchRequestInfo searchRequest = new SearchRequestInfo();
516         searchRequest.setSearchKey("cluset.search.generic");
517         searchRequest.setParams(queryParamValueList);
518         SearchParamInfo cluSetTypeParam = new SearchParamInfo();
519         cluSetTypeParam.setKey("cluset.queryParam.optionalType");
520         cluSetTypeParam.getValues().add(CluServiceConstants.CLUSET_TYPE_CREDIT_COURSE);
521         queryParamValueList.add(cluSetTypeParam);
522 
523         try {
524             SearchResultInfo clus = getCluService().search(searchRequest, getContextInfo());
525             for (SearchResultRowInfo result : clus.getRows()) {
526                 List<SearchResultCellInfo> cells = result.getCells();
527                 KrmsSuggestDisplay display = new KrmsSuggestDisplay();
528                 for (SearchResultCellInfo cell : cells) {
529                     if ("cluset.resultColumn.cluSetId".equals(cell.getKey())) {
530                         display.setId(cell.getValue());
531                     } else if ("cluset.resultColumn.name".equals(cell.getKey())) {
532                         display.setDisplayName(cell.getValue());
533                     }
534                 }
535                 displays.add(display);
536             }
537         } catch (Exception e) {
538             throw new RuntimeException(e);
539         }
540         return displays;
541     }
542     public List<KrmsSuggestDisplay> getProgramForSuggest(String programCode) {
543         List<KrmsSuggestDisplay> displays = new ArrayList<KrmsSuggestDisplay>();
544         List<SearchParamInfo> searchParams = new ArrayList<SearchParamInfo>();
545         SearchParamInfo qpv1 = new SearchParamInfo();
546 
547         qpv1.setKey("lu.queryParam.luOptionalType");
548         qpv1.getValues().add("kuali.lu.type.Program");
549         searchParams.add(qpv1);
550         SearchParamInfo qpv2 = new SearchParamInfo();
551         qpv2.setKey("lu.queryParam.luOptionalCode");
552         qpv2.getValues().add(programCode);
553         searchParams.add(qpv2);
554 
555         SearchRequestInfo searchRequest = new SearchRequestInfo();
556         searchRequest.setParams(searchParams);
557         searchRequest.setSearchKey("lu.search.generic");
558 
559         try {
560             SearchResultInfo searchResult = getCluService().search(searchRequest, ContextUtils.getContextInfo());
561             if (searchResult.getRows().size() > 0) {
562                 for(SearchResultRowInfo srrow : searchResult.getRows()){
563                     KrmsSuggestDisplay display = new KrmsSuggestDisplay();
564                     List<SearchResultCellInfo> srCells = srrow.getCells();
565                     if(srCells != null && srCells.size() > 0){
566                         for(SearchResultCellInfo srcell : srCells){
567                             if (srcell.getKey().equals("lu.resultColumn.cluId")) {
568                                 display.setId(srcell.getValue());
569 
570                             }
571                             else if(srcell.getKey().equals("lu.resultColumn.luOptionalCode")) {
572                                 display.setDisplayName(srcell.getValue());
573                             }
574 
575                         }
576                     }
577                     displays.add(display);
578                 }
579 
580             }
581 
582             return displays;
583         } catch (Exception e) {
584             throw new RuntimeException(e);
585         }
586     }
587 
588     protected CluInformationHelper getCluInfoHelper() {
589         if (cluInfoHelper == null) {
590             cluInfoHelper = new CluInformationHelper();
591             cluInfoHelper.setCluService(this.getCluService());
592             LRCService lrcService = GlobalResourceLoader.getService(new QName(LrcServiceConstants.NAMESPACE, LrcServiceConstants.SERVICE_NAME_LOCAL_PART));
593             cluInfoHelper.setLrcService(lrcService);
594         }
595         return cluInfoHelper;
596     }
597 
598     protected CluService getCluService() {
599         if (cluService == null) {
600             cluService = GlobalResourceLoader.getService(new QName(CluServiceConstants.CLU_NAMESPACE, CluServiceConstants.SERVICE_NAME_LOCAL_PART));
601         }
602         return cluService;
603     }
604 
605     protected ContextInfo getContextInfo() {
606         if (null == contextInfo) {
607             contextInfo = ContextUtils.createDefaultContextInfo();
608         }
609         return contextInfo;
610     }
611 
612     protected OrganizationService getOrganizationService() {
613         if (organizationService == null) {
614             organizationService = GlobalResourceLoader.getService(new QName(OrganizationServiceConstants.NAMESPACE, OrganizationServiceConstants.SERVICE_NAME_LOCAL_PART));
615         }
616         return organizationService;
617     }
618 
619     @Override
620     public RulePreviewTreeBuilder getPreviewTreeBuilder() {
621         if (previewTreeBuilder == null) {
622             previewTreeBuilder = new LURulePreviewTreeBuilder();
623             previewTreeBuilder.setNlHelper(this.getNaturalLanguageHelper());
624         }
625         return previewTreeBuilder;
626     }
627 
628     @Override
629     protected RuleViewTreeBuilder getViewTreeBuilder() {
630         if (viewTreeBuilder == null) {
631             viewTreeBuilder = new LURuleViewTreeBuilder();
632             viewTreeBuilder.setNlHelper(this.getNaturalLanguageHelper());
633         }
634         return viewTreeBuilder;
635     }
636 
637     @Override
638     protected RuleEditTreeBuilder getEditTreeBuilder() {
639         if (editTreeBuilder == null) {
640             editTreeBuilder = new KSRuleEditTreeBuilder();
641             editTreeBuilder.setNlHelper(this.getNaturalLanguageHelper());
642         }
643         return editTreeBuilder;
644     }
645 
646 }