BrightSide Workbench Full Report + Source Code
Participant.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.dossier.entity;
19 
20 import java.util.Date;
21 import java.util.HashSet;
22 import java.util.Objects;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.ManyToOne;
30 import javax.persistence.Temporal;
31 import org.turro.action.Contacts;
32 import org.turro.jpa.entity.IDaoEntity;
33 import org.turro.plugin.contacts.IContact;
34 import org.turro.visual.RoleUtil;
35 
40 @Entity
41 public class Participant implements java.io.Serializable, IDossierParticipant, IDaoEntity {
42 
43  @Id
44  @GeneratedValue(strategy=GenerationType.IDENTITY)
45  @Column(name="IDENTIFIER")
46  private Long id;
47 
48  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
49  private java.util.Date creation;
50 
51  @Column(name="PARTICIPANT_NAME", nullable = false)
52  private String name;
53 
54  private String idContact;
55 
56  @Column(name="PARTICIPANT_ROLE")
57  private ParticipantRole role;
58 
59  private String discriminator;
60 
61  private boolean showAllAttachments, showParticipants, showAllIssues, receiveAllEmails, bindingVote,
62  driver, coordinator, beneficiary, offerer, research, funding, support, consortium, admin;
63 
64  @ManyToOne
65  @JoinColumn(name="DOSSIER_FK")
66  private Dossier dossier;
67 
68  public Dossier getDossier() {
69  return dossier;
70  }
71 
72  public void setDossier(Dossier dossier) {
73  this.dossier = dossier;
74  }
75 
76  public Long getId() {
77  return id;
78  }
79 
80  public void setId(Long id) {
81  this.id = id;
82  }
83 
84  @Override
85  public Date getCreation() {
86  return creation;
87  }
88 
89  public void setCreation(Date creation) {
90  this.creation = creation;
91  }
92 
93  @Override
94  public String getIdContact() {
95  return idContact;
96  }
97 
98  public void setIdContact(String idContact) {
99  this.idContact = idContact;
100  resetIContact();
101  }
102 
103  @Override
104  public String getName() {
105  return name;
106  }
107 
108  public void setName(String name) {
109  this.name = name;
110  }
111 
112  @Override
113  public boolean isReceiveAllEmails() {
114  return receiveAllEmails;
115  }
116 
117  public void setReceiveAllEmails(boolean receiveAllEmails) {
118  this.receiveAllEmails = receiveAllEmails;
119  }
120 
121  @Override
123  return role;
124  }
125 
126  public void setRole(ParticipantRole role) {
127  this.role = role;
128  if(role.equals(ParticipantRole.PARTICIPANT_OWNER)) {
129  showAllAttachments = true;
130  showAllIssues = true;
131  showParticipants = true;
132  } else if(role.equals(ParticipantRole.PARTICIPANT_SUBJECT)) {
133  showAllAttachments = false;
134  showAllIssues = false;
135  showParticipants = false;
136  receiveAllEmails = false;
137  bindingVote = false;
138  }
139  }
140 
141  @Override
142  public String getDiscriminator() {
143  return discriminator;
144  }
145 
146  public void setDiscriminator(String discriminator) {
147  this.discriminator = discriminator;
148  }
149 
150  @Override
151  public boolean isShowAllAttachments() {
152  return showAllAttachments && !role.equals(ParticipantRole.PARTICIPANT_SUBJECT);
153  }
154 
155  public void setShowAllAttachments(boolean showAllAttachments) {
156  this.showAllAttachments = showAllAttachments;
157  }
158 
159  @Override
160  public boolean isShowAllIssues() {
161  return showAllIssues && !role.equals(ParticipantRole.PARTICIPANT_SUBJECT);
162  }
163 
164  public void setShowAllIssues(boolean showAllIssues) {
165  this.showAllIssues = showAllIssues;
166  }
167 
168  @Override
169  public boolean isShowParticipants() {
170  return showParticipants && !role.equals(ParticipantRole.PARTICIPANT_SUBJECT);
171  }
172 
173  public void setShowParticipants(boolean showParticipants) {
174  this.showParticipants = showParticipants;
175  }
176 
177  @Override
178  public boolean isBindingVote() {
179  return bindingVote && !role.equals(ParticipantRole.PARTICIPANT_SUBJECT);
180  }
181 
182  public void setBindingVote(boolean bindingVote) {
183  this.bindingVote = bindingVote;
184  }
185 
186  @Override
187  public boolean isDriver() {
188  return driver;
189  }
190 
191  public void setDriver(boolean driver) {
192  this.driver = driver;
193  }
194 
195  @Override
196  public boolean isCoordinator() {
197  return coordinator;
198  }
199 
200  public void setCoordinator(boolean coordinator) {
201  this.coordinator = coordinator;
202  }
203 
204  @Override
205  public boolean isBeneficiary() {
206  return beneficiary;
207  }
208 
209  public void setBeneficiary(boolean beneficiary) {
210  this.beneficiary = beneficiary;
211  }
212 
213  @Override
214  public boolean isOfferer() {
215  return offerer;
216  }
217 
218  public void setOfferer(boolean offerer) {
219  this.offerer = offerer;
220  }
221 
222  @Override
223  public boolean isResearch() {
224  return research;
225  }
226 
227  public void setResearch(boolean research) {
228  this.research = research;
229  }
230 
231  @Override
232  public boolean isFunding() {
233  return funding;
234  }
235 
236  public void setFunding(boolean funding) {
237  this.funding = funding;
238  }
239 
240  @Override
241  public boolean isSupport() {
242  return support;
243  }
244 
245  public void setSupport(boolean support) {
246  this.support = support;
247  }
248 
249  @Override
250  public boolean isConsortium() {
251  return consortium;
252  }
253 
254  public void setConsortium(boolean consortium) {
255  this.consortium = consortium;
256  }
257 
258  @Override
259  public boolean isAdmin() {
260  return admin;
261  }
262 
263  public void setAdmin(boolean admin) {
264  this.admin = admin;
265  }
266 
267  @Override
268  public boolean hasRole() {
269  return driver || coordinator || beneficiary || offerer ||
270  research || funding || support || consortium || admin;
271  }
272 
273  /* IDaoEntity */
274 
275  @Override
276  public Object entityId() {
277  return id;
278  }
279 
280  @Override
281  public boolean isEmpty() {
282  return role == null || !getIContact().isValid();
283  }
284 
285  /* Helpers */
286 
287  @Override
288  public boolean isSubject() {
289  return ParticipantRole.PARTICIPANT_SUBJECT.equals(role);
290  }
291 
292  @Override
293  public HashSet<String> getStringRoles() {
294  return RoleUtil.getStringRoles(this);
295  }
296 
299  private transient IContact _contact, _company;
300 
302  return getIContact();
303  }
304 
305  @Override
307  if(_contact == null) {
308  _contact = Contacts.getContactById(idContact);
309  }
310  return _contact;
311  }
312 
313  public void setIContact(IContact contact) {
314  _contact = contact;
315  idContact = _contact != null ? _contact.getId() : null;
316  name = _contact != null ? _contact.getName() : null;
317  }
318 
319  private void resetIContact() {
320  _contact = null;
321  }
322 
323  @Override
324  public IContact getCompany() {
325  if(_company == null) {
326  _company = getIContact().getCompanyRelations().getCompany();
327  }
328  return _company;
329  }
330 
331  /* Utils */
332 
333  @Override
334  public int hashCode() {
335  int hash = 7;
336  hash = 71 * hash + Objects.hashCode(this.id);
337  return hash;
338  }
339 
340  @Override
341  public boolean equals(Object obj) {
342  if (this == obj) {
343  return true;
344  }
345  if (obj == null) {
346  return false;
347  }
348  if (getClass() != obj.getClass()) {
349  return false;
350  }
351  final Participant other = (Participant) obj;
352  return Objects.equals(this.id, other.id);
353  }
354 
355 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setBindingVote(boolean bindingVote)
void setConsortium(boolean consortium)
void setResearch(boolean research)
void setReceiveAllEmails(boolean receiveAllEmails)
void setShowParticipants(boolean showParticipants)
void setDiscriminator(String discriminator)
void setCoordinator(boolean coordinator)
void setShowAllAttachments(boolean showAllAttachments)
void setIdContact(String idContact)
void setBeneficiary(boolean beneficiary)
void setShowAllIssues(boolean showAllIssues)
void setIContact(IContact contact)
void setDossier(Dossier dossier)
void setRole(ParticipantRole role)
static HashSet< String > getStringRoles(IDossierParticipant dp)
Definition: RoleUtil.java:35