View Javadoc
1   /**
2    * Copyright 2005-2014 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          DocumentStatusTransition.Elements.STATUS_TRANSITION_DATE_VALUE,
44      CoreConstants.CommonElements.FUTURE_ELEMENTS
45  })
46  public final class DocumentStatusTransition
47      extends AbstractDataTransferObject
48      implements DocumentStatusTransitionContract
49  {
50  
51      @XmlElement(name = Elements.ID, required = false)
52      private final String id;
53      @XmlElement(name = Elements.DOCUMENT_ID, required = false)
54      private final String documentId;
55      @XmlElement(name = Elements.OLD_APP_DOC_STATUS, required = false)
56      private final String oldStatus;
57      @XmlElement(name = Elements.NEW_APP_DOC_STATUS, required = false)
58      private final String newStatus;
59      @Deprecated
60      @XmlElement(name = Elements.STATUS_TRANSITION_DATE, required = false)
61      private final DateTime statusTransitionDate;
62      @XmlElement(name = Elements.STATUS_TRANSITION_DATE_VALUE, required = false)
63      @XmlJavaTypeAdapter(DateTimeAdapter.class)
64      private final DateTime statusTransitionDateValue;
65      @SuppressWarnings("unused")
66      @XmlAnyElement
67      private final Collection<Element> _futureElements = null;
68  
69      /**
70       * Private constructor used only by JAXB.
71       * 
72       */
73      private DocumentStatusTransition() {
74          this.id = null;
75          this.documentId = null;
76          this.oldStatus = null;
77          this.newStatus = null;
78          this.statusTransitionDate = null;
79          this.statusTransitionDateValue = null;
80  
81      }
82  
83      private DocumentStatusTransition(Builder builder) {
84          this.id = builder.getId();
85          this.documentId = builder.getDocumentId();
86          this.oldStatus = builder.getOldStatus();
87          this.newStatus = builder.getNewStatus();
88          this.statusTransitionDate = builder.getStatusTransitionDate();
89          this.statusTransitionDateValue = builder.getStatusTransitionDate();
90      }
91  
92      @Override
93      public String getId() {
94          return this.id;
95      }
96  
97      @Override
98      public String getDocumentId() {
99          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 }