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