BrightSide Workbench Full Report + Source Code
DossierParticipationsList.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.dossier.dossier;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.Set;
25 import java.util.TreeSet;
26 import java.util.function.Predicate;
27 import org.turro.string.Strings;
28 import org.turro.auth.Authentication;
29 import org.turro.dossier.entity.Category;
30 import org.turro.dossier.entity.CategoryParticipant;
31 import org.turro.dossier.entity.Dossier;
32 import org.turro.dossier.entity.IDossierParticipant;
33 import org.turro.dossier.entity.Participant;
34 import org.turro.dossier.entity.ParticipantRole;
35 import org.turro.plugin.contacts.ContactList;
36 import org.turro.plugin.contacts.IContact;
37 import org.turro.visual.RoleUtil;
38 
43 @Deprecated
44 public class DossierParticipationsList extends ArrayList<IDossierParticipant> {
45 
47  addAll(dossier.getParticipants());
48  Category category = dossier.getCategory();
49  while(category != null) {
50  addAll(category.getParticipants());
51  category = category.getParent();
52  }
53  }
54 
55  public boolean isParticipant() {
56  return isParticipant(getContact(null));
57  }
58 
59  public boolean isParticipant(IContact contact) {
60  return getParticipation(contact) != null;
61  }
62 
63  public boolean isDossierParticipant(IContact contact) {
64  return getParticipation(contact) instanceof Participant;
65  }
66 
67  public boolean isCategoryParticipant(IContact contact) {
68  return getParticipation(contact) instanceof CategoryParticipant;
69  }
70 
72  for(IDossierParticipant dp : this) {
73  if(dp.getRole().equals(participation) && dp.getIdContact().equals(getContact(contact).getId())) {
74  return dp;
75  }
76  }
77  return null;
78  }
79 
81  for(IDossierParticipant dp : this) {
82  if(!dp.getRole().equals(ParticipantRole.PARTICIPANT_SUBJECT) && dp.getIdContact().equals(contact.getId())) {
83  return dp;
84  }
85  }
86  return null;
87  }
88 
89  public String getDiscriminator(IContact contact) {
91  return dp != null ? dp.getDiscriminator() : null;
92  }
93 
94  public boolean isParticipantByDiscriminator(IContact contact, String discriminator) {
95  for(IDossierParticipant dp : this) {
96  if(dp != null && !Strings.isBlank(discriminator) && discriminator.equalsIgnoreCase(dp.getDiscriminator())
97  && dp.getIdContact().equals(contact.getId())) {
98  return true;
99  }
100  }
101  return false;
102  }
103 
104  public Collection<String> getDiscriminators() {
105  Set<String> discriminators = new TreeSet<>();
106  for(Object obj : this) {
107  if(obj instanceof IDossierParticipant) {
109  discriminators.add(dp.getDiscriminator() == null ? "" : dp.getDiscriminator());
110  }
111 
112  }
113  return discriminators;
114  }
115 
116  public Collection<IDossierParticipant> getParticipantsByDiscriminator(String discriminator) {
117  Set<IDossierParticipant> participants = new ParticipantSet<>();
118  for(IDossierParticipant dp : this) {
119  if((Strings.isBlank(discriminator) && Strings.isBlank(dp.getDiscriminator())) ||
120  discriminator.equals(dp.getDiscriminator())) {
121  participants.add(dp);
122  }
123  }
124  return participants;
125  }
126 
127  public HashSet<String> getParticipationStrings(IContact contact) {
128  HashSet<String> set = new HashSet<>();
129  for(IDossierParticipant dp : this) {
130  set.addAll(RoleUtil.getStringRoles(dp));
131  }
132  return set;
133  }
134 
135  /* IContact helpers */
136 
137  public Collection<IContact> getIParticipants() {
138  ContactList list = new ContactList();
139  this.stream().map((obj) -> (IDossierParticipant) obj).forEachOrdered((dp) -> {
140  list.add(dp.getIContact());
141  });
142  return list;
143  }
144 
145  public boolean isRole(IContact contact, ParticipantRole role) {
146  for(IDossierParticipant dp : this) {
147  if(dp.getIdContact().equals(contact.getId()) && dp.getRole().equals(role)) {
148  return true;
149  }
150  }
151  return false;
152  }
153 
154  public boolean isOwner(IContact contact) {
155  return isRole(contact, ParticipantRole.PARTICIPANT_OWNER);
156  }
157 
158  public boolean isAssistant(IContact contact) {
160  }
161 
162  public boolean isSubject(IContact contact) {
163  return isRole(contact, ParticipantRole.PARTICIPANT_SUBJECT);
164  }
165 
166  public boolean isShowAllAttachments(IContact contact) {
167  return getIShowAllAttachments().contains(getContact(contact));
168  }
169 
170  public boolean isShowAllIssues(IContact contact) {
171  return getIShowAllIssues().contains(getContact(contact));
172  }
173 
174  public boolean isShowParticipants(IContact contact) {
175  return getIShowParticipants().contains(getContact(contact));
176  }
177 
178  public boolean isReceiveAllEmails(IContact contact) {
179  return getIReceiveAllEmails().contains(getContact(contact));
180  }
181 
182  public boolean isBindingVote(IContact contact) {
183  return getIBidingVote().contains(getContact(contact));
184  }
185 
186  public boolean isDriver(IContact contact) {
187  return getIDrivers().contains(getContact(contact));
188  }
189 
190  public boolean isOfferer(IContact contact) {
191  return getIOfferers().contains(getContact(contact));
192  }
193 
194  public boolean isBeneficiary(IContact contact) {
195  return getIBeneficiaries().contains(getContact(contact));
196  }
197 
198  public boolean isCoordinator(IContact contact) {
199  return getICoordinators().contains(getContact(contact));
200  }
201 
202  public boolean isSupport(IContact contact) {
203  return getISupport().contains(getContact(contact));
204  }
205 
206  public boolean isFunding(IContact contact) {
207  return getIFunding().contains(getContact(contact));
208  }
209 
210  public boolean isResearch(IContact contact) {
211  return getIResearch().contains(getContact(contact));
212  }
213 
214  public boolean isAdmin(IContact contact) {
215  return getIAdmins().contains(getContact(contact));
216  }
217 
218  public Collection<IContact> getIOwners() {
219  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) ->
221  }
222 
223  public Collection<IContact> getIAssistants() {
224  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) ->
226  }
227 
228  public Collection<IContact> getISubjects() {
229  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) ->
231  }
232 
233  public Collection<IContact> getIShowAllAttachments() {
234  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isShowAllAttachments());
235  }
236 
237  public Collection<IContact> getIShowAllIssues() {
238  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isShowAllIssues());
239  }
240 
241  public Collection<IContact> getIShowParticipants() {
242  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isShowParticipants());
243  }
244 
245  public Collection<IContact> getIReceiveAllEmails() {
246  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isReceiveAllEmails());
247  }
248 
249  public Collection<IContact> getIBidingVote() {
250  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isBindingVote());
251  }
252 
253  public Collection<IContact> getIDrivers() {
254  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isDriver());
255  }
256 
257  public Collection<IContact> getIOfferers() {
258  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isOfferer());
259  }
260 
261  public Collection<IContact> getIBeneficiaries() {
262  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isBeneficiary());
263  }
264 
265  public Collection<IContact> getICoordinators() {
266  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isCoordinator());
267  }
268 
269  public Collection<IContact> getISupport() {
270  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isSupport());
271  }
272 
273  public Collection<IContact> getIFunding() {
274  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isFunding());
275  }
276 
277  public Collection<IContact> getIResearch() {
278  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isResearch());
279  }
280 
281  public Collection<IContact> getIAdmins() {
282  return getIContactsByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isAdmin());
283  }
284 
285  public Collection<IContact> getIContactsByFunction(Predicate whatIs) {
286  ContactList list = new ContactList();
287  this.stream().filter((dp) -> (whatIs.test(dp))).forEachOrdered((dp) -> {
288  list.add(dp.getIContact());
289  });
290  return list;
291  }
292 
293  public Collection<IDossierParticipant> getOwners() {
294  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) ->
296  }
297 
298  public Collection<IDossierParticipant> getAssistants() {
299  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) ->
301  }
302 
303  public Collection<IDossierParticipant> getSubjects() {
304  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) ->
306  }
307 
308  public Collection<IDossierParticipant> getShowAllAttachments() {
309  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isShowAllAttachments());
310  }
311 
312  public Collection<IDossierParticipant> getShowAllIssues() {
313  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isShowAllIssues());
314  }
315 
316  public Collection<IDossierParticipant> getShowParticipants() {
317  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isShowParticipants());
318  }
319 
320  public Collection<IDossierParticipant> getReceiveAllEmails() {
321  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isReceiveAllEmails());
322  }
323 
324  public Collection<IDossierParticipant> getBidingVote() {
325  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isBindingVote());
326  }
327 
328  public Collection<IDossierParticipant> getDrivers() {
329  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isDriver());
330  }
331 
332  public Collection<IDossierParticipant> getOfferers() {
333  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isOfferer());
334  }
335 
336  public Collection<IDossierParticipant> getBeneficiaries() {
337  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isBeneficiary());
338  }
339 
340  public Collection<IDossierParticipant> getCoordinators() {
341  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isCoordinator());
342  }
343 
344  public Collection<IDossierParticipant> getSupport() {
345  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isSupport());
346  }
347 
348  public Collection<IDossierParticipant> getFunding() {
349  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isFunding());
350  }
351 
352  public Collection<IDossierParticipant> getResearch() {
353  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isResearch());
354  }
355 
356  public Collection<IDossierParticipant> getAdmins() {
357  return getByFunction((Predicate<IDossierParticipant>) (IDossierParticipant t) -> t.isAdmin());
358  }
359 
360  public Collection<IDossierParticipant> getByFunction(Predicate whatIs) {
361  ArrayList list = new ArrayList();
362  this.stream().filter((dp) -> (whatIs.test(dp))).forEachOrdered((dp) -> {
363  list.add(dp);
364  });
365  return list;
366  }
367 
368  /* Authenticated */
369 
370  private IContact _contact;
371 
372  private IContact getContact(IContact contact) {
373  if(contact != null) {
374  _contact = contact;
375  }
376  if(_contact == null) {
377  _contact = Authentication.getIContact();
378  }
379  return _contact;
380  }
381 
382 }
Collection< IDossierParticipant > getParticipantsByDiscriminator(String discriminator)
boolean isRole(IContact contact, ParticipantRole role)
boolean isParticipantByDiscriminator(IContact contact, String discriminator)
Collection< IContact > getIContactsByFunction(Predicate whatIs)
IDossierParticipant participatesAs(IContact contact, ParticipantRole participation)
Collection< IDossierParticipant > getByFunction(Predicate whatIs)
Set< CategoryParticipant > getParticipants()
Definition: Category.java:116
Set< Participant > getParticipants()
Definition: Dossier.java:175
static HashSet< String > getStringRoles(IDossierParticipant dp)
Definition: RoleUtil.java:35