BrightSide Workbench Full Report + Source Code
MailItem.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.entities.db;
20 
21 import java.util.Date;
22 import java.util.HashSet;
23 import java.util.Set;
24 import javax.persistence.CascadeType;
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.FetchType;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.Lob;
32 import javax.persistence.OneToMany;
33 import javax.persistence.OrderBy;
34 import javax.persistence.Temporal;
35 import org.turro.action.Contacts;
36 import org.turro.elephant.security.IUser;
37 import org.turro.plugin.contacts.IContact;
38 
43 @Entity
44 public class MailItem implements java.io.Serializable {
45 
46  @Id
47  @GeneratedValue(strategy=GenerationType.IDENTITY)
48  @Column(name="IDENTIFIER")
49  private Long id;
50 
51  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
52  private java.util.Date itemDate;
53 
54  private String idContact, contactEmail, contactName,
55  idCategory, category, description, subject, poolName,
56  reason, sender;
57 
58  @Lob
59  @Column(length=2147483647)
60  private String message;
61 
62  @OneToMany(mappedBy = "mailItem", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
63  @OrderBy(value="name")
64  private Set<MailAttachment> mailAttachments = new HashSet<MailAttachment>();
65 
66  public Long getId() {
67  return id;
68  }
69 
70  public void setId(Long id) {
71  this.id = id;
72  }
73 
74  public Date getItemDate() {
75  return itemDate;
76  }
77 
78  public void setItemDate(Date itemDate) {
79  this.itemDate = itemDate;
80  }
81 
82  public String getIdContact() {
83  return idContact;
84  }
85 
86  public void setIdContact(String idContact) {
87  this.idContact = idContact;
88  resetIContact();
89  }
90 
91  public String getContactEmail() {
92  return contactEmail;
93  }
94 
95  public void setContactEmail(String contactEmail) {
96  this.contactEmail = contactEmail;
97  }
98 
99  public String getContactName() {
100  return contactName;
101  }
102 
103  public void setContactName(String contactName) {
104  this.contactName = contactName;
105  }
106 
107  public String getIdCategory() {
108  return idCategory;
109  }
110 
111  public void setIdCategory(String idCategory) {
112  this.idCategory = idCategory;
113  }
114 
115  public String getCategory() {
116  return category;
117  }
118 
119  public void setCategory(String category) {
120  this.category = category;
121  }
122 
123  public String getDescription() {
124  return description;
125  }
126 
127  public void setDescription(String description) {
128  this.description = description;
129  }
130 
131  public String getSubject() {
132  return subject;
133  }
134 
135  public void setSubject(String subject) {
136  this.subject = subject;
137  }
138 
139  public String getMessage() {
140  return message;
141  }
142 
143  public void setMessage(String message) {
144  this.message = message;
145  }
146 
147  public String getPoolName() {
148  return poolName;
149  }
150 
151  public void setPoolName(String poolName) {
152  this.poolName = poolName;
153  }
154 
155  public String getReason() {
156  return reason;
157  }
158 
159  public void setReason(String reason) {
160  this.reason = reason;
161  }
162 
163  public String getSender() {
164  return sender;
165  }
166 
167  public void setSender(String sender) {
168  this.sender = sender;
169  }
170 
171  public Set<MailAttachment> getMailAttachments() {
172  return mailAttachments;
173  }
174 
175  public void setMailAttachments(Set<MailAttachment> mailAttachments) {
176  this.mailAttachments = mailAttachments;
177  }
178 
181  private transient IContact _contact;
182 
184  if(_contact == null) {
185  _contact = Contacts.getContactById(idContact);
186  }
187  return _contact;
188  }
189 
190  public void setIContact(IContact contact) {
191  _contact = contact;
192  idContact = _contact != null ? _contact.getId() : null;
193  contactName = _contact != null ? _contact.getName() : null;
194  contactEmail = _contact != null ? _contact.getConnector(IUser.CONNECTOR_EMAIL) : null;
195  }
196 
197  private void resetIContact() {
198  _contact = null;
199  }
200 
201  /* Attachments */
202 
203  public MailAttachment addAttachment(String description, String name, String entityPath) {
204  MailAttachment ma = new MailAttachment();
206  ma.setDescription(description);
207  ma.setName(name);
208  ma.setEntityPath(entityPath);
209  ma.setMailItem(this);
210  getMailAttachments().add(ma);
211  return ma;
212  }
213 
214  public MailAttachment addFile(String description, String name, String filePath) {
215  MailAttachment ma = new MailAttachment();
217  ma.setDescription(description);
218  ma.setName(name);
219  ma.setEntityPath(filePath);
220  ma.setMailItem(this);
221  getMailAttachments().add(ma);
222  return ma;
223  }
224 
225  public MailAttachment addImage(String description, String name, String imagePath) {
226  MailAttachment ma = new MailAttachment();
228  ma.setDescription(description);
229  ma.setName(name);
230  ma.setEntityPath(imagePath);
231  ma.setMailItem(this);
232  getMailAttachments().add(ma);
233  return ma;
234  }
235 
236  public MailAttachment addImageURL(String description, String name, String imageURL) {
237  MailAttachment ma = new MailAttachment();
239  ma.setDescription(description);
240  ma.setName(name);
241  ma.setEntityPath(imageURL);
242  ma.setMailItem(this);
243  getMailAttachments().add(ma);
244  return ma;
245  }
246 
247 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setContactEmail(String contactEmail)
Definition: MailItem.java:95
void setIContact(IContact contact)
Definition: MailItem.java:190
void setMailAttachments(Set< MailAttachment > mailAttachments)
Definition: MailItem.java:175
void setContactName(String contactName)
Definition: MailItem.java:103
Set< MailAttachment > getMailAttachments()
Definition: MailItem.java:171
void setDescription(String description)
Definition: MailItem.java:127
MailAttachment addAttachment(String description, String name, String entityPath)
Definition: MailItem.java:203
void setIdContact(String idContact)
Definition: MailItem.java:86
MailAttachment addImage(String description, String name, String imagePath)
Definition: MailItem.java:225
MailAttachment addImageURL(String description, String name, String imageURL)
Definition: MailItem.java:236
void setIdCategory(String idCategory)
Definition: MailItem.java:111
MailAttachment addFile(String description, String name, String filePath)
Definition: MailItem.java:214
static final String CONNECTOR_EMAIL
Definition: IUser.java:27