BrightSide Workbench Full Report + Source Code
DossierAssistants.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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.assistant;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Set;
24 import org.turro.annotation.ExternalAssistant;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.entity.Category;
27 import org.turro.dossier.entity.Dossier;
28 import org.turro.dossier.entity.IDossierParticipant;
29 import org.turro.dossier.entity.Issue;
30 import org.turro.dossier.entity.IssueParticipant;
31 import org.turro.dossier.entity.Participant;
32 import org.turro.entities.Entities;
33 import org.turro.jpa.Dao;
34 import org.turro.plugin.contacts.IContact;
35 import org.turro.sql.SqlClause;
36 
41 @ExternalAssistant
42 public class DossierAssistants implements IAssistant {
43 
44  @Override
45  public void add(Object entity, boolean deep, AssistantSet assistants, Object data) {
46  if(entity instanceof String) {
47  addFromEntityPath((String) entity, deep, assistants, data);
48  } else {
49  addFromEntity(entity, deep, assistants, data);
50  }
51  }
52 
53  @Override
54  public void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data) {
55  Object entity = Entities.getController(entityPath).getEntity();
56  addFromEntity(entity, deep, assistants, data);
57  }
58 
59  @Override
60  public void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data) {
61  if(entity instanceof Category) {
62  Category category = (Category) entity;
63  assistants.addSubject(category.getFullDescription());
64  Set ps = deep ? category.getFullParticipants() : category.getParticipants();
65  for(Object p : ps) {
66  if(p instanceof IDossierParticipant) {
68  if(!dp.isSubject()) {
69  IContact c = dp.getIContact();
70  if(c != null && c.isWebUser()) {
71  assistants.add(new Assistant(c, dp));
72  }
73  }
74  }
75  }
76  } else if(entity instanceof Dossier) {
77  Dossier dossier = (Dossier) entity;
78  assistants.addSubject(dossier.getFullDescription());
79  Set ps = deep ? dossier.getFullParticipants() : dossier.getParticipants();
80  for(Object p : ps) {
81  if(p instanceof IDossierParticipant) {
83  if(!dp.isSubject()) {
84  IContact c = dp.getIContact();
85  if(c != null && c.isWebUser()) {
86  assistants.add(new Assistant(c, dp));
87  }
88  }
89  }
90  }
91  } else if(entity instanceof Issue) {
92  Issue issue = (Issue) entity;
93  assistants.addSubject(issue.getFullDescription());
94  Set ps = deep ? issue.getFullParticipants() : issue.getParticipants();
95  for(Object p : ps) {
96  if(p instanceof IDossierParticipant) {
98  if(!dp.isSubject() && dp.isShowAllIssues()) {
99  IContact c = dp.getIContact();
100  if(c != null && c.isWebUser()) {
101  assistants.add(new Assistant(c, dp));
102  }
103  }
104  } else if(p instanceof IssueParticipant) {
106  IContact c = ip.getIContact();
107  if(c != null && c.isWebUser()) {
108  assistants.add(new Assistant(c, ip));
109  }
110  }
111  }
112  }
113  }
114 
115  @Override
116  public void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data) {
117  Object entity = Entities.getController(entityPath).getEntity();
118  addFromEntityData(entity, assistants, data);
119  }
120 
121  @Override
122  public void addFromEntityData(Object entity, AssistantSet assistants, Object data) {
123  //TODO: contracts->dossier
124  }
125 
126  @Override
127  public List<String> getParticiped(IContact contact) {
128  Dao dao = new DossierPU();
129  List<String> participed = new ArrayList<>();
130 // participed.addAll(SqlClause.select("distinct p.issue.id").from("IssueParticipant p")
131 // .where().equal("p.idContact", contact.getId())
132 // .dao(dao)
133 // .resultList(Long.class)
134 // .stream()
135 // .map(p -> "/issue/" + p)
136 // .toList());
137  participed.addAll(SqlClause.select("distinct p.dossier.id").from("Participant p")
138  .where().equal("p.idContact", contact.getId())
139  .dao(dao)
140  .resultList(Long.class)
141  .stream()
142  .map(p -> "/dossier/" + p)
143  .toList());
144  participed.addAll(SqlClause.select("distinct p.category.id").from("CategoryParticipant p")
145  .where().equal("p.idContact", contact.getId())
146  .dao(dao)
147  .resultList(Long.class)
148  .stream()
149  .map(p -> "/dossier-category/" + p)
150  .toList());
151  return participed;
152  }
153 
154 }
void addFromEntityData(Object entity, AssistantSet assistants, Object data)
void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data)
void add(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data)
List< String > getParticiped(IContact contact)
void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data)
Set< CategoryParticipant > getParticipants()
Definition: Category.java:116
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Category.java:270
Set< Participant > getParticipants()
Definition: Dossier.java:175
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Dossier.java:399
ParticipantSet getFullParticipants()
Definition: Issue.java:461
Set< IssueParticipant > getParticipants()
Definition: Issue.java:114
static IElephantEntity getController(String path)
Definition: Entities.java:78