BrightSide Workbench Full Report + Source Code
PublicationsAssistant.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.Collection;
22 import java.util.Collections;
23 import java.util.List;
24 import org.turro.action.Contacts;
25 import org.turro.annotation.ExternalAssistant;
26 import org.turro.elephant.entities.db.QueueOptions;
27 import org.turro.elephant.security.IUser;
28 import org.turro.entities.Entities;
29 import org.turro.mail.queue.QueueManager;
30 import org.turro.plugin.contacts.IContact;
31 import org.turro.publication.entity.Publication;
32 import org.turro.publication.entity.PublicationCategory;
33 import org.turro.publication.util.PublicationElephantNotification;
34 
39 @ExternalAssistant
40 public class PublicationsAssistant implements IAssistant {
41 
42  @Override
43  public void add(Object entity, boolean deep, AssistantSet assistants, Object data) {
44  if(entity instanceof String) {
45  addFromEntityPath((String) entity, deep, assistants, data);
46  } else {
47  addFromEntity(entity, deep, assistants, data);
48  }
49  }
50 
51  @Override
52  public void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data) {
53  Object entity = Entities.getController(entityPath).getEntity();
54  addFromEntity(entity, deep, assistants, data);
55  }
56 
57  @Override
58  public void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data) {
59  if(entity instanceof Publication) {
60  Publication publication = (Publication) entity;
61  assistants.addSubject(publication.getTitle());
62  IContact c = publication.getContactAuthor();
63  if(c != null && c.isWebUser()) {
64  assistants.add(new Assistant(c.getName(), c.getConnector(IUser.CONNECTOR_EMAIL), c, null));
65  }
66  } else if(entity instanceof PublicationCategory) {
67  PublicationCategory pubcat = (PublicationCategory) entity;
68  assistants.addSubject(pubcat.getName());
69  }
70  }
71 
72  @Override
73  public void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data) {
74  Object entity = Entities.getController(entityPath).getEntity();
75  addFromEntityData(entity, assistants, data);
76  }
77 
78  @Override
79  public void addFromEntityData(Object entity, AssistantSet assistants, Object data) {
80  PublicationCategory publicationCategory = null;
81  if(entity instanceof Publication) {
82  publicationCategory = ((Publication) entity).getPublicationCategory();
83  } else if(entity instanceof PublicationCategory) {
84  publicationCategory = (PublicationCategory) entity;
85  }
86  if(publicationCategory != null) {
87  if((data instanceof String) && ((String) data).contains(AssistantConstants.FROM_SUBSCRIPTIONS)) {
88  QueueManager qm = new QueueManager();
89  Collection<QueueOptions> subs = qm.getSubcribers(PublicationElephantNotification.convertId(publicationCategory));
90  for(QueueOptions qo : subs) {
91  assistants.addContact(Contacts.getContactById(qo.getIdContact()), null);
92  }
93  }
94  }
95  }
96 
97  @Override
98  public List<String> getParticiped(IContact contact) {
99  return Collections.EMPTY_LIST;
100  }
101 
102 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void addContact(IContact contact, Object relationEntity)
void addFromEntityPath(String entityPath, boolean deep, AssistantSet assistants, Object data)
void add(Object entity, boolean deep, AssistantSet assistants, Object data)
List< String > getParticiped(IContact contact)
void addFromEntity(Object entity, boolean deep, AssistantSet assistants, Object data)
void addFromEntityData(Object entity, AssistantSet assistants, Object data)
void addFromEntityPathData(String entityPath, AssistantSet assistants, Object data)
static IElephantEntity getController(String path)
Definition: Entities.java:78
Collection< QueueOptions > getSubcribers(String idCategory)
static final String CONNECTOR_EMAIL
Definition: IUser.java:27