View Javadoc

1   /**
2    * Copyright 2005-2012 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.krad.bo;
17  
18  import org.hibernate.annotations.GenericGenerator;
19  import org.hibernate.annotations.Parameter;
20  import org.kuali.rice.core.api.CoreApiServiceLocator;
21  import org.kuali.rice.kim.api.identity.Person;
22  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
23  import org.kuali.rice.krad.util.KRADConstants;
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.JoinColumn;
32  import javax.persistence.OneToOne;
33  import javax.persistence.Table;
34  import javax.persistence.Transient;
35  import java.sql.Timestamp;
36  
37  /**
38   * Represents a user note in the system.
39   */
40  @Entity
41  @Table(name="KRNS_NTE_T")
42  public class Note extends PersistableBusinessObjectBase {
43      private static final long serialVersionUID = -7647166354016356770L;
44  
45      @Id
46      @GeneratedValue(generator="KRNS_NTE_S")
47  	@GenericGenerator(name="KRNS_NTE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
48  			@Parameter(name="sequence_name",value="KRNS_NTE_S"),
49  			@Parameter(name="value_column",value="id")
50  	})
51  	@Column(name="NTE_ID")
52  	private Long noteIdentifier;
53      @Column(name="RMT_OBJ_ID")
54  	private String remoteObjectIdentifier;
55      @Column(name="AUTH_PRNCPL_ID")
56  	private String authorUniversalIdentifier;
57  	@Column(name="POST_TS")
58  	private Timestamp notePostedTimestamp;
59      @Column(name="NTE_TYP_CD")
60  	private String noteTypeCode;
61      @Column(name="TXT")
62  	private String noteText;
63      @Column(name="TPC_TXT")
64  	private String noteTopicText;
65      @Column(name="PRG_CD")
66  	private String notePurgeCode;
67      @Transient
68      private String attachmentIdentifier;
69  
70      @OneToOne(fetch=FetchType.EAGER)
71  	@JoinColumn(name="NTE_TYP_CD", insertable=false, updatable=false)
72  	private NoteType noteType;
73      @Transient
74      private Person authorUniversal;
75      @OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
76  	@JoinColumn(name = "NTE_ID", insertable = false, updatable = false)
77  	private Attachment attachment;
78      @Transient
79      private AdHocRouteRecipient adHocRouteRecipient;
80  
81      /**
82       * Default constructor.
83       */
84      public Note() {
85          super();
86  
87          //this.setNotePostedTimestampToCurrent();
88          this.setNoteText(KRADConstants.EMPTY_STRING);
89          // for now just do this
90          this.setNoteTypeCode("DH");
91  
92          this.setAdHocRouteRecipient(new AdHocRoutePerson());
93      }
94      
95      /**
96       * Sets the {@link #setNotePostedTimestamp(Timestamp)} to the current time.
97       */
98      public void setNotePostedTimestampToCurrent() {
99      	final Timestamp now = CoreApiServiceLocator.getDateTimeService().getCurrentTimestamp();
100     	this.setNotePostedTimestamp(now);
101     }
102 
103     /**
104      * Gets the noteIdentifier attribute.
105      * 
106      * @return Returns the noteIdentifier.
107      */
108     public Long getNoteIdentifier() {
109         return noteIdentifier;
110     }
111 
112     /**
113      * Sets the noteIdentifier attribute value.
114      * 
115      * @param noteIdentifier The noteIdentifier to set.
116      */
117     public void setNoteIdentifier(Long noteIdentifier) {
118         this.noteIdentifier = noteIdentifier;
119     }
120 
121     /**
122      * Gets the remoteObjectIdentifier attribute.
123      * 
124      * @return Returns the remoteObjectIdentifier
125      */
126     public String getRemoteObjectIdentifier() {
127         return remoteObjectIdentifier;
128     }
129 
130     /**
131      * Sets the remoteObjectIdentifier attribute.
132      * 
133      * @param remoteObjectIdentifier The remoteObjectIdentifier to set.
134      */
135     public void setRemoteObjectIdentifier(String remoteObjectIdentifier) {
136         this.remoteObjectIdentifier = remoteObjectIdentifier;
137     }
138 
139 
140     /**
141      * Gets the authorUniversalIdentifier attribute.
142      * 
143      * @return Returns the authorUniversalIdentifier
144      */
145     public String getAuthorUniversalIdentifier() {
146         return authorUniversalIdentifier;
147     }
148 
149     /**
150      * Sets the authorUniversalIdentifier attribute.
151      * 
152      * @param noteAuthorIdentifier The author ID to be set as the AuthorUniversalIdentifier
153      */
154     public void setAuthorUniversalIdentifier(String noteAuthorIdentifier) {
155         this.authorUniversalIdentifier = noteAuthorIdentifier;
156     }
157 
158 
159     /**
160      * Gets the notePostedTimestamp attribute.
161      * 
162      * @return Returns the notePostedTimestamp
163      */
164     public Timestamp getNotePostedTimestamp() {
165         return notePostedTimestamp;
166     }
167 
168     /**
169      * Sets the notePostedTimestamp attribute.
170      * 
171      * @param notePostedTimestamp The notePostedTimestamp to set.
172      */
173     public void setNotePostedTimestamp(Timestamp notePostedTimestamp) {
174         this.notePostedTimestamp = notePostedTimestamp;
175     }
176 
177 
178     /**
179      * Gets the noteTypeCode attribute.
180      * 
181      * @return Returns the noteTypeCode
182      */
183     public String getNoteTypeCode() {
184         return noteTypeCode;
185     }
186 
187     /**
188      * Sets the noteTypeCode attribute.
189      * 
190      * @param noteTypeCode The noteTypeCode to set.
191      */
192     public void setNoteTypeCode(String noteTypeCode) {
193         this.noteTypeCode = noteTypeCode;
194     }
195 
196 
197     /**
198      * Gets the noteText attribute.
199      * 
200      * @return Returns the noteText
201      */
202     public String getNoteText() {
203         return noteText;
204     }
205 
206     /**
207      * Sets the noteText attribute.
208      * 
209      * @param noteText The noteText to set.
210      */
211     public void setNoteText(String noteText) {
212         this.noteText = noteText;
213     }
214 
215 
216     /**
217      * Gets the noteTopicText attribute.
218      * 
219      * @return Returns the noteTopicText.
220      */
221     public String getNoteTopicText() {
222         return noteTopicText;
223     }
224 
225     /**
226      * Sets the noteTopicText attribute value.
227      * 
228      * @param noteTopicText The noteTopicText to set.
229      */
230     public void setNoteTopicText(String noteTopicText) {
231         this.noteTopicText = noteTopicText;
232     }
233 
234     /**
235      * Gets the notePurgeCode attribute.
236      * 
237      * @return Returns the notePurgeCode
238      */
239     public String getNotePurgeCode() {
240         return notePurgeCode;
241     }
242 
243     /**
244      * Sets the notePurgeCode attribute.
245      * 
246      * @param notePurgeCode The notePurgeCode to set.
247      */
248     public void setNotePurgeCode(String notePurgeCode) {
249         this.notePurgeCode = notePurgeCode;
250     }
251 
252     /**
253      * Gets the noteType attribute.
254      * 
255      * @return Returns the noteType.
256      */
257     public NoteType getNoteType() {
258         return noteType;
259     }
260 
261     /**
262      * Sets the noteType attribute value.
263      * 
264      * @param noteType The noteType to set.
265      * @deprecated
266      */
267     public void setNoteType(NoteType noteType) {
268         this.noteType = noteType;
269     }
270 
271     /**
272      * Gets the authorUniversal attribute.
273      * 
274      * @return Returns the authorUniversal.
275      */
276     public Person getAuthorUniversal() {
277         authorUniversal = KimApiServiceLocator.getPersonService().updatePersonIfNecessary(authorUniversalIdentifier, authorUniversal);
278         return authorUniversal;
279     }
280 
281     /**
282      * Sets the authorUniversal attribute value.
283      * 
284      * @param authorUniversal The authorUniversal to set.
285      * @deprecated
286      */
287     public void setAuthorUniversal(Person authorUniversal) {
288         this.authorUniversal = authorUniversal;
289     }
290 
291     /**
292      * Gets the attachment attribute.
293      * 
294      * @return Returns the attachment.
295      */
296     public Attachment getAttachment() {
297         return attachment;
298     }
299 
300     /**
301      * Sets the attachment attribute value.
302      * 
303      * @param attachment The attachment to set.
304      */
305     public void setAttachment(Attachment attachment) {
306         this.attachment = attachment;
307     }
308 
309     /**
310      * Gets the attachmentIdentifier attribute.
311      * 
312      * @return Returns the attachmentIdentifier.
313      */
314     public String getAttachmentIdentifier() {
315         return attachmentIdentifier;
316     }
317 
318     /**
319      * Sets the attachmentIdentifier attribute value.
320      * 
321      * @param attachmentIdentifier The attachmentIdentifier to set.
322      */
323     public void setAttachmentIdentifier(String attachmentIdentifier) {
324         this.attachmentIdentifier = attachmentIdentifier;
325     }
326 
327     /**
328      * Adds the given attachment to this note. More specifically, sets both the attachmentIdentifier and the attachment reference,
329      * since they both need to be done separately now that we aren't using anonymous keys.
330      * 
331      * @param attachment
332      */
333     public void addAttachment(Attachment attachment) {
334         setAttachmentIdentifier(attachment.getAttachmentIdentifier());
335         setAttachment(attachment);
336 
337         // copy foreign key and redundant values into attachment
338         attachment.setNoteIdentifier(noteIdentifier);
339         // we'll need this note reference if the attachment is deleted
340         // before the note is saved
341         attachment.setNote(this);
342     }
343 
344     /**
345      * Removes the current attachment, if any. More specifically, clears both the attachmentIdentifier and the attachment reference,
346      * since they both need to be done separately now that we aren't using anonymous keys.
347      */
348     public void removeAttachment() {
349         setAttachment(null);
350         setAttachmentIdentifier(null);
351     }
352 
353     /**
354      * @return the adHocRouteRecipient
355      */
356     public AdHocRouteRecipient getAdHocRouteRecipient() {
357         return adHocRouteRecipient;
358     }
359 
360     /**
361      * @param adHocRouteRecipient the adHocRouteRecipient to set
362      */
363     public void setAdHocRouteRecipient(AdHocRouteRecipient adHocRouteRecipient) {
364         this.adHocRouteRecipient = adHocRouteRecipient;
365     }
366 
367 }
368 
369