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