Coverage Report - org.kuali.rice.kew.notes.Note
 
Classes in this File Line Coverage Branch Coverage Complexity
Note
0%
0/88
0%
0/16
1.351
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.notes;
 18  
 
 19  
 import java.io.Serializable;
 20  
 import java.sql.Timestamp;
 21  
 import java.text.DateFormat;
 22  
 import java.text.SimpleDateFormat;
 23  
 import java.util.ArrayList;
 24  
 import java.util.Calendar;
 25  
 import java.util.Date;
 26  
 import java.util.List;
 27  
 
 28  
 import javax.persistence.CascadeType;
 29  
 import javax.persistence.Column;
 30  
 import javax.persistence.Entity;
 31  
 import javax.persistence.FetchType;
 32  
 import javax.persistence.GeneratedValue;
 33  
 import javax.persistence.Id;
 34  
 import javax.persistence.NamedQueries;
 35  
 import javax.persistence.NamedQuery;
 36  
 import javax.persistence.OneToMany;
 37  
 import javax.persistence.Table;
 38  
 import javax.persistence.Transient;
 39  
 import javax.persistence.Version;
 40  
 
 41  
 import org.hibernate.annotations.Fetch;
 42  
 import org.hibernate.annotations.FetchMode;
 43  
 import org.hibernate.annotations.GenericGenerator;
 44  
 import org.hibernate.annotations.Parameter;
 45  
 import org.joda.time.DateTime;
 46  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 47  
 import org.kuali.rice.core.util.RiceConstants;
 48  
 import org.kuali.rice.kew.api.note.NoteContract;
 49  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 50  
 import org.kuali.rice.kew.util.KEWConstants;
 51  
 
 52  
 
 53  
 /**
 54  
  * A note attached to a document.  May also contain a List of attachments.
 55  
  * 
 56  
  * @see Attachment
 57  
  *
 58  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 59  
  */
 60  
 @Entity(name="org.kuali.rice.kew.notes.Note")
 61  
 @Table(name="KREW_DOC_NTE_T")
 62  
 //@Sequence(name="KREW_DOC_NTE_S",property="noteId")
 63  
 @NamedQueries({
 64  
         @NamedQuery(name="KewNote.FindNoteByNoteId",query="select n from org.kuali.rice.kew.notes.Note as n where n.noteId = :noteId"),
 65  
         @NamedQuery(name="KewNote.FindNoteByDocumentId", query="select n from org.kuali.rice.kew.notes.Note as n where n.documentId = :documentId order by n.noteId")
 66  
 })
 67  0
 public class Note implements Serializable, NoteContract {
 68  
 
 69  
         private static final long serialVersionUID = -6136544551121011531L;
 70  
         @Id
 71  
         @GeneratedValue(generator="KREW_DOC_NTE_S")
 72  
         @GenericGenerator(name="KREW_DOC_NTE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 73  
                         @Parameter(name="sequence_name",value="KREW_DOC_NTE_S"),
 74  
                         @Parameter(name="value_column",value="id")
 75  
         })
 76  
         @Column(name="DOC_NTE_ID")
 77  
         private String noteId;
 78  
     @Column(name="DOC_HDR_ID")
 79  
         private String documentId;
 80  
     @Column(name="AUTH_PRNCPL_ID")
 81  
         private String noteAuthorWorkflowId;
 82  
         @Column(name="CRT_DT")
 83  
         private Timestamp noteCreateDate;
 84  
     @Column(name="TXT")
 85  
         private String noteText;
 86  
     @Version
 87  
         @Column(name="VER_NBR")
 88  
         private Integer lockVerNbr;
 89  
     
 90  0
     @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST},
 91  
             targetEntity=org.kuali.rice.kew.notes.Attachment.class, mappedBy="note")
 92  
     @Fetch(value = FetchMode.SELECT)
 93  
     private List<Attachment> attachments = new ArrayList<Attachment>();
 94  
 
 95  
     //additional data not in database
 96  
     @Transient
 97  
     private String noteAuthorEmailAddress;
 98  
     @Transient
 99  
     private String noteAuthorNetworkId;
 100  
     @Transient
 101  
     private String noteAuthorFullName;
 102  
     @Transient
 103  
     private Long noteCreateLongDate;
 104  
     @Transient
 105  
     private Boolean authorizedToEdit; 
 106  
     @Transient
 107  
     private Boolean editingNote;
 108  
     
 109  
     public Integer getLockVerNbr() {
 110  0
         return lockVerNbr;
 111  
     }
 112  
 
 113  
     public void setLockVerNbr(Integer lockVerNbr) {
 114  0
         this.lockVerNbr = lockVerNbr;
 115  0
     }
 116  
 
 117  
     public String getNoteAuthorWorkflowId() {
 118  0
         return noteAuthorWorkflowId;
 119  
     }
 120  
 
 121  
     public void setNoteAuthorWorkflowId(String noteAuthorWorkflowId) {
 122  0
         this.noteAuthorWorkflowId = noteAuthorWorkflowId;
 123  0
     }
 124  
 
 125  
     public Timestamp getNoteCreateDate() {
 126  0
         return noteCreateDate;
 127  
     }
 128  
 
 129  
     public void setNoteCreateDate(Timestamp noteCreateDate) {
 130  0
         this.noteCreateDate = noteCreateDate;
 131  0
     }
 132  
 
 133  
     public String getNoteId() {
 134  0
         return noteId;
 135  
     }
 136  
  
 137  
     public void setNoteId(String noteId) {
 138  0
         this.noteId = noteId;
 139  0
     }
 140  
  
 141  
     public String getNoteText() {
 142  0
         return noteText;
 143  
     }
 144  
 
 145  
     public void setNoteText(String noteText) {
 146  0
         this.noteText = noteText;
 147  0
     }
 148  
 
 149  
     public String getDocumentId() {
 150  0
         return documentId;
 151  
     }
 152  
 
 153  
     public void setDocumentId(String documentId) {
 154  0
         this.documentId = documentId;
 155  0
     }
 156  
 
 157  
     public String getNoteAuthorEmailAddress() {
 158  0
         return noteAuthorEmailAddress;
 159  
     }
 160  
  
 161  
     public void setNoteAuthorEmailAddress(String noteAuthorEmailAddress) {
 162  0
         this.noteAuthorEmailAddress = noteAuthorEmailAddress;
 163  0
     }
 164  
 
 165  
     public String getNoteAuthorFullName() {
 166  0
         return noteAuthorFullName;
 167  
     }
 168  
 
 169  
     public void setNoteAuthorFullName(String noteAuthorFullName) {
 170  0
         this.noteAuthorFullName = noteAuthorFullName;
 171  0
     }
 172  
 
 173  
     public String getNoteAuthorNetworkId() {
 174  0
         return noteAuthorNetworkId;
 175  
     }
 176  
 
 177  
     public void setNoteAuthorNetworkId(String noteAuthorNetworkId) {
 178  0
         this.noteAuthorNetworkId = noteAuthorNetworkId;
 179  0
     }
 180  
 
 181  
     public Long getNoteCreateLongDate() {
 182  0
         return noteCreateLongDate;
 183  
     }
 184  
 
 185  
     public void setNoteCreateLongDate(Long noteCreateLongDate) {
 186  0
         this.noteCreateLongDate = noteCreateLongDate;
 187  0
     }
 188  
 
 189  
     public Boolean getAuthorizedToEdit() {
 190  0
         return authorizedToEdit;
 191  
     }
 192  
 
 193  
     public void setAuthorizedToEdit(Boolean authorizedToEdit) {
 194  0
         this.authorizedToEdit = authorizedToEdit;
 195  0
     }
 196  
 
 197  
     public Boolean getEditingNote() {
 198  0
         return editingNote;
 199  
     }
 200  
 
 201  
     public void setEditingNote(Boolean editingNote) {
 202  0
         this.editingNote = editingNote;
 203  0
     }
 204  
 
 205  
     public String getFormattedCreateDateTime() {
 206  0
         long time = getNoteCreateDate().getTime();
 207  0
         Calendar calendar = Calendar.getInstance();
 208  0
         calendar.setTimeInMillis(time);
 209  0
         Date date = calendar.getTime();
 210  0
         DateFormat dateFormat = new SimpleDateFormat(KEWConstants.TIMESTAMP_DATE_FORMAT_PATTERN2);
 211  0
         return dateFormat.format(date);
 212  
     }
 213  
 
 214  
     public String getFormattedCreateDate() {
 215  0
         long time = getNoteCreateDate().getTime();
 216  0
         Calendar calendar = Calendar.getInstance();
 217  0
         calendar.setTimeInMillis(time);
 218  0
         Date date = calendar.getTime();
 219  0
         DateFormat dateFormat = RiceConstants.getDefaultDateFormat();
 220  0
         return dateFormat.format(date);
 221  
     }
 222  
     
 223  
     public String getFormattedCreateTime() {
 224  0
         long time = getNoteCreateDate().getTime();
 225  0
         Calendar calendar = Calendar.getInstance();
 226  0
         calendar.setTimeInMillis(time);
 227  0
         Date date = calendar.getTime();
 228  0
         DateFormat dateFormat = RiceConstants.getDefaultTimeFormat();
 229  0
         return dateFormat.format(date);
 230  
     }
 231  
 
 232  
         public List<Attachment> getAttachments() {
 233  0
                 return attachments;
 234  
         }
 235  
 
 236  
         public void setAttachments(List<Attachment> attachments) {
 237  0
                 this.attachments = attachments;
 238  0
         }
 239  
         
 240  
         //@PrePersist
 241  
         public void beforeInsert(){
 242  0
                 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
 243  0
         }
 244  
         
 245  
         // new methods from NoteContract in 2.0
 246  
 
 247  
         @Override
 248  
         public String getId() {
 249  0
                 if (getNoteId() == null) {
 250  0
                         return null;
 251  
                 }
 252  0
                 return getNoteId().toString();
 253  
         }
 254  
 
 255  
         @Override
 256  
         public Long getVersionNumber() {
 257  0
                 if (getLockVerNbr() == null) {
 258  0
                         return null;
 259  
                 }
 260  0
                 return new Long(getLockVerNbr().longValue());
 261  
         }
 262  
 
 263  
         @Override
 264  
         public String getAuthorPrincipalId() {
 265  0
                 return getNoteAuthorWorkflowId();
 266  
         }
 267  
 
 268  
         @Override
 269  
         public DateTime getCreateDate() {
 270  0
                 if (getNoteCreateDate() == null) {
 271  0
                         return null;
 272  
                 }
 273  0
                 return new DateTime(getNoteCreateDate().getTime());
 274  
         }
 275  
 
 276  
         @Override
 277  
         public String getText() {
 278  0
                 return getNoteText();
 279  
         }
 280  
         
 281  
         public static org.kuali.rice.kew.api.note.Note to(Note note) {
 282  0
                 if (note == null) {
 283  0
                         return null;
 284  
                 }
 285  0
                 return org.kuali.rice.kew.api.note.Note.Builder.create(note).build();
 286  
         }
 287  
         
 288  
         public static Note from(org.kuali.rice.kew.api.note.Note note) {
 289  0
                 if (note == null) {
 290  0
                         return null;
 291  
                 }
 292  0
                 Note noteBo = new Note();
 293  0
                 if (note.getId() != null) {
 294  0
                         noteBo.setNoteId(note.getId());
 295  
                 }
 296  0
                 noteBo.setDocumentId(note.getDocumentId());
 297  0
                 noteBo.setNoteAuthorWorkflowId(note.getAuthorPrincipalId());
 298  0
                 if (note.getCreateDate() != null) {
 299  0
                         noteBo.setNoteCreateDate(new Timestamp(note.getCreateDate().getMillis()));
 300  
                 }
 301  0
                 noteBo.setNoteText(note.getText());
 302  0
                 if (note.getVersionNumber() != null) {
 303  0
                         noteBo.setLockVerNbr(Integer.valueOf(note.getVersionNumber().intValue()));
 304  
                 }
 305  0
                 return noteBo;
 306  
         }
 307  
         
 308  
 }
 309