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.edl.impl.extract;
017
018 import org.kuali.rice.core.api.util.RiceConstants;
019 import org.kuali.rice.edl.framework.extract.DumpDTO;
020 import org.kuali.rice.edl.framework.extract.FieldDTO;
021 import org.kuali.rice.kew.api.KewApiConstants;
022
023 import javax.persistence.CascadeType;
024 import javax.persistence.Column;
025 import javax.persistence.Entity;
026 import javax.persistence.FetchType;
027 import javax.persistence.Id;
028 import javax.persistence.OneToMany;
029 import javax.persistence.Table;
030 import javax.persistence.Version;
031 import java.io.Serializable;
032 import java.sql.Timestamp;
033 import java.text.DateFormat;
034 import java.text.SimpleDateFormat;
035 import java.util.ArrayList;
036 import java.util.Calendar;
037 import java.util.Date;
038 import java.util.List;
039
040 /**
041 * @author Kuali Rice Team (rice.collab@kuali.org)
042 *
043 */
044 @Entity
045 @Table(name="KREW_EDL_DMP_T")
046 public class Dump implements Serializable {
047
048 // private static final long serialVersionUID = -6136544551121011531L;
049
050 @Id
051 @Column(name="DOC_HDR_ID", nullable = false)
052 private String docId;
053
054 @Column(name="DOC_TYP_NM", nullable = false)
055 private String docTypeName;
056
057 @Column(name="DOC_HDR_STAT_CD", nullable = false)
058 private String docRouteStatusCode;
059
060 @Column(name="DOC_HDR_MDFN_DT", nullable = false)
061 private Timestamp docModificationDate;
062
063 @Column(name="DOC_HDR_CRTE_DT", nullable = false)
064 private Timestamp docCreationDate;
065
066 @Column(name="DOC_HDR_TTL")
067 private String docDescription;
068
069 @Column(name="DOC_HDR_INITR_PRNCPL_ID", nullable = false)
070 private String docInitiatorId;
071
072 @Column(name="CRNT_NODE_NM", nullable = false)
073 private String docCurrentNodeName;
074
075 @Version
076 @Column(name="VER_NBR", nullable = false)
077 private Integer lockVerNbr;
078
079 @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.ALL},mappedBy="dump")
080 private List<Fields> fields = new ArrayList<Fields>();
081
082 /**
083 * Returns the document creation timestamp.
084 * @return the doucment creation timestamp
085 */
086 public Timestamp getDocCreationDate() {
087 return docCreationDate;
088 }
089
090 /**
091 *
092 * @see #getDocCreationDate()
093 */
094 public void setDocCreationDate(final Timestamp docCreationDate) {
095 this.docCreationDate = docCreationDate;
096 }
097
098 /**
099 * 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