View Javadoc
1   /**
2    * Copyright 2005-2015 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.api.repository.agenda;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlAnyElement;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlRootElement;
26  import javax.xml.bind.annotation.XmlType;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.kuali.rice.core.api.CoreConstants;
30  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31  import org.kuali.rice.core.api.mo.ModelBuilder;
32  import org.kuali.rice.krms.api.KrmsConstants;
33  import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
34  
35  /**
36   * Concrete model object implementation of KRMS Repository AgendaItemDefinition
37   * immutable. 
38   * Instances of AgendaItemDefinition can be (un)marshalled to and from XML.
39   *
40   * @see AgendaItemDefinitionContract
41   */
42  @XmlRootElement(name = AgendaItemDefinition.Constants.ROOT_ELEMENT_NAME)
43  @XmlAccessorType(XmlAccessType.NONE)
44  @XmlType(name = AgendaItemDefinition.Constants.TYPE_NAME, propOrder = {
45  		AgendaItemDefinition.Elements.ID,
46  		AgendaItemDefinition.Elements.AGENDA_ID,
47  		AgendaItemDefinition.Elements.RULE_ID,
48  		AgendaItemDefinition.Elements.SUB_AGENDA_ID,
49  		AgendaItemDefinition.Elements.WHEN_TRUE_ID,
50  		AgendaItemDefinition.Elements.WHEN_FALSE_ID,
51  		AgendaItemDefinition.Elements.ALWAYS_ID,
52  		AgendaItemDefinition.Elements.RULE,
53  		AgendaItemDefinition.Elements.SUB_AGENDA,
54  		AgendaItemDefinition.Elements.WHEN_TRUE,
55  		AgendaItemDefinition.Elements.WHEN_FALSE,
56  		AgendaItemDefinition.Elements.ALWAYS,
57          CoreConstants.CommonElements.VERSION_NUMBER,
58  		CoreConstants.CommonElements.FUTURE_ELEMENTS
59  })
60  public final class AgendaItemDefinition extends AbstractDataTransferObject implements AgendaItemDefinitionContract {
61  	private static final long serialVersionUID = 2783959459503209577L;
62  
63  	@XmlElement(name = Elements.ID, required=true)
64  	private String id;
65  	@XmlElement(name = Elements.AGENDA_ID, required=true)
66  	private String agendaId;
67  	@XmlElement(name = Elements.RULE_ID, required=false)
68  	private String ruleId;
69  	@XmlElement(name = Elements.SUB_AGENDA_ID, required=false)
70  	private String subAgendaId;
71  	@XmlElement(name = Elements.WHEN_TRUE_ID, required=false)
72  	private String whenTrueId;
73  	@XmlElement(name = Elements.WHEN_FALSE_ID, required=false)
74  	private String whenFalseId;
75  	@XmlElement(name = Elements.ALWAYS_ID, required=false)
76  	private String alwaysId;
77  	
78  	@XmlElement(name = Elements.RULE, required=false)
79  	private RuleDefinition rule;;
80  	@XmlElement(name = Elements.SUB_AGENDA, required=false)
81  	private AgendaDefinition subAgenda;
82  	@XmlElement(name = Elements.WHEN_TRUE, required=false)
83  	private AgendaItemDefinition whenTrue;
84  	@XmlElement(name = Elements.WHEN_FALSE, required=false)
85  	private AgendaItemDefinition whenFalse;
86  	@XmlElement(name = Elements.ALWAYS, required=false)
87  	private AgendaItemDefinition always;
88  	
89      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
90      private final Long versionNumber;
91      	
92  	@SuppressWarnings("unused")
93      @XmlAnyElement
94      private final Collection<org.w3c.dom.Element> _futureElements = null;
95  	
96  	
97  	 /** 
98       * This constructor should never be called.  
99       * It is only present for use during JAXB unmarshalling. 
100      */
101     private AgendaItemDefinition() {
102     	this.id = null;
103     	this.agendaId = null;
104     	this.ruleId = null;
105     	this.subAgendaId = null;
106     	this.whenTrueId = null;
107     	this.whenFalseId = null;
108     	this.alwaysId = null;
109     	
110     	this.rule = null;
111     	this.subAgenda = null;
112     	
113     	this.whenTrue = null;
114     	this.whenFalse = null;
115     	this.always = null;
116     	
117         this.versionNumber = null;
118     }
119     
120     /**
121 	 * Constructs a KRMS Repository AgendaItemDefinition object from the given builder.
122 	 * This constructor is private and should only ever be invoked from the builder.
123 	 * 
124 	 * @param builder the Builder from which to construct the AgendaItemDefinition
125 	 */
126     private AgendaItemDefinition(Builder builder) {
127     	this.id = builder.getId();
128     	this.agendaId = builder.getAgendaId();
129     	this.ruleId = builder.getRuleId();
130     	this.subAgendaId = builder.getSubAgendaId();
131     	this.whenTrueId = builder.getWhenTrueId();
132     	this.whenFalseId = builder.getWhenFalseId();
133     	this.alwaysId = builder.getAlwaysId();
134         this.versionNumber = builder.getVersionNumber();
135 
136     	if (builder.getRule() != null) { this.rule = builder.getRule().build(); }
137     	if (builder.getSubAgenda() != null) { this.subAgenda = builder.getSubAgenda().build(); }
138     	if (builder.getWhenTrue() != null) { this.whenTrue  = builder.getWhenTrue().build(); }
139     	if (builder.getWhenFalse() != null) { this.whenFalse = builder.getWhenFalse().build(); }
140     	if (builder.getAlways() != null) { this.always = builder.getAlways().build(); }
141     }
142 
143 	@Override
144 	public String getId() {
145 		return this.id;
146 	}
147 
148 	@Override
149 	public String getAgendaId() {
150 		return this.agendaId;
151 	}
152 
153 	@Override
154 	public String getRuleId() {
155 		return this.ruleId;
156 	}
157 
158 	@Override
159 	public String getSubAgendaId() {
160 		return this.subAgendaId;
161 	}
162 
163 	@Override
164 	public String getWhenTrueId() {
165 		return this.whenTrueId;
166 	}
167 
168 	@Override
169 	public String getWhenFalseId() {
170 		return this.whenFalseId;
171 	}
172 
173 	@Override
174 	public String getAlwaysId() {
175 		return this.alwaysId;
176 	}
177 
178 	@Override
179 	public RuleDefinition getRule() {
180 		return this.rule; 
181 	}
182 
183 	@Override
184 	public AgendaDefinition getSubAgenda() {
185 		return this.subAgenda; 
186 	}
187 
188 	@Override
189 	public AgendaItemDefinition getWhenTrue() {
190 		return this.whenTrue; 
191 	}
192 
193 	@Override
194 	public AgendaItemDefinition getWhenFalse() {
195 		return this.whenFalse; 
196 	}
197 
198 	@Override
199 	public AgendaItemDefinition getAlways() {
200 		return this.always; 
201 	}
202 
203     @Override
204     public Long getVersionNumber() {
205         return versionNumber;
206     }
207         
208 	/**
209      * This builder is used to construct instances of KRMS Repository AgendaItemDefinition.  It enforces the constraints of the {@link AgendaItemDefinitionContract}.
210      */
211     public static class Builder implements AgendaItemDefinitionContract, ModelBuilder, Serializable {
212 		
213         private String id;
214         private String agendaId;
215         private String ruleId;
216         private String subAgendaId;
217         private String whenTrueId;
218         private String whenFalseId;
219         private String alwaysId;
220         private Long versionNumber;
221         
222         private RuleDefinition.Builder rule;
223         private AgendaDefinition.Builder subAgenda;
224         
225         private AgendaItemDefinition.Builder whenTrue;
226         private AgendaItemDefinition.Builder whenFalse;
227         private AgendaItemDefinition.Builder always;
228         
229 
230 		/**
231 		 * Private constructor for creating a builder with all of it's required attributes.
232 		 */
233         private Builder(String id, String agendaId) {
234         	setId(id);
235         	setAgendaId(agendaId);
236             setVersionNumber(0L);
237         }
238 
239         /**
240          * Create a builder with the given parameters.
241          *
242          * @param id
243          * @param agendaId
244          * @return Builder
245          */
246         public static Builder create(String id, String agendaId){
247         	return new Builder(id, agendaId);
248         }
249 
250         /**
251          * Creates a builder by populating it with data from the given {@link AgendaItemDefinitionContract}.
252          * 
253          * @param contract the contract from which to populate this builder
254          * @return an instance of the builder populated with data from the contract
255          * @throws IllegalArgumentException if the contract is null
256          */
257         public static Builder create(AgendaItemDefinitionContract contract) {
258         	if (contract == null) {
259                 throw new IllegalArgumentException("contract is null");
260         	}
261         	Builder builder =  new Builder(contract.getId(), contract.getAgendaId());
262         	builder.setRuleId(contract.getRuleId());
263         	builder.setSubAgendaId(contract.getSubAgendaId());
264         	builder.setWhenTrueId(contract.getWhenTrueId());
265         	builder.setWhenFalseId(contract.getWhenFalseId());
266         	builder.setAlwaysId(contract.getAlwaysId());
267         	
268         	if (contract.getRule() != null){
269         		builder.setRule(RuleDefinition.Builder.create( contract.getRule() ));
270         	}
271         	if (contract.getSubAgenda() != null){
272         		builder.setSubAgenda( AgendaDefinition.Builder.create( contract.getSubAgenda()));
273         	}
274         	if (contract.getWhenTrue() != null){
275         		builder.setWhenTrue( AgendaItemDefinition.Builder.create( contract.getWhenTrue()));
276         	}
277         	if (contract.getWhenFalse() != null){
278         		builder.setWhenFalse( AgendaItemDefinition.Builder.create( contract.getWhenFalse()));
279         	}
280         	if (contract.getAlways() != null){
281         		builder.setAlways( AgendaItemDefinition.Builder.create( contract.getAlways()));
282         	}
283             builder.setVersionNumber(contract.getVersionNumber());
284         	return builder;
285         }
286 
287 		/**
288 		 * Sets the value of the id on this builder to the given value.
289 		 * 
290 		 * @param agendaItemId the agenda item id to set, may be null, must not be blank
291          * <p>The agenda item id is generated by the system.  For new agenda items (not yet persisted) this field is null.
292          *    For existing agenda items this field is the generated id.</p>
293 		 * @throws IllegalArgumentException if the id is blank
294 		 */
295         public void setId(String agendaItemId) {
296             if (agendaItemId != null && StringUtils.isBlank(agendaItemId)) {
297                 throw new IllegalArgumentException("agendaItemId must be null or non-blank");
298             }
299 			this.id = agendaItemId;
300 		}
301 
302         /**
303          * Set the value of the agenda id on this builder to the given value.
304          *
305          * @param agendaId the agenda id of the agenda item to set, must not be null or blank
306          * @throws IllegalArgumentException if the agenda id is null or blank
307          */
308         public void setAgendaId(String agendaId) {
309             if (StringUtils.isBlank(agendaId)) {
310                 throw new IllegalArgumentException("agendaId is blank");
311             }
312 			this.agendaId = agendaId;
313 		}
314 
315         /**
316          * Set the value of the rule id on this builder to the given value.
317          * @param ruleId the rule id of the agenda item to set
318          */
319 		public void setRuleId(String ruleId) {
320 			this.ruleId = ruleId;
321 		}
322 
323         /**
324          * Set the value of the sub agenda id on this builder to the given value.
325          * @param subAgendaId the sub agenda id of the agenda item to set
326          */
327 		public void setSubAgendaId(String subAgendaId) {
328 			this.subAgendaId = subAgendaId;
329 		}
330 
331         /**
332          * Set the value of the agenda item id for the "when true" condition on this builder to the given value.
333          * @param whenTrueId the agenda item id for the "when true" condition of the agenda item to set
334          */
335 		public void setWhenTrueId(String whenTrueId) {
336 			this.whenTrueId = whenTrueId;
337 		}
338 
339         /**
340          * Set the value of the agenda item id for the "when false" condition on this builder to the given value.
341          * @param whenFalseId the agenda item id for the "when false" condition of the agenda item to set
342          */
343 		public void setWhenFalseId(String whenFalseId) {
344 			this.whenFalseId = whenFalseId;
345 		}
346 
347         /**
348          * Set the value of the agenda item id for the "always" condition on this builder to the given value.
349          * @param alwaysId the agenda item id for the "always" condition of the agenda item to set
350          */
351 		public void setAlwaysId(String alwaysId) {
352 			this.alwaysId = alwaysId;
353 		}
354 
355         /**
356          * Set the value of the rule on this builder to the given value.
357          * @param rule the rule of the agenda item to set
358          */
359 		public void setRule(RuleDefinition.Builder rule) {
360 			this.rule = rule;
361 		}
362 
363         /**
364          * Set the value of the sub agenda on this builder to the given value.
365          * @param subAgenda the sub agenda of the agenda item to set
366          */
367 		public void setSubAgenda(AgendaDefinition.Builder subAgenda) {
368 			this.subAgenda = subAgenda;
369 		}
370 
371         /**
372          * Set the value of the agenda item for the "when true" condition on this builder to the given value.
373          * Has the additional side effect of setting whenTrueId to the ID value of the {{whenTrue}} argument.
374          * @param whenTrue the agenda item for the "when true" condition of the agenda item to set
375          */
376 		public void setWhenTrue(AgendaItemDefinition.Builder whenTrue) {
377 			this.whenTrue = whenTrue;
378             this.whenTrueId = (whenTrue != null) ? whenTrue.getId() : null;
379 		}
380 
381         /**
382          * Set the value of the agenda item for the "when false" condition on this builder to the given value.
383          * Has the additional side effect of setting whenTrueId to the ID value of the {{whenFalse}} argument.
384          * @param whenFalse the agenda item for the "when false" condition of the agenda item to set
385          */
386 		public void setWhenFalse(AgendaItemDefinition.Builder whenFalse) {
387 			this.whenFalse = whenFalse;
388             this.whenFalseId = (whenFalse != null) ? whenFalse.getId() : null;
389         }
390 
391         /**
392          * Set the value of the agenda item for the "always" condition on this builder to the given value.
393          * Has the additional side effect of setting {{whenTrueId}} to the ID value of the always argument.
394          * @param always the agenda item for the "always" condition of the agenda item to set
395          */
396 		public void setAlways(AgendaItemDefinition.Builder always) {
397 			this.always = always;
398             this.alwaysId = (always != null) ? always.getId() : null;
399 		}
400 
401         /**
402          * Set the value of the version number on this builder to the given value.
403          * @param versionNumber the version number set
404          */
405 		public void setVersionNumber(Long versionNumber){
406             this.versionNumber = versionNumber;
407         }
408         		
409 		@Override
410 		public String getId() {
411 			return id;
412 		}
413 
414 		@Override
415 		public String getAgendaId() {
416 			return agendaId;
417 		}
418 
419 		@Override
420 		public String getRuleId() {
421 			return ruleId;
422 		}
423 
424 		@Override
425 		public String getSubAgendaId() {
426 			return subAgendaId;
427 		}
428 
429 		@Override
430 		public String getWhenTrueId() {
431 			return whenTrueId;
432 		}
433 
434 		@Override
435 		public String getWhenFalseId() {
436 			return whenFalseId;
437 		}
438 
439 		@Override
440 		public String getAlwaysId() {
441 			return alwaysId;
442 		}
443 
444 		@Override
445 		public RuleDefinition.Builder getRule() {
446 			return rule;
447 		}
448 
449 		@Override
450 		public AgendaDefinition.Builder getSubAgenda() {
451 			return subAgenda;
452 		}
453 
454 		@Override
455 		public AgendaItemDefinition.Builder getWhenTrue() {
456 			return whenTrue;
457 		}
458 
459 		@Override
460 		public AgendaItemDefinition.Builder getWhenFalse() {
461 			return whenFalse;
462 		}
463 
464 		@Override
465 		public AgendaItemDefinition.Builder getAlways() {
466 			return always;
467 		}
468 
469         @Override
470         public Long getVersionNumber() {
471             return versionNumber;
472         }
473 
474 		/**
475 		 * Builds an instance of a AgendaItemDefinition based on the current state of the builder.
476 		 * 
477 		 * @return the fully-constructed AgendaItemDefinition
478 		 */
479         @Override
480         public AgendaItemDefinition build() {
481             return new AgendaItemDefinition(this);
482         }
483 		
484     }
485 	
486 	/**
487 	 * Defines some internal constants used on this class.
488 	 */
489 	static class Constants {
490 		final static String ROOT_ELEMENT_NAME = "AgendaItemDefinition";
491 		final static String TYPE_NAME = "AgendaItemType";
492 	}
493 	
494 	/**
495 	 * A private class which exposes constants which define the XML element names to use
496 	 * when this object is marshalled to XML.
497 	 */
498 	public static class Elements {
499 		final static String ID = "id";
500 		final static String AGENDA_ID = "agendaId";
501 		final static String RULE_ID = "ruleId";
502 		final static String SUB_AGENDA_ID = "subAgendaId";
503 		final static String WHEN_TRUE_ID = "whenTrueId";
504 		final static String WHEN_FALSE_ID = "whenFalseId";
505 		final static String ALWAYS_ID = "alwaysId";
506 
507 		final static String RULE = "rule";
508 		final static String SUB_AGENDA = "subAgenda";
509 		final static String WHEN_TRUE = "whenTrue";
510 		final static String WHEN_FALSE = "whenFalse";
511 		final static String ALWAYS = "always";
512 	}
513 
514     public static class Cache {
515         public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + AgendaItemDefinition.Constants.TYPE_NAME;
516     }
517 }