View Javadoc
1   /**
2    * Copyright 2005-2014 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 javax.persistence.Column;
19  import javax.persistence.Entity;
20  import javax.persistence.FetchType;
21  import javax.persistence.GeneratedValue;
22  import javax.persistence.Id;
23  import javax.persistence.JoinColumn;
24  import javax.persistence.ManyToOne;
25  import javax.persistence.NamedQueries;
26  import javax.persistence.NamedQuery;
27  import javax.persistence.Table;
28  import javax.persistence.Transient;
29  import javax.persistence.Version;
30  import java.io.InputStream;
31  import java.util.Map;
32  
33  /**
34   * An attachment which is attached to a {@link Note}.
35   * 
36   * @see Note
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  @Entity(name="org.kuali.rice.kew.notes.Attachment")
41  @Table(name="KREW_ATT_T")
42  @NamedQueries({
43  	@NamedQuery(name="Attachment.FindAttachmentById",query="select a from org.kuali.rice.kew.notes.Attachment as a where a.attachmentId = :attachmentId")
44  })
45  public class Attachment {
46  
47  	@Id
48  	@GeneratedValue(generator="KREW_DOC_NTE_S")
49  	@Column(name="ATTACHMENT_ID")
50  	private String attachmentId;
51  	@Transient
52  	private String noteId;
53  	@Column(name="FILE_NM")
54  	private String fileName;
55  	@Column(name="FILE_LOC")
56  	private String fileLoc;
57  	@Column(name="MIME_TYP")
58  	private String mimeType;
59  	@Version
60  	@Column(name="VER_NBR")
61  	private Integer lockVerNbr;
62      @Transient
63  	private InputStream attachedObject;
64  	@ManyToOne(fetch=FetchType.EAGER)
65  	@JoinColumn(name="NTE_ID")
66  	private Note note;
67  	
68  	public String getAttachmentId() {
69  		return attachmentId;
70  	}
71  	public void setAttachmentId(String attachmentId) {
72  		this.attachmentId = attachmentId;
73  	}
74  	public String getFileLoc() {
75  		return fileLoc;
76  	}
77  	public void setFileLoc(String fileLoc) {
78  		this.fileLoc = fileLoc;
79  	}
80  	public String getFileName() {
81  		return fileName;
82  	}
83  	public void setFileName(String fileName) {
84  		this.fileName = fileName;
85  	}
86  	public Integer getLockVerNbr() {
87  		return lockVerNbr;
88  	}
89  	public void setLockVerNbr(Integer lockVerNbr) {
90  		this.lockVerNbr = lockVerNbr;
91  	}
92  	public String getMimeType() {
93  		return mimeType;
94  	}
95  	public void setMimeType(String mimeType) {
96  		this.mimeType = mimeType;
97  	}
98  	public String getNoteId() {
99  		//noteId field not mapped in JPA 
100 		if (noteId == null && note != null){
101 			return note.getNoteId();
102 		}
103 		return noteId;
104 	}
105 	public void setNoteId(String noteId) {
106 		this.noteId = noteId;
107 	}
108 	public Note getNote() {
109 		return note;
110 	}
111 	public void setNote(Note note) {
112 		this.note = note;
113 	}
114 	public InputStream getAttachedObject() {
115 		return attachedObject;
116 	}
117 	public void setAttachedObject(InputStream attachedObject) {
118 		this.attachedObject = attachedObject;
119 	}
120 
121     public Attachment deepCopy(Map<Object, Object> visited) {
122         if (visited.containsKey(this)) {
123             return (Attachment)visited.get(this);
124         }
125         Attachment copy = new Attachment();
126         visited.put(this, copy);
127         copy.attachmentId = attachmentId;
128         copy.noteId = noteId;
129         copy.fileName = fileName;
130         copy.fileLoc = fileLoc;
131         copy.mimeType = mimeType;
132         copy.lockVerNbr = lockVerNbr;
133         if (note != null) {
134             copy.note = note.deepCopy(visited);
135         }
136         return copy;
137     }
138 }
139