Coverage Report - org.kuali.rice.student.lookup.keyvalues.CocValuesFinder
 
Classes in this File Line Coverage Branch Coverage Complexity
CocValuesFinder
0%
0/36
0%
0/10
9
 
 1  
 /**
 2  
  * Copyright 2010 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  
 
 16  
 package org.kuali.rice.student.lookup.keyvalues;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.kuali.rice.core.api.util.ConcreteKeyValue;
 24  
 import org.kuali.rice.core.api.util.KeyValue;
 25  
 import org.kuali.student.common.search.dto.SearchParam;
 26  
 import org.kuali.student.common.search.dto.SearchRequest;
 27  
 import org.kuali.student.common.search.dto.SearchResult;
 28  
 import org.kuali.student.common.search.dto.SearchResultCell;
 29  
 import org.kuali.student.common.search.dto.SearchResultRow;
 30  
 
 31  0
 public abstract class CocValuesFinder extends StudentKeyValuesBase {
 32  
 
 33  
         /**
 34  
          * Find the curriculum committee Orgs with specified orgType.
 35  
          * Each org should have a kuali.org.CurriculumParent relationship with
 36  
          * an org with kuali.org.COC type.
 37  
          * 
 38  
          * @param orgType
 39  
          * @return
 40  
          */
 41  
         public static List<KeyValue> findCocOrgs(String orgType) {
 42  0
                 List<KeyValue> orgEntities = new ArrayList<KeyValue>();
 43  
 
 44  0
                 List<SearchParam> queryParamValues = new ArrayList<SearchParam>(2);
 45  0
                 SearchParam qpOrgType = new SearchParam();
 46  0
                 qpOrgType.setKey("org.queryParam.relationType");
 47  0
                 qpOrgType.setValue("kuali.org.CurriculumParent");
 48  0
                 queryParamValues.add(qpOrgType);
 49  
                 
 50  0
                 qpOrgType = new SearchParam();
 51  0
         qpOrgType.setKey("org.queryParam.orgType");
 52  0
         qpOrgType.setValue(orgType);
 53  0
                 queryParamValues.add(qpOrgType);
 54  
                 
 55  0
                 qpOrgType = new SearchParam();
 56  0
                 qpOrgType.setKey("org.queryParam.relatedOrgType");
 57  0
                 qpOrgType.setValue("kuali.org.COC");
 58  0
                 queryParamValues.add(qpOrgType);
 59  
                 
 60  0
                 SearchRequest searchRequest = new SearchRequest();
 61  0
                 searchRequest.setParams(queryParamValues);
 62  0
         searchRequest.setSearchKey("org.search.orgQuickViewByRelationTypeOrgTypeRelatedOrgType");
 63  
 
 64  
                 try {
 65  0
                         SearchResult results = getOrganizationService().search(searchRequest);
 66  
 
 67  0
                         for (SearchResultRow result : results.getRows()) {
 68  0
                                 String orgId = "";
 69  0
                                 String orgShortName = "";
 70  0
                                 String orgLongName = "";
 71  0
                                 for (SearchResultCell resultCell : result.getCells()) {
 72  0
                                         if ("org.resultColumn.orgId".equals(resultCell
 73  
                                                         .getKey())) {
 74  0
                                                 orgId = resultCell.getValue();
 75  0
                                                 orgLongName = getOrganizationService().getOrganization(orgId).getLongName();
 76  0
                                         } else if ("org.resultColumn.orgShortName"
 77  
                                                         .equals(resultCell.getKey())) {
 78  0
                                                 orgShortName = resultCell.getValue();
 79  
                                         }                                        
 80  
                                 }
 81  0
                         if (StringUtils.isBlank(orgLongName)) {
 82  
                            //use shortName when longName is blank
 83  0
                             orgEntities.add(buildKeyValue(orgId, orgShortName, null, null));
 84  
                         }
 85  
                         else {
 86  
                             /*
 87  
                              * The requirement is that in the RICE portal, when we add a principal to a role
 88  
                              * the drop-down list for DepartmentCoC or DivisionCoC should display the full/long 
 89  
                              * names instead of short names.
 90  
                              */
 91  0
                             orgEntities.add(new ConcreteKeyValue(orgId, orgLongName));
 92  
                         }
 93  
 //                        orgEntities.add(buildKeyValue(orgId, null, orgLongName, null));
 94  0
                         }
 95  
 
 96  0
                         return orgEntities;
 97  0
                 } catch (Exception e) {
 98  0
                         throw new RuntimeException(e);
 99  
                 }
 100  
         }
 101  
 }