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