View Javadoc

1   /**
2    * Copyright 2005-2012 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.kew.notes;
17  
18  import java.io.InputStream;
19  
20  import javax.persistence.Column;
21  import javax.persistence.Entity;
22  import javax.persistence.FetchType;
23  import javax.persistence.GeneratedValue;
24  import javax.persistence.Id;
25  import javax.persistence.JoinColumn;
26  import javax.persistence.ManyToOne;
27  import javax.persistence.NamedQueries;
28  import javax.persistence.NamedQuery;
29  import javax.persistence.Table;
30  import javax.persistence.Transient;
31  import javax.persistence.Version;
32  
33  import org.hibernate.annotations.GenericGenerator;
34  import org.hibernate.annotations.Parameter;
35  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
36  import org.kuali.rice.krad.service.KRADServiceLocator;
37  
38  /**
39   * An attachment which is attached to a {@link Note}.
40   * 
41   * @see Note
42   *
43   * @author Kuali Rice Team (rice.collab@kuali.org)
44   */
45  @Entity(name="org.kuali.rice.kew.notes.Attachment")
46  @Table(name="KREW_ATT_T")
47  //@Sequence(name="KREW_DOC_NTE_S",property="attachmentId")
48  @NamedQueries({
49  	@NamedQuery(name="Attachment.FindAttachmentById",query="select a from org.kuali.rice.kew.notes.Attachment as a where a.attachmentId = :attachmentId")
50  })
51  public class Attachment {
52  
53  	@Id
54  	@GeneratedValue(generator="KREW_DOC_NTE_S")
55  	@GenericGenerator(name="KREW_DOC_NTE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
56  			@Parameter(name="sequence_name",value="KREW_DOC_NTE_S"),
57  			@Parameter(name="value_column",value="id")
58  	})
59  	@Column(name="ATTACHMENT_ID")
60  	private String attachmentId;
61  	@Transient
62  	private String noteId;
63  	@Column(name="FILE_NM")
64  	private String fileName;
65  	@Column(name="FILE_LOC")
66  	private String fileLoc;
67  	@Column(name="MIME_TYP")
68  	private String mimeType;
69  	@Version
70  	@Column(name="VER_NBR")
71  	private Integer lockVerNbr;
72      @Transient
73  	private InputStream attachedObject;
74  	@ManyToOne(fetch=FetchType.EAGER)
75  	@JoinColumn(name="NTE_ID")
76  	private Note note;
77  	
78  	public String getAttachmentId() {
79  		return attachmentId;
80  	}
81  	public void setAttachmentId(String attachmentId) {
82  		this.attachmentId = attachmentId;
83  	}
84  	public String getFileLoc() {
85  		return fileLoc;
86  	}
87  	public void setFileLoc(String fileLoc) {
88  		this.fileLoc = fileLoc;
89  	}
90  	public String getFileName() {
91  		return fileName;
92  	}
93  	public void setFileName(String fileName) {
94  		this.fileName = fileName;
95  	}
96  	public Integer getLockVerNbr() {
97  		return lockVerNbr;
98  	}
99  	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