Move the DTOs outside the client package, now that they're no more used there, so...
[pithos] / gss / src / gr / ebs / gss / server / domain / dto / FileHeaderDTO.java
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 gr.ebs.gss.server.domain.dto;
20
21 import java.io.Serializable;
22 import java.util.List;
23
24 import com.google.gwt.i18n.client.NumberFormat;
25
26 /**
27  * @author chstath
28  */
29 public class FileHeaderDTO implements Serializable {
30
31         /**
32          * The preamble of every REST API URI.
33          */
34         public static final String PATH_GSS = "http://gss.grnet.gr/gss/rest/";
35
36         /**
37          * The path for the resource manipulation subsystem.
38          */
39         public static final String PATH_FILES = "/files";
40
41         /**
42          * The serial version UID.
43          */
44         private static final long serialVersionUID = 1L;
45
46         /**
47          * The persistence ID of the object.
48          */
49         private Long id;
50
51         /**
52          * The file name.
53          */
54         private String name;
55
56         /**
57          * The file path.
58          */
59         private String path;
60
61         /**
62          * Is this a versioned file?
63          */
64         private boolean versioned;
65
66         /**
67          * The current version
68          */
69         private int version = 0;
70
71         /**
72          * The owner of this file.
73          */
74         private UserDTO owner;
75
76         /**
77          * The folder that contains this file.
78          */
79         private FolderDTO folder;
80
81         /**
82          * The size of the file
83          */
84         private long fileSize;
85
86         /**
87          * The MIME type of this file.
88          */
89         private String mimeType;
90
91         /**
92          * The original filename (with which file was uploaded).
93          */
94         private String originalFilename;
95
96         /**
97          * The original filename URL-encoded.
98          */
99         private String originalFilenameEncoded;
100
101         /**
102          * The audit information for this object.
103          */
104         private AuditInfoDTO auditInfo;
105
106         /**
107          * A list of tags (Strings).
108          *
109          *
110          */
111         private List<String> tags;
112         /**
113          * is this file deleted?
114          */
115         private boolean deleted=false;
116         /**
117          * Anyone can read this file?
118          */
119         private boolean readForAll=false;
120         /**
121          * @return the id
122          */
123         public Long getId() {
124                 return id;
125         }
126
127         /**
128          * @param newId the id to set
129          */
130         public void setId(final Long newId) {
131                 id = newId;
132         }
133
134         /**
135          * @return the name
136          */
137         public String getName() {
138                 return name;
139         }
140
141         /**
142          * @param newName the name to set
143          */
144         public void setName(final String newName) {
145                 name = newName;
146         }
147
148         /**
149          * @return the versioned
150          */
151         public boolean isVersioned() {
152                 return versioned;
153         }
154
155         /**
156          * @param newVersioned the versioned to set
157          */
158         public void setVersioned(final boolean newVersioned) {
159                 versioned = newVersioned;
160         }
161
162         /**
163          * @return the owner
164          */
165         public UserDTO getOwner() {
166                 return owner;
167         }
168
169         /**
170          * @param newOwner the owner to set
171          */
172         public void setOwner(final UserDTO newOwner) {
173                 owner = newOwner;
174         }
175
176         /**
177          * @return the version
178          */
179         public int getVersion() {
180                 return version;
181         }
182
183         /**
184          * @param newVersion the version to set
185          */
186         public void setVersion(final int newVersion) {
187                 version = newVersion;
188         }
189
190         /**
191          * @return the fileSize
192          */
193         public long getFileSize() {
194                 return fileSize;
195         }
196
197         /**
198          * @param newFileSize the fileSize to set
199          */
200         public void setFileSize(final long newFileSize) {
201                 fileSize = newFileSize;
202         }
203
204         /**
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).
207          *
208          * @return the fileSize
209          */
210         public String getFileSizeAsString() {
211                 if (fileSize < 1024)
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";
218         }
219
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);
224         }
225
226         /**
227          * Retrieve the auditInfo.
228          *
229          * @return the auditInfo
230          */
231         public AuditInfoDTO getAuditInfo() {
232                 return auditInfo;
233         }
234
235         /**
236          * Modify the auditInfo.
237          *
238          * @param newAuditInfo the auditInfo to set
239          */
240         public void setAuditInfo(final AuditInfoDTO newAuditInfo) {
241                 auditInfo = newAuditInfo;
242         }
243
244
245         /**
246          * Retrieve the tags.
247          *
248          * @return the tags
249          */
250         public List<String> getTags() {
251                 return tags;
252         }
253
254
255         /**
256          * Modify the tags.
257          *
258          * @param newTags the tags to set
259          */
260         public void setTags(List<String> newTags) {
261                 tags = newTags;
262         }
263
264
265         /**
266          * Retrieve the mimeType.
267          *
268          * @return the mimeType
269          */
270         public String getMimeType() {
271                 return mimeType;
272         }
273
274
275         /**
276          * Modify the mimeType.
277          *
278          * @param newMimeType the mimeType to set
279          */
280         public void setMimeType(String newMimeType) {
281                 mimeType = newMimeType;
282         }
283
284
285         /**
286          * Retrieve the originalFilename.
287          *
288          * @return the originalFilename
289          */
290         public String getOriginalFilename() {
291                 return originalFilename;
292         }
293
294
295         /**
296          * Modify the originalFilename.
297          *
298          * @param newOriginalFilename the originalFilename to set
299          */
300         public void setOriginalFilename(String newOriginalFilename) {
301                 originalFilename = newOriginalFilename;
302         }
303
304
305         /**
306          * Retrieve the originalFilenameEncoded.
307          *
308          * @return the originalFilenameEncoded
309          */
310         public String getOriginalFilenameEncoded() {
311                 return originalFilenameEncoded;
312         }
313
314
315         /**
316          * Modify the originalFilenameEncoded.
317          *
318          * @param newOriginalFilenameEncoded the originalFilenameEncoded to set
319          */
320         public void setOriginalFilenameEncoded(String newOriginalFilenameEncoded) {
321                 originalFilenameEncoded = newOriginalFilenameEncoded;
322         }
323
324
325         /**
326          * Retrieve the deleted.
327          *
328          * @return the deleted
329          */
330         public boolean isDeleted() {
331                 return deleted;
332         }
333
334
335         /**
336          * Modify the deleted.
337          *
338          * @param newDeleted the deleted to set
339          */
340         public void setDeleted(boolean newDeleted) {
341                 deleted = newDeleted;
342         }
343
344
345         /**
346          * Retrieve the readForAll.
347          *
348          * @return the readForAll
349          */
350         public boolean isReadForAll() {
351                 return readForAll;
352         }
353
354
355         /**
356          * Modify the readForAll.
357          *
358          * @param aReadForAll the readForAll to set
359          */
360         public void setReadForAll(boolean aReadForAll) {
361                 readForAll = aReadForAll;
362         }
363
364         /**
365          * Retrieve the path.
366          *
367          * @return the path
368          */
369         public String getPath() {
370                 return path;
371         }
372
373         /**
374          * Modify the path.
375          *
376          * @param aPath the path to set
377          */
378         public void setPath(String aPath) {
379                 path = aPath;
380         }
381
382
383         /**
384          * Retrieve the URI for this resource. This unique identifier can
385          * be used to refer to the resource from various GSS clients.
386          *
387          * @return the URI
388          */
389         public String getURI() {
390                 return PATH_GSS + owner.getUsername() + PATH_FILES + getPath();
391         }
392
393
394         /**
395          * Retrieve the folder.
396          *
397          * @return the folder
398          */
399         public FolderDTO getFolder() {
400                 return folder;
401         }
402
403
404         /**
405          * Modify the folder.
406          *
407          * @param aFolder the folder to set
408          */
409         public void setFolder(FolderDTO aFolder) {
410                 folder = aFolder;
411         }
412 }