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 java.io.IOException;
19 import java.io.InputStream;
20
21 import javax.persistence.CascadeType;
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 javax.persistence.UniqueConstraint;
30
31 import org.apache.commons.lang.StringUtils;
32 import org.kuali.rice.core.api.util.RiceUtilities;
33 import org.kuali.rice.krad.service.KRADServiceLocator;
34
35
36
37
38 @Entity
39 @Table(name = "KRNS_ATT_T", uniqueConstraints = {@UniqueConstraint(name = "KRNS_ATT_TC0", columnNames = "OBJ_ID")})
40 public class Attachment extends PersistableBusinessObjectBaseAdapter {
41 private static final long serialVersionUID = 402432724949441326L;
42
43 @Id @Column(name = "NTE_ID", length = 14, precision = 0, updatable = false)
44 private Long noteIdentifier;
45 @Column(name = "MIME_TYP", length = 255)
46 private String attachmentMimeTypeCode;
47 @Column(name = "FILE_NM", length = 250)
48 private String attachmentFileName;
49 @Column(name = "ATT_ID", length = 36)
50 private String attachmentIdentifier;
51 @Column(name = "FILE_SZ", length = 14, precision = 0)
52 private Long attachmentFileSize;
53 @Column(name = "ATT_TYP_CD", length = 40)
54 private String attachmentTypeCode;
55
56 @OneToOne(fetch = FetchType.EAGER, cascade = {CascadeType.REFRESH, CascadeType.DETACH}) @JoinColumn(name = "NTE_ID",
57 updatable = false, insertable = false)
58 private Note note;
59
60
61
62
63 public Attachment() {
64
65 }
66
67
68
69
70
71
72 public Long getNoteIdentifier() {
73 return noteIdentifier;
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 public String getAttachmentMimeTypeCode() {
91 return attachmentMimeTypeCode;
92 }
93
94
95
96
97
98
99 public void setAttachmentMimeTypeCode(String attachmentMimeTypeCode) {
100 this.attachmentMimeTypeCode = attachmentMimeTypeCode;
101 }
102
103
104
105
106
107
108 public String getAttachmentFileName() {
109 return attachmentFileName;
110 }
111
112
113
114
115
116
117 public void setAttachmentFileName(String attachmentFileName) {
118 this.attachmentFileName = attachmentFileName;
119 }
120
121
122
123
124
125
126 public String getAttachmentIdentifier() {
127 return attachmentIdentifier;
128 }
129
130
131
132
133
134
135 public void setAttachmentIdentifier(String attachmentIdentifier) {
136 this.attachmentIdentifier = attachmentIdentifier;
137 }
138
139
140
141
142
143
144 public Long getAttachmentFileSize() {
145 return attachmentFileSize;
146 }
147
148
149
150
151
152
153 public void setAttachmentFileSize(Long attachmentFileSize) {
154 this.attachmentFileSize = attachmentFileSize;
155 }
156
157
158
159
160
161
162 public String getAttachmentFileSizeWithUnits() {
163 if (attachmentFileSize != null) {
164 return RiceUtilities.getFileSizeUnits(attachmentFileSize);
165 }
166
167 return "";
168 }
169
170
171
172
173
174
175 public String getAttachmentTypeCode() {
176 return attachmentTypeCode;
177 }
178
179
180
181
182
183
184 public void setAttachmentTypeCode(String attachmentTypeCode) {
185 this.attachmentTypeCode = attachmentTypeCode;
186 }
187
188
189
190
191
192
193 public Note getNote() {
194 return note;
195 }
196
197
198
199
200
201
202 public void setNote(Note note) {
203 this.note = note;
204 }
205
206
207
208
209 public boolean isComplete() {
210 return (StringUtils.isNotBlank(attachmentIdentifier) && StringUtils.isNotBlank(attachmentFileName) && (
211 attachmentFileSize
212 != null) && StringUtils.isNotBlank(attachmentMimeTypeCode));
213 }
214
215 public InputStream getAttachmentContents() throws IOException {
216 return KRADServiceLocator.getAttachmentService().retrieveAttachmentContents(this);
217 }
218 }
219