1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.notes; |
18 | |
|
19 | |
import org.hibernate.annotations.Fetch; |
20 | |
import org.hibernate.annotations.FetchMode; |
21 | |
import org.hibernate.annotations.GenericGenerator; |
22 | |
import org.hibernate.annotations.Parameter; |
23 | |
import org.joda.time.DateTime; |
24 | |
import org.kuali.rice.core.api.util.RiceConstants; |
25 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
26 | |
import org.kuali.rice.kew.api.note.NoteContract; |
27 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
28 | |
import org.kuali.rice.kew.util.KEWConstants; |
29 | |
|
30 | |
import javax.persistence.CascadeType; |
31 | |
import javax.persistence.Column; |
32 | |
import javax.persistence.Entity; |
33 | |
import javax.persistence.FetchType; |
34 | |
import javax.persistence.GeneratedValue; |
35 | |
import javax.persistence.Id; |
36 | |
import javax.persistence.NamedQueries; |
37 | |
import javax.persistence.NamedQuery; |
38 | |
import javax.persistence.OneToMany; |
39 | |
import javax.persistence.Table; |
40 | |
import javax.persistence.Transient; |
41 | |
import javax.persistence.Version; |
42 | |
import java.io.Serializable; |
43 | |
import java.sql.Timestamp; |
44 | |
import java.text.DateFormat; |
45 | |
import java.text.SimpleDateFormat; |
46 | |
import java.util.ArrayList; |
47 | |
import java.util.Calendar; |
48 | |
import java.util.Date; |
49 | |
import java.util.List; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@Entity(name="org.kuali.rice.kew.notes.Note") |
60 | |
@Table(name="KREW_DOC_NTE_T") |
61 | |
|
62 | |
@NamedQueries({ |
63 | |
@NamedQuery(name="KewNote.FindNoteByNoteId",query="select n from org.kuali.rice.kew.notes.Note as n where n.noteId = :noteId"), |
64 | |
@NamedQuery(name="KewNote.FindNoteByDocumentId", query="select n from org.kuali.rice.kew.notes.Note as n where n.documentId = :documentId order by n.noteId") |
65 | |
}) |
66 | 0 | public class Note implements Serializable, NoteContract { |
67 | |
|
68 | |
private static final long serialVersionUID = -6136544551121011531L; |
69 | |
@Id |
70 | |
@GeneratedValue(generator="KREW_DOC_NTE_S") |
71 | |
@GenericGenerator(name="KREW_DOC_NTE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ |
72 | |
@Parameter(name="sequence_name",value="KREW_DOC_NTE_S"), |
73 | |
@Parameter(name="value_column",value="id") |
74 | |
}) |
75 | |
@Column(name="DOC_NTE_ID") |
76 | |
private String noteId; |
77 | |
@Column(name="DOC_HDR_ID") |
78 | |
private String documentId; |
79 | |
@Column(name="AUTH_PRNCPL_ID") |
80 | |
private String noteAuthorWorkflowId; |
81 | |
@Column(name="CRT_DT") |
82 | |
private Timestamp noteCreateDate; |
83 | |
@Column(name="TXT") |
84 | |
private String noteText; |
85 | |
@Version |
86 | |
@Column(name="VER_NBR") |
87 | |
private Integer lockVerNbr; |
88 | |
|
89 | 0 | @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST}, |
90 | |
targetEntity=org.kuali.rice.kew.notes.Attachment.class, mappedBy="note") |
91 | |
@Fetch(value = FetchMode.SELECT) |
92 | |
private List<Attachment> attachments = new ArrayList<Attachment>(); |
93 | |
|
94 | |
|
95 | |
@Transient |
96 | |
private String noteAuthorEmailAddress; |
97 | |
@Transient |
98 | |
private String noteAuthorNetworkId; |
99 | |
@Transient |
100 | |
private String noteAuthorFullName; |
101 | |
@Transient |
102 | |
private Long noteCreateLongDate; |
103 | |
@Transient |
104 | |
private Boolean authorizedToEdit; |
105 | |
@Transient |
106 | |
private Boolean editingNote; |
107 | |
|
108 | |
public Integer getLockVerNbr() { |
109 | 0 | return lockVerNbr; |
110 | |
} |
111 | |
|
112 | |
public void setLockVerNbr(Integer lockVerNbr) { |
113 | 0 | this.lockVerNbr = lockVerNbr; |
114 | 0 | } |
115 | |
|
116 | |
public String getNoteAuthorWorkflowId() { |
117 | 0 | return noteAuthorWorkflowId; |
118 | |
} |
119 | |
|
120 | |
public void setNoteAuthorWorkflowId(String noteAuthorWorkflowId) { |
121 | 0 | this.noteAuthorWorkflowId = noteAuthorWorkflowId; |
122 | 0 | } |
123 | |
|
124 | |
public Timestamp getNoteCreateDate() { |
125 | 0 | return noteCreateDate; |
126 | |
} |
127 | |
|
128 | |
public void setNoteCreateDate(Timestamp noteCreateDate) { |
129 | 0 | this.noteCreateDate = noteCreateDate; |
130 | 0 | } |
131 | |
|
132 | |
public String getNoteId() { |
133 | 0 | return noteId; |
134 | |
} |
135 | |
|
136 | |
public void setNoteId(String noteId) { |
137 | 0 | this.noteId = noteId; |
138 | 0 | } |
139 | |
|
140 | |
public String getNoteText() { |
141 | 0 | return noteText; |
142 | |
} |
143 | |
|
144 | |
public void setNoteText(String noteText) { |
145 | 0 | this.noteText = noteText; |
146 | 0 | } |
147 | |
|
148 | |
public String getDocumentId() { |
149 | 0 | return documentId; |
150 | |
} |
151 | |
|
152 | |
public void setDocumentId(String documentId) { |
153 | 0 | this.documentId = documentId; |
154 | 0 | } |
155 | |
|
156 | |
public String getNoteAuthorEmailAddress() { |
157 | 0 | return noteAuthorEmailAddress; |
158 | |
} |
159 | |
|
160 | |
public void setNoteAuthorEmailAddress(String noteAuthorEmailAddress) { |
161 | 0 | this.noteAuthorEmailAddress = noteAuthorEmailAddress; |
162 | 0 | } |
163 | |
|
164 | |
public String getNoteAuthorFullName() { |
165 | 0 | return noteAuthorFullName; |
166 | |
} |
167 | |
|
168 | |
public void setNoteAuthorFullName(String noteAuthorFullName) { |
169 | 0 | this.noteAuthorFullName = noteAuthorFullName; |
170 | 0 | } |
171 | |
|
172 | |
public String getNoteAuthorNetworkId() { |
173 | 0 | return noteAuthorNetworkId; |
174 | |
} |
175 | |
|
176 | |
public void setNoteAuthorNetworkId(String noteAuthorNetworkId) { |
177 | 0 | this.noteAuthorNetworkId = noteAuthorNetworkId; |
178 | 0 | } |
179 | |
|
180 | |
public Long getNoteCreateLongDate() { |
181 | 0 | return noteCreateLongDate; |
182 | |
} |
183 | |
|
184 | |
public void setNoteCreateLongDate(Long noteCreateLongDate) { |
185 | 0 | this.noteCreateLongDate = noteCreateLongDate; |
186 | 0 | } |
187 | |
|
188 | |
public Boolean getAuthorizedToEdit() { |
189 | 0 | return authorizedToEdit; |
190 | |
} |
191 | |
|
192 | |
public void setAuthorizedToEdit(Boolean authorizedToEdit) { |
193 | 0 | this.authorizedToEdit = authorizedToEdit; |
194 | 0 | } |
195 | |
|
196 | |
public Boolean getEditingNote() { |
197 | 0 | return editingNote; |
198 | |
} |
199 | |
|
200 | |
public void setEditingNote(Boolean editingNote) { |
201 | 0 | this.editingNote = editingNote; |
202 | 0 | } |
203 | |
|
204 | |
public String getFormattedCreateDateTime() { |
205 | 0 | long time = getNoteCreateDate().getTime(); |
206 | 0 | Calendar calendar = Calendar.getInstance(); |
207 | 0 | calendar.setTimeInMillis(time); |
208 | 0 | Date date = calendar.getTime(); |
209 | 0 | DateFormat dateFormat = new SimpleDateFormat(KEWConstants.TIMESTAMP_DATE_FORMAT_PATTERN2); |
210 | 0 | return dateFormat.format(date); |
211 | |
} |
212 | |
|
213 | |
public String getFormattedCreateDate() { |
214 | 0 | long time = getNoteCreateDate().getTime(); |
215 | 0 | Calendar calendar = Calendar.getInstance(); |
216 | 0 | calendar.setTimeInMillis(time); |
217 | 0 | Date date = calendar.getTime(); |
218 | 0 | DateFormat dateFormat = RiceConstants.getDefaultDateFormat(); |
219 | 0 | return dateFormat.format(date); |
220 | |
} |
221 | |
|
222 | |
public String getFormattedCreateTime() { |
223 | 0 | long time = getNoteCreateDate().getTime(); |
224 | 0 | Calendar calendar = Calendar.getInstance(); |
225 | 0 | calendar.setTimeInMillis(time); |
226 | 0 | Date date = calendar.getTime(); |
227 | 0 | DateFormat dateFormat = RiceConstants.getDefaultTimeFormat(); |
228 | 0 | return dateFormat.format(date); |
229 | |
} |
230 | |
|
231 | |
public List<Attachment> getAttachments() { |
232 | 0 | return attachments; |
233 | |
} |
234 | |
|
235 | |
public void setAttachments(List<Attachment> attachments) { |
236 | 0 | this.attachments = attachments; |
237 | 0 | } |
238 | |
|
239 | |
|
240 | |
public void beforeInsert(){ |
241 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
242 | 0 | } |
243 | |
|
244 | |
|
245 | |
|
246 | |
@Override |
247 | |
public String getId() { |
248 | 0 | if (getNoteId() == null) { |
249 | 0 | return null; |
250 | |
} |
251 | 0 | return getNoteId().toString(); |
252 | |
} |
253 | |
|
254 | |
@Override |
255 | |
public Long getVersionNumber() { |
256 | 0 | if (getLockVerNbr() == null) { |
257 | 0 | return null; |
258 | |
} |
259 | 0 | return new Long(getLockVerNbr().longValue()); |
260 | |
} |
261 | |
|
262 | |
@Override |
263 | |
public String getAuthorPrincipalId() { |
264 | 0 | return getNoteAuthorWorkflowId(); |
265 | |
} |
266 | |
|
267 | |
@Override |
268 | |
public DateTime getCreateDate() { |
269 | 0 | if (getNoteCreateDate() == null) { |
270 | 0 | return null; |
271 | |
} |
272 | 0 | return new DateTime(getNoteCreateDate().getTime()); |
273 | |
} |
274 | |
|
275 | |
@Override |
276 | |
public String getText() { |
277 | 0 | return getNoteText(); |
278 | |
} |
279 | |
|
280 | |
public static org.kuali.rice.kew.api.note.Note to(Note note) { |
281 | 0 | if (note == null) { |
282 | 0 | return null; |
283 | |
} |
284 | 0 | return org.kuali.rice.kew.api.note.Note.Builder.create(note).build(); |
285 | |
} |
286 | |
|
287 | |
public static Note from(org.kuali.rice.kew.api.note.Note note) { |
288 | 0 | if (note == null) { |
289 | 0 | return null; |
290 | |
} |
291 | 0 | Note noteBo = new Note(); |
292 | 0 | if (note.getId() != null) { |
293 | 0 | noteBo.setNoteId(note.getId()); |
294 | |
} |
295 | 0 | noteBo.setDocumentId(note.getDocumentId()); |
296 | 0 | noteBo.setNoteAuthorWorkflowId(note.getAuthorPrincipalId()); |
297 | 0 | if (note.getCreateDate() != null) { |
298 | 0 | noteBo.setNoteCreateDate(new Timestamp(note.getCreateDate().getMillis())); |
299 | |
} |
300 | 0 | noteBo.setNoteText(note.getText()); |
301 | 0 | if (note.getVersionNumber() != null) { |
302 | 0 | noteBo.setLockVerNbr(Integer.valueOf(note.getVersionNumber().intValue())); |
303 | |
} |
304 | 0 | return noteBo; |
305 | |
} |
306 | |
|
307 | |
} |
308 | |
|