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