Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Attachment |
|
| 1.1666666666666667;1.167 |
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 javax.persistence.JoinColumn; | |
19 | import javax.persistence.FetchType; | |
20 | import javax.persistence.OneToOne; | |
21 | import javax.persistence.Version; | |
22 | import javax.persistence.Column; | |
23 | import javax.persistence.Id; | |
24 | import javax.persistence.CascadeType; | |
25 | import javax.persistence.Table; | |
26 | import javax.persistence.Entity; | |
27 | ||
28 | import java.io.IOException; | |
29 | import java.io.InputStream; | |
30 | import java.util.LinkedHashMap; | |
31 | ||
32 | import org.apache.commons.lang.StringUtils; | |
33 | import org.kuali.rice.kns.service.KNSServiceLocator; | |
34 | ||
35 | /** | |
36 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
37 | */ | |
38 | @Entity | |
39 | @Table(name="KRNS_ATT_T") | |
40 | public class Attachment extends PersistableBusinessObjectBase { | |
41 | ||
42 | @Id | |
43 | @Column(name="NTE_ID") | |
44 | private Long noteIdentifier; | |
45 | @Column(name="MIME_TYP") | |
46 | private String attachmentMimeTypeCode; | |
47 | @Column(name="FILE_NM") | |
48 | private String attachmentFileName; | |
49 | @Column(name="ATT_ID") | |
50 | private String attachmentIdentifier; | |
51 | @Column(name="FILE_SZ") | |
52 | private Long attachmentFileSize; | |
53 | @Column(name="ATT_TYP_CD") | |
54 | private String attachmentTypeCode; | |
55 | ||
56 | @OneToOne(fetch=FetchType.EAGER) | |
57 | @JoinColumn(name="NTE_ID") | |
58 | private Note note; | |
59 | ||
60 | /** | |
61 | * Default constructor. | |
62 | */ | |
63 | 0 | public Attachment() { |
64 | ||
65 | 0 | } |
66 | ||
67 | /** | |
68 | * Gets the noteIdentifier attribute. | |
69 | * | |
70 | * @return Returns the noteIdentifier | |
71 | * | |
72 | */ | |
73 | public Long getNoteIdentifier() { | |
74 | 0 | return noteIdentifier; |
75 | } | |
76 | ||
77 | /** | |
78 | * Sets the noteIdentifier attribute. | |
79 | * | |
80 | * @param noteIdentifier The noteIdentifier to set. | |
81 | * | |
82 | */ | |
83 | public void setNoteIdentifier(Long noteIdentifier) { | |
84 | 0 | this.noteIdentifier = noteIdentifier; |
85 | 0 | } |
86 | ||
87 | ||
88 | /** | |
89 | * Gets the attachmentMimeTypeCode attribute. | |
90 | * | |
91 | * @return Returns the attachmentMimeTypeCode | |
92 | * | |
93 | */ | |
94 | public String getAttachmentMimeTypeCode() { | |
95 | 0 | return attachmentMimeTypeCode; |
96 | } | |
97 | ||
98 | /** | |
99 | * Sets the attachmentMimeTypeCode attribute. | |
100 | * | |
101 | * @param attachmentMimeTypeCode The attachmentMimeTypeCode to set. | |
102 | * | |
103 | */ | |
104 | public void setAttachmentMimeTypeCode(String attachmentMimeTypeCode) { | |
105 | 0 | this.attachmentMimeTypeCode = attachmentMimeTypeCode; |
106 | 0 | } |
107 | ||
108 | ||
109 | /** | |
110 | * Gets the attachmentFileName attribute. | |
111 | * | |
112 | * @return Returns the attachmentFileName | |
113 | * | |
114 | */ | |
115 | public String getAttachmentFileName() { | |
116 | 0 | 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 | 0 | this.attachmentFileName = attachmentFileName; |
127 | 0 | } |
128 | ||
129 | ||
130 | /** | |
131 | * Gets the attachmentIdentifier attribute. | |
132 | * | |
133 | * @return Returns the attachmentIdentifier | |
134 | * | |
135 | */ | |
136 | public String getAttachmentIdentifier() { | |
137 | 0 | 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 | 0 | this.attachmentIdentifier = attachmentIdentifier; |
148 | 0 | } |
149 | ||
150 | ||
151 | /** | |
152 | * Gets the attachmentFileSize attribute. | |
153 | * | |
154 | * @return Returns the attachmentFileSize | |
155 | * | |
156 | */ | |
157 | public Long getAttachmentFileSize() { | |
158 | 0 | 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 | 0 | this.attachmentFileSize = attachmentFileSize; |
169 | 0 | } |
170 | ||
171 | ||
172 | /** | |
173 | * Gets the attachmentTypeCode attribute. | |
174 | * | |
175 | * @return Returns the attachmentTypeCode | |
176 | * | |
177 | */ | |
178 | public String getAttachmentTypeCode() { | |
179 | 0 | 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 | 0 | this.attachmentTypeCode = attachmentTypeCode; |
190 | 0 | } |
191 | ||
192 | /** | |
193 | * Gets the note attribute. | |
194 | * @return Returns the note. | |
195 | */ | |
196 | public Note getNote() { | |
197 | 0 | 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 | 0 | this.note = note; |
206 | 0 | } |
207 | /** | |
208 | * @return false if any of the required fields (attachmentId, fileName, fileSize, and mimeType) are blank | |
209 | */ | |
210 | public boolean isComplete() { | |
211 | 0 | 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.DocumentAttachmentService#retrieveAttachmentContents(org.kuali.rice.kns.document.DocumentAttachment) | |
218 | */ | |
219 | public InputStream getAttachmentContents() throws IOException { | |
220 | 0 | return KNSServiceLocator.getAttachmentService().retrieveAttachmentContents(this); |
221 | } | |
222 | /** | |
223 | * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() | |
224 | */ | |
225 | protected LinkedHashMap toStringMapper() { | |
226 | 0 | LinkedHashMap m = new LinkedHashMap(); |
227 | 0 | m.put("noteIdentifier", this.noteIdentifier); |
228 | 0 | return m; |
229 | } | |
230 | } | |
231 |