1
2
3
4 package de.tivsource.page.entity.request;
5
6 import java.io.File;
7 import java.io.FileInputStream;
8 import java.util.Date;
9 import java.util.UUID;
10
11 import javax.persistence.Basic;
12 import javax.persistence.Column;
13 import javax.persistence.Entity;
14 import javax.persistence.FetchType;
15 import javax.persistence.Id;
16 import javax.persistence.JoinColumn;
17 import javax.persistence.ManyToOne;
18 import javax.persistence.Temporal;
19 import javax.persistence.Transient;
20
21 import org.apache.logging.log4j.LogManager;
22 import org.apache.logging.log4j.Logger;
23 import org.apache.tika.Tika;
24 import org.hibernate.envers.Audited;
25 import org.hibernate.search.annotations.DocumentId;
26
27 import de.tivsource.page.common.file.FileActions;
28 import de.tivsource.page.entity.location.Location;
29
30
31
32
33
34 @Audited
35 @Entity
36 public class Request {
37
38 private static final Logger logger = LogManager.getLogger(Request.class);
39
40
41
42
43 protected static String uploadPath = "/srv/tiv-page/request/";
44
45
46
47
48
49
50 @Id
51 @DocumentId
52 @Column(name="uuid", unique=true, length=42)
53 private String uuid;
54
55
56
57
58
59
60
61
62
63 private Character gender;
64
65 private String firstname;
66
67 private String lastname;
68
69 @Temporal(javax.persistence.TemporalType.TIMESTAMP)
70 private Date birthday;
71
72 private String mail;
73
74 @ManyToOne(targetEntity = Reason.class, fetch = FetchType.EAGER)
75 @JoinColumn(name = "reason_uuid")
76 private Reason reason;
77
78 private String proofOfAuthority;
79
80 @ManyToOne(fetch = FetchType.EAGER)
81 @JoinColumn(name = "location_uuid")
82 private Location location;
83
84 private String comment;
85
86 @Basic
87 @org.hibernate.annotations.Type(type = "yes_no")
88 private Boolean privacy;
89
90 @Basic
91 @org.hibernate.annotations.Type(type = "yes_no")
92 private Boolean confirmed;
93
94 private String confirmedAddress;
95
96 @Temporal(javax.persistence.TemporalType.TIMESTAMP)
97 private Date confirmedDate;
98
99 private String confirmedBy;
100
101 @Temporal(javax.persistence.TemporalType.TIMESTAMP)
102 private Date created;
103
104 private String createdAddress;
105
106
107
108
109 @Transient
110 private File uploadFile;
111
112
113
114
115 public String getUuid() {
116 return uuid;
117 }
118
119
120
121
122 public void setUuid(String uuid) {
123 this.uuid = uuid;
124 }
125
126
127
128
129 public Character getGender() {
130 return gender;
131 }
132
133
134
135
136 public void setGender(Character gender) {
137 this.gender = gender;
138 }
139
140
141
142
143 public String getFirstname() {
144 return firstname;
145 }
146
147
148
149
150 public void setFirstname(String firstname) {
151 this.firstname = firstname;
152 }
153
154
155
156
157 public String getLastname() {
158 return lastname;
159 }
160
161
162
163
164 public void setLastname(String lastname) {
165 this.lastname = lastname;
166 }
167
168
169
170
171 public Date getBirthday() {
172 return birthday;
173 }
174
175
176
177
178 public void setBirthday(Date birthday) {
179 this.birthday = birthday;
180 }
181
182
183
184
185 public String getMail() {
186 return mail;
187 }
188
189
190
191
192 public void setMail(String mail) {
193 this.mail = mail;
194 }
195
196
197
198
199 public Reason getReason() {
200 return reason;
201 }
202
203
204
205
206 public void setReason(Reason reason) {
207 this.reason = reason;
208 }
209
210
211
212
213 public String getProofOfAuthority() {
214 return proofOfAuthority;
215 }
216
217
218
219
220 public void setProofOfAuthority(String proofOfAuthority) {
221 this.proofOfAuthority = proofOfAuthority;
222 }
223
224
225
226
227 public Location getLocation() {
228 return location;
229 }
230
231
232
233
234 public void setLocation(Location location) {
235 this.location = location;
236 }
237
238
239
240
241 public String getComment() {
242 return comment;
243 }
244
245
246
247
248 public void setComment(String comment) {
249 this.comment = comment;
250 }
251
252
253
254
255 public Boolean getPrivacy() {
256 return privacy;
257 }
258
259
260
261
262 public void setPrivacy(Boolean privacy) {
263 this.privacy = privacy;
264 }
265
266
267
268
269 public Boolean getConfirmed() {
270 return confirmed;
271 }
272
273
274
275
276 public void setConfirmed(Boolean confirmed) {
277 this.confirmed = confirmed;
278 }
279
280
281
282
283 public String getConfirmedAddress() {
284 return confirmedAddress;
285 }
286
287
288
289
290 public void setConfirmedAddress(String confirmedAddress) {
291 this.confirmedAddress = confirmedAddress;
292 }
293
294
295
296
297 public Date getConfirmedDate() {
298 return confirmedDate;
299 }
300
301
302
303
304 public void setConfirmedDate(Date confirmedDate) {
305 this.confirmedDate = confirmedDate;
306 }
307
308
309
310
311 public String getConfirmedBy() {
312 return confirmedBy;
313 }
314
315
316
317
318 public void setConfirmedBy(String confirmedBy) {
319 this.confirmedBy = confirmedBy;
320 }
321
322
323
324
325 public Date getCreated() {
326 return created;
327 }
328
329
330
331
332 public void setCreated(Date created) {
333 this.created = created;
334 }
335
336
337
338
339 public String getCreatedAddress() {
340 return createdAddress;
341 }
342
343
344
345
346 public void setCreatedAddress(String createdAddress) {
347 this.createdAddress = createdAddress;
348 }
349
350
351
352
353 public File getUploadFile() {
354 return uploadFile;
355 }
356
357
358
359
360 public void setUploadFile(File uploadFile) {
361 this.uploadFile = uploadFile;
362 }
363
364 public FileInputStream getProofOfAuthorityFileInputStream() {
365 try {
366 return new FileInputStream(new File(this.proofOfAuthority));
367 } catch (Exception e) {
368 e.printStackTrace();
369 return null;
370 }
371 }
372
373 public void generate() {
374
375
376 String pictureSaveName = UUID.randomUUID().toString();
377
378 try {
379
380 Tika tika = new Tika();
381 String mimeType = tika.detect(uploadFile);
382 String type = mimeType.split("/")[1];
383
384 File fileToCreate = new File(uploadPath, pictureSaveName + ".org." + type);
385 this.proofOfAuthority = uploadPath + pictureSaveName + ".org." + type;
386 logger.debug("Absoluter Pfad der neuen Picture-Datei : "
387 + fileToCreate.getAbsolutePath());
388
389
390 if (!fileToCreate.exists()) {
391 FileActions.savePictureFile(this.getUploadFile(), fileToCreate);
392 }
393 }
394 catch (Exception e) {
395 logger.error(e.getMessage());
396 }
397 }
398 }