BrightSide Workbench Full Report + Source Code
ElephantAssistant.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.annotation.ExternalAssistant;
24 import org.turro.elephant.entities.db.Poll;
25 import org.turro.elephant.entities.db.PollVote;
26 import org.turro.entities.Entities;
27 import org.turro.plugin.contacts.IContact;
28 
33 @ExternalAssistant
34 public class ElephantAssistant implements IAssistant {
35 
36  @Override
37  public void add(Object entity, boolean deep, AssistantSet assistants, Object data) {
38  if(entity instanceof String) {
39  addFromEntityPath((String) entity, deep, assistants, data);
40  } else {
41  addFromEntity(entity, deep, assistants, data);
42  }
43  }
44 
45  @Override
46  public void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data) {
47  Object entity = Entities.getController(entityPath).getEntity();
48  addFromEntity(entity, deep, assistants, data);
49  }
50 
51  @Override
52  public void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data) {
53  if(entity instanceof Poll) {
54  Poll poll = (Poll) entity;
55  assistants.addSubject(poll.getTitle());
56  for(PollVote pv : poll.getVotes()) {
57  assistants.addContact(pv.getContact(), null);
58  }
59  }
60  }
61 
62  @Override
63  public void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data) {
64  Object entity = Entities.getController(entityPath).getEntity();
65  addFromEntityData(entity, assistants, data);
66  }
67 
68  @Override
69  public void addFromEntityData(Object entity, AssistantSet assistants, Object data) {
70  // noting
71  }
72 
73  @Override
74  public List<String> getParticiped(IContact contact) {
75  return Collections.EMPTY_LIST;
76  }
77 
78 }
void addContact(IContact contact, Object relationEntity)
void add(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data)
void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data)
List< String > getParticiped(IContact contact)
void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data)
void addFromEntityData(Object entity, AssistantSet assistants, Object data)
List< PollVote > getVotes()
Definition: Poll.java:235
static IElephantEntity getController(String path)
Definition: Entities.java:78