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