View Javadoc
1   /**
2    * Copyright 2005-2015 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.edl.impl.extract;
17  
18  import org.kuali.rice.core.api.util.RiceConstants;
19  import org.kuali.rice.edl.framework.extract.DumpDTO;
20  import org.kuali.rice.edl.framework.extract.FieldDTO;
21  import org.kuali.rice.kew.api.KewApiConstants;
22  
23  import javax.persistence.CascadeType;
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.FetchType;
27  import javax.persistence.Id;
28  import javax.persistence.OneToMany;
29  import javax.persistence.Table;
30  import javax.persistence.Version;
31  import java.io.Serializable;
32  import java.sql.Timestamp;
33  import java.text.DateFormat;
34  import java.text.SimpleDateFormat;
35  import java.util.ArrayList;
36  import java.util.Calendar;
37  import java.util.Date;
38  import java.util.List;
39  
40  /**
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   *
43   */
44  @Entity
45  @Table(name="KREW_EDL_DMP_T")
46  public class Dump implements Serializable {
47  
48      //	private static final long serialVersionUID = -6136544551121011531L;
49  
50      @Id
51      @Column(name="DOC_HDR_ID", nullable = false)
52      private String docId;
53  
54      @Column(name="DOC_TYP_NM", nullable = false)
55      private String docTypeName;
56  
57      @Column(name="DOC_HDR_STAT_CD", nullable = false)
58      private String docRouteStatusCode;
59  
60      @Column(name="DOC_HDR_MDFN_DT", nullable = false)
61      private Timestamp docModificationDate;
62  
63      @Column(name="DOC_HDR_CRTE_DT", nullable = false)
64      private Timestamp docCreationDate;
65  
66      @Column(name="DOC_HDR_TTL")
67      private String docDescription;
68  
69      @Column(name="DOC_HDR_INITR_PRNCPL_ID", nullable = false)
70      private String docInitiatorId;
71  
72      @Column(name="CRNT_NODE_NM", nullable = false)
73      private String docCurrentNodeName;
74  
75      @Version
76      @Column(name="VER_NBR", nullable = false)
77      private Integer lockVerNbr;
78  
79      @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.ALL},mappedBy="dump")
80      private List<Fields> fields = new ArrayList<Fields>();
81  
82      /**
83       * Returns the document creation timestamp.
84       * @return the doucment creation timestamp
85       */
86      public Timestamp getDocCreationDate() {
87          return docCreationDate;
88      }
89  
90      /**
91       *
92       * @see #getDocCreationDate()
93       */
94      public void setDocCreationDate(final Timestamp docCreationDate) {
95          this.docCreationDate = docCreationDate;
96      }
97  
98      /**
99       * Rreturns document current node nam.e
100      * @return document current node name
101      */
102     public String getDocCurrentNodeName() {
103         return docCurrentNodeName;
104     }
105 
106     /**
107      *
108      * @see #getDocCurrentNodeName()
109      */
110     public void setDocCurrentNodeName(final String docCurrentNodeName) {
111         this.docCurrentNodeName = docCurrentNodeName;
112     }
113 
114     /**
115      * Returns the description.
116      * @return the description
117      */
118     public String getDocDescription() {
119         return docDescription;
120     }
121 
122     /**
123      *
124      * @see #getDocDescription()
125      */
126     public void setDocDescription(final String docDescription) {
127         this.docDescription = docDescription;
128     }
129 
130     /**
131      * Returns the document id.
132      * @return the document id
133      */
134     public String getDocId() {
135         return docId;
136     }
137 
138     /**
139      * Returns document initiator id.
140      * @return document initiator id
141      */
142     public String getDocInitiatorId() {
143         return docInitiatorId;
144     }
145 
146     /**
147      *
148      * @see #getDocInitiatorId()
149      */
150     public void setDocInitiatorId(final String docInitiatorId) {
151         this.docInitiatorId = docInitiatorId;
152     }
153 
154     /**
155      * Returns document modification date
156      * @return the document modification date
157      */
158     public Timestamp getDocModificationDate() {
159         return docModificationDate;
160     }
161 
162     /**
163      *
164      * @see #getDocModificationDate()
165      */
166     public void setDocModificationDate(final Timestamp docModificationDate) {
167         this.docModificationDate = docModificationDate;
168     }
169 
170     /**
171      * Returns document route status code.
172      * @return document route status code
173      */
174     public String getDocRouteStatusCode() {
175         return docRouteStatusCode;
176     }
177 
178     /**
179      *
180      * @see #getDocRouteStatusCode()
181      */
182     public void setDocRouteStatusCode(final String docRouteStatusCode) {
183         this.docRouteStatusCode = docRouteStatusCode;
184     }
185 
186     /**
187      * Returns the document type name.
188      * @return the document type name
189      */
190     public String getDocTypeName() {
191         return docTypeName;
192     }
193 
194     /**
195      *
196      * @see #getDocTypeName()
197      */
198     public void setDocTypeName(final String docTypeName) {
199         this.docTypeName = docTypeName;
200     }
201 
202     /**
203      * Returns the lock version number.
204      * @return the lock version number
205      */
206     public Integer getLockVerNbr() {
207         return lockVerNbr;
208     }
209 
210     /**
211      *
212      * @see #getLockVerNbr()
213      */
214     public void setLockVerNbr(final Integer lockVerNbr) {
215         this.lockVerNbr = lockVerNbr;
216     }
217 
218     /**
219      * Returns the creation timestamp specially formatted.
220      * @return the creation timestamp, specially formatted.
221      */
222     public String getFormattedCreateDateTime() {
223         long time = getDocCreationDate().getTime();
224         Calendar calendar = Calendar.getInstance();
225         calendar.setTimeInMillis(time);
226         Date date = calendar.getTime();
227         DateFormat dateFormat = new SimpleDateFormat(KewApiConstants.TIMESTAMP_DATE_FORMAT_PATTERN2);
228         return dateFormat.format(date);
229     }
230 
231     /**
232      * Returns the date portion of the creation timestamp.
233      * @return the date portion of the creation timestamp.
234      */
235     public String getFormattedCreateDate() {
236         long time = getDocCreationDate().getTime();
237         Calendar calendar = Calendar.getInstance();
238         calendar.setTimeInMillis(time);
239         Date date = calendar.getTime();
240         DateFormat dateFormat = RiceConstants.getDefaultDateFormat();
241         return dateFormat.format(date);
242     }
243 
244     /**
245      *
246      * @see #getDocId()
247      */
248     public void setDocId(final String docId) {
249         this.docId = docId;
250     }
251 
252     /**
253      * Returns the {@link Fields}
254      * @return the {@link Fields}
255      */
256     public List<Fields> getFields() {
257         return fields;
258     }
259 
260     /**
261      *
262      * @see #getFields()
263      */
264     public void setFields(final List<Fields> fields) {
265         this.fields = fields;
266     }
267 
268     /**
269      * Converts a {@link Dump} to a {@link DumpDTO}
270      * @param dump the {@link Dump} to convert.
271      * @return a {@link DumpDTO}
272      */
273     public static DumpDTO to(Dump dump) {
274         if (dump == null) {
275             return null;
276         }
277         DumpDTO dumpDTO = new DumpDTO();
278         dumpDTO.setDocCreationDate(dump.getDocCreationDate());
279         dumpDTO.setDocCurrentNodeName(dump.getDocCurrentNodeName());
280         dumpDTO.setDocDescription(dump.getDocDescription());
281         dumpDTO.setDocId(dump.getDocId());
282         dumpDTO.setDocInitiatorId(dump.getDocInitiatorId());
283         dumpDTO.setDocModificationDate(dump.getDocModificationDate());
284         dumpDTO.setDocRouteStatusCode(dump.getDocRouteStatusCode());
285         dumpDTO.setDocTypeName(dump.getDocTypeName());
286         dumpDTO.setLockVerNbr(dump.getLockVerNbr());
287         List<FieldDTO> fields = new ArrayList<FieldDTO>();
288         for (Fields field : dump.getFields()) {
289             fields.add(Fields.to(field));
290         }
291         dumpDTO.setFields(fields);
292         return dumpDTO;
293     }
294 
295     /**
296      * Converts a {@link DumpDTO} to a {@link Dump}
297      * @param dumpDTO the {@link DumpDTO} to convert
298      * @return a {@link Dump}
299      */
300     public static Dump from(DumpDTO dumpDTO) {
301         if (dumpDTO == null) {
302             return null;
303         }
304         Dump dump = new Dump();
305         dump.setDocCreationDate(dumpDTO.getDocCreationDate());
306         dump.setDocCurrentNodeName(dumpDTO.getDocCurrentNodeName());
307         dump.setDocDescription(dumpDTO.getDocDescription());
308         dump.setDocId(dumpDTO.getDocId());
309         dump.setDocInitiatorId(dumpDTO.getDocInitiatorId());
310         dump.setDocModificationDate(dumpDTO.getDocModificationDate());
311         dump.setDocRouteStatusCode(dumpDTO.getDocRouteStatusCode());
312         dump.setDocTypeName(dumpDTO.getDocTypeName());
313         dump.setLockVerNbr(dumpDTO.getLockVerNbr());
314         List<Fields> fields = new ArrayList<Fields>();
315         for (FieldDTO fieldDTO : dumpDTO.getFields()) {
316             fields.add(Fields.from(fieldDTO, dump));
317         }
318         dump.setFields(fields);
319         return dump;
320     }
321 }
322