001    /**
002     * Copyright 2005-2012 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 org.joda.time.DateTime;
027    import org.kuali.rice.core.api.CoreConstants;
028    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
029    import org.kuali.rice.core.api.mo.ModelBuilder;
030    import org.w3c.dom.Element;
031    
032    @XmlRootElement(name = DocumentStatusTransition.Constants.ROOT_ELEMENT_NAME)
033    @XmlAccessorType(XmlAccessType.NONE)
034    @XmlType(name = DocumentStatusTransition.Constants.TYPE_NAME, propOrder = {
035        DocumentStatusTransition.Elements.ID,
036        DocumentStatusTransition.Elements.DOCUMENT_ID,
037        DocumentStatusTransition.Elements.OLD_APP_DOC_STATUS,
038        DocumentStatusTransition.Elements.NEW_APP_DOC_STATUS,
039        DocumentStatusTransition.Elements.STATUS_TRANSITION_DATE,
040        CoreConstants.CommonElements.FUTURE_ELEMENTS
041    })
042    public final class DocumentStatusTransition
043        extends AbstractDataTransferObject
044        implements DocumentStatusTransitionContract
045    {
046    
047        @XmlElement(name = Elements.ID, required = false)
048        private final String id;
049        @XmlElement(name = Elements.DOCUMENT_ID, required = false)
050        private final String documentId;
051        @XmlElement(name = Elements.OLD_APP_DOC_STATUS, required = false)
052        private final String oldStatus;
053        @XmlElement(name = Elements.NEW_APP_DOC_STATUS, required = false)
054        private final String newStatus;
055        @XmlElement(name = Elements.STATUS_TRANSITION_DATE, required = false)
056        private final DateTime statusTransitionDate;
057        @SuppressWarnings("unused")
058        @XmlAnyElement
059        private final Collection<Element> _futureElements = null;
060    
061        /**
062         * Private constructor used only by JAXB.
063         * 
064         */
065        private DocumentStatusTransition() {
066            this.id = null;
067            this.documentId = null;
068            this.oldStatus = null;
069            this.newStatus = null;
070            this.statusTransitionDate = null;
071        }
072    
073        private DocumentStatusTransition(Builder builder) {
074            this.id = builder.getId();
075            this.documentId = builder.getDocumentId();
076            this.oldStatus = builder.getOldStatus();
077            this.newStatus = builder.getNewStatus();
078            this.statusTransitionDate = builder.getStatusTransitionDate();
079        }
080    
081        @Override
082        public String getId() {
083            return this.id;
084        }
085    
086        @Override
087        public String getDocumentId() {
088            return this.documentId;
089        }
090    
091        @Override
092        public String getOldStatus() {
093            return this.oldStatus;
094        }
095    
096        @Override
097        public String getNewStatus() {
098            return this.newStatus;
099        }
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    }