View Javadoc

1   /**
2    * Copyright 2005-2011 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.rice.krms.impl.repository;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
23  import org.kuali.rice.krms.api.repository.agenda.AgendaItem;
24  
25  /**
26   * Agenda Item business object
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   *
30   */
31  public class AgendaItemBo extends PersistableBusinessObjectBase {
32  
33  	private String id;
34  	private String agendaId;
35  	private String ruleId;
36  	private String subAgendaId;
37  	private String whenTrueId;
38  	private String whenFalseId;
39  	private String alwaysId;
40  	
41  	private RuleBo rule;
42  	
43  	private AgendaItemBo whenTrue;
44  	private AgendaItemBo whenFalse;
45  	private AgendaItemBo always;
46  	
47  	public String getUl(AgendaItemBo firstItem) {
48  		return ("<ul>" + getUlHelper(firstItem) + "</ul>");
49  	}
50  	
51  	public String getUlHelper(AgendaItemBo item) {
52  		StringBuilder sb = new StringBuilder();
53  		sb.append("<li>" + ruleId + "</li>");
54  		if (whenTrue != null) {
55  			sb.append("<ul><li>when true</li><ul>");
56  			sb.append(getUlHelper(whenTrue));
57  			sb.append("</ul></ul>");
58  		}
59  		if (whenFalse != null) {
60  			sb.append("<ul><li>when false</li><ul>");
61  			sb.append(getUlHelper(whenFalse));
62  			sb.append("</ul></ul>");
63  		}
64  		if (always != null) {
65  			sb.append(getUlHelper(always));
66  		}
67  		return sb.toString();
68  	}
69  
70      public String getRuleText() {
71          StringBuilder resultBuilder = new StringBuilder();
72          if (getRule() != null) {
73              if (StringUtils.isBlank(getRule().getName())) {
74                  resultBuilder.append("- unnamed rule -");
75              } else {
76                  resultBuilder.append(getRule().getName());
77              }
78              if (!StringUtils.isBlank(getRule().getDescription())) {
79                  resultBuilder.append(": ");
80                  resultBuilder.append(getRule().getDescription());
81              }
82          } else {
83              throw new IllegalStateException();
84          }
85          return resultBuilder.toString();
86      }
87  
88  //	def List<AgendaItemBo> alwaysList
89  //	def List<AgendaItemBo> whenTrueList
90  //	def List<AgendaItemBo> whenFalseList
91  	
92  	public List<AgendaItemBo> getAlwaysList() {
93  		List<AgendaItemBo> results = new ArrayList<AgendaItemBo>();
94  		
95  		AgendaItemBo currentNode = this;
96  		while (currentNode.always != null) {
97  			results.add(currentNode.always);
98  			currentNode = currentNode.always;
99  		}
100 		
101 		return results;
102 	}
103 
104 	/**
105 	 * @return the id
106 	 */
107 	public String getId() {
108 		return this.id;
109 	}
110 
111 	/**
112 	 * @param id the id to set
113 	 */
114 	public void setId(String id) {
115 		this.id = id;
116 	}
117 
118 	/**
119 	 * @return the agendaId
120 	 */
121 	public String getAgendaId() {
122 		return this.agendaId;
123 	}
124 
125 	/**
126 	 * @param agendaId the agendaId to set
127 	 */
128 	public void setAgendaId(String agendaId) {
129 		this.agendaId = agendaId;
130 	}
131 
132 	/**
133 	 * @return the ruleId
134 	 */
135 	public String getRuleId() {
136 		return this.ruleId;
137 	}
138 
139 	/**
140 	 * @param ruleId the ruleId to set
141 	 */
142 	public void setRuleId(String ruleId) {
143 		this.ruleId = ruleId;
144 	}
145 
146 	/**
147 	 * @return the subAgendaId
148 	 */
149 	public String getSubAgendaId() {
150 		return this.subAgendaId;
151 	}
152 
153 	/**
154 	 * @param subAgendaId the subAgendaId to set
155 	 */
156 	public void setSubAgendaId(String subAgendaId) {
157 		this.subAgendaId = subAgendaId;
158 	}
159 
160 
161 	/**
162 	 * @return the whenTrueId
163 	 */
164 	public String getWhenTrueId() {
165 		return this.whenTrueId;
166 	}
167 
168 	/**
169 	 * @param whenTrueId the whenTrueId to set
170 	 */
171 	public void setWhenTrueId(String whenTrueId) {
172 		this.whenTrueId = whenTrueId;
173 	}
174 
175 	/**
176 	 * @return the whenFalseId
177 	 */
178 	public String getWhenFalseId() {
179 		return this.whenFalseId;
180 	}
181 
182 	/**
183 	 * @param whenFalseId the whenFalseId to set
184 	 */
185 	public void setWhenFalseId(String whenFalseId) {
186 		this.whenFalseId = whenFalseId;
187 	}
188 
189 	/**
190 	 * @return the alwaysId
191 	 */
192 	public String getAlwaysId() {
193 		return this.alwaysId;
194 	}
195 
196 	/**
197 	 * @param alwaysId the alwaysId to set
198 	 */
199 	public void setAlwaysId(String alwaysId) {
200 		this.alwaysId = alwaysId;
201 	}
202 
203 	/**
204 	 * @return the whenTrue
205 	 */
206 	public AgendaItemBo getWhenTrue() {
207 		return this.whenTrue;
208 	}
209 
210 	/**
211 	 * @param whenTrue the whenTrue to set
212 	 */
213 	public void setWhenTrue(AgendaItemBo whenTrue) {
214 		this.whenTrue = whenTrue;
215 	}
216 
217 	/**
218 	 * @return the whenFalse
219 	 */
220 	public AgendaItemBo getWhenFalse() {
221 		return this.whenFalse;
222 	}
223 
224 	/**
225 	 * @param whenFalse the whenFalse to set
226 	 */
227 	public void setWhenFalse(AgendaItemBo whenFalse) {
228 		this.whenFalse = whenFalse;
229 	}
230 
231 	/**
232 	 * @return the always
233 	 */
234 	public AgendaItemBo getAlways() {
235 		return this.always;
236 	}
237 
238 	/**
239 	 * @param always the always to set
240 	 */
241 	public void setAlways(AgendaItemBo always) {
242 		this.always = always;
243 	}
244 	
245     /**
246      * @return the rule
247      */
248     public RuleBo getRule() {
249         return this.rule;
250     }
251 
252     /**
253      * @param rule the rule to set
254      */
255     public void setRule(RuleBo rule) {
256         this.rule = rule;
257     }
258 
259 	
260     /**
261 	* Converts a mutable bo to it's immutable counterpart
262 	* @param bo the mutable business object
263 	* @return the immutable object
264 	*/
265    static AgendaItem to(AgendaItemBo bo) {
266 	   if (bo == null) { return null; }
267 	   org.kuali.rice.krms.api.repository.agenda.AgendaItem.Builder builder = 
268 		   org.kuali.rice.krms.api.repository.agenda.AgendaItem.Builder.create(bo.getId(), bo.getAgendaId());
269 	   builder.setRuleId(bo.getRuleId());
270 	   builder.setSubAgendaId(bo.getSubAgendaId());
271 	   builder.setWhenTrueId(bo.getWhenTrueId());
272 	   builder.setWhenFalseId(bo.getWhenFalseId());
273 	   builder.setAlwaysId(bo.getAlwaysId());
274 	   
275 	   return builder.build();
276    }
277 
278    /**
279 	* Converts a immutable object to it's mutable bo counterpart
280 	* @param im immutable object
281 	* @return the mutable bo
282 	*/
283    static AgendaItemBo from(AgendaItem im) {
284 	   if (im == null) { return null; }
285 
286 	   AgendaItemBo bo = new AgendaItemBo();
287 	   bo.id = im.getId();
288 	   bo.agendaId = im.getAgendaId();
289 	   bo.ruleId = im.getRuleId();
290 	   bo.subAgendaId = im.getSubAgendaId();
291 	   bo.whenTrueId = im.getWhenTrueId();
292 	   bo.whenFalseId = im.getWhenFalseId();
293 	   bo.alwaysId = im.getAlwaysId();
294 	   
295 	   return bo;
296    }
297 }