001/*
002 $Id: FileData.java 4263 2011-10-19 08:51:40Z fredrik $
003
004 Copyright (C) 2006, 2007 Gregory Vincic, Olle Mansson
005
006 This file is part of Proteios.
007 Available at http://www.proteios.org/
008
009 Proteios is free software; you can redistribute it and/or modify it
010 under the terms of the GNU General Public License as published by
011 the Free Software Foundation; either version 2 of the License, or
012 (at your option) any later version.
013
014 Proteios is distributed in the hope that it will be useful, but
015 WITHOUT ANY WARRANTY; without even the implied warranty of
016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017 General Public License for more details.
018
019 You should have received a copy of the GNU General Public License
020 along with this program; if not, write to the Free Software
021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
022 02111-1307, USA.
023 */
024package org.proteios.core.data;
025
026import java.util.Date;
027import java.util.HashSet;
028import java.util.Set;
029
030/**
031 * This class holds information about a file.
032 * 
033 * @author enell
034 * @version 2.0
035 * @see org.proteios.core.File
036 * @base.modified $Date: 2011-10-19 10:51:40 +0200 (Wed, 19 Oct 2011) $
037 * @hibernate.class table="`Files`" lazy="true"
038 */
039public class FileData
040                extends AnnotatedData
041                implements DiskConsumableData, CreationInterface
042{
043        private Date created;
044
045
046        public Date getCreated()
047        {
048                return created;
049        }
050
051
052        public void setCreated(Date created)
053        {
054                this.created = created;
055        }
056
057
058        /*
059         * From the NameableData interface
060         * -------------------------------------------
061         */
062        /**
063         * Get the name of the item.
064         * 
065         * @return A <code>String</code> with the name of the item
066         * @hibernate.property type="string"
067         * @hibernate.column name="`name`" length="255" not-null="true"
068         *                   index="name_idx" unique-key="uniquefile"
069         */
070        @Override
071        public String getName()
072        {
073                return super.getName();
074        }
075
076        // -------------------------------------------
077        /*
078         * From the DiskConsumableData interface
079         * -------------------------------------------
080         */
081        private DiskUsageData diskUsage;
082
083
084        public DiskUsageData getDiskUsage()
085        {
086                if (diskUsage == null)
087                        diskUsage = new DiskUsageData();
088                return diskUsage;
089        }
090
091
092        void setDiskUsage(DiskUsageData diskUsage)
093        {
094                this.diskUsage = diskUsage;
095        }
096
097        // -------------------------------------------
098        private long size;
099
100
101        /**
102         * Get the size in bytes for this <code>FileData</code> object.
103         * 
104         * @hibernate.property column="`size`" type="long" not-null="true"
105         */
106        public long getSize()
107        {
108                return size;
109        }
110
111
112        public void setSize(long size)
113        {
114                this.size = size;
115        }
116
117        private String md5;
118
119
120        /**
121         * Get the MD5 hash of the file contents. It is always returned as a string
122         * with 32 hexadecimal characters.
123         * 
124         * @hibernate.property column="`md5`" type="string" length="32"
125         *                     not-null="false"
126         */
127        public String getMd5()
128        {
129                return md5;
130        }
131
132
133        public void setMd5(String md5)
134        {
135                this.md5 = md5;
136        }
137
138        private int action;
139
140
141        /**
142         * Get the value of the action variable for this <code>FileData</code>
143         * object.
144         * 
145         * @hibernate.property column="`action`" type="int" not-null="true"
146         */
147        public int getAction()
148        {
149                return action;
150        }
151
152
153        public void setAction(int action)
154        {
155                this.action = action;
156        }
157
158        private int location;
159
160
161        /**
162         * Get the {@link org.proteios.core.Location} of this <code>FileData</code>
163         * 
164         * @hibernate.property column="`location`" type="int" not-null="true"
165         */
166        public int getLocation()
167        {
168                return location;
169        }
170
171
172        public void setLocation(int location)
173        {
174                this.location = location;
175        }
176
177        private String mimeType;
178        public static final int MAX_MIMETYPE_LENGTH = 255;
179
180
181        /**
182         * Get the mime type of this <code>FileData</code> item.
183         * 
184         * @hibernate.property column="`mimetype`" type="string" length="255"
185         */
186        public String getMimeType()
187        {
188                return mimeType;
189        }
190
191
192        public void setMimeType(String mimeType)
193        {
194                this.mimeType = mimeType;
195        }
196
197        private DirectoryData directory;
198
199
200        /**
201         * Get the associated {@link DirectoryData} item.
202         * 
203         * @hibernate.many-to-one outer-join="false"
204         * @hibernate.column name="`directory_id`" not-null="true"
205         *                   unique-key="uniquefile"
206         */
207        public DirectoryData getDirectory()
208        {
209                return directory;
210        }
211
212
213        public void setDirectory(DirectoryData directory)
214        {
215                this.directory = directory;
216        }
217
218        private FileTypeData fileType;
219
220
221        /**
222         * Get the associated {@link FileTypeData} item.
223         * 
224         * @hibernate.many-to-one column="`filetype_id`" not-null="false"
225         */
226        public FileTypeData getFileType()
227        {
228                return fileType;
229        }
230
231
232        public void setFileType(FileTypeData fileType)
233        {
234                this.fileType = fileType;
235        }
236
237        private boolean compressed;
238
239
240        /**
241         * If the file is stored in a compressed format or not.
242         * 
243         * @return boolean Returns true if the file is stored in compressed format.
244         * @hibernate.property column="`compressed`" type="boolean" not-null="true"
245         */
246        public boolean isCompressed()
247        {
248                return compressed;
249        }
250
251
252        /**
253         * Set the flag indicating that the file is stored in a compressed format.
254         * 
255         * @param compressed boolean The the file is stored in a compressed format.
256         */
257        public void setCompressed(boolean compressed)
258        {
259                this.compressed = compressed;
260        }
261
262        private long compressedSize;
263
264
265        /**
266         * Get the size in bytes that this <code>FileData</code> object uses after
267         * compression. If the file is not compressed, this value is the same as
268         * {@link #getSize()}
269         * 
270         * @return long The size in bytes of the compressed file.
271         * @hibernate.property column="`compressed_size`" type="long"
272         *                     not-null="true"
273         */
274        public long getCompressedSize()
275        {
276                return compressedSize;
277        }
278
279
280        /**
281         * Set the size in bytes that the file object uses after compression.
282         * 
283         * @param compressedSize long The size in bytes that the file object uses
284         *        after compression.
285         */
286        public void setCompressedSize(long compressedSize)
287        {
288                this.compressedSize = compressedSize;
289        }
290
291        private String internalName;
292
293
294        /**
295         * Get the internal name associated with this file.
296         * 
297         * @hibernate.property column="`internalname`" type="string" length="255"
298         *                     not-null="false"
299         */
300        public String getInternalName()
301        {
302                return internalName;
303        }
304
305
306        public void setInternalName(String internalName)
307        {
308                this.internalName = internalName;
309        }
310
311        private String uniformResourceIdentifier;
312        public static final int MAX_URI_LENGTH = 255;
313
314
315        /**
316         * Get the URI of this file. This is only set in the database if the file is
317         * not found in the Proteios primary storage. That is internalName = null.
318         * 
319         * @hibernate.property column="`uniformResourceIdentifier`" type="string"
320         *                     length="255" not-null="false"
321         */
322        public String getUniformResourceIdentifier()
323        {
324                return uniformResourceIdentifier;
325        }
326
327
328        /**
329         * Set the URI of this file. This must only be set in the database if the
330         * file is not found in the Proteios primary storage. That is internalName =
331         * null.
332         */
333        public void setUniformResourceIdentifier(String uniformResourceIdentifier)
334        {
335                this.uniformResourceIdentifier = uniformResourceIdentifier;
336        }
337
338        private Set<BioMaterialData> bioMaterials;
339
340
341        /**
342         * @hibernate.set table="`BioMaterialFiles`" lazy="true"
343         * @hibernate.collection-key column="`file_id`"
344         * @hibernate.collection-many-to-many 
345         *                                    class="org.proteios.core.data.BioMaterialData"
346         *                                    column="`biomaterial_id`"
347         * @return Returns the bioMaterials. Empty Set if no bioMaterials
348         */
349        public Set<BioMaterialData> getBioMaterials()
350        {
351                if (bioMaterials == null)
352                {
353                        bioMaterials = new HashSet<BioMaterialData>();
354                }
355                return bioMaterials;
356        }
357
358
359        public void setBioMaterials(Set<BioMaterialData> bioMaterials)
360        {
361                this.bioMaterials = bioMaterials;
362        }
363
364        private Set<MascotParameterSetStorageData> mascotParameterSet;
365
366
367        /**
368         * Get the mascotParameterSet.
369         * 
370         * @hibernate.set table="`MascotParameterSetStorage`" lazy="true"
371         *                inverse="true" cascade="all"
372         * @hibernate.collection-one-to-many 
373         *                                   class="org.proteios.core.data.MascotParameterSetStorageData"
374         *                                   not-null="false"
375         * @hibernate.collection-key column="`parameterFile`"
376         */
377        public Set<MascotParameterSetStorageData> getMascotParameterSet()
378        {
379                return this.mascotParameterSet;
380        }
381
382
383        /**
384         * Set the mascotParameterSets
385         * 
386         * @param mascotParameterSet The {@link MascotParameterSetStorageData}
387         *        mascotParameterSet
388         */
389        public void setMascotParameterSet(
390                        Set<MascotParameterSetStorageData> mascotParameterSet)
391        {
392                this.mascotParameterSet = mascotParameterSet;
393        }
394
395        private Set<XTandemParameterSetStorageData> xTandemParameterSet;
396
397
398        /**
399         * Get the xTandemParameterSets.
400         * 
401         * @hibernate.set table="`XTandemParameterSetStorage`" lazy="true"
402         *                inverse="true" cascade="all"
403         * @hibernate.collection-one-to-many 
404         *                                   class="org.proteios.core.data.XTandemParameterSetStorageData"
405         *                                   not-null="false"
406         * @hibernate.collection-key column="`parameterFile`"
407         */
408        public Set<XTandemParameterSetStorageData> getXTandemParameterSet()
409        {
410                return this.xTandemParameterSet;
411        }
412
413
414        /**
415         * Set the xTandemParameterSets
416         * 
417         * @param xTandemParameterSet The {@link XTandemParameterSetStorageData}
418         *        xTandemParameterSet
419         */
420        public void setXTandemParameterSet(
421                        Set<XTandemParameterSetStorageData> xTandemParameterSet)
422        {
423                this.xTandemParameterSet = xTandemParameterSet;
424        }
425
426        private Set<OMSSAParameterSetStorageData> oMSSAParameterSet;
427
428
429        /**
430         * Get the OMSSAParameterSets.
431         * 
432         * @hibernate.set table="`OMSSAParameterSetStorage`" lazy="true"
433         *                inverse="true" cascade="all"
434         * @hibernate.collection-one-to-many 
435         *                                   class="org.proteios.core.data.OMSSAParameterSetStorageData"
436         *                                   not-null="false"
437         * @hibernate.collection-key column="`parameterFile`"
438         */
439        public Set<OMSSAParameterSetStorageData> getOMSSAParameterSet()
440        {
441                return this.oMSSAParameterSet;
442        }
443
444
445        /**
446         * Set the OMSSAParameterSets
447         * 
448         * @param oMSSAParameterSet The {@link OMSSAParameterSetStorageData}
449         *        oMSSAParameterSet
450         */
451        public void setOMSSAParameterSet(
452                        Set<OMSSAParameterSetStorageData> oMSSAParameterSet)
453        {
454                this.oMSSAParameterSet = oMSSAParameterSet;
455        }
456}