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