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.kew.api.document; 017 018 import java.io.Serializable; 019 import java.util.Collection; 020 import javax.xml.bind.annotation.XmlAccessType; 021 import javax.xml.bind.annotation.XmlAccessorType; 022 import javax.xml.bind.annotation.XmlAnyElement; 023 import javax.xml.bind.annotation.XmlElement; 024 import javax.xml.bind.annotation.XmlRootElement; 025 import javax.xml.bind.annotation.XmlType; 026 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 027 028 import org.joda.time.DateTime; 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.core.api.util.jaxb.DateTimeAdapter; 033 import org.w3c.dom.Element; 034 035 @XmlRootElement(name = DocumentStatusTransition.Constants.ROOT_ELEMENT_NAME) 036 @XmlAccessorType(XmlAccessType.NONE) 037 @XmlType(name = DocumentStatusTransition.Constants.TYPE_NAME, propOrder = { 038 DocumentStatusTransition.Elements.ID, 039 DocumentStatusTransition.Elements.DOCUMENT_ID, 040 DocumentStatusTransition.Elements.OLD_APP_DOC_STATUS, 041 DocumentStatusTransition.Elements.NEW_APP_DOC_STATUS, 042 DocumentStatusTransition.Elements.STATUS_TRANSITION_DATE, 043 DocumentStatusTransition.Elements.STATUS_TRANSITION_DATE_VALUE, 044 CoreConstants.CommonElements.FUTURE_ELEMENTS 045 }) 046 public final class DocumentStatusTransition 047 extends AbstractDataTransferObject 048 implements DocumentStatusTransitionContract 049 { 050 051 @XmlElement(name = Elements.ID, required = false) 052 private final String id; 053 @XmlElement(name = Elements.DOCUMENT_ID, required = false) 054 private final String documentId; 055 @XmlElement(name = Elements.OLD_APP_DOC_STATUS, required = false) 056 private final String oldStatus; 057 @XmlElement(name = Elements.NEW_APP_DOC_STATUS, required = false) 058 private final String newStatus; 059 @Deprecated 060 @XmlElement(name = Elements.STATUS_TRANSITION_DATE, required = false) 061 private final DateTime statusTransitionDate; 062 @XmlElement(name = Elements.STATUS_TRANSITION_DATE_VALUE, required = false) 063 @XmlJavaTypeAdapter(DateTimeAdapter.class) 064 private final DateTime statusTransitionDateValue; 065 @SuppressWarnings("unused") 066 @XmlAnyElement 067 private final Collection<Element> _futureElements = null; 068 069 /** 070 * Private constructor used only by JAXB. 071 * 072 */ 073 private DocumentStatusTransition() { 074 this.id = null; 075 this.documentId = null; 076 this.oldStatus = null; 077 this.newStatus = null; 078 this.statusTransitionDate = null; 079 this.statusTransitionDateValue = null; 080 081 } 082 083 private DocumentStatusTransition(Builder builder) { 084 this.id = builder.getId(); 085 this.documentId = builder.getDocumentId(); 086 this.oldStatus = builder.getOldStatus(); 087 this.newStatus = builder.getNewStatus(); 088 this.statusTransitionDate = builder.getStatusTransitionDate(); 089 this.statusTransitionDateValue = builder.getStatusTransitionDate(); 090 } 091 092 @Override 093 public String getId() { 094 return this.id; 095 } 096 097 @Override 098 public String getDocumentId() { 099 return this.documentId; 100 } 101 102 @Override 103 public String getOldStatus() { 104 return this.oldStatus; 105 } 106 107 @Override 108 public String getNewStatus() { 109 return this.newStatus; 110 } 111 112 @Override 113 public DateTime getStatusTransitionDate() { 114 return this.statusTransitionDateValue == null ? this.statusTransitionDate : this.statusTransitionDateValue; 115 } 116 117 118 /** 119 * A builder which can be used to construct {@link DocumentStatusTransition} instances. Enforces the constraints of the {@link DocumentStatusTransitionContract}. 120 * 121 */ 122 public final static class Builder 123 implements Serializable, ModelBuilder, DocumentStatusTransitionContract 124 { 125 126 private String id; 127 private String documentId; 128 private String oldStatus; 129 private String newStatus; 130 private DateTime statusTransitionDate; 131 132 private Builder(String documentId, String oldStatus, String newStatus) { 133 setDocumentId(documentId); 134 setOldStatus(oldStatus); 135 setNewStatus(newStatus); 136 } 137 138 public static Builder create(String documentId, String oldStatus, String newStatus) { 139 return new Builder(documentId, oldStatus, newStatus); 140 } 141 142 public static Builder create(DocumentStatusTransitionContract contract) { 143 if (contract == null) { 144 throw new IllegalArgumentException("contract was null"); 145 } 146 Builder builder = create(contract.getDocumentId(), contract.getOldStatus(), contract.getNewStatus()); 147 builder.setId(contract.getId()); 148 builder.setStatusTransitionDate(contract.getStatusTransitionDate()); 149 return builder; 150 } 151 152 public DocumentStatusTransition build() { 153 return new DocumentStatusTransition(this); 154 } 155 156 @Override 157 public String getId() { 158 return this.id; 159 } 160 161 @Override 162 public String getDocumentId() { 163 return this.documentId; 164 } 165 166 @Override 167 public String getOldStatus() { 168 return this.oldStatus; 169 } 170 171 @Override 172 public String getNewStatus() { 173 return this.newStatus; 174 } 175 176 @Override 177 public DateTime getStatusTransitionDate() { 178 return this.statusTransitionDate; 179 } 180 181 public void setId(String id) { 182 // TODO add validation of input value if required and throw IllegalArgumentException if needed 183 this.id = id; 184 } 185 186 public void setDocumentId(String documentId) { 187 // TODO add validation of input value if required and throw IllegalArgumentException if needed 188 this.documentId = documentId; 189 } 190 191 public void setOldStatus(String oldStatus) { 192 // TODO add validation of input value if required and throw IllegalArgumentException if needed 193 this.oldStatus = oldStatus; 194 } 195 196 public void setNewStatus(String newStatus) { 197 // TODO add validation of input value if required and throw IllegalArgumentException if needed 198 this.newStatus = newStatus; 199 } 200 201 public void setStatusTransitionDate(DateTime statusTransitionDate) { 202 // TODO add validation of input value if required and throw IllegalArgumentException if needed 203 this.statusTransitionDate = statusTransitionDate; 204 } 205 206 } 207 208 209 /** 210 * Defines some internal constants used on this class. 211 * 212 */ 213 static class Constants { 214 215 final static String ROOT_ELEMENT_NAME = "documentStatusTransition"; 216 final static String TYPE_NAME = "DocumentStatusTransitionType"; 217 218 } 219 220 221 /** 222 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 223 * 224 */ 225 static class Elements { 226 227 final static String ID = "id"; 228 final static String DOCUMENT_ID = "documentId"; 229 final static String OLD_APP_DOC_STATUS = "oldStatus"; 230 final static String NEW_APP_DOC_STATUS = "newStatus"; 231 final static String STATUS_TRANSITION_DATE = "statusTransitionDate"; 232 final static String STATUS_TRANSITION_DATE_VALUE = "statusTransitionDateValue"; 233 234 } 235 236 }