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