View Javadoc

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