001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krad.bo; 017 018 import org.hibernate.annotations.GenericGenerator; 019 import org.hibernate.annotations.Parameter; 020 import org.kuali.rice.core.api.CoreApiServiceLocator; 021 import org.kuali.rice.kim.api.identity.Person; 022 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 023 import org.kuali.rice.krad.util.KRADConstants; 024 025 import javax.persistence.CascadeType; 026 import javax.persistence.Column; 027 import javax.persistence.Entity; 028 import javax.persistence.FetchType; 029 import javax.persistence.GeneratedValue; 030 import javax.persistence.Id; 031 import javax.persistence.JoinColumn; 032 import javax.persistence.OneToOne; 033 import javax.persistence.Table; 034 import javax.persistence.Transient; 035 import java.sql.Timestamp; 036 037 /** 038 * Represents a user note in the system. 039 */ 040 @Entity 041 @Table(name="KRNS_NTE_T") 042 public class Note extends PersistableBusinessObjectBase { 043 private static final long serialVersionUID = -7647166354016356770L; 044 045 @Id 046 @GeneratedValue(generator="KRNS_NTE_S") 047 @GenericGenerator(name="KRNS_NTE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ 048 @Parameter(name="sequence_name",value="KRNS_NTE_S"), 049 @Parameter(name="value_column",value="id") 050 }) 051 @Column(name="NTE_ID") 052 private Long noteIdentifier; 053 @Column(name="RMT_OBJ_ID") 054 private String remoteObjectIdentifier; 055 @Column(name="AUTH_PRNCPL_ID") 056 private String authorUniversalIdentifier; 057 @Column(name="POST_TS") 058 private Timestamp notePostedTimestamp; 059 @Column(name="NTE_TYP_CD") 060 private String noteTypeCode; 061 @Column(name="TXT") 062 private String noteText; 063 @Column(name="TPC_TXT") 064 private String noteTopicText; 065 @Column(name="PRG_CD") 066 private String notePurgeCode; 067 @Transient 068 private String attachmentIdentifier; 069 070 @OneToOne(fetch=FetchType.EAGER) 071 @JoinColumn(name="NTE_TYP_CD", insertable=false, updatable=false) 072 private NoteType noteType; 073 @Transient 074 private transient Person authorUniversal; 075 @OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }) 076 @JoinColumn(name = "NTE_ID", insertable = false, updatable = false) 077 private Attachment attachment; 078 @Transient 079 private AdHocRouteRecipient adHocRouteRecipient; 080 081 /** 082 * Default constructor. 083 */ 084 public Note() { 085 super(); 086 087 //this.setNotePostedTimestampToCurrent(); 088 this.setNoteText(KRADConstants.EMPTY_STRING); 089 // for now just do this 090 this.setNoteTypeCode("DH"); 091 092 this.setAdHocRouteRecipient(new AdHocRoutePerson()); 093 } 094 095 /** 096 * Sets the {@link #setNotePostedTimestamp(Timestamp)} to the current time. 097 */ 098 public void setNotePostedTimestampToCurrent() { 099 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