Salome HOME
4596b6ecdb61c8bb472fdda47ec42bfc05aa2e91
[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.Column;
17 import javax.persistence.Entity;
18 import javax.persistence.Id;
19 import javax.persistence.NamedQueries;
20 import javax.persistence.NamedQuery;
21 import javax.persistence.OneToMany;
22 import javax.persistence.Table;
23 import javax.persistence.Temporal;
24 import javax.persistence.TemporalType;
25 import javax.validation.constraints.NotNull;
26 import javax.validation.constraints.Size;
27 import javax.xml.bind.annotation.XmlRootElement;
28
29 /**
30  *
31  * @author F62173
32  */
33 @Entity(name = "File")
34 @Table(name = "file")
35 @XmlRootElement
36 @NamedQueries({
37     @NamedQuery(name = "File.findAll", query = "SELECT f FROM File f"),
38     @NamedQuery(name = "File.findById", query = "SELECT f FROM File f WHERE f.id = :id"),
39     @NamedQuery(name = "File.findByName", query = "SELECT f FROM File f WHERE f.name = :name"),
40     //@NamedQuery(name = "File.findByLength", query = "SELECT f FROM File f WHERE f.length = :length"),
41     //@NamedQuery(name = "File.findByChecksum", query = "SELECT f FROM File f WHERE f.checksum = :checksum"),
42     @NamedQuery(name = "File.findByCreationDate", query = "SELECT f FROM File f WHERE f.creationDate = :creationDate"),
43     @NamedQuery(name = "File.findByUpdateDate", query = "SELECT f FROM File f WHERE f.updateDate = :updateDate"),
44     //@NamedQuery(name = "File.findByValid", query = "SELECT f FROM File f WHERE f.valid = :valid"),
45     //@NamedQuery(name = "File.findByDeleted", query = "SELECT f FROM File f WHERE f.deleted = :deleted"),
46     @NamedQuery(name = "File.findByDeletionDate", query = "SELECT f FROM File f WHERE f.deletionDate = :deletionDate")
47 })
48 public class GDEFile implements Serializable {
49     private static final long serialVersionUID = 1L;
50
51     @Id
52     @Basic(optional = false)
53     @NotNull
54     @Column(name = "id")
55     private long id;
56     @Size(max = 255)
57     @Column(name = "name")
58     private String name;
59     @Column(name = "length")
60     private long length;
61     @Size(max = 255)
62     @Column(name = "checksum")
63     private String checksum;
64     @Column(name = "creation_date")
65     @Temporal(TemporalType.TIMESTAMP)
66     private Date creationDate;
67     @Column(name = "update_date")
68     @Temporal(TemporalType.TIMESTAMP)
69     private Date updateDate;
70     @Column(name = "valid")
71     private Boolean valid;
72     @Column(name = "deleted")
73     private Boolean deleted;
74     @Column(name = "deletion_date")
75     @Temporal(TemporalType.TIMESTAMP)
76     private Date deletionDate;
77     //@JoinColumn(name = "group_id", referencedColumnName = "id", nullable = false)
78     @Column(name = "group_id", nullable = false)
79     //@ManyToOne
80     private long groupId;
81     @OneToMany
82     private Collection<Chunk> chunks;
83     
84     public GDEFile() {
85     }
86
87     public GDEFile(long id) {
88         this.id = id;
89     }
90
91     public long getId() {
92         return id;
93     }
94
95     public void setId(long id) {
96         this.id = id;
97     }
98
99     public String getName() {
100         return name;
101     }
102
103     public void setName(String name) {
104         this.name = name;
105     }
106
107     public long getLength() {
108         return length;
109     }
110
111     public void setLength(long length) {
112         this.length = length;
113     }
114
115     public String getChecksum() {
116         return checksum;
117     }
118
119     public void setChecksum(String checksum) {
120         this.checksum = checksum;
121     }
122
123     public Date getCreationDate() {
124         return creationDate;
125     }
126
127     public void setCreationDate(Date creationDate) {
128         this.creationDate = creationDate;
129     }
130
131     public Date getUpdateDate() {
132         return updateDate;
133     }
134
135     public void setUpdateDate(Date updateDate) {
136         this.updateDate = updateDate;
137     }
138
139     public Boolean getValid() {
140         return valid;
141     }
142
143     public void setValid(Boolean valid) {
144         this.valid = valid;
145     }
146
147     public Boolean getDeleted() {
148         return deleted;
149     }
150
151     public void setDeleted(Boolean deleted) {
152         this.deleted = deleted;
153     }
154
155     public Date getDeletionDate() {
156         return deletionDate;
157     }
158
159     public void setDeletionDate(Date deletionDate) {
160         this.deletionDate = deletionDate;
161     }
162
163     public long getGroupId() {
164         return groupId;
165     }
166
167     public void setGroupId(long groupId) {
168         this.groupId = groupId;
169     }
170
171     public Collection<Chunk> getChunks() {
172         return chunks;
173     }
174
175     public void setChunks(Collection<Chunk> chunks) {
176         this.chunks = chunks;
177     }
178
179     public static GDEFile fromFileTO(FileTO fto) {
180         GDEFile f = new GDEFile();
181         f.checksum = fto.getChecksum();
182
183         f.chunks = new ArrayList<>();
184         Collection<ChunkTO> chunks = fto.getChunks();
185         for (ChunkTO cto : chunks) {
186             f.chunks.add(Chunk.fromChunkTO(cto));
187         }
188         
189         f.creationDate = fto.getCreationDate();
190         f.deleted = fto.getDeleted();
191         f.deletionDate = fto.getDeletionDate();
192         f.groupId = 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.chunks) {
207             ctos.add(c.toChunkTO());
208         }
209         fto.setChunks(ctos);
210         
211         fto.setCreationDate(this.creationDate);
212         fto.setDeleted(this.deleted);
213         fto.setDeletionDate(this.deletionDate);
214         fto.setAttributeGroupId(this.groupId);
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.File[ id=" + id + " ]";
226     }
227
228     @Override
229     public int hashCode() {
230         int hash = 5;
231         hash = 41 * hash + (int) (this.id ^ (this.id >>> 32));
232         hash = 41 * hash + Objects.hashCode(this.name);
233         hash = 41 * hash + (int) (this.length ^ (this.length >>> 32));
234         hash = 41 * hash + Objects.hashCode(this.checksum);
235         hash = 41 * hash + Objects.hashCode(this.creationDate);
236         hash = 41 * hash + Objects.hashCode(this.updateDate);
237         hash = 41 * hash + Objects.hashCode(this.valid);
238         hash = 41 * hash + Objects.hashCode(this.deleted);
239         hash = 41 * hash + Objects.hashCode(this.deletionDate);
240         hash = 41 * hash + (int) (this.groupId ^ (this.groupId >>> 32));
241         hash = 41 * hash + Objects.hashCode(this.chunks);
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 }