001/** 002 * Copyright 2005-2015 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 */ 016package org.kuali.rice.kew.notes; 017 018import java.io.InputStream; 019 020import javax.persistence.Column; 021import javax.persistence.Entity; 022import javax.persistence.FetchType; 023import javax.persistence.GeneratedValue; 024import javax.persistence.Id; 025import javax.persistence.JoinColumn; 026import javax.persistence.ManyToOne; 027import javax.persistence.NamedQueries; 028import javax.persistence.NamedQuery; 029import javax.persistence.Table; 030import javax.persistence.Transient; 031import javax.persistence.Version; 032 033import org.hibernate.annotations.GenericGenerator; 034import org.hibernate.annotations.Parameter; 035import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; 036import org.kuali.rice.krad.service.KRADServiceLocator; 037 038/** 039 * An attachment which is attached to a {@link Note}. 040 * 041 * @see Note 042 * 043 * @author Kuali Rice Team (rice.collab@kuali.org) 044 */ 045@Entity(name="org.kuali.rice.kew.notes.Attachment") 046@Table(name="KREW_ATT_T") 047//@Sequence(name="KREW_DOC_NTE_S",property="attachmentId") 048@NamedQueries({ 049 @NamedQuery(name="Attachment.FindAttachmentById",query="select a from org.kuali.rice.kew.notes.Attachment as a where a.attachmentId = :attachmentId") 050}) 051public class Attachment { 052 053 @Id 054 @GeneratedValue(generator="KREW_DOC_NTE_S") 055 @GenericGenerator(name="KREW_DOC_NTE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ 056 @Parameter(name="sequence_name",value="KREW_DOC_NTE_S"), 057 @Parameter(name="value_column",value="id") 058 }) 059 @Column(name="ATTACHMENT_ID") 060 private String attachmentId; 061 @Transient 062 private String noteId; 063 @Column(name="FILE_NM") 064 private String fileName; 065 @Column(name="FILE_LOC") 066 private String fileLoc; 067 @Column(name="MIME_TYP") 068 private String mimeType; 069 @Version 070 @Column(name="VER_NBR") 071 private Integer lockVerNbr; 072 @Transient 073 private InputStream attachedObject; 074 @ManyToOne(fetch=FetchType.EAGER) 075 @JoinColumn(name="NTE_ID") 076 private Note note; 077 078 public String getAttachmentId() { 079 return attachmentId; 080 } 081 public void setAttachmentId(String attachmentId) { 082 this.attachmentId = attachmentId; 083 } 084 public String getFileLoc() { 085 return fileLoc; 086 } 087 public void setFileLoc(String fileLoc) { 088 this.fileLoc = fileLoc; 089 } 090 public String getFileName() { 091 return fileName; 092 } 093 public void setFileName(String fileName) { 094 this.fileName = fileName; 095 } 096 public Integer getLockVerNbr() { 097 return lockVerNbr; 098 } 099 public void setLockVerNbr(Integer lockVerNbr) { 100 this.lockVerNbr = lockVerNbr; 101 } 102 public String getMimeType() { 103 return mimeType; 104 } 105 public void setMimeType(String mimeType) { 106 this.mimeType = mimeType; 107 } 108 public String getNoteId() { 109 //noteId field not mapped in JPA 110 if (noteId == null && note != null){ 111 return note.getNoteId(); 112 } 113 return noteId; 114 } 115 public void setNoteId(String noteId) { 116 this.noteId = noteId; 117 } 118 public Note getNote() { 119 return note; 120 } 121 public void setNote(Note note) { 122 this.note = note; 123 } 124 public InputStream getAttachedObject() { 125 return attachedObject; 126 } 127 public void setAttachedObject(InputStream attachedObject) { 128 this.attachedObject = attachedObject; 129 } 130 131 //@PrePersist 132 public void beforeInsert(){ 133 OrmUtils.populateAutoIncValue(this, KRADServiceLocator.getEntityManagerFactory().createEntityManager()); 134 } 135 136} 137