BrightSide Workbench Full Report + Source Code
DossierVisualElement.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.Collection;
22 import java.util.EnumSet;
23 import java.util.HashSet;
24 import java.util.Set;
25 import org.turro.dossier.dossier.ParticipantSet;
26 import org.turro.dossier.entity.Dossier;
27 import org.turro.dossier.entity.Issue;
28 import org.turro.dossier.entity.IssueResolution;
29 import org.turro.dossier.entity.IssueType;
30 import org.turro.dossier.entity.ParticipantRole;
31 import org.turro.phase.PhaseType;
32 import org.turro.plugin.contacts.IContact;
33 
38 public class DossierVisualElement extends VisualElement<DossierVisualElements, DossierVisualElement, Dossier> {
39 
40  private Set<Integer> phases;
41  private EnumSet<PhaseType> phaseTypes;
42  private EnumSet<ParticipantRole> roles;
43  private HashSet<String> discriminators;
44  private Boolean showAllAttachments, showParticipants, showAllIssues, receiveAllEmails, bindingVote,
45  driver, coordinator, beneficiary, offerer, research, funding, support;
46  private Boolean directOwner, participates, branchAdmin;
47 
48  public DossierVisualElement(String name, DossierVisualElements factory) {
49  super(name, factory);
50  }
51 
52  public DossierVisualElement setShowAllAttachments(Boolean showAllAttachments) {
53  this.showAllAttachments = showAllAttachments;
54  return this;
55  }
56 
57  public DossierVisualElement setShowParticipants(Boolean showParticipants) {
58  this.showParticipants = showParticipants;
59  return this;
60  }
61 
62  public DossierVisualElement setShowAllIssues(Boolean showAllIssues) {
63  this.showAllIssues = showAllIssues;
64  return this;
65  }
66 
67  public DossierVisualElement setReceiveAllEmails(Boolean receiveAllEmails) {
68  this.receiveAllEmails = receiveAllEmails;
69  return this;
70  }
71 
72  public DossierVisualElement setBindingVote(Boolean bindingVote) {
73  this.bindingVote = bindingVote;
74  return this;
75  }
76 
77  public DossierVisualElement setDriver(Boolean driver) {
78  this.driver = driver;
79  return this;
80  }
81 
82  public DossierVisualElement setCoordinator(Boolean coordinator) {
83  this.coordinator = coordinator;
84  return this;
85  }
86 
87  public DossierVisualElement setBeneficiary(Boolean beneficiary) {
88  this.beneficiary = beneficiary;
89  return this;
90  }
91 
92  public DossierVisualElement setOfferer(Boolean offerer) {
93  this.offerer = offerer;
94  return this;
95  }
96 
97  public DossierVisualElement setResearch(Boolean research) {
98  this.research = research;
99  return this;
100  }
101 
102  public DossierVisualElement setFunding(Boolean funding) {
103  this.funding = funding;
104  return this;
105  }
106 
107  public DossierVisualElement setSupport(Boolean support) {
108  this.support = support;
109  return this;
110  }
111 
112  public DossierVisualElement setDirectOwner(Boolean directOwner) {
113  this.directOwner = directOwner;
114  return this;
115  }
116 
117  public DossierVisualElement setParticipates(Boolean participates) {
118  this.participates = participates;
119  return this;
120  }
121 
122  public DossierVisualElement setBranchAdmin(Boolean branchAdmin) {
123  this.branchAdmin = branchAdmin;
124  return this;
125  }
126 
127  public DossierVisualElement addPhase(int phase) {
128  if(phase > -1) {
129  if(phases == null) {
130  phases = new HashSet<>();
131  }
132  phases.add(phase);
133  }
134  return this;
135  }
136 
138  if(phaseTypes == null) {
139  phaseTypes = EnumSet.of(type);
140  } else {
141  phaseTypes.add(type);
142  }
143  return this;
144  }
145 
147  if(roles == null) {
148  roles = EnumSet.of(role);
149  } else {
150  roles.add(role);
151  }
152  return this;
153  }
154 
155  public DossierVisualElement addDiscriminator(String discriminator) {
156  if(discriminators == null) {
157  discriminators = new HashSet<>();
158  }
159  discriminators.add(discriminator);
160  return this;
161  }
162 
163  @Override
164  protected boolean emptyEntityConstraints() {
165  return roles == null && discriminators == null && participates == null &&
166  directOwner == null && branchAdmin == null && showAllAttachments == null &&
167  showParticipants == null && showAllIssues == null && receiveAllEmails == null &&
168  bindingVote == null && driver == null && coordinator == null &&
169  beneficiary == null && offerer == null && research == null &&
170  funding == null && support == null;
171  }
172 
173  @Override
174  protected boolean checkAllMatch(Dossier entity, IContact contact) {
175  return entity.getProject() == null || (
176  (phases == null || phases.contains(entity.getProject().getPhase())) &&
177  (phaseTypes == null || entity.getProject().getPhaseDefinition().anyTypeMatch(phaseTypes)));
178  }
179 
180  @Override
181  protected boolean checkAnyMatch(Dossier entity, IContact contact) {
182  ParticipantSet dpl = entity.getFullParticipants();
183 
184  return checkRoles(dpl, contact) ||
185  checkDiscriminators(dpl, contact) ||
186  checkAttributes(dpl, contact) ||
187  checkDirectOwner(entity, contact) ||
188  checkBranchAdmin(entity, contact) ||
189  checkParticipates(dpl, contact);
190  }
191 
192  @Override
193  protected boolean checkEval(Dossier entity,IContact contact) {
194  if(hasScript()) {
195  getScript().addVariable("dossier", entity);
196  getScript().addVariable("dpl", entity.getFullParticipants());
197  return super.checkEval(entity, contact);
198  }
199  return false;
200  }
201 
202  private boolean checkRoles(ParticipantSet dpl, IContact contact) {
203  if(roles != null) {
204  for(ParticipantRole role : roles) {
205  if(dpl.isRole(contact, role)) {
206  return true;
207  }
208  }
209  }
210  return false;
211  }
212 
213  private boolean checkDiscriminators(ParticipantSet dpl, IContact contact) {
214  if(discriminators != null) {
215  for(String discriminator : discriminators) {
216  if(dpl.isParticipantByDiscriminator(contact, discriminator)) {
217  return true;
218  }
219  }
220  }
221  return false;
222  }
223 
224  private boolean checkAttributes(ParticipantSet dpl, IContact contact) {
225  return (showAllAttachments == null ? false : showAllAttachments.equals(dpl.isShowAllAttachments(contact))) ||
226  (showParticipants == null ? false : showParticipants.equals(dpl.isShowParticipants(contact))) ||
227  (showAllIssues == null ? false : showAllIssues.equals(dpl.isShowAllIssues(contact))) ||
228  (receiveAllEmails == null ? false : receiveAllEmails.equals(dpl.isReceiveAllEmails(contact))) ||
229  (bindingVote == null ? false : bindingVote.equals(dpl.isBindingVote(contact))) ||
230  (driver == null ? false : driver.equals(dpl.isDriver(contact))) ||
231  (coordinator == null ? false : coordinator.equals(dpl.isCoordinator(contact))) ||
232  (beneficiary == null ? false : beneficiary.equals(dpl.isBeneficiary(contact))) ||
233  (offerer == null ? false : offerer.equals(dpl.isOfferer(contact))) ||
234  (research == null ? false : research.equals(dpl.isResearch(contact))) ||
235  (funding == null ? false : funding.equals(dpl.isFunding(contact))) ||
236  (support == null ? false : support.equals(dpl.isSupport(contact))) ||
237  (branchAdmin == null ? false : branchAdmin.equals(dpl.isAdmin(contact)));
238  }
239 
240  private boolean checkParticipates(ParticipantSet dpl, IContact contact) {
241  return isNullOrFalse(participates) ? false : dpl.isParticipant(contact);
242  }
243 
244  private boolean checkDirectOwner(Dossier dossier, IContact contact) {
245  return isNullOrFalse(directOwner) ? false : dossier.isDirectOwner(contact);
246  }
247 
248  private boolean checkBranchAdmin(Dossier dossier, IContact contact) {
249  return isNullOrFalse(branchAdmin) ? false : dossier.isBranchAdmin(contact);
250  }
251 
252  /* Utility checks for sub-elements. Out of check() */
253 
254  public boolean isAdministrator(Dossier dossier, IContact contact) {
255  return checkContact(contact) && dossier.isBranchAdmin(contact);
256  }
257 
258  public boolean isPatron(IContact contact) {
259  return checkContact(contact) && contact.getSyndications().contains("patron");
260  }
261 
262  public boolean isInComission(Dossier dossier, IContact contact) {
263  return checkContact(contact) && dossier.getFullParticipants().isParticipant(contact);
264  }
265 
266  public boolean isPartner(IContact contact) {
267  return checkContact(contact) && contact.getSyndications().contains("partner");
268  }
269 
270  public boolean participatesAs(Dossier dossier, String discriminator, IContact contact) {
271  return checkContact(contact) && dossier.getFullParticipants().isParticipantByDiscriminator(contact, discriminator);
272  }
273 
274  public boolean participates(Dossier dossier, IContact contact) {
275  return isNullOrFalse(participates) || (checkContact(contact) && dossier.getFullParticipants().isParticipant(contact));
276  }
277 
278  public boolean isDirectOwner(Dossier dossier, IContact contact) {
279  return isNullOrFalse(directOwner) || (checkContact(contact) && dossier.isDirectOwner(contact));
280  }
281 
282  public boolean isOwnReporter(Issue issue, IContact contact) {
283  return checkContact(contact) && issue.getIssueParticipants().isReporter(contact);
284  }
285 
286  public boolean isWinReporter(Issue issue, IContact contact) {
287  if(isOwnReporter(issue, contact)) {
288  if(IssueResolution.RESOLUTION_FIXED.equals(issue.getResolution())) {
289  return true;
290  }
291  }
292  return false;
293  }
294 
295  public boolean isOwnResponsible(Issue issue, IContact contact) {
296  return checkContact(contact) && issue.getIssueParticipants().isResponsible(contact);
297  }
298 
299  public boolean isWinResponsible(Issue issue, IContact contact) {
300  if(isOwnResponsible(issue, contact)) {
301  if(IssueResolution.RESOLUTION_FIXED.equals(issue.getResolution())) {
302  return true;
303  }
304  }
305  return false;
306  }
307 
308  public boolean canShowOffer(Issue issue, IContact contact) {
309  return (getSubElements() != null && getSubElements().getElement("Offer", issue.getDossier(), contact) != null) ||
310  isOwnReporter(issue, contact);
311  }
312 
313  public boolean canShowAddDocsOffer(Issue issue, IContact contact) {
314  if((getSubElements() != null && getSubElements().getElement("Working Documents", issue.getDossier(), contact) != null) ||
315  isOwnReporter(issue, contact)) {
316  return true;
317  }
318  if((getSubElements() != null && getSubElements().getElement("Final Documents", issue.getDossier(), contact) != null) ||
319  isWinReporter(issue, contact)) {
320  return true;
321  }
322  return false;
323  }
324 
325  public boolean canShowUploadOffer(Dossier dossier, IContact contact) {
326  if(getSubElements() != null && getSubElements().getElement("Upload Offer", dossier, contact) != null) {
327  return true;
328  }
329  return false;
330  }
331 
332  public Collection<Issue> getIssuesByType(Dossier dossier, String type) {
333  return dossier.getIssuesByType(IssueType.valueOf(type));
334  }
335 
336  /* Offers */
337 
338  public boolean canShowOffer(Dossier dossier, IContact contact) {
339  return (getSubElements() != null && getSubElements().getElement("Offer", dossier, contact) != null);
340  }
341 
342  public boolean canAddWorkingOffer(Dossier dossier, IContact contact) {
343  if((getSubElements() != null && getSubElements().getElement("Working Documents", dossier, contact) != null)) {
344  return true;
345  }
346  return false;
347  }
348 
349  public boolean canAddFinalOffer(Dossier dossier, IContact contact) {
350  if((getSubElements() != null && getSubElements().getElement("Final Documents", dossier, contact) != null)) {
351  return true;
352  }
353  return false;
354  }
355 
356  public boolean canCreateOffer(Dossier dossier, IContact contact) {
357  if(getSubElements() != null && getSubElements().getElement("Upload Offer", dossier, contact) != null) {
358  return true;
359  }
360  return false;
361  }
362 
363 
364 }
boolean isDirectOwner(IContact contact)
Definition: Dossier.java:569
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Dossier.java:399
Collection< Issue > getIssuesByType(IssueType type)
Definition: Dossier.java:362
boolean isBranchAdmin(IContact contact)
Definition: Dossier.java:580
IssueResolution getResolution()
Definition: Issue.java:226
ParticipantSet< IssueParticipant > getIssueParticipants()
Definition: Issue.java:469
boolean anyTypeMatch(Collection< PhaseType > types)
boolean canCreateOffer(Dossier dossier, IContact contact)
DossierVisualElement setDriver(Boolean driver)
DossierVisualElement setDirectOwner(Boolean directOwner)
boolean isWinReporter(Issue issue, IContact contact)
boolean canShowOffer(Issue issue, IContact contact)
boolean canShowAddDocsOffer(Issue issue, IContact contact)
DossierVisualElement setResearch(Boolean research)
DossierVisualElement setShowParticipants(Boolean showParticipants)
boolean canAddFinalOffer(Dossier dossier, IContact contact)
DossierVisualElement setShowAllIssues(Boolean showAllIssues)
DossierVisualElement addPhase(int phase)
DossierVisualElement addDiscriminator(String discriminator)
boolean participatesAs(Dossier dossier, String discriminator, IContact contact)
boolean canShowOffer(Dossier dossier, IContact contact)
DossierVisualElement setFunding(Boolean funding)
DossierVisualElement addRole(ParticipantRole role)
boolean isInComission(Dossier dossier, IContact contact)
DossierVisualElement setBranchAdmin(Boolean branchAdmin)
boolean participates(Dossier dossier, IContact contact)
boolean isOwnResponsible(Issue issue, IContact contact)
DossierVisualElement setCoordinator(Boolean coordinator)
DossierVisualElement(String name, DossierVisualElements factory)
boolean canShowUploadOffer(Dossier dossier, IContact contact)
DossierVisualElement setParticipates(Boolean participates)
boolean isDirectOwner(Dossier dossier, IContact contact)
boolean checkAnyMatch(Dossier entity, IContact contact)
DossierVisualElement setBindingVote(Boolean bindingVote)
boolean checkEval(Dossier entity, IContact contact)
DossierVisualElement setOfferer(Boolean offerer)
boolean isWinResponsible(Issue issue, IContact contact)
Collection< Issue > getIssuesByType(Dossier dossier, String type)
DossierVisualElement setShowAllAttachments(Boolean showAllAttachments)
DossierVisualElement setSupport(Boolean support)
boolean canAddWorkingOffer(Dossier dossier, IContact contact)
boolean isOwnReporter(Issue issue, IContact contact)
DossierVisualElement setBeneficiary(Boolean beneficiary)
boolean isAdministrator(Dossier dossier, IContact contact)
DossierVisualElement addPhaseType(PhaseType type)
boolean checkAllMatch(Dossier entity, IContact contact)
DossierVisualElement setReceiveAllEmails(Boolean receiveAllEmails)