BrightSide Workbench Full Report + Source Code
ContactsAssistant.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.Collections;
22 import java.util.List;
23 import org.turro.mail.MailValidator;
24 import org.turro.string.Strings;
25 import org.turro.action.Contacts;
26 import org.turro.annotation.ExternalAssistant;
27 import org.turro.commentit.CommentItUtil;
28 import org.turro.contacts.Attendee;
29 import org.turro.contacts.CommentIt;
30 import org.turro.contacts.Contact;
31 import org.turro.contacts.Convocation;
32 import org.turro.contacts.VoteIt;
33 import org.turro.elephant.security.IUser;
34 import org.turro.entities.Entities;
35 import org.turro.plugin.contacts.IContact;
36 import org.turro.voteit.VoteItUtil;
37 
43 public class ContactsAssistant implements IAssistant {
44 
45  @Override
46  public void add(Object entity, boolean deep, AssistantSet assistants, Object data) {
47  if(entity instanceof String) {
48  addFromEntityPath((String) entity, deep, assistants, data);
49  } else {
50  addFromEntity(entity, deep, assistants, data);
51  }
52  }
53 
54  @Override
55  public void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data) {
56  Object entity = Entities.getController(entityPath).getEntity();
57  addFromEntity(entity, deep, assistants, data);
58  }
59 
60  @Override
61  public void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data) {
62  if(entity instanceof Convocation) {
63  Convocation convocation = (Convocation) entity;
64  assistants.addSubject(convocation.getName());
65  for(Attendee attendee :convocation.getAttendees()) {
66  if(attendee != null && !attendee.isEmpty()) {
67  IContact contact = attendee.getIContact();
68  if(contact.isWebUser()) {
69  assistants.add(new Assistant(contact.getName(), contact.getConnector(IUser.CONNECTOR_EMAIL), contact, null));
70  }
71  }
72  }
73  } if(entity instanceof Contact) {
74  IContact contact = Contacts.getContact(entity);
75  if(contact != null && contact.isValid()) {
76  if(contact.isCompany() || contact.isCenter()) {
77  for(IContact c : contact.getCoworkers(contact)) {
78  if(c.isWebUser()) {
79  assistants.add(new Assistant(c.getName(), c.getConnector(IUser.CONNECTOR_EMAIL), c, null));
80  }
81  }
82  } else {
83  if(contact.isWebUser()) {
84  assistants.add(new Assistant(contact.getName(), contact.getConnector(IUser.CONNECTOR_EMAIL), contact, null));
85  }
86  }
87  }
88  }
89  }
90 
91  @Override
92  public void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data) {
93  if((data instanceof String) && ((String) data).contains(AssistantConstants.FROM_COMMENTS)) {
94  for(CommentIt ci : CommentItUtil.allComments(entityPath)) {
95  if(ci.getCreator() != null) {
96  String name = ci.getName(), mail = ci.getEmail();
97  if(!Strings.isBlank(name) && MailValidator.check(mail)) {
98  assistants.add(new Assistant(name, mail, Contacts.getContact(ci.getCreator()), ci));
99  }
100  }
101  }
102  }
103  if((data instanceof String) && ((String) data).contains(AssistantConstants.FROM_VOTES)) {
104  for(VoteIt vi : VoteItUtil.allVotes(entityPath)) {
105  if(vi.getCreator() != null) {
106  String name = vi.getName(), mail = vi.getEmail();
107  if(!Strings.isBlank(name) && MailValidator.check(mail)) {
108  assistants.add(new Assistant(name, mail, Contacts.getContact(vi.getCreator()), vi));
109  }
110  }
111  }
112  }
113  }
114 
115  @Override
116  public void addFromEntityData(Object entity, AssistantSet assistants, Object data) {
117  if((data instanceof String) && (((String) data).contains(AssistantConstants.FROM_COMMENTS) ||
118  ((String) data).contains(AssistantConstants.FROM_VOTES))) {
119  String entityPath = Entities.getController(entity).getPath();
120  addFromEntityPathData(entityPath, assistants, data);
121  }
122  }
123 
124  @Override
125  public List<String> getParticiped(IContact contact) {
126  return Collections.EMPTY_LIST;
127  }
128 
129 }
static IContact getContact(Object object)
Definition: Contacts.java:109
void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data)
void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data)
void addFromEntityData(Object entity, AssistantSet assistants, Object data)
void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data)
void add(Object entity, boolean deep, AssistantSet assistants, Object data)
List< String > getParticiped(IContact contact)
static Collection< CommentIt > allComments(Object entity)
Set< Attendee > getAttendees()
static IElephantEntity getController(String path)
Definition: Entities.java:78
static List< VoteIt > allVotes(String path)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27