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 org.joda.time.DateTime;
27  import org.kuali.rice.core.api.CoreConstants;
28  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
29  import org.kuali.rice.core.api.mo.ModelBuilder;
30  import org.w3c.dom.Element;
31  
32  @XmlRootElement(name = DocumentStatusTransition.Constants.ROOT_ELEMENT_NAME)
33  @XmlAccessorType(XmlAccessType.NONE)
34  @XmlType(name = DocumentStatusTransition.Constants.TYPE_NAME, propOrder = {
35      DocumentStatusTransition.Elements.ID,
36      DocumentStatusTransition.Elements.DOCUMENT_ID,
37      DocumentStatusTransition.Elements.OLD_APP_DOC_STATUS,
38      DocumentStatusTransition.Elements.NEW_APP_DOC_STATUS,
39      DocumentStatusTransition.Elements.STATUS_TRANSITION_DATE,
40      CoreConstants.CommonElements.FUTURE_ELEMENTS
41  })
42  public final class DocumentStatusTransition
43      extends AbstractDataTransferObject
44      implements DocumentStatusTransitionContract
45  {
46  
47      @XmlElement(name = Elements.ID, required = false)
48      private final String id;
49      @XmlElement(name = Elements.DOCUMENT_ID, required = false)
50      private final String documentId;
51      @XmlElement(name = Elements.OLD_APP_DOC_STATUS, required = false)
52      private final String oldStatus;
53      @XmlElement(name = Elements.NEW_APP_DOC_STATUS, required = false)
54      private final String newStatus;
55      @XmlElement(name = Elements.STATUS_TRANSITION_DATE, required = false)
56      private final DateTime statusTransitionDate;
57      @SuppressWarnings("unused")
58      @XmlAnyElement
59      private final Collection<Element> _futureElements = null;
60  
61      /**
62       * Private constructor used only by JAXB.
63       * 
64       */
65      private DocumentStatusTransition() {
66          this.id = null;
67          this.documentId = null;
68          this.oldStatus = null;
69          this.newStatus = null;
70          this.statusTransitionDate = null;
71      }
72  
73      private DocumentStatusTransition(Builder builder) {
74          this.id = builder.getId();
75          this.documentId = builder.getDocumentId();
76          this.oldStatus = builder.getOldStatus();
77          this.newStatus = builder.getNewStatus();
78          this.statusTransitionDate = builder.getStatusTransitionDate();
79      }
80  
81      @Override
82      public String getId() {
83          return this.id;
84      }
85  
86      @Override
87      public String getDocumentId() {
88          return this.documentId;
89      }
90  
91      @Override
92      public String getOldStatus() {
93          return this.oldStatus;
94      }
95  
96      @Override
97      public String getNewStatus() {
98          return this.newStatus;
99      }
100 
101     @Override
102     public DateTime getStatusTransitionDate() {
103         return this.statusTransitionDate;
104     }
105 
106 
107     /**
108      * A builder which can be used to construct {@link DocumentStatusTransition} instances.  Enforces the constraints of the {@link DocumentStatusTransitionContract}.
109      * 
110      */
111     public final static class Builder
112         implements Serializable, ModelBuilder, DocumentStatusTransitionContract
113     {
114 
115         private String id;
116         private String documentId;
117         private String oldStatus;
118         private String newStatus;
119         private DateTime statusTransitionDate;
120 
121         private Builder(String documentId, String oldStatus, String newStatus) {
122             setDocumentId(documentId);
123             setOldStatus(oldStatus);
124             setNewStatus(newStatus);
125         }
126 
127         public static Builder create(String documentId, String oldStatus, String newStatus) {
128             return new Builder(documentId, oldStatus, newStatus);
129         }
130 
131         public static Builder create(DocumentStatusTransitionContract contract) {
132             if (contract == null) {
133                 throw new IllegalArgumentException("contract was null");
134             }
135             Builder builder = create(contract.getDocumentId(), contract.getOldStatus(), contract.getNewStatus());
136             builder.setId(contract.getId());
137             builder.setStatusTransitionDate(contract.getStatusTransitionDate());
138             return builder;
139         }
140 
141         public DocumentStatusTransition build() {
142             return new DocumentStatusTransition(this);
143         }
144 
145         @Override
146         public String getId() {
147             return this.id;
148         }
149 
150         @Override
151         public String getDocumentId() {
152             return this.documentId;
153         }
154 
155         @Override
156         public String getOldStatus() {
157             return this.oldStatus;
158         }
159 
160         @Override
161         public String getNewStatus() {
162             return this.newStatus;
163         }
164 
165         @Override
166         public DateTime getStatusTransitionDate() {
167             return this.statusTransitionDate;
168         }
169 
170         public void setId(String id) {
171             // TODO add validation of input value if required and throw IllegalArgumentException if needed
172             this.id = id;
173         }
174 
175         public void setDocumentId(String documentId) {
176             // TODO add validation of input value if required and throw IllegalArgumentException if needed
177             this.documentId = documentId;
178         }
179 
180         public void setOldStatus(String oldStatus) {
181             // TODO add validation of input value if required and throw IllegalArgumentException if needed
182             this.oldStatus = oldStatus;
183         }
184 
185         public void setNewStatus(String newStatus) {
186             // TODO add validation of input value if required and throw IllegalArgumentException if needed
187             this.newStatus = newStatus;
188         }
189 
190         public void setStatusTransitionDate(DateTime statusTransitionDate) {
191             // TODO add validation of input value if required and throw IllegalArgumentException if needed
192             this.statusTransitionDate = statusTransitionDate;
193         }
194 
195     }
196 
197 
198     /**
199      * Defines some internal constants used on this class.
200      * 
201      */
202     static class Constants {
203 
204         final static String ROOT_ELEMENT_NAME = "documentStatusTransition";
205         final static String TYPE_NAME = "DocumentStatusTransitionType";
206 
207     }
208 
209 
210     /**
211      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
212      * 
213      */
214     static class Elements {
215 
216         final static String ID = "id";
217         final static String DOCUMENT_ID = "documentId";
218         final static String OLD_APP_DOC_STATUS = "oldStatus";
219         final static String NEW_APP_DOC_STATUS = "newStatus";
220         final static String STATUS_TRANSITION_DATE = "statusTransitionDate";
221 
222     }
223 
224 }