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