001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krms.api.repository.agenda;
017
018 import java.io.Serializable;
019 import java.util.Collection;
020
021 import javax.xml.bind.annotation.XmlAccessType;
022 import javax.xml.bind.annotation.XmlAccessorType;
023 import javax.xml.bind.annotation.XmlAnyElement;
024 import javax.xml.bind.annotation.XmlElement;
025 import javax.xml.bind.annotation.XmlRootElement;
026 import javax.xml.bind.annotation.XmlType;
027
028 import org.apache.commons.lang.StringUtils;
029 import org.kuali.rice.core.api.CoreConstants;
030 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
031 import org.kuali.rice.core.api.mo.ModelBuilder;
032 import org.kuali.rice.krms.api.KrmsConstants;
033 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
034
035 /**
036 * Concrete model object implementation of KRMS Repository AgendaItemDefinition
037 * immutable.
038 * Instances of AgendaItemDefinition can be (un)marshalled to and from XML.
039 *
040 * @see AgendaItemDefinitionContract
041 */
042 @XmlRootElement(name = AgendaItemDefinition.Constants.ROOT_ELEMENT_NAME)
043 @XmlAccessorType(XmlAccessType.NONE)
044 @XmlType(name = AgendaItemDefinition.Constants.TYPE_NAME, propOrder = {
045 AgendaItemDefinition.Elements.ID,
046 AgendaItemDefinition.Elements.AGENDA_ID,
047 AgendaItemDefinition.Elements.RULE_ID,
048 AgendaItemDefinition.Elements.SUB_AGENDA_ID,
049 AgendaItemDefinition.Elements.WHEN_TRUE_ID,
050 AgendaItemDefinition.Elements.WHEN_FALSE_ID,
051 AgendaItemDefinition.Elements.ALWAYS_ID,
052 AgendaItemDefinition.Elements.RULE,
053 AgendaItemDefinition.Elements.SUB_AGENDA,
054 AgendaItemDefinition.Elements.WHEN_TRUE,
055 AgendaItemDefinition.Elements.WHEN_FALSE,
056 AgendaItemDefinition.Elements.ALWAYS,
057 CoreConstants.CommonElements.VERSION_NUMBER,
058 CoreConstants.CommonElements.FUTURE_ELEMENTS
059 })
060 public final class AgendaItemDefinition extends AbstractDataTransferObject implements AgendaItemDefinitionContract {
061 private static final long serialVersionUID = 2783959459503209577L;
062
063 @XmlElement(name = Elements.ID, required=true)
064 private String id;
065 @XmlElement(name = Elements.AGENDA_ID, required=true)
066 private String agendaId;
067 @XmlElement(name = Elements.RULE_ID, required=false)
068 private String ruleId;
069 @XmlElement(name = Elements.SUB_AGENDA_ID, required=false)
070 private String subAgendaId;
071 @XmlElement(name = Elements.WHEN_TRUE_ID, required=false)
072 private String whenTrueId;
073 @XmlElement(name = Elements.WHEN_FALSE_ID, required=false)
074 private String whenFalseId;
075 @XmlElement(name = Elements.ALWAYS_ID, required=false)
076 private String alwaysId;
077
078 @XmlElement(name = Elements.RULE, required=false)
079 private RuleDefinition rule;;
080 @XmlElement(name = Elements.SUB_AGENDA, required=false)
081 private AgendaDefinition subAgenda;
082 @XmlElement(name = Elements.WHEN_TRUE, required=false)
083 private AgendaItemDefinition whenTrue;
084 @XmlElement(name = Elements.WHEN_FALSE, required=false)
085 private AgendaItemDefinition whenFalse;
086 @XmlElement(name = Elements.ALWAYS, required=false)
087 private AgendaItemDefinition always;
088
089 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
090 private final Long versionNumber;
091
092 @SuppressWarnings("unused")
093 @XmlAnyElement
094 private final Collection<org.w3c.dom.Element> _futureElements = null;
095
096
097 /**
098 * This constructor should never be called.
099 * 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 }
237
238 /**
239 * Create a builder with the given parameters.
240 *
241 * @param id
242 * @param agendaId
243 * @return Builder
244 */
245 public static Builder create(String id, String agendaId){
246 return new Builder(id, agendaId);
247 }
248
249 /**
250 * Creates a builder by populating it with data from the given {@link AgendaItemDefinitionContract}.
251 *
252 * @param contract the contract from which to populate this builder
253 * @return an instance of the builder populated with data from the contract
254 * @throws IllegalArgumentException if the contract is null
255 */
256 public static Builder create(AgendaItemDefinitionContract contract) {
257 if (contract == null) {
258 throw new IllegalArgumentException("contract is null");
259 }
260 Builder builder = new Builder(contract.getId(), contract.getAgendaId());
261 builder.setRuleId(contract.getRuleId());
262 builder.setSubAgendaId(contract.getSubAgendaId());
263 builder.setWhenTrueId(contract.getWhenTrueId());
264 builder.setWhenFalseId(contract.getWhenFalseId());
265 builder.setAlwaysId(contract.getAlwaysId());
266
267 if (contract.getRule() != null){
268 builder.setRule(RuleDefinition.Builder.create( contract.getRule() ));
269 }
270 if (contract.getSubAgenda() != null){
271 builder.setSubAgenda( AgendaDefinition.Builder.create( contract.getSubAgenda()));
272 }
273 if (contract.getWhenTrue() != null){
274 builder.setWhenTrue( AgendaItemDefinition.Builder.create( contract.getWhenTrue()));
275 }
276 if (contract.getWhenFalse() != null){
277 builder.setWhenFalse( AgendaItemDefinition.Builder.create( contract.getWhenFalse()));
278 }
279 if (contract.getAlways() != null){
280 builder.setAlways( AgendaItemDefinition.Builder.create( contract.getAlways()));
281 }
282 builder.setVersionNumber(contract.getVersionNumber());
283 return builder;
284 }
285
286 /**
287 * Sets the value of the id on this builder to the given value.
288 *
289 * @param agendaItemId the agenda item id to set, may be null, must not be blank
290 * <p>The agenda item id is generated by the system. For new agenda items (not yet persisted) this field is null.
291 * For existing agenda items this field is the generated id.</p>
292 * @throws IllegalArgumentException if the id is blank
293 */
294 public void setId(String agendaItemId) {
295 if (agendaItemId != null && StringUtils.isBlank(agendaItemId)) {
296 throw new IllegalArgumentException("agendaItemId must be null or non-blank");
297 }
298 this.id = agendaItemId;
299 }
300
301 /**
302 * Set the value of the agenda id on this builder to the given value.
303 *
304 * @param agendaId the agenda id of the agenda item to set, must not be null or blank
305 * @throws IllegalArgumentException if the agenda id is null or blank
306 */
307 public void setAgendaId(String agendaId) {
308 if (StringUtils.isBlank(agendaId)) {
309 throw new IllegalArgumentException("agendaId is blank");
310 }
311 this.agendaId = agendaId;
312 }
313
314 /**
315 * Set the value of the rule id on this builder to the given value.
316 * @param ruleId the rule id of the agenda item to set
317 */
318 public void setRuleId(String ruleId) {
319 this.ruleId = ruleId;
320 }
321
322 /**
323 * Set the value of the sub agenda id on this builder to the given value.
324 * @param subAgendaId the sub agenda id of the agenda item to set
325 */
326 public void setSubAgendaId(String subAgendaId) {
327 this.subAgendaId = subAgendaId;
328 }
329
330 /**
331 * Set the value of the agenda item id for the "when true" condition on this builder to the given value.
332 * @param whenTrueId the agenda item id for the "when true" condition of the agenda item to set
333 */
334 public void setWhenTrueId(String whenTrueId) {
335 this.whenTrueId = whenTrueId;
336 }
337
338 /**
339 * Set the value of the agenda item id for the "when false" condition on this builder to the given value.
340 * @param whenFalseId the agenda item id for the "when false" condition of the agenda item to set
341 */
342 public void setWhenFalseId(String whenFalseId) {
343 this.whenFalseId = whenFalseId;
344 }
345
346 /**
347 * Set the value of the agenda item id for the "always" condition on this builder to the given value.
348 * @param alwaysId the agenda item id for the "always" condition of the agenda item to set
349 */
350 public void setAlwaysId(String alwaysId) {
351 this.alwaysId = alwaysId;
352 }
353
354 /**
355 * Set the value of the rule on this builder to the given value.
356 * @param rule the rule of the agenda item to set
357 */
358 public void setRule(RuleDefinition.Builder rule) {
359 this.rule = rule;
360 }
361
362 /**
363 * Set the value of the sub agenda on this builder to the given value.
364 * @param subAgenda the sub agenda of the agenda item to set
365 */
366 public void setSubAgenda(AgendaDefinition.Builder subAgenda) {
367 this.subAgenda = subAgenda;
368 }
369
370 /**
371 * Set the value of the agenda item for the "when true" condition on this builder to the given value.
372 * @param whenTrue the agenda item for the "when true" condition of the agenda item to set
373 */
374 public void setWhenTrue(AgendaItemDefinition.Builder whenTrue) {
375 this.whenTrue = whenTrue;
376 }
377
378 /**
379 * Set the value of the agenda item for the "when false" condition on this builder to the given value.
380 * @param whenFalse the agenda item for the "when false" condition of the agenda item to set
381 */
382 public void setWhenFalse(AgendaItemDefinition.Builder whenFalse) {
383 this.whenFalse = whenFalse;
384 }
385
386 /**
387 * Set the value of the agenda item for the "always" condition on this builder to the given value.
388 * @param always the agenda item for the "always" condition of the agenda item to set
389 */
390 public void setAlways(AgendaItemDefinition.Builder always) {
391 this.always = always;
392 }
393
394 /**
395 * Set the value of the version number on this builder to the given value.
396 * @param versionNumber the version number set
397 */
398 public void setVersionNumber(Long versionNumber){
399 this.versionNumber = versionNumber;
400 }
401
402 @Override
403 public String getId() {
404 return id;
405 }
406
407 @Override
408 public String getAgendaId() {
409 return agendaId;
410 }
411
412 @Override
413 public String getRuleId() {
414 return ruleId;
415 }
416
417 @Override
418 public String getSubAgendaId() {
419 return subAgendaId;
420 }
421
422 @Override
423 public String getWhenTrueId() {
424 return whenTrueId;
425 }
426
427 @Override
428 public String getWhenFalseId() {
429 return whenFalseId;
430 }
431
432 @Override
433 public String getAlwaysId() {
434 return alwaysId;
435 }
436
437 @Override
438 public RuleDefinition.Builder getRule() {
439 return rule;
440 }
441
442 @Override
443 public AgendaDefinition.Builder getSubAgenda() {
444 return subAgenda;
445 }
446
447 @Override
448 public AgendaItemDefinition.Builder getWhenTrue() {
449 return whenTrue;
450 }
451
452 @Override
453 public AgendaItemDefinition.Builder getWhenFalse() {
454 return whenFalse;
455 }
456
457 @Override
458 public AgendaItemDefinition.Builder getAlways() {
459 return always;
460 }
461
462 @Override
463 public Long getVersionNumber() {
464 return versionNumber;
465 }
466
467 /**
468 * Builds an instance of a AgendaItemDefinition based on the current state of the builder.
469 *
470 * @return the fully-constructed AgendaItemDefinition
471 */
472 @Override
473 public AgendaItemDefinition build() {
474 return new AgendaItemDefinition(this);
475 }
476
477 }
478
479 /**
480 * Defines some internal constants used on this class.
481 */
482 static class Constants {
483 final static String ROOT_ELEMENT_NAME = "AgendaItemDefinition";
484 final static String TYPE_NAME = "AgendaItemType";
485 }
486
487 /**
488 * A private class which exposes constants which define the XML element names to use
489 * when this object is marshalled to XML.
490 */
491 public static class Elements {
492 final static String ID = "id";
493 final static String AGENDA_ID = "agendaId";
494 final static String RULE_ID = "ruleId";
495 final static String SUB_AGENDA_ID = "subAgendaId";
496 final static String WHEN_TRUE_ID = "whenTrueId";
497 final static String WHEN_FALSE_ID = "whenFalseId";
498 final static String ALWAYS_ID = "alwaysId";
499
500 final static String RULE = "rule";
501 final static String SUB_AGENDA = "subAgenda";
502 final static String WHEN_TRUE = "whenTrue";
503 final static String WHEN_FALSE = "whenFalse";
504 final static String ALWAYS = "always";
505 }
506
507 public static class Cache {
508 public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + AgendaItemDefinition.Constants.TYPE_NAME;
509 }
510 }