001 /** 002 * Copyright 2005-2013 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.kim.api.identity.external; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.joda.time.DateTime; 020 import org.kuali.rice.core.api.CoreConstants; 021 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 022 import org.kuali.rice.core.api.mo.ModelBuilder; 023 import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils; 024 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter; 025 import org.w3c.dom.Element; 026 027 import javax.xml.bind.annotation.XmlAccessType; 028 import javax.xml.bind.annotation.XmlAccessorType; 029 import javax.xml.bind.annotation.XmlAnyElement; 030 import javax.xml.bind.annotation.XmlElement; 031 import javax.xml.bind.annotation.XmlRootElement; 032 import javax.xml.bind.annotation.XmlType; 033 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 034 import java.io.Serializable; 035 import java.util.Collection; 036 037 @XmlRootElement(name = EntityExternalIdentifierHistory.Constants.ROOT_ELEMENT_NAME) 038 @XmlAccessorType(XmlAccessType.NONE) 039 @XmlType(name = EntityExternalIdentifierHistory.Constants.TYPE_NAME, propOrder = { 040 EntityExternalIdentifierHistory.Elements.ID, 041 EntityExternalIdentifierHistory.Elements.ENTITY_ID, 042 EntityExternalIdentifierHistory.Elements.EXTERNAL_IDENTIFIER_TYPE_CODE, 043 EntityExternalIdentifierHistory.Elements.EXTERNAL_IDENTIFIER_TYPE, 044 EntityExternalIdentifierHistory.Elements.EXTERNAL_ID, 045 CoreConstants.CommonElements.HISTORY_ID, 046 CoreConstants.CommonElements.ACTIVE_FROM_DATE, 047 CoreConstants.CommonElements.ACTIVE_TO_DATE, 048 CoreConstants.CommonElements.VERSION_NUMBER, 049 CoreConstants.CommonElements.OBJECT_ID, 050 CoreConstants.CommonElements.FUTURE_ELEMENTS 051 }) 052 public final class EntityExternalIdentifierHistory extends AbstractDataTransferObject 053 implements EntityExternalIdentifierHistoryContract 054 { 055 @XmlElement(name = Elements.ENTITY_ID, required = false) 056 private final String entityId; 057 @XmlElement(name = Elements.EXTERNAL_IDENTIFIER_TYPE_CODE, required = false) 058 private final String externalIdentifierTypeCode; 059 @XmlElement(name = Elements.EXTERNAL_IDENTIFIER_TYPE, required = false) 060 private final EntityExternalIdentifierTypeHistory externalIdentifierType; 061 @XmlElement(name = Elements.EXTERNAL_ID, required = false) 062 private final String externalId; 063 @XmlElement(name = CoreConstants.CommonElements.HISTORY_ID, required = false) 064 private final Long historyId; 065 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false) 066 @XmlJavaTypeAdapter(DateTimeAdapter.class) 067 private final DateTime activeFromDate; 068 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false) 069 @XmlJavaTypeAdapter(DateTimeAdapter.class) 070 private final DateTime activeToDate; 071 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 072 private final Long versionNumber; 073 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) 074 private final String objectId; 075 @XmlElement(name = Elements.ID, required = false) 076 private final String id; 077 @SuppressWarnings("unused") 078 @XmlAnyElement 079 private final Collection<Element> _futureElements = null; 080 081 /** 082 * Private constructor used only by JAXB. 083 * 084 */ 085 private EntityExternalIdentifierHistory() { 086 this.entityId = null; 087 this.externalIdentifierTypeCode = null; 088 this.externalIdentifierType = null; 089 this.externalId = null; 090 this.versionNumber = null; 091 this.objectId = null; 092 this.id = null; 093 this.historyId = null; 094 this.activeFromDate = null; 095 this.activeToDate = null; 096 } 097 098 private EntityExternalIdentifierHistory(Builder builder) { 099 this.entityId = builder.getEntityId(); 100 this.externalIdentifierTypeCode = builder.getExternalIdentifierTypeCode(); 101 this.externalIdentifierType = builder.getExternalIdentifierType() != null ? builder.getExternalIdentifierType().build() : null; 102 this.externalId = builder.getExternalId(); 103 this.versionNumber = builder.getVersionNumber(); 104 this.objectId = builder.getObjectId(); 105 this.id = builder.getId(); 106 this.historyId = builder.getHistoryId(); 107 this.activeFromDate = builder.getActiveFromDate(); 108 this.activeToDate = builder.getActiveToDate(); 109 } 110 111 @Override 112 public String getEntityId() { 113 return this.entityId; 114 } 115 116 @Override 117 public String getExternalIdentifierTypeCode() { 118 return this.externalIdentifierTypeCode; 119 } 120 121 @Override 122 public EntityExternalIdentifierTypeHistory getExternalIdentifierType() { 123 return this.externalIdentifierType; 124 } 125 126 @Override 127 public String getExternalId() { 128 return this.externalId; 129 } 130 131 @Override 132 public Long getVersionNumber() { 133 return this.versionNumber; 134 } 135 136 @Override 137 public String getObjectId() { 138 return this.objectId; 139 } 140 141 @Override 142 public String getId() { 143 return this.id; 144 } 145 146 @Override 147 public Long getHistoryId() { 148 return this.historyId; 149 } 150 151 @Override 152 public DateTime getActiveFromDate() { 153 return this.activeFromDate; 154 } 155 156 @Override 157 public DateTime getActiveToDate() { 158 return this.activeToDate; 159 } 160 161 @Override 162 public boolean isActiveNow() { 163 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null); 164 } 165 166 @Override 167 public boolean isActive(DateTime activeAsOf) { 168 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf); 169 } 170 171 @Override 172 public boolean isActive() { 173 return isActiveNow(); 174 } 175 176 /** 177 * A builder which can be used to construct {@link org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierHistory} instances. Enforces the constraints of the {@link org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierContract}. 178 * 179 */ 180 public final static class Builder 181 implements Serializable, ModelBuilder, EntityExternalIdentifierHistoryContract 182 { 183 184 private String entityId; 185 private String externalIdentifierTypeCode; 186 private EntityExternalIdentifierTypeHistory.Builder externalIdentifierType; 187 private String externalId; 188 private Long versionNumber; 189 private String objectId; 190 private String id; 191 private Long historyId; 192 private DateTime activeFromDate; 193 private DateTime activeToDate; 194 195 private Builder() { } 196 197 public static Builder create() { 198 return new Builder(); 199 } 200 201 public static Builder create(EntityExternalIdentifierHistoryContract contract) { 202 if (contract == null) { 203 throw new IllegalArgumentException("contract was null"); 204 } 205 Builder builder = create(); 206 builder.setEntityId(contract.getEntityId()); 207 builder.setExternalIdentifierTypeCode(contract.getExternalIdentifierTypeCode()); 208 if (contract.getExternalIdentifierType() != null) { 209 builder.setExternalIdentifierType( 210 EntityExternalIdentifierTypeHistory.Builder.create(contract.getExternalIdentifierType())); 211 } 212 builder.setExternalId(contract.getExternalId()); 213 builder.setVersionNumber(contract.getVersionNumber()); 214 builder.setObjectId(contract.getObjectId()); 215 builder.setId(contract.getId()); 216 builder.setHistoryId(contract.getHistoryId()); 217 builder.setActiveFromDate(contract.getActiveFromDate()); 218 builder.setActiveToDate(contract.getActiveToDate()); 219 return builder; 220 } 221 222 public EntityExternalIdentifierHistory build() { 223 return new EntityExternalIdentifierHistory(this); 224 } 225 226 @Override 227 public String getEntityId() { 228 return this.entityId; 229 } 230 231 @Override 232 public String getExternalIdentifierTypeCode() { 233 return this.externalIdentifierTypeCode; 234 } 235 236 @Override 237 public EntityExternalIdentifierTypeHistory.Builder getExternalIdentifierType() { 238 return this.externalIdentifierType; 239 } 240 241 @Override 242 public String getExternalId() { 243 return this.externalId; 244 } 245 246 @Override 247 public Long getVersionNumber() { 248 return this.versionNumber; 249 } 250 251 @Override 252 public String getObjectId() { 253 return this.objectId; 254 } 255 256 @Override 257 public String getId() { 258 return this.id; 259 } 260 261 @Override 262 public Long getHistoryId() { 263 return this.historyId; 264 } 265 266 @Override 267 public boolean isActiveNow() { 268 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null); 269 } 270 271 @Override 272 public boolean isActive(DateTime activeAsOf) { 273 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf); 274 } 275 276 @Override 277 public DateTime getActiveFromDate() { 278 return this.activeFromDate; 279 } 280 281 @Override 282 public boolean isActive() { 283 return isActiveNow(); 284 } 285 286 @Override 287 public DateTime getActiveToDate() { 288 return this.activeToDate; 289 } 290 291 public void setHistoryId(Long historyId) { 292 this.historyId = historyId; 293 } 294 295 public void setActiveFromDate(DateTime activeFromDate) { 296 this.activeFromDate = activeFromDate; 297 } 298 299 public void setActiveToDate(DateTime activeToDate) { 300 this.activeToDate = activeToDate; 301 } 302 303 public void setEntityId(String entityId) { 304 this.entityId = entityId; 305 } 306 307 public void setExternalIdentifierTypeCode(String externalIdentifierTypeCode) { 308 this.externalIdentifierTypeCode = externalIdentifierTypeCode; 309 } 310 311 public void setExternalIdentifierType(EntityExternalIdentifierTypeHistory.Builder externalIdentifierType) { 312 this.externalIdentifierType = externalIdentifierType; 313 } 314 315 public void setExternalId(String externalId) { 316 this.externalId = externalId; 317 } 318 319 public void setVersionNumber(Long versionNumber) { 320 this.versionNumber = versionNumber; 321 } 322 323 public void setObjectId(String objectId) { 324 this.objectId = objectId; 325 } 326 327 public void setId(String id) { 328 if (StringUtils.isWhitespace(id)) { 329 throw new IllegalArgumentException("id is blank"); 330 } 331 this.id = id; 332 } 333 334 } 335 336 337 /** 338 * Defines some internal constants used on this class. 339 * 340 */ 341 static class Constants { 342 343 final static String ROOT_ELEMENT_NAME = "entityExternalIdentifier"; 344 final static String TYPE_NAME = "EntityExternalIdentifierType"; 345 } 346 347 348 /** 349 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 350 * 351 */ 352 static class Elements { 353 354 final static String ENTITY_ID = "entityId"; 355 final static String EXTERNAL_IDENTIFIER_TYPE = "externalIdentifierType"; 356 final static String EXTERNAL_IDENTIFIER_TYPE_CODE = "externalIdentifierTypeCode"; 357 final static String EXTERNAL_ID = "externalId"; 358 final static String ID = "id"; 359 360 } 361 362 }