BrightSide Workbench Full Report + Source Code
AssistantQueueUtils.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.mail.queue;
20 
21 import java.util.Collection;
22 import org.turro.string.Strings;
23 import org.turro.action.Contacts;
24 import org.turro.action.IAgreements;
25 import org.turro.action.Plugins;
26 import org.turro.action.queue.NotificationCategory;
27 import org.turro.action.queue.Notifications;
28 import org.turro.action.queue.QueuePeriod;
29 import org.turro.assistant.AssistantSet;
30 import org.turro.elephant.entities.db.QueueOptions;
31 import org.turro.plugin.contacts.IContact;
32 
37 public class AssistantQueueUtils {
38 
39  public static void addFromCategory(String idCategory, AssistantSet assistants) {
40  if(!Strings.isBlank(idCategory)) {
41  QueueManager qm = new QueueManager();
42  Collection<QueueOptions> subs = qm.getSubcribers(idCategory);
43  for(QueueOptions qo : subs) {
44  if(qo.getIdContact() != null && !QueuePeriod.DONT_SEND.equals(qo.getPeriod())) {
45  IContact c = Contacts.getContactById(qo.getIdContact());
46  if(c.isWebUser()) {
47  assistants.addContact(c, null);
48  }
49  }
50  }
51  }
52  }
53 
54  public static void addFromCategoryWithAgreements(String idCategory, AssistantSet assistants) {
55  if(!Strings.isBlank(idCategory)) {
56  IAgreements agreements = Plugins.loadImplementation(IAgreements.class, "agreements");
58  QueueManager qm = new QueueManager();
59  Collection<QueueOptions> subs = qm.getSubcribers(idCategory);
60  for(QueueOptions qo : subs) {
61  if(qo.getIdContact() != null && !QueuePeriod.DONT_SEND.equals(qo.getPeriod())) {
62  IContact c = Contacts.getContactById(qo.getIdContact());
63  if(c.isWebUser()) {
64  agreements.setContact(c);
65  if(agreements.canSendEmails(nc)) {
66  assistants.addContact(c, null);
67  }
68  }
69  }
70  }
71  }
72  }
73 
74  private AssistantQueueUtils() {
75  }
76 
77 }
static IContact getContactById(String id)
Definition: Contacts.java:72
static< T > T loadImplementation(Class< T > jclass)
Definition: Plugins.java:57
static NotificationCategory getCategory(String id)
void addContact(IContact contact, Object relationEntity)
static void addFromCategory(String idCategory, AssistantSet assistants)
static void addFromCategoryWithAgreements(String idCategory, AssistantSet assistants)
Collection< QueueOptions > getSubcribers(String idCategory)
boolean canSendEmails(NotificationCategory nc)
void setContact(IContact contact)