001/** 002 * Copyright 2005-2017 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 javax.persistence.Column; 019import javax.persistence.Entity; 020import javax.persistence.FetchType; 021import javax.persistence.GeneratedValue; 022import javax.persistence.Id; 023import javax.persistence.JoinColumn; 024import javax.persistence.ManyToOne; 025import javax.persistence.NamedQueries; 026import javax.persistence.NamedQuery; 027import javax.persistence.Table; 028import javax.persistence.Transient; 029import javax.persistence.Version; 030import java.io.InputStream; 031import java.util.Map; 032 033/** 034 * An attachment which is attached to a {@link Note}. 035 * 036 * @see Note 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 */ 040@Entity(name="org.kuali.rice.kew.notes.Attachment") 041@Table(name="KREW_ATT_T") 042@NamedQueries({ 043 @NamedQuery(name="Attachment.FindAttachmentById",query="select a from org.kuali.rice.kew.notes.Attachment as a where a.attachmentId = :attachmentId") 044}) 045public class Attachment { 046 047 @Id 048 @GeneratedValue(generator="KREW_DOC_NTE_S") 049 @Column(name="ATTACHMENT_ID") 050 private String attachmentId; 051 @Transient 052 private String noteId; 053 @Column(name="FILE_NM") 054 private String fileName; 055 @Column(name="FILE_LOC") 056 private String fileLoc; 057 @Column(name="MIME_TYP") 058 private String mimeType; 059 @Version 060 @Column(name="VER_NBR") 061 private Integer lockVerNbr; 062 @Transient 063 private InputStream attachedObject; 064 @ManyToOne(fetch=FetchType.EAGER) 065 @JoinColumn(name="NTE_ID") 066 private Note note; 067 068 public String getAttachmentId() { 069 return attachmentId; 070 } 071 public void setAttachmentId(String attachmentId) { 072 this.attachmentId = attachmentId; 073 } 074 public String getFileLoc() { 075 return fileLoc; 076 } 077 public void setFileLoc(String fileLoc) { 078 this.fileLoc = fileLoc; 079 } 080 public String getFileName() { 081 return fileName; 082 } 083 public void setFileName(String fileName) { 084 this.fileName = fileName; 085 } 086 public Integer getLockVerNbr() { 087 return lockVerNbr; 088 } 089 public void setLockVerNbr(Integer lockVerNbr) { 090 this.lockVerNbr = lockVerNbr; 091 } 092 public String getMimeType() { 093 return mimeType; 094 } 095 public void setMimeType(String mimeType) { 096 this.mimeType = mimeType; 097 } 098 public String getNoteId() { 099 //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