001 /* 002 * Copyright 2007 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 */ 016 package org.kuali.rice.kns.bo; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.kns.service.KNSServiceLocator; 020 021 import javax.persistence.*; 022 import java.io.IOException; 023 import java.io.InputStream; 024 import java.util.LinkedHashMap; 025 026 /** 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 */ 029 @Entity 030 @Table(name="KRNS_ATT_T") 031 public class Attachment extends PersistableBusinessObjectBase { 032 033 @Id 034 @Column(name="NTE_ID") 035 private Long noteIdentifier; 036 @Column(name="MIME_TYP") 037 private String attachmentMimeTypeCode; 038 @Column(name="FILE_NM") 039 private String attachmentFileName; 040 @Column(name="ATT_ID") 041 private String attachmentIdentifier; 042 @Column(name="FILE_SZ") 043 private Long attachmentFileSize; 044 @Column(name="ATT_TYP_CD") 045 private String attachmentTypeCode; 046 047 @OneToOne(fetch=FetchType.EAGER) 048 @JoinColumn(name="NTE_ID") 049 private Note note; 050 051 /** 052 * Default constructor. 053 */ 054 public Attachment() { 055 056 } 057 058 /** 059 * Gets the noteIdentifier attribute. 060 * 061 * @return Returns the noteIdentifier 062 * 063 */ 064 public Long getNoteIdentifier() { 065 return noteIdentifier; 066 } 067 068 /** 069 * Sets the noteIdentifier attribute. 070 * 071 * @param noteIdentifier The noteIdentifier to set. 072 * 073 */ 074 public void setNoteIdentifier(Long noteIdentifier) { 075 this.noteIdentifier = noteIdentifier; 076 } 077 078 079 /** 080 * Gets the attachmentMimeTypeCode attribute. 081 * 082 * @return Returns the attachmentMimeTypeCode 083 * 084 */ 085 public String getAttachmentMimeTypeCode() { 086 return attachmentMimeTypeCode; 087 } 088 089 /** 090 * Sets the attachmentMimeTypeCode attribute. 091 * 092 * @param attachmentMimeTypeCode The attachmentMimeTypeCode to set. 093 * 094 */ 095 public void setAttachmentMimeTypeCode(String attachmentMimeTypeCode) { 096 this.attachmentMimeTypeCode = attachmentMimeTypeCode; 097 } 098 099 /* 100 * This method determines the Image Icon to display based on the mime type associated with the given class. 101 * This method pulls from the service layer when called. 102 * 103 * @return Returns the Icon based on the Mime Type 104 */ 105 public String getAttachmentIconPathByMimeType() { 106 return KNSServiceLocator.getAttachmentService().convertMimeTypeToIconPath(getAttachmentMimeTypeCode()); 107 } 108 109 /** 110 * Gets the attachmentFileName attribute. 111 * 112 * @return Returns the attachmentFileName 113 * 114 */ 115 public String getAttachmentFileName() { 116 return attachmentFileName; 117 } 118 119 /** 120 * Sets the attachmentFileName attribute. 121 * 122 * @param attachmentFileName The attachmentFileName to set. 123 * 124 */ 125 public void setAttachmentFileName(String attachmentFileName) { 126 this.attachmentFileName = attachmentFileName; 127 } 128 129 130 /** 131 * Gets the attachmentIdentifier attribute. 132 * 133 * @return Returns the attachmentIdentifier 134 * 135 */ 136 public String getAttachmentIdentifier() { 137 return attachmentIdentifier; 138 } 139 140 /** 141 * Sets the attachmentIdentifier attribute. 142 * 143 * @param attachmentIdentifier The attachmentIdentifier to set. 144 * 145 */ 146 public void setAttachmentIdentifier(String attachmentIdentifier) { 147 this.attachmentIdentifier = attachmentIdentifier; 148 } 149 150 151 /** 152 * Gets the attachmentFileSize attribute. 153 * 154 * @return Returns the attachmentFileSize 155 * 156 */ 157 public Long getAttachmentFileSize() { 158 return attachmentFileSize; 159 } 160 161 /** 162 * Sets the attachmentFileSize attribute. 163 * 164 * @param attachmentFileSize The attachmentFileSize to set. 165 * 166 */ 167 public void setAttachmentFileSize(Long attachmentFileSize) { 168 this.attachmentFileSize = attachmentFileSize; 169 } 170 171 172 /** 173 * Gets the attachmentTypeCode attribute. 174 * 175 * @return Returns the attachmentTypeCode 176 * 177 */ 178 public String getAttachmentTypeCode() { 179 return attachmentTypeCode; 180 } 181 182 /** 183 * Sets the attachmentTypeCode attribute. 184 * 185 * @param attachmentTypeCode The attachmentTypeCode to set. 186 * 187 */ 188 public void setAttachmentTypeCode(String attachmentTypeCode) { 189 this.attachmentTypeCode = attachmentTypeCode; 190 } 191 192 /** 193 * Gets the note attribute. 194 * @return Returns the note. 195 */ 196 public Note getNote() { 197 return note; 198 } 199 200 /** 201 * Sets the note attribute value. 202 * @param note The note to set. 203 */ 204 public void setNote(Note note) { 205 this.note = note; 206 } 207 /** 208 * @return false if any of the required fields (attachmentId, fileName, fileSize, and mimeType) are blank 209 */ 210 public boolean isComplete() { 211 return (StringUtils.isNotBlank(attachmentIdentifier) && StringUtils.isNotBlank(attachmentFileName) && (attachmentFileSize != null) && StringUtils.isNotBlank(attachmentMimeTypeCode)); 212 } 213 214 /** 215 * (non-Javadoc) 216 * 217 * @see org.kuali.rice.kns.service.AttachmentService#retrieveAttachmentContents(org.kuali.rice.kns.bo.Attachment) 218 */ 219 public InputStream getAttachmentContents() throws IOException { 220 return KNSServiceLocator.getAttachmentService().retrieveAttachmentContents(this); 221 } 222 /** 223 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 224 */ 225 protected LinkedHashMap toStringMapper() { 226 LinkedHashMap m = new LinkedHashMap(); 227 m.put("noteIdentifier", this.noteIdentifier); 228 return m; 229 } 230 } 231