BrightSide Workbench Full Report + Source Code
GenericEntityAssistant.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.assistant;
20 
21 import java.util.Collections;
22 import java.util.EnumSet;
23 import java.util.List;
24 import org.turro.action.Contacts;
25 import org.turro.annotation.ExternalAssistant;
26 import org.turro.elephant.db.ElephantPU;
27 import org.turro.elephant.db.WhereClause;
28 import org.turro.elephant.entities.db.EntityParticipation;
29 import org.turro.elephant.security.IUser;
30 import org.turro.entities.Entities;
31 import org.turro.jpa.Dao;
32 import org.turro.participation.ParticipationReason;
33 import org.turro.path.Path;
34 import org.turro.plugin.contacts.IContact;
35 
40 @ExternalAssistant
41 public class GenericEntityAssistant implements IAssistant {
42 
43  @Override
44  public void add(Object entity, boolean deep, AssistantSet assistants, Object data) {
45  if(entity instanceof String) {
46  addFromEntityPath((String) entity, deep, assistants, data);
47  } else {
48  addFromEntity(entity, deep, assistants, data);
49  }
50  }
51 
52  @Override
53  public void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data) {
54  Dao dao = new ElephantPU();
55  WhereClause wc = new WhereClause();
56  wc.addClause("select ep from EntityParticipation ep");
57  wc.addClause("where ep.entityPath = :entityPath");
58  wc.addNamedValue("entityPath", entityPath);
59  wc.addClause("and ep.reason in (:reasons)");
61  dao.getResultList(EntityParticipation.class, wc).stream().forEach((ea) -> {
62  Path path = new Path(ea.getParticipatorPath());
63  if("contact".equals(path.getRoot())) {
64  IContact contact = Contacts.getContactById(path.getNode(1));
65  if(contact != null && contact.isWebUser()) {
66  assistants.add(new Assistant(contact.getName(), contact.getConnector(IUser.CONNECTOR_EMAIL), contact, null));
67  }
68  }
69  });
70  }
71 
72  @Override
73  public void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data) {
74  String entityPath = Entities.getController(entity).getPath();
75  addFromEntityPath(entityPath, deep, assistants, data);
76  }
77 
78  @Override
79  public void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data) {
80  }
81 
82  @Override
83  public void addFromEntityData(Object entity, AssistantSet assistants, Object data) {
84  }
85 
86  @Override
87  public List<String> getParticiped(IContact contact) {
88  return Collections.EMPTY_LIST;
89  }
90 
91 }
static IContact getContactById(String id)
Definition: Contacts.java:72
List< String > getParticiped(IContact contact)
void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data)
void add(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntityData(Object entity, AssistantSet assistants, Object data)
void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data)
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static final String CONNECTOR_EMAIL
Definition: IUser.java:27