BrightSide Workbench Full Report + Source Code
CategoryVisualElement.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.visual;
20 
21 import java.util.EnumSet;
22 import java.util.HashSet;
23 import org.turro.dossier.dossier.ParticipantSet;
24 import org.turro.dossier.entity.Category;
25 import org.turro.dossier.entity.ParticipantRole;
26 import org.turro.plugin.contacts.IContact;
27 import org.turro.script.DossierFunctions;
28 
33 public class CategoryVisualElement extends VisualElement<CategoryVisualElements, CategoryVisualElement, Category> {
34 
35  private EnumSet<ParticipantRole> roles;
36  private HashSet<String> discriminators;
37  private Boolean showAllAttachments, showParticipants, showAllIssues, receiveAllEmails, bindingVote,
38  driver, coordinator, beneficiary, offerer, research, funding, support;
39  private Boolean directOwner, participates, branchAdmin;
40 
41  public CategoryVisualElement(String name, CategoryVisualElements factory) {
42  super(name, factory);
43  }
44 
45  public CategoryVisualElement setShowAllAttachments(Boolean showAllAttachments) {
46  this.showAllAttachments = showAllAttachments;
47  return this;
48  }
49 
50  public CategoryVisualElement setShowParticipants(Boolean showParticipants) {
51  this.showParticipants = showParticipants;
52  return this;
53  }
54 
55  public CategoryVisualElement setShowAllIssues(Boolean showAllIssues) {
56  this.showAllIssues = showAllIssues;
57  return this;
58  }
59 
60  public CategoryVisualElement setReceiveAllEmails(Boolean receiveAllEmails) {
61  this.receiveAllEmails = receiveAllEmails;
62  return this;
63  }
64 
65  public CategoryVisualElement setBindingVote(Boolean bindingVote) {
66  this.bindingVote = bindingVote;
67  return this;
68  }
69 
70  public CategoryVisualElement setDriver(Boolean driver) {
71  this.driver = driver;
72  return this;
73  }
74 
75  public CategoryVisualElement setCoordinator(Boolean coordinator) {
76  this.coordinator = coordinator;
77  return this;
78  }
79 
80  public CategoryVisualElement setBeneficiary(Boolean beneficiary) {
81  this.beneficiary = beneficiary;
82  return this;
83  }
84 
85  public CategoryVisualElement setOfferer(Boolean offerer) {
86  this.offerer = offerer;
87  return this;
88  }
89 
90  public CategoryVisualElement setResearch(Boolean research) {
91  this.research = research;
92  return this;
93  }
94 
95  public CategoryVisualElement setFunding(Boolean funding) {
96  this.funding = funding;
97  return this;
98  }
99 
100  public CategoryVisualElement setSupport(Boolean support) {
101  this.support = support;
102  return this;
103  }
104 
105  public CategoryVisualElement setDirectOwner(Boolean directOwner) {
106  this.directOwner = directOwner;
107  return this;
108  }
109 
110  public CategoryVisualElement setParticipates(Boolean participates) {
111  this.participates = participates;
112  return this;
113  }
114 
115  public CategoryVisualElement setBranchAdmin(Boolean branchAdmin) {
116  this.branchAdmin = branchAdmin;
117  return this;
118  }
119 
121  if(roles == null) {
122  roles = EnumSet.of(role);
123  } else {
124  roles.add(role);
125  }
126  return this;
127  }
128 
129  public CategoryVisualElement addDiscriminator(String discriminator) {
130  if(discriminators == null) {
131  discriminators = new HashSet<>();
132  }
133  discriminators.add(discriminator);
134  return this;
135  }
136 
137  @Override
138  protected boolean emptyEntityConstraints() {
139  return roles == null && discriminators == null && participates == null &&
140  directOwner == null && branchAdmin == null && showAllAttachments == null &&
141  showParticipants == null && showAllIssues == null && receiveAllEmails == null &&
142  bindingVote == null && driver == null && coordinator == null &&
143  beneficiary == null && offerer == null && research == null &&
144  funding == null && support == null;
145  }
146 
147  @Override
148  protected boolean checkEval(Category entity,IContact contact) {
149  if(hasScript()) {
150  getScript().addMethodsFromClass(DossierFunctions.class);
151  getScript().addVariable("category", entity);
152  getScript().addVariable("dpl", entity.getFullParticipants());
153  return super.checkEval(entity, contact);
154  }
155  return false;
156  }
157 
158  @Override
159  protected boolean checkAllMatch(Category entity, IContact contact) {
160  return true;
161  }
162 
163  @Override
164  protected boolean checkAnyMatch(Category entity, IContact contact) {
165  ParticipantSet dpl = entity.getFullParticipants();
166 
167  return checkRoles(dpl, contact) ||
168  checkDiscriminators(dpl, contact) ||
169  checkAttributes(dpl, contact) ||
170  checkDirectOwner(entity, contact) ||
171  checkBranchAdmin(entity, contact) ||
172  checkParticipates(dpl, contact);
173  }
174 
175  private boolean checkRoles(ParticipantSet dpl, IContact contact) {
176  if(roles != null) {
177  for(ParticipantRole role : roles) {
178  if(dpl.isRole(contact, role)) {
179  return true;
180  }
181  }
182  }
183  return false;
184  }
185 
186  private boolean checkDiscriminators(ParticipantSet dpl, IContact contact) {
187  if(discriminators != null) {
188  for(String discriminator : discriminators) {
189  if(dpl.isParticipantByDiscriminator(contact, discriminator)) {
190  return true;
191  }
192  }
193  }
194  return false;
195  }
196 
197  private boolean checkAttributes(ParticipantSet dpl, IContact contact) {
198  return (showAllAttachments == null ? false : showAllAttachments.equals(dpl.isShowAllAttachments(contact))) ||
199  (showParticipants == null ? false : showParticipants.equals(dpl.isShowParticipants(contact))) ||
200  (showAllIssues == null ? false : showAllIssues.equals(dpl.isShowAllIssues(contact))) ||
201  (receiveAllEmails == null ? false : receiveAllEmails.equals(dpl.isReceiveAllEmails(contact))) ||
202  (bindingVote == null ? false : bindingVote.equals(dpl.isBindingVote(contact))) ||
203  (driver == null ? false : driver.equals(dpl.isDriver(contact))) ||
204  (coordinator == null ? false : coordinator.equals(dpl.isCoordinator(contact))) ||
205  (beneficiary == null ? false : beneficiary.equals(dpl.isBeneficiary(contact))) ||
206  (offerer == null ? false : offerer.equals(dpl.isOfferer(contact))) ||
207  (research == null ? false : research.equals(dpl.isResearch(contact))) ||
208  (funding == null ? false : funding.equals(dpl.isFunding(contact))) ||
209  (support == null ? false : support.equals(dpl.isSupport(contact))) ||
210  (branchAdmin == null ? false : branchAdmin.equals(dpl.isAdmin(contact)));
211  }
212 
213  private boolean checkParticipates(ParticipantSet dpl, IContact contact) {
214  return isNullOrFalse(participates) ? false : dpl.isParticipant(contact);
215  }
216 
217  private boolean checkDirectOwner(Category category, IContact contact) {
218  return isNullOrFalse(directOwner) ? false : category.isDirectOwner(contact);
219  }
220 
221  private boolean checkBranchAdmin(Category category, IContact contact) {
222  return isNullOrFalse(branchAdmin) ? false : category.isBranchAdmin(contact);
223  }
224 
225  /* Utility checks for sub-elements. Out of check() */
226 
227  public boolean isAdministrator(Category category, IContact contact) {
228  return checkContact(contact) && category.isBranchAdmin(contact);
229  }
230 
231  public boolean isPatron(IContact contact) {
232  return checkContact(contact) && contact.getSyndications().contains("patron");
233  }
234 
235  public boolean isInComission(Category category, IContact contact) {
236  return checkContact(contact) && category.getFullParticipants().isParticipant(contact);
237  }
238 
239  public boolean isPartner(IContact contact) {
240  return checkContact(contact) && contact.getSyndications().contains("partner");
241  }
242 
243  public boolean participatesAs(Category Category, String discriminator, IContact contact) {
244  return checkContact(contact) && Category.getFullParticipants().isParticipantByDiscriminator(contact, discriminator);
245  }
246 
247  public boolean participates(Category category, IContact contact) {
248  return isNullOrFalse(participates) || (checkContact(contact) && category.getFullParticipants().isParticipant(contact));
249  }
250 
251  public boolean isDirectOwner(Category category, IContact contact) {
252  return isNullOrFalse(directOwner) || (checkContact(contact) && category.isDirectOwner(contact));
253  }
254 
255 }
boolean isBranchAdmin(IContact contact)
Definition: Category.java:235
boolean isDirectOwner(IContact contact)
Definition: Category.java:224
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Category.java:270
boolean isDirectOwner(Category category, IContact contact)
CategoryVisualElement setDirectOwner(Boolean directOwner)
CategoryVisualElement setBranchAdmin(Boolean branchAdmin)
CategoryVisualElement setBindingVote(Boolean bindingVote)
CategoryVisualElement setFunding(Boolean funding)
CategoryVisualElement setShowParticipants(Boolean showParticipants)
CategoryVisualElement setReceiveAllEmails(Boolean receiveAllEmails)
boolean participatesAs(Category Category, String discriminator, IContact contact)
boolean participates(Category category, IContact contact)
CategoryVisualElement setShowAllIssues(Boolean showAllIssues)
boolean checkAllMatch(Category entity, IContact contact)
CategoryVisualElement setParticipates(Boolean participates)
boolean isInComission(Category category, IContact contact)
CategoryVisualElement setOfferer(Boolean offerer)
CategoryVisualElement(String name, CategoryVisualElements factory)
CategoryVisualElement addDiscriminator(String discriminator)
boolean checkEval(Category entity, IContact contact)
CategoryVisualElement setDriver(Boolean driver)
boolean checkAnyMatch(Category entity, IContact contact)
CategoryVisualElement setBeneficiary(Boolean beneficiary)
CategoryVisualElement setSupport(Boolean support)
boolean isAdministrator(Category category, IContact contact)
CategoryVisualElement setResearch(Boolean research)
CategoryVisualElement addRole(ParticipantRole role)
CategoryVisualElement setShowAllAttachments(Boolean showAllAttachments)
CategoryVisualElement setCoordinator(Boolean coordinator)