View Javadoc

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   * @author Marc Michele
32   *
33   */
34  @Audited
35  @Entity
36  public class Request {
37  
38      private static final Logger logger = LogManager.getLogger(Request.class);
39  
40      /**
41       * Datei-Pfad unter dem das Bild abgelegt wird.
42       */
43      protected static String uploadPath = "/srv/tiv-page/request/";
44  
45      /**
46       * UUID des Objektes der Klasse Request, diese ID ist einmalig über alle
47       * Objekte hinweg und sollte der bevorzugte weg sein auf bestimmte Objekte
48       * zuzugreifen.
49       */
50      @Id
51      @DocumentId
52      @Column(name="uuid", unique=true, length=42)
53      private String uuid;
54  
55      /**
56       * Attribut das angibt wie jemand angesprochen werden möchte, es kann aus
57       * den folgenden Geschlechtern ausgewählt werden: M = Male (Männlich), F =
58       * Female (Weiblich), O = Other (Anderes).
59       * 
60       * Dabei gilt das die Anrede bei M = Herr x yz, F = Frau x yz und O = x yz
61       * benutzt wird.
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      * Datei, die aus einem Formular hochgeladen wird.
108      */
109     @Transient
110     private File uploadFile;
111 
112     /**
113      * @return the uuid
114      */
115     public String getUuid() {
116         return uuid;
117     }
118 
119     /**
120      * @param uuid the uuid to set
121      */
122     public void setUuid(String uuid) {
123         this.uuid = uuid;
124     }
125 
126     /**
127      * @return the gender
128      */
129     public Character getGender() {
130         return gender;
131     }
132 
133     /**
134      * @param gender the gender to set
135      */
136     public void setGender(Character gender) {
137         this.gender = gender;
138     }
139 
140     /**
141      * @return the firstname
142      */
143     public String getFirstname() {
144         return firstname;
145     }
146 
147     /**
148      * @param firstname the firstname to set
149      */
150     public void setFirstname(String firstname) {
151         this.firstname = firstname;
152     }
153 
154     /**
155      * @return the lastname
156      */
157     public String getLastname() {
158         return lastname;
159     }
160 
161     /**
162      * @param lastname the lastname to set
163      */
164     public void setLastname(String lastname) {
165         this.lastname = lastname;
166     }
167 
168     /**
169      * @return the birthday
170      */
171     public Date getBirthday() {
172         return birthday;
173     }
174 
175     /**
176      * @param birthday the birthday to set
177      */
178     public void setBirthday(Date birthday) {
179         this.birthday = birthday;
180     }
181 
182     /**
183      * @return the mail
184      */
185     public String getMail() {
186         return mail;
187     }
188 
189     /**
190      * @param mail the mail to set
191      */
192     public void setMail(String mail) {
193         this.mail = mail;
194     }
195 
196     /**
197      * @return the reason
198      */
199     public Reason getReason() {
200         return reason;
201     }
202 
203     /**
204      * @param reason the reason to set
205      */
206     public void setReason(Reason reason) {
207         this.reason = reason;
208     }
209 
210     /**
211      * @return the proofOfAuthority
212      */
213     public String getProofOfAuthority() {
214         return proofOfAuthority;
215     }
216 
217     /**
218      * @param proofOfAuthority the proofOfAuthority to set
219      */
220     public void setProofOfAuthority(String proofOfAuthority) {
221         this.proofOfAuthority = proofOfAuthority;
222     }
223 
224     /**
225      * @return the location
226      */
227     public Location getLocation() {
228         return location;
229     }
230 
231     /**
232      * @param location the location to set
233      */
234     public void setLocation(Location location) {
235         this.location = location;
236     }
237 
238     /**
239      * @return the comment
240      */
241     public String getComment() {
242         return comment;
243     }
244 
245     /**
246      * @param comment the comment to set
247      */
248     public void setComment(String comment) {
249         this.comment = comment;
250     }
251 
252     /**
253      * @return the privacy
254      */
255     public Boolean getPrivacy() {
256         return privacy;
257     }
258 
259     /**
260      * @param privacy the privacy to set
261      */
262     public void setPrivacy(Boolean privacy) {
263         this.privacy = privacy;
264     }
265 
266     /**
267      * @return the confirmed
268      */
269     public Boolean getConfirmed() {
270         return confirmed;
271     }
272 
273     /**
274      * @param confirmed the confirmed to set
275      */
276     public void setConfirmed(Boolean confirmed) {
277         this.confirmed = confirmed;
278     }
279 
280     /**
281      * @return the confirmedAddress
282      */
283     public String getConfirmedAddress() {
284         return confirmedAddress;
285     }
286 
287     /**
288      * @param confirmedAddress the confirmedAddress to set
289      */
290     public void setConfirmedAddress(String confirmedAddress) {
291         this.confirmedAddress = confirmedAddress;
292     }
293 
294     /**
295      * @return the confirmedDate
296      */
297     public Date getConfirmedDate() {
298         return confirmedDate;
299     }
300 
301     /**
302      * @param confirmedDate the confirmedDate to set
303      */
304     public void setConfirmedDate(Date confirmedDate) {
305         this.confirmedDate = confirmedDate;
306     }
307 
308     /**
309      * @return the confirmedBy
310      */
311     public String getConfirmedBy() {
312         return confirmedBy;
313     }
314 
315     /**
316      * @param confirmedBy the confirmedBy to set
317      */
318     public void setConfirmedBy(String confirmedBy) {
319         this.confirmedBy = confirmedBy;
320     }
321 
322     /**
323      * @return the created
324      */
325     public Date getCreated() {
326         return created;
327     }
328 
329     /**
330      * @param created the created to set
331      */
332     public void setCreated(Date created) {
333         this.created = created;
334     }
335 
336     /**
337      * @return the createdAddress
338      */
339     public String getCreatedAddress() {
340         return createdAddress;
341     }
342 
343     /**
344      * @param createdAddress the createdAddress to set
345      */
346     public void setCreatedAddress(String createdAddress) {
347         this.createdAddress = createdAddress;
348     }
349 
350     /**
351      * @return the uploadFile
352      */
353     public File getUploadFile() {
354         return uploadFile;
355     }
356 
357     /**
358      * @param uploadFile the uploadFile to set
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         // Generiere UUID für den Dateinamen
376         String pictureSaveName = UUID.randomUUID().toString();
377 
378         try {
379             // Erstelle Content Analyse Toolkit
380             Tika tika = new Tika();
381             String mimeType = tika.detect(uploadFile);
382             String type = mimeType.split("/")[1];
383             // Datei die erstellt werden soll
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             // Wenn die Datei noch nicht existiert wird Sie erstellt.
390             if (!fileToCreate.exists()) {
391                 FileActions.savePictureFile(this.getUploadFile(), fileToCreate);
392             }// Ende if
393         } // Ende try
394         catch (Exception e) {
395             logger.error(e.getMessage());
396         }// Ende Catch
397     }        
398 }// Ende class