2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
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.
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.
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/>.
19 package gr.ebs.gss.server.domain.dto;
21 import java.io.Serializable;
22 import java.util.List;
24 import com.google.gwt.i18n.client.NumberFormat;
29 public class FileHeaderDTO implements Serializable {
32 * The preamble of every REST API URI.
34 public static final String PATH_GSS = "http://gss.grnet.gr/gss/rest/";
37 * The path for the resource manipulation subsystem.
39 public static final String PATH_FILES = "/files";
42 * The serial version UID.
44 private static final long serialVersionUID = 1L;
47 * The persistence ID of the object.
62 * Is this a versioned file?
64 private boolean versioned;
69 private int version = 0;
72 * The owner of this file.
74 private UserDTO owner;
77 * The folder that contains this file.
79 private FolderDTO folder;
82 * The size of the file
84 private long fileSize;
87 * The MIME type of this file.
89 private String mimeType;
92 * The original filename (with which file was uploaded).
94 private String originalFilename;
97 * The original filename URL-encoded.
99 private String originalFilenameEncoded;
102 * The audit information for this object.
104 private AuditInfoDTO auditInfo;
107 * A list of tags (Strings).
111 private List<String> tags;
113 * is this file deleted?
115 private boolean deleted=false;
117 * Anyone can read this file?
119 private boolean readForAll=false;
123 public Long getId() {
128 * @param newId the id to set
130 public void setId(final Long newId) {
137 public String getName() {
142 * @param newName the name to set
144 public void setName(final String newName) {
149 * @return the versioned
151 public boolean isVersioned() {
156 * @param newVersioned the versioned to set
158 public void setVersioned(final boolean newVersioned) {
159 versioned = newVersioned;
165 public UserDTO getOwner() {
170 * @param newOwner the owner to set
172 public void setOwner(final UserDTO newOwner) {
177 * @return the version
179 public int getVersion() {
184 * @param newVersion the version to set
186 public void setVersion(final int newVersion) {
187 version = newVersion;
191 * @return the fileSize
193 public long getFileSize() {
198 * @param newFileSize the fileSize to set
200 public void setFileSize(final long newFileSize) {
201 fileSize = newFileSize;
205 * Return the file size in a humanly readable form, using SI units to denote
206 * size information, e.g. 1 KB = 1000 B (bytes).
208 * @return the fileSize
210 public String getFileSizeAsString() {
212 return String.valueOf(fileSize) + " B";
213 else if (fileSize <= 1024*1024)
214 return getSize(fileSize, 1024D) + " KB";
215 else if (fileSize <= 1024*1024*1024)
216 return getSize(fileSize,(1024D*1024D)) + " MB";
217 return getSize(fileSize , (1024D*1024D*1024D)) + " GB";
220 private String getSize(Long size, Double division){
221 Double res = Double.valueOf(size.toString())/division;
222 NumberFormat nf = NumberFormat.getFormat("######.###");
223 return nf.format(res);
227 * Retrieve the auditInfo.
229 * @return the auditInfo
231 public AuditInfoDTO getAuditInfo() {
236 * Modify the auditInfo.
238 * @param newAuditInfo the auditInfo to set
240 public void setAuditInfo(final AuditInfoDTO newAuditInfo) {
241 auditInfo = newAuditInfo;
250 public List<String> getTags() {
258 * @param newTags the tags to set
260 public void setTags(List<String> newTags) {
266 * Retrieve the mimeType.
268 * @return the mimeType
270 public String getMimeType() {
276 * Modify the mimeType.
278 * @param newMimeType the mimeType to set
280 public void setMimeType(String newMimeType) {
281 mimeType = newMimeType;
286 * Retrieve the originalFilename.
288 * @return the originalFilename
290 public String getOriginalFilename() {
291 return originalFilename;
296 * Modify the originalFilename.
298 * @param newOriginalFilename the originalFilename to set
300 public void setOriginalFilename(String newOriginalFilename) {
301 originalFilename = newOriginalFilename;
306 * Retrieve the originalFilenameEncoded.
308 * @return the originalFilenameEncoded
310 public String getOriginalFilenameEncoded() {
311 return originalFilenameEncoded;
316 * Modify the originalFilenameEncoded.
318 * @param newOriginalFilenameEncoded the originalFilenameEncoded to set
320 public void setOriginalFilenameEncoded(String newOriginalFilenameEncoded) {
321 originalFilenameEncoded = newOriginalFilenameEncoded;
326 * Retrieve the deleted.
328 * @return the deleted
330 public boolean isDeleted() {
336 * Modify the deleted.
338 * @param newDeleted the deleted to set
340 public void setDeleted(boolean newDeleted) {
341 deleted = newDeleted;
346 * Retrieve the readForAll.
348 * @return the readForAll
350 public boolean isReadForAll() {
356 * Modify the readForAll.
358 * @param aReadForAll the readForAll to set
360 public void setReadForAll(boolean aReadForAll) {
361 readForAll = aReadForAll;
369 public String getPath() {
376 * @param aPath the path to set
378 public void setPath(String aPath) {
384 * Retrieve the URI for this resource. This unique identifier can
385 * be used to refer to the resource from various GSS clients.
389 public String getURI() {
390 return PATH_GSS + owner.getUsername() + PATH_FILES + getPath();
395 * Retrieve the folder.
399 public FolderDTO getFolder() {
407 * @param aFolder the folder to set
409 public void setFolder(FolderDTO aFolder) {