Coverage Report - org.kuali.student.lum.statement.config.context.util.NLCluSet
 
Classes in this File Line Coverage Branch Coverage Complexity
NLCluSet
76%
43/56
63%
23/36
2.333
 
 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.student.lum.statement.config.context.util;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.student.common.search.dto.SearchParam;
 21  
 import org.kuali.student.lum.lu.dto.CluInfo;
 22  
 import org.kuali.student.lum.lu.dto.CluSetInfo;
 23  
 
 24  
 /**
 25  
  * <p><b><u>Warning</u></b><br/>
 26  
  * DO NOT change the public method signatures of this class.<br/>
 27  
  * The natural language templates are coded against this class's public methods.
 28  
  * If the method signatures are changed then all the templates referencing 
 29  
  * this class will need to be changed as well.</p>
 30  
  * 
 31  
  * This class is inserted into the template engine to get Clu and CluSet 
 32  
  * information. <code>$cluSet</code> is this class.
 33  
  * <p>
 34  
  * Example:
 35  
  * <code>"Student must have completed $intValue of $cluSet.getCluSetAsShortName()"</code>
 36  
  * </p>
 37  
  * 
 38  
  * {@link MockCluSetInfo} wrapper class.
 39  
  */
 40  
 public class NLCluSet {
 41  
 
 42  
         private String cluSetId;
 43  
         private List<CluInfo> cluList;
 44  
         private CluSetInfo cluSet;
 45  
         
 46  0
         public NLCluSet(String cluSetId, List<CluInfo> cluList) {
 47  0
                 this.cluSetId = cluSetId;
 48  0
                 this.cluList = cluList;
 49  0
         }
 50  
         
 51  53
         public NLCluSet(String cluSetId, List<CluInfo> cluList, CluSetInfo cluSet) {
 52  53
                 this.cluSetId = cluSetId;
 53  53
                 this.cluList = cluList;
 54  53
                 this.cluSet = cluSet;
 55  53
         }
 56  
         
 57  
         /**
 58  
          * Gets the CLU set id.
 59  
          * 
 60  
          * @return Clu set id
 61  
          */
 62  
         public String getCluSetId() {
 63  4
                 return cluSetId;
 64  
         }
 65  
 
 66  
         /**
 67  
          * Gets a list of CLUs.
 68  
          *  
 69  
          * @return List of CLUs
 70  
          */
 71  
         public List<CluInfo> getCluList() {
 72  23
                 return this.cluList;
 73  
         }
 74  
 
 75  
         /**
 76  
          * Gets a particular CLU's official identifier short name.
 77  
          * 
 78  
          * @param index Index in CLU set
 79  
          * @return CLU official identifier short name
 80  
          */
 81  
         public String getCluAsShortName(int index) {
 82  2
                 return this.cluList.get(index).getOfficialIdentifier().getShortName();
 83  
         }
 84  
 
 85  
         /**
 86  
          * Gets a particular CLU's official identifier code at <code>index</code>
 87  
          * @param index
 88  
          * @return CLU's official identifier code
 89  
          */
 90  
         public String getCluAsCode(int index) {
 91  2
                 return this.cluList.get(index).getOfficialIdentifier().getCode();
 92  
         }
 93  
 
 94  
         /**
 95  
          * Gets all the CLUs' official identifier short name in the CLU set 
 96  
          * as a comma separated list.
 97  
          *   
 98  
          * @return Comma separated list of CLUs' official identifier short name 
 99  
          */
 100  
         public String getCluSetAsShortName() {
 101  1
                 return getCluSetAsShortName(",");
 102  
         }
 103  
         
 104  
         /**
 105  
      * Gets all the CLUs' official identifier short name in the CLU set 
 106  
      * as a list of values separated by the specified separator.
 107  
      * 
 108  
      * @param The string value that is used to separate the values in the list.
 109  
      * @return Character separated list of CLUs' official identifier short name 
 110  
      */
 111  
         public String getCluSetAsShortName(String separator) {
 112  1
         StringBuilder sb = new StringBuilder();
 113  1
         if (this.cluList.size() > 1) {
 114  1
             sb.append("(");
 115  
         }
 116  1
         for(CluInfo clu : this.cluList) {
 117  2
             sb.append(clu.getOfficialIdentifier().getShortName());
 118  2
             if (this.cluList.indexOf(clu) < (this.cluList.size() - 1)) {
 119  1
                 sb.append(separator + " ");
 120  
             }
 121  
         }
 122  1
         if (this.cluList.size() > 1) {
 123  1
             sb.append(")");
 124  
         }       
 125  1
         return getString(sb);
 126  
     }
 127  
 
 128  
         /**
 129  
          * Gets all the CLUs' official identifier long name in the CLU set 
 130  
          * as a comma separated list.
 131  
          * 
 132  
          * @return Comma separated list of CLUs' official identifier long name 
 133  
          */
 134  
         public String getCluSetAsLongName() {
 135  12
                 return getCluSetAsLongName(",");
 136  
         }
 137  
         
 138  
         /**
 139  
          * Gets all the CLUs' official identifier long name in the CLU set 
 140  
      * as a list of values separated by the specified separator.
 141  
          *           
 142  
          * @param separator The string value that is used to separate the values in the list.
 143  
          * @return Character separated list of CLUs' official identifier long name 
 144  
          */
 145  
         public String getCluSetAsLongName(String separator) {
 146  16
             StringBuilder sb = new StringBuilder();
 147  16
         if (this.cluList.size() > 1) {
 148  7
             sb.append("(");
 149  
         }       
 150  16
         for(CluInfo clu : this.cluList) {
 151  23
             sb.append(clu.getOfficialIdentifier().getLongName());
 152  23
             if (this.cluList.indexOf(clu) < (this.cluList.size() - 1)) {
 153  7
                 sb.append(separator + " ");
 154  
             }
 155  
         }
 156  16
         if (this.cluList.size() > 1) {
 157  7
             sb.append(")");
 158  
         }       
 159  16
         return getString(sb);
 160  
         }
 161  
 
 162  
         /**
 163  
          * Gets all the CLUs' official identifier code in the CLU set 
 164  
          * as a comma separated list.
 165  
          * 
 166  
          * @return Comma separated list of CLUs' official identifier code 
 167  
          */
 168  
         public String getCluSetAsCode() {
 169  31
                 return getCluSetAsCode(",");
 170  
         }
 171  
         
 172  
         /**
 173  
      * Gets all the CLUs' official identifier code in the CLU set 
 174  
      * as a list of values separated by the specified separator.
 175  
      * 
 176  
      * @param separator The string value that is used to separate the values in the list.
 177  
      * @return Character separated list of CLUs' official identifier code 
 178  
      */
 179  
     public String getCluSetAsCode(String separator) {
 180  31
         StringBuilder sb = new StringBuilder();
 181  31
         if (this.cluList.size() > 1) {
 182  27
             sb.append("(");
 183  
         }       
 184  31
         for(CluInfo clu : this.cluList) {
 185  61
             sb.append(clu.getOfficialIdentifier().getCode());
 186  61
             if (this.cluList.indexOf(clu) < (this.cluList.size() - 1)) {
 187  30
                 sb.append(separator + " ");
 188  
             }
 189  
         }
 190  31
         if (this.cluList.size() > 1) {
 191  27
             sb.append(")");
 192  
         }       
 193  31
         return getString(sb);
 194  
     }
 195  
 
 196  
         private String getString(StringBuilder sb) {
 197  48
                 return (sb.length() == 0 ? "No CLUs available in CluSet" : sb.toString());
 198  
         }
 199  
 
 200  
         public String toString() {
 201  0
                 if(this.cluList == null) {
 202  0
                         return "Null CluSet";
 203  
                 }
 204  0
                 return "id=" + this.cluSetId;
 205  
         }
 206  
         
 207  
         public String getQueryValueFromParam(String param) {
 208  0
                 String value = "";
 209  0
                 if (cluSet.getMembershipQuery() != null && !cluSet.getMembershipQuery().getQueryParamValueList().isEmpty()) 
 210  0
                         for (SearchParam searchParam : cluSet.getMembershipQuery().getQueryParamValueList()) 
 211  0
                                 if (searchParam.getKey().equals(param)) 
 212  0
                                         return (String)searchParam.getValue();
 213  0
                 return value;
 214  
         }        
 215  
 }