001 /** 002 * Copyright 2005-2012 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.repository.rule.RuleDefinition; 033 034 /** 035 * Concrete model object implementation of KRMS Repository AgendaItemDefinition 036 * immutable. 037 * Instances of AgendaItemDefinition can be (un)marshalled to and from XML. 038 * 039 * @see AgendaItemDefinitionContract 040 */ 041 @XmlRootElement(name = AgendaItemDefinition.Constants.ROOT_ELEMENT_NAME) 042 @XmlAccessorType(XmlAccessType.NONE) 043 @XmlType(name = AgendaItemDefinition.Constants.TYPE_NAME, propOrder = { 044 AgendaItemDefinition.Elements.ID, 045 AgendaItemDefinition.Elements.AGENDA_ID, 046 AgendaItemDefinition.Elements.RULE_ID, 047 AgendaItemDefinition.Elements.SUB_AGENDA_ID, 048 AgendaItemDefinition.Elements.WHEN_TRUE_ID, 049 AgendaItemDefinition.Elements.WHEN_FALSE_ID, 050 AgendaItemDefinition.Elements.ALWAYS_ID, 051 AgendaItemDefinition.Elements.RULE, 052 AgendaItemDefinition.Elements.SUB_AGENDA, 053 AgendaItemDefinition.Elements.WHEN_TRUE, 054 AgendaItemDefinition.Elements.WHEN_FALSE, 055 AgendaItemDefinition.Elements.ALWAYS, 056 CoreConstants.CommonElements.VERSION_NUMBER, 057 CoreConstants.CommonElements.FUTURE_ELEMENTS 058 }) 059 public final class AgendaItemDefinition extends AbstractDataTransferObject implements AgendaItemDefinitionContract { 060 private static final long serialVersionUID = 2783959459503209577L; 061 062 @XmlElement(name = Elements.ID, required=true) 063 private String id; 064 @XmlElement(name = Elements.AGENDA_ID, required=true) 065 private String agendaId; 066 @XmlElement(name = Elements.RULE_ID, required=false) 067 private String ruleId; 068 @XmlElement(name = Elements.SUB_AGENDA_ID, required=false) 069 private String subAgendaId; 070 @XmlElement(name = Elements.WHEN_TRUE_ID, required=false) 071 private String whenTrueId; 072 @XmlElement(name = Elements.WHEN_FALSE_ID, required=false) 073 private String whenFalseId; 074 @XmlElement(name = Elements.ALWAYS_ID, required=false) 075 private String alwaysId; 076 077 @XmlElement(name = Elements.RULE, required=false) 078 private RuleDefinition rule;; 079 @XmlElement(name = Elements.SUB_AGENDA, required=false) 080 private AgendaDefinition subAgenda; 081 @XmlElement(name = Elements.WHEN_TRUE, required=false) 082 private AgendaItemDefinition whenTrue; 083 @XmlElement(name = Elements.WHEN_FALSE, required=false) 084 private AgendaItemDefinition whenFalse; 085 @XmlElement(name = Elements.ALWAYS, required=false) 086 private AgendaItemDefinition always; 087 088 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 089 private final Long versionNumber; 090 091 @SuppressWarnings("unused") 092 @XmlAnyElement 093 private final Collection<org.w3c.dom.Element> _futureElements = null; 094 095 096 /** 097 * This constructor should never be called. 098 * It is only present for use during JAXB unmarshalling. 099 */ 100 private AgendaItemDefinition() { 101 this.id = null; 102 this.agendaId = null; 103 this.ruleId = null; 104 this.subAgendaId = null; 105 this.whenTrueId = null; 106 this.whenFalseId = null; 107 this.alwaysId = null; 108 109 this.rule = null; 110 this.subAgenda = null; 111 112 this.whenTrue = null; 113 this.whenFalse = null; 114 this.always = null; 115 116 this.versionNumber = null; 117 } 118 119 /** 120 * Constructs a KRMS Repository AgendaItemDefinition object from the given builder. 121 * This constructor is private and should only ever be invoked from the builder. 122 * 123 * @param builder the Builder from which to construct the AgendaItemDefinition 124 */ 125 private AgendaItemDefinition(Builder builder) { 126 this.id = builder.getId(); 127 this.agendaId = builder.getAgendaId(); 128 this.ruleId = builder.getRuleId(); 129 this.subAgendaId = builder.getSubAgendaId(); 130 this.whenTrueId = builder.getWhenTrueId(); 131 this.whenFalseId = builder.getWhenFalseId(); 132 this.alwaysId = builder.getAlwaysId(); 133 this.versionNumber = builder.getVersionNumber(); 134 135 if (builder.getRule() != null) { this.rule = builder.getRule().build(); } 136 if (builder.getSubAgenda() != null) { this.subAgenda = builder.getSubAgenda().build(); } 137 if (builder.getWhenTrue() != null) { this.whenTrue = builder.getWhenTrue().build(); } 138 if (builder.getWhenFalse() != null) { this.whenFalse = builder.getWhenFalse().build(); } 139 if (builder.getAlways() != null) { this.always = builder.getAlways().build(); } 140 } 141 142 @Override 143 public String getId() { 144 return this.id; 145 } 146 147 @Override 148 public String getAgendaId() { 149 return this.agendaId; 150 } 151 152 @Override 153 public String getRuleId() { 154 return this.ruleId; 155 } 156 157 @Override 158 public String getSubAgendaId() { 159 return this.subAgendaId; 160 } 161 162 @Override 163 public String getWhenTrueId() { 164 return this.whenTrueId; 165 } 166 167 @Override 168 public String getWhenFalseId() { 169 return this.whenFalseId; 170 } 171 172 @Override 173 public String getAlwaysId() { 174 return this.alwaysId; 175 } 176 177 @Override 178 public RuleDefinition getRule() { 179 return this.rule; 180 } 181 182 @Override 183 public AgendaDefinition getSubAgenda() { 184 return this.subAgenda; 185 } 186 187 @Override 188 public AgendaItemDefinition getWhenTrue() { 189 return this.whenTrue; 190 } 191 192 @Override 193 public AgendaItemDefinition getWhenFalse() { 194 return this.whenFalse; 195 } 196 197 @Override 198 public AgendaItemDefinition getAlways() { 199 return this.always; 200 } 201 202 @Override 203 public Long getVersionNumber() { 204 return versionNumber; 205 } 206 207 /** 208 * This builder is used to construct instances of KRMS Repository AgendaItemDefinition. It enforces the constraints of the {@link AgendaItemDefinitionContract}. 209 */ 210 public static class Builder implements AgendaItemDefinitionContract, ModelBuilder, Serializable { 211 212 private String id; 213 private String agendaId; 214 private String ruleId; 215 private String subAgendaId; 216 private String whenTrueId; 217 private String whenFalseId; 218 private String alwaysId; 219 private Long versionNumber; 220 221 private RuleDefinition.Builder rule; 222 private AgendaDefinition.Builder subAgenda; 223 224 private AgendaItemDefinition.Builder whenTrue; 225 private AgendaItemDefinition.Builder whenFalse; 226 private AgendaItemDefinition.Builder always; 227 228 229 /** 230 * Private constructor for creating a builder with all of it's required attributes. 231 */ 232 private Builder(String id, String agendaId) { 233 setId(id); 234 setAgendaId(agendaId); 235 } 236 237 /** 238 * Create a builder with the given parameters. 239 * 240 * @param id 241 * @param agendaId 242 * @return Builder 243 */ 244 public static Builder create(String id, String agendaId){ 245 return new Builder(id, agendaId); 246 } 247 248 /** 249 * Creates a builder by populating it with data from the given {@link AgendaItemDefinitionContract}. 250 * 251 * @param contract the contract from which to populate this builder 252 * @return an instance of the builder populated with data from the contract 253 * @throws IllegalArgumentException if the contract is null 254 */ 255 public static Builder create(AgendaItemDefinitionContract contract) { 256 if (contract == null) { 257 throw new IllegalArgumentException("contract is null"); 258 } 259 Builder builder = new Builder(contract.getId(), contract.getAgendaId()); 260 builder.setRuleId(contract.getRuleId()); 261 builder.setSubAgendaId(contract.getSubAgendaId()); 262 builder.setWhenTrueId(contract.getWhenTrueId()); 263 builder.setWhenFalseId(contract.getWhenFalseId()); 264 builder.setAlwaysId(contract.getAlwaysId()); 265 266 if (contract.getRule() != null){ 267 builder.setRule(RuleDefinition.Builder.create( contract.getRule() )); 268 } 269 if (contract.getSubAgenda() != null){ 270 builder.setSubAgenda( AgendaDefinition.Builder.create( contract.getSubAgenda())); 271 } 272 if (contract.getWhenTrue() != null){ 273 builder.setWhenTrue( AgendaItemDefinition.Builder.create( contract.getWhenTrue())); 274 } 275 if (contract.getWhenFalse() != null){ 276 builder.setWhenFalse( AgendaItemDefinition.Builder.create( contract.getWhenFalse())); 277 } 278 if (contract.getAlways() != null){ 279 builder.setAlways( AgendaItemDefinition.Builder.create( contract.getAlways())); 280 } 281 builder.setVersionNumber(contract.getVersionNumber()); 282 return builder; 283 } 284 285 /** 286 * Sets the value of the id on this builder to the given value. 287 * 288 * @param agendaItemId the agenda item id to set, may be null, must not be blank 289 * <p>The agenda item id is generated by the system. For new agenda items (not yet persisted) this field is null. 290 * For existing agenda items this field is the generated id.</p> 291 * @throws IllegalArgumentException if the id is blank 292 */ 293 public void setId(String agendaItemId) { 294 if (id != null && StringUtils.isBlank(agendaItemId)) { 295 throw new IllegalArgumentException("agendaItemId must be null or non-blank"); 296 } 297 this.id = agendaItemId; 298 } 299 300 /** 301 * Set the value of the agenda id on this builder to the given value. 302 * 303 * @param agendaId the agenda id of the agenda item to set, must not be null or blank 304 * @throws IllegalArgumentException if the agenda id is null or blank 305 */ 306 public void setAgendaId(String agendaId) { 307 if (StringUtils.isBlank(agendaId)) { 308 throw new IllegalArgumentException("agendaId is blank"); 309 } 310 this.agendaId = agendaId; 311 } 312 313 /** 314 * Set the value of the rule id on this builder to the given value. 315 * @param ruleId the rule id of the agenda item to set 316 */ 317 public void setRuleId(String ruleId) { 318 this.ruleId = ruleId; 319 } 320 321 /** 322 * Set the value of the sub agenda id on this builder to the given value. 323 * @param subAgendaId the sub agenda id of the agenda item to set 324 */ 325 public void setSubAgendaId(String subAgendaId) { 326 this.subAgendaId = subAgendaId; 327 } 328 329 /** 330 * Set the value of the agenda item id for the "when true" condition on this builder to the given value. 331 * @param whenTrueId the agenda item id for the "when true" condition of the agenda item to set 332 */ 333 public void setWhenTrueId(String whenTrueId) { 334 this.whenTrueId = whenTrueId; 335 } 336 337 /** 338 * Set the value of the agenda item id for the "when false" condition on this builder to the given value. 339 * @param whenFalseId the agenda item id for the "when false" condition of the agenda item to set 340 */ 341 public void setWhenFalseId(String whenFalseId) { 342 this.whenFalseId = whenFalseId; 343 } 344 345 /** 346 * Set the value of the agenda item id for the "always" condition on this builder to the given value. 347 * @param alwaysId the agenda item id for the "always" condition of the agenda item to set 348 */ 349 public void setAlwaysId(String alwaysId) { 350 this.alwaysId = alwaysId; 351 } 352 353 /** 354 * Set the value of the rule on this builder to the given value. 355 * @param rule the rule of the agenda item to set 356 */ 357 public void setRule(RuleDefinition.Builder rule) { 358 this.rule = rule; 359 } 360 361 /** 362 * Set the value of the sub agenda on this builder to the given value. 363 * @param subAgenda the sub agenda of the agenda item to set 364 */ 365 public void setSubAgenda(AgendaDefinition.Builder subAgenda) { 366 this.subAgenda = subAgenda; 367 } 368 369 /** 370 * Set the value of the agenda item for the "when true" condition on this builder to the given value. 371 * @param whenTrue the agenda item for the "when true" condition of the agenda item to set 372 */ 373 public void setWhenTrue(AgendaItemDefinition.Builder whenTrue) { 374 this.whenTrue = whenTrue; 375 } 376 377 /** 378 * Set the value of the agenda item for the "when false" condition on this builder to the given value. 379 * @param whenFalse the agenda item for the "when false" condition of the agenda item to set 380 */ 381 public void setWhenFalse(AgendaItemDefinition.Builder whenFalse) { 382 this.whenTrue = whenFalse; 383 } 384 385 /** 386 * Set the value of the agenda item for the "always" condition on this builder to the given value. 387 * @param always the agenda item for the "always" condition of the agenda item to set 388 */ 389 public void setAlways(AgendaItemDefinition.Builder always) { 390 this.always = always; 391 } 392 393 /** 394 * Set the value of the version number on this builder to the given value. 395 * @param versionNumber the version number set 396 */ 397 public void setVersionNumber(Long versionNumber){ 398 this.versionNumber = versionNumber; 399 } 400 401 @Override 402 public String getId() { 403 return id; 404 } 405 406 @Override 407 public String getAgendaId() { 408 return agendaId; 409 } 410 411 @Override 412 public String getRuleId() { 413 return ruleId; 414 } 415 416 @Override 417 public String getSubAgendaId() { 418 return subAgendaId; 419 } 420 421 @Override 422 public String getWhenTrueId() { 423 return whenTrueId; 424 } 425 426 @Override 427 public String getWhenFalseId() { 428 return whenFalseId; 429 } 430 431 @Override 432 public String getAlwaysId() { 433 return alwaysId; 434 } 435 436 @Override 437 public RuleDefinition.Builder getRule() { 438 return rule; 439 } 440 441 @Override 442 public AgendaDefinition.Builder getSubAgenda() { 443 return subAgenda; 444 } 445 446 @Override 447 public AgendaItemDefinition.Builder getWhenTrue() { 448 return whenTrue; 449 } 450 451 @Override 452 public AgendaItemDefinition.Builder getWhenFalse() { 453 return whenFalse; 454 } 455 456 @Override 457 public AgendaItemDefinition.Builder getAlways() { 458 return always; 459 } 460 461 @Override 462 public Long getVersionNumber() { 463 return versionNumber; 464 } 465 466 /** 467 * Builds an instance of a AgendaItemDefinition based on the current state of the builder. 468 * 469 * @return the fully-constructed AgendaItemDefinition 470 */ 471 @Override 472 public AgendaItemDefinition build() { 473 return new AgendaItemDefinition(this); 474 } 475 476 } 477 478 /** 479 * Defines some internal constants used on this class. 480 */ 481 static class Constants { 482 final static String ROOT_ELEMENT_NAME = "AgendaItemDefinition"; 483 final static String TYPE_NAME = "AgendaItemType"; 484 } 485 486 /** 487 * A private class which exposes constants which define the XML element names to use 488 * when this object is marshalled to XML. 489 */ 490 public static class Elements { 491 final static String ID = "id"; 492 final static String AGENDA_ID = "agendaId"; 493 final static String RULE_ID = "ruleId"; 494 final static String SUB_AGENDA_ID = "subAgendaId"; 495 final static String WHEN_TRUE_ID = "whenTrueId"; 496 final static String WHEN_FALSE_ID = "whenFalseId"; 497 final static String ALWAYS_ID = "alwaysId"; 498 499 final static String RULE = "rule"; 500 final static String SUB_AGENDA = "subAgenda"; 501 final static String WHEN_TRUE = "whenTrue"; 502 final static String WHEN_FALSE = "whenFalse"; 503 final static String ALWAYS = "always"; 504 } 505 506 }