Salome HOME
Add study
[modules/gde.git] / projects / GDE_App / GDE-ejb / src / java / com / edf / gde / entities / GDEFile.java
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package com.edf.gde.entities;
7
8 import com.edf.gde.transferables.ChunkTO;
9 import com.edf.gde.transferables.FileTO;
10 import java.io.Serializable;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Date;
14 import java.util.Objects;
15 import javax.persistence.Basic;
16 import javax.persistence.CascadeType;
17 import javax.persistence.Column;
18 import javax.persistence.Entity;
19 import javax.persistence.Id;
20 import javax.persistence.NamedQueries;
21 import javax.persistence.NamedQuery;
22 import javax.persistence.OneToMany;
23 import javax.persistence.Table;
24 import javax.persistence.Temporal;
25 import javax.persistence.TemporalType;
26 import javax.validation.constraints.NotNull;
27 import javax.validation.constraints.Size;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.bind.annotation.XmlTransient;
30
31 /**
32  *
33  * @author F62173
34  */
35 @Entity(name = "File")
36 @Table(name = "gde_file")
37 @XmlRootElement
38 @NamedQueries({
39     @NamedQuery(name = "File.findAll", query = "SELECT f FROM File f"),
40     @NamedQuery(name = "File.findById", query = "SELECT f FROM File f WHERE f.id = :id"),
41     @NamedQuery(name = "File.findByName", query = "SELECT f FROM File f WHERE f.name = :name"),
42     //@NamedQuery(name = "File.findByLength", query = "SELECT f FROM File f WHERE f.length = :length"),
43     //@NamedQuery(name = "File.findByChecksum", query = "SELECT f FROM File f WHERE f.checksum = :checksum"),
44     @NamedQuery(name = "File.findByCreationDate", query = "SELECT f FROM File f WHERE f.creationDate = :creationDate"),
45     @NamedQuery(name = "File.findByUpdateDate", query = "SELECT f FROM File f WHERE f.updateDate = :updateDate"),
46     //@NamedQuery(name = "File.findByValid", query = "SELECT f FROM File f WHERE f.valid = :valid"),
47     //@NamedQuery(name = "File.findByDeleted", query = "SELECT f FROM File f WHERE f.deleted = :deleted"),
48     @NamedQuery(name = "File.findByDeletionDate", query = "SELECT f FROM File f WHERE f.deletionDate = :deletionDate")
49 })
50 public class GDEFile implements Serializable {
51     private static final long serialVersionUID = 1L;
52     @Id
53     @Basic(optional = false)
54     @NotNull
55     @Column(name = "id")
56     private long id;
57     @Size(max = 255)
58     @Column(name = "name")
59     private String name;
60     @Column(name = "length")
61     private long length;
62     @Size(max = 255)
63     @Column(name = "checksum")
64     private String checksum;
65     @Column(name = "creation_date")
66     @Temporal(TemporalType.TIMESTAMP)
67     private Date creationDate;
68     @Column(name = "update_date")
69     @Temporal(TemporalType.TIMESTAMP)
70     private Date updateDate;
71     @Column(name = "valid")
72     private Boolean valid;
73     @Column(name = "deleted")
74     private Boolean deleted;
75     @Column(name = "deletion_date")
76     @Temporal(TemporalType.TIMESTAMP)
77     private Date deletionDate;
78     @OneToMany(cascade = CascadeType.ALL)
79     private Collection<Chunk> chunkCollection;
80     @Column(name = "attribute_group_id")
81     private long attributeGroupId;
82
83     public GDEFile() {
84     }
85
86     public GDEFile(long id) {
87         this.id = id;
88     }
89
90     public long getId() {
91         return id;
92     }
93
94     public void setId(long id) {
95         this.id = id;
96     }
97
98     public String getName() {
99         return name;
100     }
101
102     public void setName(String name) {
103         this.name = name;
104     }
105
106     public long getLength() {
107         return length;
108     }
109
110     public void setLength(long length) {
111         this.length = length;
112     }
113
114     public String getChecksum() {
115         return checksum;
116     }
117
118     public void setChecksum(String checksum) {
119         this.checksum = checksum;
120     }
121
122     public Date getCreationDate() {
123         return creationDate;
124     }
125
126     public void setCreationDate(Date creationDate) {
127         this.creationDate = creationDate;
128     }
129
130     public Date getUpdateDate() {
131         return updateDate;
132     }
133
134     public void setUpdateDate(Date updateDate) {
135         this.updateDate = updateDate;
136     }
137
138     public Boolean getValid() {
139         return valid;
140     }
141
142     public void setValid(Boolean valid) {
143         this.valid = valid;
144     }
145
146     public Boolean getDeleted() {
147         return deleted;
148     }
149
150     public void setDeleted(Boolean deleted) {
151         this.deleted = deleted;
152     }
153
154     public Date getDeletionDate() {
155         return deletionDate;
156     }
157
158     public void setDeletionDate(Date deletionDate) {
159         this.deletionDate = deletionDate;
160     }
161
162     @XmlTransient
163     public Collection<Chunk> getChunkCollection() {
164         return chunkCollection;
165     }
166
167     public void setChunkCollection(Collection<Chunk> chunkCollection) {
168         this.chunkCollection = chunkCollection;
169     }
170
171     public long getAttributeGroupId() {
172         return attributeGroupId;
173     }
174
175     public void setAttributeGroupId(long attributeGroupId) {
176         this.attributeGroupId = attributeGroupId;
177     }
178
179     public static GDEFile fromFileTO(FileTO fto) {
180         GDEFile f = new GDEFile();
181         f.checksum = fto.getChecksum();
182
183         f.chunkCollection = new ArrayList<>();
184         Collection<ChunkTO> chunks = fto.getChunkCollection();
185         for (ChunkTO cto : chunks) {
186             f.chunkCollection.add(Chunk.fromChunkTO(cto));
187         }
188         
189         f.creationDate = fto.getCreationDate();
190         f.deleted = fto.getDeleted();
191         f.deletionDate = fto.getDeletionDate();
192         f.attributeGroupId = fto.getAttributeGroupId();
193         f.id = fto.getId();
194         f.length = fto.getLength();
195         f.name = fto.getName();
196         f.updateDate = fto.getUpdateDate();
197         f.valid = fto.getValid();
198         return f;
199     }
200
201     public FileTO toFileTO() {
202         FileTO fto = new FileTO();
203         fto.setChecksum(this.checksum);
204         
205         Collection<ChunkTO> ctos = new ArrayList<>();
206         for (Chunk c : this.chunkCollection) {
207             ctos.add(c.toChunkTO());
208         }
209         fto.setChunkCollection(ctos);
210         
211         fto.setCreationDate(this.creationDate);
212         fto.setDeleted(this.deleted);
213         fto.setDeletionDate(this.deletionDate);
214         fto.setAttributeGroupId(this.attributeGroupId);
215         fto.setId(this.id);
216         fto.setLength(this.length);
217         fto.setName(this.name);
218         fto.setUpdateDate(this.updateDate);
219         fto.setValid(this.valid);
220         return fto;
221     }
222
223     @Override
224     public String toString() {
225         return "com.edf.gde.entities.GDEFile[ id=" + id + " ]";
226     }
227
228     @Override
229     public int hashCode() {
230         int hash = 3;
231         hash = 29 * hash + (int) (this.id ^ (this.id >>> 32));
232         hash = 29 * hash + Objects.hashCode(this.name);
233         hash = 29 * hash + (int) (this.length ^ (this.length >>> 32));
234         hash = 29 * hash + Objects.hashCode(this.checksum);
235         hash = 29 * hash + Objects.hashCode(this.creationDate);
236         hash = 29 * hash + Objects.hashCode(this.updateDate);
237         hash = 29 * hash + Objects.hashCode(this.valid);
238         hash = 29 * hash + Objects.hashCode(this.deleted);
239         hash = 29 * hash + Objects.hashCode(this.deletionDate);
240         hash = 29 * hash + Objects.hashCode(this.chunkCollection);
241         hash = 29 * hash + (int) (this.attributeGroupId ^ (this.attributeGroupId >>> 32));
242         return hash;
243     }
244
245     @Override
246     public boolean equals(Object obj) {
247         if (obj == null) {
248             return false;
249         }
250         if (getClass() != obj.getClass()) {
251             return false;
252         }
253         final GDEFile other = (GDEFile) obj;
254         if (this.id != other.id) {
255             return false;
256         }
257         return true;
258     }
259
260 }