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.routeheader;
017    
018    import org.joda.time.DateTime;
019    import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
020    
021    import javax.persistence.Column;
022    import javax.persistence.Entity;
023    import javax.persistence.GeneratedValue;
024    import javax.persistence.Id;
025    import javax.persistence.JoinColumn;
026    import javax.persistence.ManyToOne;
027    import javax.persistence.Table;
028    import java.sql.Timestamp;
029    import java.util.Map;
030    
031    /**
032     * Model bean representing the valid application document statuses for a document type
033     * 
034     * @author Kuali Rice Team (kuali-rice@googlegroups.com)
035     *
036     */
037    @Entity
038    @Table(name="KREW_APP_DOC_STAT_TRAN_T")
039    public class DocumentStatusTransition extends PersistableBusinessObjectBase {
040            private static final long serialVersionUID = -2212481684546954746L;
041    
042            @Id
043            @GeneratedValue(generator="KREW_DOC_HDR_S")
044            @Column(name="APP_DOC_STAT_TRAN_ID")
045            private String statusTransitionId;
046            
047            @Column(name="DOC_HDR_ID")
048            private String documentId;
049            
050            @Column(name="APP_DOC_STAT_FROM")
051            private String oldAppDocStatus;
052            
053            @Column(name="APP_DOC_STAT_TO")
054            private String newAppDocStatus;
055            
056            @Column(name="STAT_TRANS_DATE")
057            private java.sql.Timestamp statusTransitionDate;
058    
059        @ManyToOne
060        @JoinColumn(name="DOC_HDR_ID", insertable = false, updatable = false)
061        private DocumentRouteHeaderValue documentRouteHeaderValue;
062            
063        public DocumentStatusTransition() {
064        }
065    
066        public DocumentStatusTransition(String documentId, String oldStatus, String newStatus) {
067            this.documentId = documentId;
068            this.oldAppDocStatus = oldStatus;
069            this.newAppDocStatus = newStatus;
070            this.statusTransitionDate = new Timestamp(System.currentTimeMillis());
071        }
072    
073            public String getStatusTransitionId() {
074                    return this.statusTransitionId;
075            }
076    
077            public void setStatusTransitionId(String statusTransitionId) {
078                    this.statusTransitionId = statusTransitionId;
079            }
080    
081            public String getDocumentId() {
082                    return this.documentId;
083            }
084    
085            public void setDocumentId(String documentId) {
086                    this.documentId = documentId;
087            }
088    
089            public String getOldAppDocStatus() {
090                    return this.oldAppDocStatus;
091            }
092    
093            public void setOldAppDocStatus(String oldAppDocStatus) {
094                    this.oldAppDocStatus = oldAppDocStatus;
095            }
096    
097            public String getNewAppDocStatus() {
098                    return this.newAppDocStatus;
099            }
100    
101            public void setNewAppDocStatus(String newAppDocStatus) {
102                    this.newAppDocStatus = newAppDocStatus;
103            }
104    
105            public java.sql.Timestamp getStatusTransitionDate() {
106                    return this.statusTransitionDate;
107            }
108    
109            public void setStatusTransitionDate(java.sql.Timestamp statusTransitionDate) {
110                    this.statusTransitionDate = statusTransitionDate;
111            }
112    
113        public DocumentStatusTransition deepCopy(Map<Object, Object> visited) {
114            if (visited.containsKey(this)) {
115                return (DocumentStatusTransition)visited.get(this);
116            }
117            DocumentStatusTransition copy = new DocumentStatusTransition();
118            visited.put(this, copy);
119            copy.statusTransitionId = statusTransitionId;
120            copy.documentId = documentId;
121            copy.oldAppDocStatus = oldAppDocStatus;
122            copy.newAppDocStatus = newAppDocStatus;
123            if (statusTransitionDate != null) {
124                copy.statusTransitionDate = new Timestamp(statusTransitionDate.getTime());
125            }
126            if (documentRouteHeaderValue != null) {
127                copy.documentRouteHeaderValue = documentRouteHeaderValue.deepCopy(visited);
128            }
129            return copy;
130        }
131    
132        public static DocumentStatusTransition from(org.kuali.rice.kew.api.document.DocumentStatusTransition im) {
133            if (im == null) {
134                return null;
135            }
136            DocumentStatusTransition transition = new DocumentStatusTransition(im.getDocumentId(), im.getOldStatus(), im.getNewStatus());
137            transition.setStatusTransitionId(im.getId());
138            if (im.getStatusTransitionDate() != null) {
139                transition.setStatusTransitionDate(new Timestamp(im.getStatusTransitionDate().getMillis()));
140            }
141            return transition;
142        }
143    
144        public static org.kuali.rice.kew.api.document.DocumentStatusTransition to(DocumentStatusTransition bo) {
145            if (bo == null) {
146                return null;
147            }
148    
149            org.kuali.rice.kew.api.document.DocumentStatusTransition.Builder builder = org.kuali.rice.kew.api.document.DocumentStatusTransition.Builder.create(bo.getDocumentId(), bo.getOldAppDocStatus(), bo.getNewAppDocStatus());
150            builder.setId(bo.getStatusTransitionId());
151            if (bo.getStatusTransitionDate() != null) {
152                builder.setStatusTransitionDate(new DateTime(bo.getStatusTransitionDate().getTime()));
153            }
154            return builder.build();
155        }
156    
157        public DocumentRouteHeaderValue getDocumentRouteHeaderValue() {
158            return documentRouteHeaderValue;
159        }
160    
161        public void setDocumentRouteHeaderValue(DocumentRouteHeaderValue documentRouteHeaderValue) {
162            this.documentRouteHeaderValue = documentRouteHeaderValue;
163        }
164    }