root / src / org / gss_project / gss / server / domain / FileBody.java @ 1206:292dec4eae08
History | View | Annotate | Download (5.4 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package org.gss_project.gss.server.domain; |
20 |
|
21 |
import org.gss_project.gss.common.dto.FileBodyDTO; |
22 |
|
23 |
import java.io.Serializable; |
24 |
import java.io.UnsupportedEncodingException; |
25 |
import java.net.URLEncoder; |
26 |
|
27 |
import javax.persistence.Embedded; |
28 |
import javax.persistence.Entity; |
29 |
import javax.persistence.GeneratedValue; |
30 |
import javax.persistence.Id; |
31 |
import javax.persistence.ManyToOne; |
32 |
import javax.persistence.Version; |
33 |
|
34 |
import org.apache.commons.logging.Log; |
35 |
import org.apache.commons.logging.LogFactory; |
36 |
import org.hibernate.annotations.Cache; |
37 |
import org.hibernate.annotations.CacheConcurrencyStrategy; |
38 |
|
39 |
/**
|
40 |
* The mutable part of the structure of a file on the GSS service.
|
41 |
*/
|
42 |
@Entity
|
43 |
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
|
44 |
public final class FileBody implements Serializable{ |
45 |
/**
|
46 |
* The logger.
|
47 |
*/
|
48 |
private static Log logger = LogFactory.getLog(FileBody.class); |
49 |
|
50 |
/**
|
51 |
* The persistence ID of the object.
|
52 |
*/
|
53 |
@Id
|
54 |
@GeneratedValue
|
55 |
private Long id; |
56 |
|
57 |
/**
|
58 |
* Version field for optimistic locking. Renamed to avoid conflict with file
|
59 |
* body version.
|
60 |
*/
|
61 |
@SuppressWarnings("unused") |
62 |
@Version
|
63 |
private int dbVersion; |
64 |
|
65 |
/**
|
66 |
* The audit information.
|
67 |
*/
|
68 |
@Embedded
|
69 |
private AuditInfo auditInfo;
|
70 |
|
71 |
/**
|
72 |
* The version of the file, not the JPA version field!
|
73 |
*/
|
74 |
private int version; |
75 |
|
76 |
/**
|
77 |
* The header of the file.
|
78 |
*/
|
79 |
@ManyToOne
|
80 |
private FileHeader header;
|
81 |
|
82 |
/**
|
83 |
* The MIME type of this file.
|
84 |
*/
|
85 |
private String mimeType; |
86 |
|
87 |
/**
|
88 |
* The original filename (with which file was uploaded)
|
89 |
*/
|
90 |
private String originalFilename; |
91 |
|
92 |
/**
|
93 |
* The full file path (path+filename) under which file is currently stored
|
94 |
* in local file system
|
95 |
*/
|
96 |
private String storedFilePath; |
97 |
|
98 |
/**
|
99 |
* The file size in bytes
|
100 |
*/
|
101 |
private long fileSize; |
102 |
|
103 |
|
104 |
public Long getId() { |
105 |
return id;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Returns the version
|
110 |
*
|
111 |
* @return int
|
112 |
*/
|
113 |
public int getVersion() { |
114 |
return version;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Sets a new version
|
119 |
*
|
120 |
* @param newVersion
|
121 |
*/
|
122 |
public void setVersion(final int newVersion) { |
123 |
version = newVersion; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Retrieve the file header.
|
128 |
*
|
129 |
* @return the file header
|
130 |
*/
|
131 |
public FileHeader getHeader() {
|
132 |
return header;
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Modify the file header.
|
137 |
*
|
138 |
* @param newHeader the new header
|
139 |
*/
|
140 |
public void setHeader(final FileHeader newHeader) { |
141 |
header = newHeader; |
142 |
} |
143 |
|
144 |
|
145 |
public AuditInfo getAuditInfo() {
|
146 |
return auditInfo;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Retrieve the MIME type.
|
151 |
*
|
152 |
* @return the MIME type
|
153 |
*/
|
154 |
public String getMimeType() { |
155 |
return mimeType;
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* Modify the MIME type.
|
160 |
*
|
161 |
* @param newMimeType the new MIME type
|
162 |
*/
|
163 |
public void setMimeType(final String newMimeType) { |
164 |
mimeType = newMimeType; |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Retrieve the original filename.
|
169 |
*
|
170 |
* @return the original filename
|
171 |
*/
|
172 |
public String getOriginalFilename() { |
173 |
return originalFilename;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Modify the original filename.
|
178 |
*
|
179 |
* @param newOriginalFilename the new original filename
|
180 |
*/
|
181 |
public void setOriginalFilename(final String newOriginalFilename) { |
182 |
originalFilename = newOriginalFilename; |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Retrieve the stored file path.
|
187 |
*
|
188 |
* @return the file path
|
189 |
*/
|
190 |
public String getStoredFilePath() { |
191 |
return storedFilePath;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* Modify the stored file path.
|
196 |
*
|
197 |
* @param newStoredFilePath the new file path
|
198 |
*/
|
199 |
public void setStoredFilePath(final String newStoredFilePath) { |
200 |
storedFilePath = newStoredFilePath; |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Retrieve the file size.
|
205 |
*
|
206 |
* @return the file size
|
207 |
*/
|
208 |
public long getFileSize() { |
209 |
return fileSize;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* Modify the file size.
|
214 |
*
|
215 |
* @param newFileSize the new file size
|
216 |
*/
|
217 |
public void setFileSize(final long newFileSize) { |
218 |
fileSize = newFileSize; |
219 |
} |
220 |
|
221 |
/**
|
222 |
* Modify the audit info.
|
223 |
*
|
224 |
* @param newAuditInfo the new audit info
|
225 |
*/
|
226 |
public void setAuditInfo(final AuditInfo newAuditInfo) { |
227 |
auditInfo = newAuditInfo; |
228 |
} |
229 |
|
230 |
/**
|
231 |
* Return the original filename URL-encoded.
|
232 |
*
|
233 |
* @return the original filename URL-encoded.
|
234 |
*/
|
235 |
public String getOriginalFilenameEncoded() { |
236 |
try {
|
237 |
return URLEncoder.encode(getOriginalFilename(), "UTF-8"); |
238 |
} catch (UnsupportedEncodingException e) { |
239 |
logger.error("", e);
|
240 |
return getOriginalFilename();
|
241 |
} |
242 |
} |
243 |
|
244 |
public FileBodyDTO getDTO(){
|
245 |
FileBodyDTO dto = new FileBodyDTO();
|
246 |
dto.setId(id); |
247 |
dto.setVersion(version); |
248 |
dto.setFileHeaderId(getHeader().getId()); |
249 |
dto.setFileSize(fileSize); |
250 |
dto.setMimeType(mimeType); |
251 |
dto.setOriginalFilename(originalFilename); |
252 |
dto.setOriginalFilenameEncoded(getOriginalFilenameEncoded()); |
253 |
dto.setAuditInfo(auditInfo.getDTO()); |
254 |
return dto;
|
255 |
|
256 |
} |
257 |
} |