View Javadoc

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