2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\r
6 * GSS is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * GSS is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
\r
19 package gr.ebs.gss.server.domain;
\r
21 import gr.ebs.gss.server.domain.dto.FileBodyDTO;
\r
23 import java.io.Serializable;
\r
24 import java.io.UnsupportedEncodingException;
\r
25 import java.net.URLEncoder;
\r
27 import javax.persistence.Embedded;
\r
28 import javax.persistence.Entity;
\r
29 import javax.persistence.GeneratedValue;
\r
30 import javax.persistence.Id;
\r
31 import javax.persistence.ManyToOne;
\r
32 import javax.persistence.Version;
\r
34 import org.apache.commons.logging.Log;
\r
35 import org.apache.commons.logging.LogFactory;
\r
36 import org.hibernate.annotations.Cache;
\r
37 import org.hibernate.annotations.CacheConcurrencyStrategy;
\r
40 * The mutable part of the structure of a file on the GSS service.
\r
43 @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
\r
44 public final class FileBody implements Serializable{
\r
48 private static Log logger = LogFactory.getLog(FileBody.class);
\r
51 * The persistence ID of the object.
\r
58 * Version field for optimistic locking. Renamed to avoid conflict with file
\r
61 @SuppressWarnings("unused")
\r
63 private int dbVersion;
\r
66 * The audit information.
\r
69 private AuditInfo auditInfo;
\r
72 * The version of the file, not the JPA version field!
\r
74 private int version;
\r
77 * The header of the file.
\r
80 private FileHeader header;
\r
83 * The MIME type of this file.
\r
85 private String mimeType;
\r
88 * The original filename (with which file was uploaded)
\r
90 private String originalFilename;
\r
93 * The full file path (path+filename) under which file is currently stored
\r
94 * in local file system
\r
96 private String storedFilePath;
\r
99 * The file size in bytes
\r
101 private long fileSize;
\r
104 public Long getId() {
\r
109 * Returns the version
\r
113 public int getVersion() {
\r
118 * Sets a new version
\r
120 * @param newVersion
\r
122 public void setVersion(final int newVersion) {
\r
123 version = newVersion;
\r
127 * Retrieve the file header.
\r
129 * @return the file header
\r
131 public FileHeader getHeader() {
\r
136 * Modify the file header.
\r
138 * @param newHeader the new header
\r
140 public void setHeader(final FileHeader newHeader) {
\r
141 header = newHeader;
\r
145 public AuditInfo getAuditInfo() {
\r
150 * Retrieve the MIME type.
\r
152 * @return the MIME type
\r
154 public String getMimeType() {
\r
159 * Modify the MIME type.
\r
161 * @param newMimeType the new MIME type
\r
163 public void setMimeType(final String newMimeType) {
\r
164 mimeType = newMimeType;
\r
168 * Retrieve the original filename.
\r
170 * @return the original filename
\r
172 public String getOriginalFilename() {
\r
173 return originalFilename;
\r
177 * Modify the original filename.
\r
179 * @param newOriginalFilename the new original filename
\r
181 public void setOriginalFilename(final String newOriginalFilename) {
\r
182 originalFilename = newOriginalFilename;
\r
186 * Retrieve the stored file path.
\r
188 * @return the file path
\r
190 public String getStoredFilePath() {
\r
191 return storedFilePath;
\r
195 * Modify the stored file path.
\r
197 * @param newStoredFilePath the new file path
\r
199 public void setStoredFilePath(final String newStoredFilePath) {
\r
200 storedFilePath = newStoredFilePath;
\r
204 * Retrieve the file size.
\r
206 * @return the file size
\r
208 public long getFileSize() {
\r
213 * Modify the file size.
\r
215 * @param newFileSize the new file size
\r
217 public void setFileSize(final long newFileSize) {
\r
218 fileSize = newFileSize;
\r
222 * Modify the audit info.
\r
224 * @param newAuditInfo the new audit info
\r
226 public void setAuditInfo(final AuditInfo newAuditInfo) {
\r
227 auditInfo = newAuditInfo;
\r
231 * Return the original filename URL-encoded.
\r
233 * @return the original filename URL-encoded.
\r
235 public String getOriginalFilenameEncoded() {
\r
237 return URLEncoder.encode(getOriginalFilename(), "UTF-8");
\r
238 } catch (UnsupportedEncodingException e) {
\r
239 logger.error("", e);
\r
240 return getOriginalFilename();
\r
244 public FileBodyDTO getDTO(){
\r
245 FileBodyDTO dto = new FileBodyDTO();
\r
247 dto.setVersion(version);
\r
248 dto.setFileHeaderId(getHeader().getId());
\r
249 dto.setFileSize(fileSize);
\r
250 dto.setMimeType(mimeType);
\r
251 dto.setOriginalFilename(originalFilename);
\r
252 dto.setOriginalFilenameEncoded(getOriginalFilenameEncoded());
\r
253 dto.setAuditInfo(auditInfo.getDTO());
\r