001/** 002 * Copyright 2004-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 */ 016package org.kuali.kpme.pm.api.positionreportgroup; 017 018import java.io.Serializable; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.Collections; 022import java.util.List; 023import java.util.Set; 024import javax.xml.bind.annotation.XmlAccessType; 025import javax.xml.bind.annotation.XmlAccessorType; 026import javax.xml.bind.annotation.XmlAnyElement; 027import javax.xml.bind.annotation.XmlElement; 028import javax.xml.bind.annotation.XmlRootElement; 029import javax.xml.bind.annotation.XmlType; 030 031import org.apache.commons.collections.CollectionUtils; 032import org.apache.commons.lang.StringUtils; 033import org.joda.time.DateTime; 034import org.joda.time.LocalDate; 035import org.kuali.kpme.core.api.groupkey.HrGroupKey; 036import org.kuali.kpme.core.api.groupkey.HrGroupKeyContract; 037import org.kuali.kpme.core.api.mo.EffectiveKey; 038import org.kuali.kpme.core.api.mo.EffectiveKeyContract; 039import org.kuali.rice.core.api.CoreConstants; 040import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 041import org.kuali.rice.core.api.mo.ModelBuilder; 042import org.kuali.rice.core.api.mo.ModelObjectUtils; 043import org.w3c.dom.Element; 044 045@XmlRootElement(name = PositionReportGroup.Constants.ROOT_ELEMENT_NAME) 046@XmlAccessorType(XmlAccessType.NONE) 047@XmlType(name = PositionReportGroup.Constants.TYPE_NAME, propOrder = { 048 PositionReportGroup.Elements.PM_POSITION_REPORT_GROUP_ID, 049 PositionReportGroup.Elements.EFFECTIVE_KEY_SET, 050 PositionReportGroup.Elements.DESCRIPTION, 051 PositionReportGroup.Elements.POSITION_REPORT_GROUP, 052 CoreConstants.CommonElements.VERSION_NUMBER, 053 CoreConstants.CommonElements.OBJECT_ID, 054 PositionReportGroup.Elements.ACTIVE, 055 PositionReportGroup.Elements.ID, 056 PositionReportGroup.Elements.EFFECTIVE_LOCAL_DATE, 057 PositionReportGroup.Elements.CREATE_TIME, 058 PositionReportGroup.Elements.USER_PRINCIPAL_ID, 059 PositionReportGroup.Elements.GROUP_KEY_CODE_SET, 060 PositionReportGroup.Elements.GROUP_KEY_SET, 061 CoreConstants.CommonElements.FUTURE_ELEMENTS 062}) 063public final class PositionReportGroup extends AbstractDataTransferObject implements PositionReportGroupContract { 064 065 private static final long serialVersionUID = -41287964136831033L; 066 067 @XmlElement(name = Elements.PM_POSITION_REPORT_GROUP_ID, required = false) 068 private final String pmPositionReportGroupId; 069 @XmlElement(name = Elements.EFFECTIVE_KEY_SET, required = false) 070 private final Set<EffectiveKey> effectiveKeySet; 071 @XmlElement(name = Elements.DESCRIPTION, required = false) 072 private final String description; 073 @XmlElement(name = Elements.POSITION_REPORT_GROUP, required = false) 074 private final String positionReportGroup; 075 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 076 private final Long versionNumber; 077 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) 078 private final String objectId; 079 @XmlElement(name = Elements.ACTIVE, required = false) 080 private final boolean active; 081 @XmlElement(name = Elements.ID, required = false) 082 private final String id; 083 @XmlElement(name = Elements.EFFECTIVE_LOCAL_DATE, required = false) 084 private final LocalDate effectiveLocalDate; 085 @XmlElement(name = Elements.CREATE_TIME, required = false) 086 private final DateTime createTime; 087 @XmlElement(name = Elements.USER_PRINCIPAL_ID, required = false) 088 private final String userPrincipalId; 089 @XmlElement(name = Elements.GROUP_KEY_CODE_SET, required = false) 090 private final Set<String> groupKeyCodeSet; 091 @XmlElement(name = Elements.GROUP_KEY_SET, required = false) 092 private final Set<HrGroupKey> groupKeySet; 093 @XmlAnyElement 094 private final Collection<Element> _futureElements = null; 095 096 /** 097 * Private constructor used only by JAXB. 098 * 099 */ 100 private PositionReportGroup() { 101 this.pmPositionReportGroupId = null; 102 this.effectiveKeySet = null; 103 this.description = null; 104 this.positionReportGroup = null; 105 this.versionNumber = null; 106 this.objectId = null; 107 this.active = false; 108 this.id = null; 109 this.effectiveLocalDate = null; 110 this.createTime = null; 111 this.userPrincipalId = null; 112 this.groupKeyCodeSet = null; 113 this.groupKeySet = null; 114 } 115 116 private PositionReportGroup(Builder builder) { 117 this.pmPositionReportGroupId = builder.getPmPositionReportGroupId(); 118 this.effectiveKeySet = ModelObjectUtils.<EffectiveKey>buildImmutableCopy(builder.getEffectiveKeySet()); 119 this.description = builder.getDescription(); 120 this.positionReportGroup = builder.getPositionReportGroup(); 121 this.versionNumber = builder.getVersionNumber(); 122 this.objectId = builder.getObjectId(); 123 this.active = builder.isActive(); 124 this.id = builder.getId(); 125 this.effectiveLocalDate = builder.getEffectiveLocalDate(); 126 this.createTime = builder.getCreateTime(); 127 this.userPrincipalId = builder.getUserPrincipalId(); 128 this.groupKeyCodeSet = builder.getGroupKeyCodeSet(); 129 this.groupKeySet = ModelObjectUtils.<HrGroupKey>buildImmutableCopy(builder.getGroupKeySet()); 130 } 131 132 @Override 133 public String getPmPositionReportGroupId() { 134 return this.pmPositionReportGroupId; 135 } 136 137 @Override 138 public Set<EffectiveKey> getEffectiveKeySet() { 139 return this.effectiveKeySet; 140 } 141 142 // helper method to convert from key-set to key-list 143 public List<EffectiveKey> getEffectiveKeyList() { 144 if (CollectionUtils.isEmpty(this.effectiveKeySet)) { 145 return Collections.emptyList(); 146 } 147 List<EffectiveKey> copy = new ArrayList<EffectiveKey>(); 148 for (EffectiveKey key : this.effectiveKeySet) { 149 copy.add(key); 150 } 151 return Collections.unmodifiableList(copy); 152 } 153 154 @Override 155 public String getDescription() { 156 return this.description; 157 } 158 159 @Override 160 public String getPositionReportGroup() { 161 return this.positionReportGroup; 162 } 163 164 @Override 165 public Long getVersionNumber() { 166 return this.versionNumber; 167 } 168 169 @Override 170 public String getObjectId() { 171 return this.objectId; 172 } 173 174 @Override 175 public boolean isActive() { 176 return this.active; 177 } 178 179 @Override 180 public String getId() { 181 return this.id; 182 } 183 184 @Override 185 public LocalDate getEffectiveLocalDate() { 186 return this.effectiveLocalDate; 187 } 188 189 @Override 190 public DateTime getCreateTime() { 191 return this.createTime; 192 } 193 194 @Override 195 public String getUserPrincipalId() { 196 return this.userPrincipalId; 197 } 198 199 @Override 200 public Set<String> getGroupKeyCodeSet() { 201 return this.groupKeyCodeSet; 202 } 203 204 @Override 205 public Set<HrGroupKey> getGroupKeySet() { 206 return this.groupKeySet; 207 } 208 209 210 /** 211 * A builder which can be used to construct {@link PositionReportGroup} instances. Enforces the constraints of the {@link PositionReportGroupContract}. 212 * 213 */ 214 public final static class Builder implements Serializable, PositionReportGroupContract, ModelBuilder { 215 216 private static final long serialVersionUID = 6845448497862211410L; 217 218 private String pmPositionReportGroupId; 219 private Set<EffectiveKey.Builder> effectiveKeySet; 220 private String description; 221 private String positionReportGroup; 222 private Long versionNumber; 223 private String objectId; 224 private boolean active; 225 private String id; 226 private LocalDate effectiveLocalDate; 227 private DateTime createTime; 228 private String userPrincipalId; 229 private Set<String> groupKeyCodeSet; 230 private Set<HrGroupKey.Builder> groupKeySet; 231 232 private static final ModelObjectUtils.Transformer<EffectiveKeyContract, EffectiveKey.Builder> toEffectiveKeyBuilder 233 = new ModelObjectUtils.Transformer<EffectiveKeyContract, EffectiveKey.Builder>() { 234 public EffectiveKey.Builder transform(EffectiveKeyContract input) { 235 return EffectiveKey.Builder.create(input); 236 } 237 }; 238 239 private static final ModelObjectUtils.Transformer<HrGroupKeyContract, HrGroupKey.Builder> toHrGroupKeyBuilder 240 = new ModelObjectUtils.Transformer<HrGroupKeyContract, HrGroupKey.Builder>() { 241 public HrGroupKey.Builder transform(HrGroupKeyContract input) { 242 return HrGroupKey.Builder.create(input); 243 } 244 }; 245 246 private Builder(String positionReportGroup) { 247 // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods 248 setPositionReportGroup(positionReportGroup); 249 } 250 251 public static Builder create(String positionReportGroup) { 252 253 return new Builder(positionReportGroup); 254 } 255 256 public static Builder create(PositionReportGroupContract contract) { 257 if (contract == null) { 258 throw new IllegalArgumentException("contract was null"); 259 } 260 261 Builder builder = create(contract.getPositionReportGroup()); 262 builder.setPmPositionReportGroupId(contract.getPmPositionReportGroupId()); 263 builder.setEffectiveKeySet(ModelObjectUtils.transformSet(contract.getEffectiveKeySet(), toEffectiveKeyBuilder)); 264 builder.setDescription(contract.getDescription()); 265 builder.setVersionNumber(contract.getVersionNumber()); 266 builder.setObjectId(contract.getObjectId()); 267 builder.setActive(contract.isActive()); 268 builder.setId(contract.getId()); 269 builder.setEffectiveLocalDate(contract.getEffectiveLocalDate()); 270 builder.setCreateTime(contract.getCreateTime()); 271 builder.setUserPrincipalId(contract.getUserPrincipalId()); 272 builder.setGroupKeyCodeSet(contract.getGroupKeyCodeSet()); 273 builder.setGroupKeySet(ModelObjectUtils.transformSet(contract.getGroupKeySet(), toHrGroupKeyBuilder)); 274 return builder; 275 } 276 277 public PositionReportGroup build() { 278 return new PositionReportGroup(this); 279 } 280 281 @Override 282 public String getPmPositionReportGroupId() { 283 return this.pmPositionReportGroupId; 284 } 285 286 @Override 287 public Set<EffectiveKey.Builder> getEffectiveKeySet() { 288 return this.effectiveKeySet; 289 } 290 291 @Override 292 public String getDescription() { 293 return this.description; 294 } 295 296 @Override 297 public String getPositionReportGroup() { 298 return this.positionReportGroup; 299 } 300 301 @Override 302 public Long getVersionNumber() { 303 return this.versionNumber; 304 } 305 306 @Override 307 public String getObjectId() { 308 return this.objectId; 309 } 310 311 @Override 312 public boolean isActive() { 313 return this.active; 314 } 315 316 @Override 317 public String getId() { 318 return this.id; 319 } 320 321 @Override 322 public LocalDate getEffectiveLocalDate() { 323 return this.effectiveLocalDate; 324 } 325 326 @Override 327 public DateTime getCreateTime() { 328 return this.createTime; 329 } 330 331 @Override 332 public String getUserPrincipalId() { 333 return this.userPrincipalId; 334 } 335 336 @Override 337 public Set<String> getGroupKeyCodeSet() { 338 return this.groupKeyCodeSet; 339 } 340 341 @Override 342 public Set<HrGroupKey.Builder> getGroupKeySet() { 343 return this.groupKeySet; 344 } 345 346 public void setPmPositionReportGroupId(String pmPositionReportGroupId) { 347 348 this.pmPositionReportGroupId = pmPositionReportGroupId; 349 } 350 351 public void setEffectiveKeySet(Set<EffectiveKey.Builder> effectiveKeySet) { 352 353 this.effectiveKeySet = effectiveKeySet; 354 } 355 356 public void setDescription(String description) { 357 358 this.description = description; 359 } 360 361 public void setPositionReportGroup(String positionReportGroup) { 362 363 if (StringUtils.isWhitespace(positionReportGroup) || (positionReportGroup == null)) { 364 throw new IllegalArgumentException("positionReportGroup is blank"); 365 } 366 this.positionReportGroup = positionReportGroup; 367 } 368 369 public void setVersionNumber(Long versionNumber) { 370 371 this.versionNumber = versionNumber; 372 } 373 374 public void setObjectId(String objectId) { 375 376 this.objectId = objectId; 377 } 378 379 public void setActive(boolean active) { 380 381 this.active = active; 382 } 383 384 public void setId(String id) { 385 386 this.id = id; 387 } 388 389 public void setEffectiveLocalDate(LocalDate effectiveLocalDate) { 390 391 this.effectiveLocalDate = effectiveLocalDate; 392 } 393 394 public void setCreateTime(DateTime createTime) { 395 396 this.createTime = createTime; 397 } 398 399 public void setUserPrincipalId(String userPrincipalId) { 400 401 this.userPrincipalId = userPrincipalId; 402 } 403 404 public void setGroupKeyCodeSet(Set<String> groupKeyCodeSet) { 405 406 this.groupKeyCodeSet = groupKeyCodeSet; 407 } 408 409 public void setGroupKeySet(Set<HrGroupKey.Builder> groupKeySet) { 410 411 this.groupKeySet = groupKeySet; 412 } 413 414 } 415 416 417 /** 418 * Defines some internal constants used on this class. 419 * 420 */ 421 static class Constants { 422 423 final static String ROOT_ELEMENT_NAME = "positionReportGroup"; 424 final static String TYPE_NAME = "PositionReportGroupType"; 425 426 } 427 428 429 /** 430 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 431 * 432 */ 433 static class Elements { 434 435 final static String PM_POSITION_REPORT_GROUP_ID = "pmPositionReportGroupId"; 436 final static String EFFECTIVE_KEY_SET = "effectiveKeySet"; 437 final static String DESCRIPTION = "description"; 438 final static String POSITION_REPORT_GROUP = "positionReportGroup"; 439 final static String ACTIVE = "active"; 440 final static String ID = "id"; 441 final static String EFFECTIVE_LOCAL_DATE = "effectiveLocalDate"; 442 final static String CREATE_TIME = "createTime"; 443 final static String USER_PRINCIPAL_ID = "userPrincipalId"; 444 final static String GROUP_KEY_CODE_SET = "groupKeyCodeSet"; 445 final static String GROUP_KEY_SET = "groupKeySet"; 446 447 } 448 449}