View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.api.document;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  import javax.xml.bind.annotation.XmlAccessType;
21  import javax.xml.bind.annotation.XmlAccessorType;
22  import javax.xml.bind.annotation.XmlAnyElement;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlRootElement;
25  import javax.xml.bind.annotation.XmlType;
26  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
27  
28  import org.joda.time.DateTime;
29  import org.kuali.rice.core.api.CoreConstants;
30  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31  import org.kuali.rice.core.api.mo.ModelBuilder;
32  import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
33  import org.w3c.dom.Element;
34  
35  @XmlRootElement(name = DocumentStatusTransition.Constants.ROOT_ELEMENT_NAME)
36  @XmlAccessorType(XmlAccessType.NONE)
37  @XmlType(name = DocumentStatusTransition.Constants.TYPE_NAME, propOrder = {
38      DocumentStatusTransition.Elements.ID,
39      DocumentStatusTransition.Elements.DOCUMENT_ID,
40      DocumentStatusTransition.Elements.OLD_APP_DOC_STATUS,
41      DocumentStatusTransition.Elements.NEW_APP_DOC_STATUS,
42      DocumentStatusTransition.Elements.STATUS_TRANSITION_DATE,
43      CoreConstants.CommonElements.FUTURE_ELEMENTS
44  })
45  public final class DocumentStatusTransition
46      extends AbstractDataTransferObject
47      implements DocumentStatusTransitionContract
48  {
49  
50      @XmlElement(name = Elements.ID, required = false)
51      private final String id;
52      @XmlElement(name = Elements.DOCUMENT_ID, required = false)
53      private final String documentId;
54      @XmlElement(name = Elements.OLD_APP_DOC_STATUS, required = false)
55      private final String oldStatus;
56      @XmlElement(name = Elements.NEW_APP_DOC_STATUS, required = false)
57      private final String newStatus;
58      @XmlElement(name = Elements.STATUS_TRANSITION_DATE, required = false)
59      @XmlJavaTypeAdapter(DateTimeAdapter.class)
60      private final DateTime statusTransitionDate;
61      @SuppressWarnings("unused")
62      @XmlAnyElement
63      private final Collection<Element> _futureElements = null;
64  
65      /**
66       * Private constructor used only by JAXB.
67       * 
68       */
69      private DocumentStatusTransition() {
70          this.id = null;
71          this.documentId = null;
72          this.oldStatus = null;
73          this.newStatus = null;
74          this.statusTransitionDate = null;
75      }
76  
77      private DocumentStatusTransition(Builder builder) {
78          this.id = builder.getId();
79          this.documentId = builder.getDocumentId();
80          this.oldStatus = builder.getOldStatus();
81          this.newStatus = builder.getNewStatus();
82          this.statusTransitionDate = builder.getStatusTransitionDate();
83      }
84  
85      @Override
86      public String getId() {
87          return this.id;
88      }
89  
90      @Override
91      public String getDocumentId() {
92          return this.documentId;
93      }
94  
95      @Override
96      public String getOldStatus() {
97          return this.oldStatus;
98      }
99  
100     @Override
101     public String getNewStatus() {
102         return this.newStatus;
103     }
104 
105     @Override
106     public DateTime getStatusTransitionDate() {
107         return this.statusTransitionDate;
108     }
109 
110 
111     /**
112      * A builder which can be used to construct {@link DocumentStatusTransition} instances.  Enforces the constraints of the {@link DocumentStatusTransitionContract}.
113      * 
114      */
115     public final static class Builder
116         implements Serializable, ModelBuilder, DocumentStatusTransitionContract
117     {
118 
119         private String id;
120         private String documentId;
121         private String oldStatus;
122         private String newStatus;
123         private DateTime statusTransitionDate;
124 
125         private Builder(String documentId, String oldStatus, String newStatus) {
126             setDocumentId(documentId);
127             setOldStatus(oldStatus);
128             setNewStatus(newStatus);
129         }
130 
131         public static Builder create(String documentId, String oldStatus, String newStatus) {
132             return new Builder(documentId, oldStatus, newStatus);
133         }
134 
135         public static Builder create(DocumentStatusTransitionContract contract) {
136             if (contract == null) {
137                 throw new IllegalArgumentException("contract was null");
138             }
139             Builder builder = create(contract.getDocumentId(), contract.getOldStatus(), contract.getNewStatus());
140             builder.setId(contract.getId());
141             builder.setStatusTransitionDate(contract.getStatusTransitionDate());
142             return builder;
143         }
144 
145         public DocumentStatusTransition build() {
146             return new DocumentStatusTransition(this);
147         }
148 
149         @Override
150         public String getId() {
151             return this.id;
152         }
153 
154         @Override
155         public String getDocumentId() {
156             return this.documentId;
157         }
158 
159         @Override
160         public String getOldStatus() {
161             return this.oldStatus;
162         }
163 
164         @Override
165         public String getNewStatus() {
166             return this.newStatus;
167         }
168 
169         @Override
170         public DateTime getStatusTransitionDate() {
171             return this.statusTransitionDate;
172         }
173 
174         public void setId(String id) {
175             // TODO add validation of input value if required and throw IllegalArgumentException if needed
176             this.id = id;
177         }
178 
179         public void setDocumentId(String documentId) {
180             // TODO add validation of input value if required and throw IllegalArgumentException if needed
181             this.documentId = documentId;
182         }
183 
184         public void setOldStatus(String oldStatus) {
185             // TODO add validation of input value if required and throw IllegalArgumentException if needed
186             this.oldStatus = oldStatus;
187         }
188 
189         public void setNewStatus(String newStatus) {
190             // TODO add validation of input value if required and throw IllegalArgumentException if needed
191             this.newStatus = newStatus;
192         }
193 
194         public void setStatusTransitionDate(DateTime statusTransitionDate) {
195             // TODO add validation of input value if required and throw IllegalArgumentException if needed
196             this.statusTransitionDate = statusTransitionDate;
197         }
198 
199     }
200 
201 
202     /**
203      * Defines some internal constants used on this class.
204      * 
205      */
206     static class Constants {
207 
208         final static String ROOT_ELEMENT_NAME = "documentStatusTransition";
209         final static String TYPE_NAME = "DocumentStatusTransitionType";
210 
211     }
212 
213 
214     /**
215      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
216      * 
217      */
218     static class Elements {
219 
220         final static String ID = "id";
221         final static String DOCUMENT_ID = "documentId";
222         final static String OLD_APP_DOC_STATUS = "oldStatus";
223         final static String NEW_APP_DOC_STATUS = "newStatus";
224         final static String STATUS_TRANSITION_DATE = "statusTransitionDate";
225 
226     }
227 
228 }