1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
60
61 public Attachment() {
62
63 }
64
65
66
67
68
69
70
71 public Long getNoteIdentifier() {
72 return noteIdentifier;
73 }
74
75
76
77
78
79
80
81 public void setNoteIdentifier(Long noteIdentifier) {
82 this.noteIdentifier = noteIdentifier;
83 }
84
85
86
87
88
89
90
91
92 public String getAttachmentMimeTypeCode() {
93 return attachmentMimeTypeCode;
94 }
95
96
97
98
99
100
101
102 public void setAttachmentMimeTypeCode(String attachmentMimeTypeCode) {
103 this.attachmentMimeTypeCode = attachmentMimeTypeCode;
104 }
105
106
107
108
109
110
111
112
113 public String getAttachmentFileName() {
114 return attachmentFileName;
115 }
116
117
118
119
120
121
122
123 public void setAttachmentFileName(String attachmentFileName) {
124 this.attachmentFileName = attachmentFileName;
125 }
126
127
128
129
130
131
132
133
134 public String getAttachmentIdentifier() {
135 return attachmentIdentifier;
136 }
137
138
139
140
141
142
143
144 public void setAttachmentIdentifier(String attachmentIdentifier) {
145 this.attachmentIdentifier = attachmentIdentifier;
146 }
147
148
149
150
151
152
153
154
155 public Long getAttachmentFileSize() {
156 return attachmentFileSize;
157 }
158
159
160
161
162
163
164
165 public void setAttachmentFileSize(Long attachmentFileSize) {
166 this.attachmentFileSize = attachmentFileSize;
167 }
168
169
170
171
172
173
174 public String getAttachmentFileSizeWithUnits() {
175 if (attachmentFileSize != null) {
176 return RiceUtilities.getFileSizeUnits(attachmentFileSize);
177 }
178
179 return "";
180 }
181
182
183
184
185
186
187
188 public String getAttachmentTypeCode() {
189 return attachmentTypeCode;
190 }
191
192
193
194
195
196
197
198 public void setAttachmentTypeCode(String attachmentTypeCode) {
199 this.attachmentTypeCode = attachmentTypeCode;
200 }
201
202
203
204
205
206 public Note getNote() {
207 return note;
208 }
209
210
211
212
213
214 public void setNote(Note note) {
215 this.note = note;
216 }
217
218
219
220 public boolean isComplete() {
221 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 return KRADServiceLocator.getAttachmentService().retrieveAttachmentContents(this);
230 }
231 }
232