| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Attachment |
|
| 1.2777777777777777;1.278 |
| 1 | /* | |
| 2 | * Copyright 2007 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.kns.bo; | |
| 17 | ||
| 18 | import java.io.IOException; | |
| 19 | import java.io.InputStream; | |
| 20 | ||
| 21 | import javax.persistence.Column; | |
| 22 | import javax.persistence.Entity; | |
| 23 | import javax.persistence.FetchType; | |
| 24 | import javax.persistence.Id; | |
| 25 | import javax.persistence.JoinColumn; | |
| 26 | import javax.persistence.OneToOne; | |
| 27 | import javax.persistence.Table; | |
| 28 | ||
| 29 | import org.apache.commons.lang.StringUtils; | |
| 30 | import org.kuali.rice.core.util.RiceUtilities; | |
| 31 | import org.kuali.rice.kns.service.KNSServiceLocator; | |
| 32 | ||
| 33 | /** | |
| 34 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 35 | */ | |
| 36 | @Entity | |
| 37 | @Table(name="KRNS_ATT_T") | |
| 38 | public class Attachment extends PersistableBusinessObjectBase { | |
| 39 | private static final long serialVersionUID = 402432724949441326L; | |
| 40 | ||
| 41 | @Id | |
| 42 | @Column(name="NTE_ID") | |
| 43 | private Long noteIdentifier; | |
| 44 | @Column(name="MIME_TYP") | |
| 45 | private String attachmentMimeTypeCode; | |
| 46 | @Column(name="FILE_NM") | |
| 47 | private String attachmentFileName; | |
| 48 | @Column(name="ATT_ID") | |
| 49 | private String attachmentIdentifier; | |
| 50 | @Column(name="FILE_SZ") | |
| 51 | private Long attachmentFileSize; | |
| 52 | @Column(name="ATT_TYP_CD") | |
| 53 | private String attachmentTypeCode; | |
| 54 | ||
| 55 | @OneToOne(fetch=FetchType.EAGER) | |
| 56 | @JoinColumn(name="NTE_ID") | |
| 57 | private Note note; | |
| 58 | ||
| 59 | /** | |
| 60 | * Default constructor. | |
| 61 | */ | |
| 62 | 0 | public Attachment() { |
| 63 | ||
| 64 | 0 | } |
| 65 | ||
| 66 | /** | |
| 67 | * Gets the noteIdentifier attribute. | |
| 68 | * | |
| 69 | * @return Returns the noteIdentifier | |
| 70 | * | |
| 71 | */ | |
| 72 | public Long getNoteIdentifier() { | |
| 73 | 0 | return noteIdentifier; |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Sets the noteIdentifier attribute. | |
| 78 | * | |
| 79 | * @param noteIdentifier The noteIdentifier to set. | |
| 80 | * | |
| 81 | */ | |
| 82 | public void setNoteIdentifier(Long noteIdentifier) { | |
| 83 | 0 | this.noteIdentifier = noteIdentifier; |
| 84 | 0 | } |
| 85 | ||
| 86 | ||
| 87 | /** | |
| 88 | * Gets the attachmentMimeTypeCode attribute. | |
| 89 | * | |
| 90 | * @return Returns the attachmentMimeTypeCode | |
| 91 | * | |
| 92 | */ | |
| 93 | public String getAttachmentMimeTypeCode() { | |
| 94 | 0 | return attachmentMimeTypeCode; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Sets the attachmentMimeTypeCode attribute. | |
| 99 | * | |
| 100 | * @param attachmentMimeTypeCode The attachmentMimeTypeCode to set. | |
| 101 | * | |
| 102 | */ | |
| 103 | public void setAttachmentMimeTypeCode(String attachmentMimeTypeCode) { | |
| 104 | 0 | this.attachmentMimeTypeCode = attachmentMimeTypeCode; |
| 105 | 0 | } |
| 106 | ||
| 107 | ||
| 108 | /** | |
| 109 | * Gets the attachmentFileName attribute. | |
| 110 | * | |
| 111 | * @return Returns the attachmentFileName | |
| 112 | * | |
| 113 | */ | |
| 114 | public String getAttachmentFileName() { | |
| 115 | 0 | return attachmentFileName; |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * Sets the attachmentFileName attribute. | |
| 120 | * | |
| 121 | * @param attachmentFileName The attachmentFileName to set. | |
| 122 | * | |
| 123 | */ | |
| 124 | public void setAttachmentFileName(String attachmentFileName) { | |
| 125 | 0 | this.attachmentFileName = attachmentFileName; |
| 126 | 0 | } |
| 127 | ||
| 128 | ||
| 129 | /** | |
| 130 | * Gets the attachmentIdentifier attribute. | |
| 131 | * | |
| 132 | * @return Returns the attachmentIdentifier | |
| 133 | * | |
| 134 | */ | |
| 135 | public String getAttachmentIdentifier() { | |
| 136 | 0 | return attachmentIdentifier; |
| 137 | } | |
| 138 | ||
| 139 | /** | |
| 140 | * Sets the attachmentIdentifier attribute. | |
| 141 | * | |
| 142 | * @param attachmentIdentifier The attachmentIdentifier to set. | |
| 143 | * | |
| 144 | */ | |
| 145 | public void setAttachmentIdentifier(String attachmentIdentifier) { | |
| 146 | 0 | this.attachmentIdentifier = attachmentIdentifier; |
| 147 | 0 | } |
| 148 | ||
| 149 | ||
| 150 | /** | |
| 151 | * Gets the attachmentFileSize attribute. | |
| 152 | * | |
| 153 | * @return Returns the attachmentFileSize | |
| 154 | * | |
| 155 | */ | |
| 156 | public Long getAttachmentFileSize() { | |
| 157 | 0 | return attachmentFileSize; |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * Sets the attachmentFileSize attribute. | |
| 162 | * | |
| 163 | * @param attachmentFileSize The attachmentFileSize to set. | |
| 164 | * | |
| 165 | */ | |
| 166 | public void setAttachmentFileSize(Long attachmentFileSize) { | |
| 167 | 0 | this.attachmentFileSize = attachmentFileSize; |
| 168 | 0 | } |
| 169 | ||
| 170 | /** | |
| 171 | * Returns the size of the attachment with units (byte, kilobyte, ...) | |
| 172 | * | |
| 173 | * @return String attachment file size | |
| 174 | */ | |
| 175 | public String getAttachmentFileSizeWithUnits() { | |
| 176 | 0 | if (attachmentFileSize != null) { |
| 177 | 0 | return RiceUtilities.getFileSizeUnits(attachmentFileSize); |
| 178 | } | |
| 179 | ||
| 180 | 0 | return ""; |
| 181 | } | |
| 182 | ||
| 183 | /** | |
| 184 | * Gets the attachmentTypeCode attribute. | |
| 185 | * | |
| 186 | * @return Returns the attachmentTypeCode | |
| 187 | * | |
| 188 | */ | |
| 189 | public String getAttachmentTypeCode() { | |
| 190 | 0 | return attachmentTypeCode; |
| 191 | } | |
| 192 | ||
| 193 | /** | |
| 194 | * Sets the attachmentTypeCode attribute. | |
| 195 | * | |
| 196 | * @param attachmentTypeCode The attachmentTypeCode to set. | |
| 197 | * | |
| 198 | */ | |
| 199 | public void setAttachmentTypeCode(String attachmentTypeCode) { | |
| 200 | 0 | this.attachmentTypeCode = attachmentTypeCode; |
| 201 | 0 | } |
| 202 | ||
| 203 | /** | |
| 204 | * Gets the note attribute. | |
| 205 | * @return Returns the note. | |
| 206 | */ | |
| 207 | public Note getNote() { | |
| 208 | 0 | return note; |
| 209 | } | |
| 210 | ||
| 211 | /** | |
| 212 | * Sets the note attribute value. | |
| 213 | * @param note The note to set. | |
| 214 | */ | |
| 215 | public void setNote(Note note) { | |
| 216 | 0 | this.note = note; |
| 217 | 0 | } |
| 218 | /** | |
| 219 | * @return false if any of the required fields (attachmentId, fileName, fileSize, and mimeType) are blank | |
| 220 | */ | |
| 221 | public boolean isComplete() { | |
| 222 | 0 | return (StringUtils.isNotBlank(attachmentIdentifier) && StringUtils.isNotBlank(attachmentFileName) && (attachmentFileSize != null) && StringUtils.isNotBlank(attachmentMimeTypeCode)); |
| 223 | } | |
| 224 | ||
| 225 | /** | |
| 226 | * | |
| 227 | * | |
| 228 | */ | |
| 229 | public InputStream getAttachmentContents() throws IOException { | |
| 230 | 0 | return KNSServiceLocator.getAttachmentService().retrieveAttachmentContents(this); |
| 231 | } | |
| 232 | } | |
| 233 |