1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.edl.impl.extract;
18
19 import java.sql.Timestamp;
20 import java.text.DateFormat;
21 import java.text.SimpleDateFormat;
22 import java.util.ArrayList;
23 import java.util.Calendar;
24 import java.util.Date;
25 import java.util.List;
26
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.FetchType;
31 import javax.persistence.Id;
32 import javax.persistence.OneToMany;
33 import javax.persistence.Table;
34 import javax.persistence.Version;
35
36 import org.hibernate.annotations.Fetch;
37 import org.hibernate.annotations.FetchMode;
38 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
39 import org.kuali.rice.core.util.RiceConstants;
40 import org.kuali.rice.edl.framework.extract.DumpDTO;
41 import org.kuali.rice.edl.framework.extract.FieldDTO;
42 import org.kuali.rice.kew.util.KEWConstants;
43 import org.kuali.rice.krad.service.KRADServiceLocator;
44
45
46
47
48
49
50
51
52 @Entity
53 @Table(name="KREW_EDL_DMP_T")
54
55 public class Dump {
56
57 private static final long serialVersionUID = -6136544551121011531L;
58
59 @Id
60 @Column(name="DOC_HDR_ID")
61 private String docId;
62 @Column(name="DOC_TYP_NM")
63 private String docTypeName;
64 @Column(name="DOC_HDR_STAT_CD")
65 private String docRouteStatusCode;
66 @Column(name="DOC_HDR_MDFN_DT")
67 private Timestamp docModificationDate;
68 @Column(name="DOC_HDR_CRTE_DT")
69 private Timestamp docCreationDate;
70 @Column(name="DOC_HDR_TTL")
71 private String docDescription;
72 @Column(name="DOC_HDR_INITR_PRNCPL_ID")
73 private String docInitiatorId;
74 @Column(name="CRNT_NODE_NM")
75 private String docCurrentNodeName;
76 @Version
77 @Column(name="VER_NBR")
78 private Integer lockVerNbr;
79
80 @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},mappedBy="dump")
81 @Fetch(value = FetchMode.SELECT)
82 private List<Fields> fields = new ArrayList<Fields>();
83
84
85 public void beforeInsert(){
86 OrmUtils.populateAutoIncValue(this, KRADServiceLocator.getEntityManagerFactory().createEntityManager());
87 }
88
89
90 public Timestamp getDocCreationDate() {
91 return docCreationDate;
92 }
93 public void setDocCreationDate(final Timestamp docCreationDate) {
94 this.docCreationDate = docCreationDate;
95 }
96 public String getDocCurrentNodeName() {
97 return docCurrentNodeName;
98 }
99 public void setDocCurrentNodeName(final String docCurrentNodeName) {
100 this.docCurrentNodeName = docCurrentNodeName;
101 }
102 public String getDocDescription() {
103 return docDescription;
104 }
105 public void setDocDescription(final String docDescription) {
106 this.docDescription = docDescription;
107 }
108 public String getDocId() {
109 return docId;
110 }
111 public String getDocInitiatorId() {
112 return docInitiatorId;
113 }
114 public void setDocInitiatorId(final String docInitiatorId) {
115 this.docInitiatorId = docInitiatorId;
116 }
117 public Timestamp getDocModificationDate() {
118 return docModificationDate;
119 }
120 public void setDocModificationDate(final Timestamp docModificationDate) {
121 this.docModificationDate = docModificationDate;
122 }
123 public String getDocRouteStatusCode() {
124 return docRouteStatusCode;
125 }
126 public void setDocRouteStatusCode(final String docRouteStatusCode) {
127 this.docRouteStatusCode = docRouteStatusCode;
128 }
129 public String getDocTypeName() {
130 return docTypeName;
131 }
132 public void setDocTypeName(final String docTypeName) {
133 this.docTypeName = docTypeName;
134 }
135 public Integer getLockVerNbr() {
136 return lockVerNbr;
137 }
138 public void setLockVerNbr(final Integer lockVerNbr) {
139 this.lockVerNbr = lockVerNbr;
140 }
141 public String getFormattedCreateDateTime() {
142 long time = getDocCreationDate().getTime();
143 Calendar calendar = Calendar.getInstance();
144 calendar.setTimeInMillis(time);
145 Date date = calendar.getTime();
146 DateFormat dateFormat = new SimpleDateFormat(KEWConstants.TIMESTAMP_DATE_FORMAT_PATTERN2);
147 return dateFormat.format(date);
148 }
149
150 public String getFormattedCreateDate() {
151 long time = getDocCreationDate().getTime();
152 Calendar calendar = Calendar.getInstance();
153 calendar.setTimeInMillis(time);
154 Date date = calendar.getTime();
155 DateFormat dateFormat = RiceConstants.getDefaultDateFormat();
156 return dateFormat.format(date);
157 }
158 public void setDocId(final String docId) {
159 this.docId = docId;
160 }
161
162
163 public List<Fields> getFields() {
164 return fields;
165 }
166
167 public void setFields(final List<Fields> fields) {
168 this.fields = fields;
169 }
170
171 public static DumpDTO to(Dump dump) {
172 if (dump == null) {
173 return null;
174 }
175 DumpDTO dumpDTO = new DumpDTO();
176 dumpDTO.setDocCreationDate(dump.getDocCreationDate());
177 dumpDTO.setDocCurrentNodeName(dump.getDocCurrentNodeName());
178 dumpDTO.setDocDescription(dump.getDocDescription());
179 dumpDTO.setDocId(dump.getDocId());
180 dumpDTO.setDocInitiatorId(dump.getDocInitiatorId());
181 dumpDTO.setDocModificationDate(dump.getDocModificationDate());
182 dumpDTO.setDocRouteStatusCode(dump.getDocRouteStatusCode());
183 dumpDTO.setDocTypeName(dump.getDocTypeName());
184 dumpDTO.setLockVerNbr(dump.getLockVerNbr());
185 List<FieldDTO> fields = new ArrayList<FieldDTO>();
186 for (Fields field : dump.getFields()) {
187 fields.add(Fields.to(field));
188 }
189 dumpDTO.setFields(fields);
190 return dumpDTO;
191 }
192
193 public static Dump from(DumpDTO dumpDTO) {
194 if (dumpDTO == null) {
195 return null;
196 }
197 Dump dump = new Dump();
198 dump.setDocCreationDate(dumpDTO.getDocCreationDate());
199 dump.setDocCurrentNodeName(dumpDTO.getDocCurrentNodeName());
200 dump.setDocDescription(dumpDTO.getDocDescription());
201 dump.setDocId(dumpDTO.getDocId());
202 dump.setDocInitiatorId(dumpDTO.getDocInitiatorId());
203 dump.setDocModificationDate(dumpDTO.getDocModificationDate());
204 dump.setDocRouteStatusCode(dumpDTO.getDocRouteStatusCode());
205 dump.setDocTypeName(dumpDTO.getDocTypeName());
206 dump.setLockVerNbr(dumpDTO.getLockVerNbr());
207 List<Fields> fields = new ArrayList<Fields>();
208 for (FieldDTO fieldDTO : dumpDTO.getFields()) {
209 fields.add(Fields.from(fieldDTO, dump));
210 }
211 dump.setFields(fields);
212 return dump;
213 }
214
215 }
216