BrightSide Workbench Full Report + Source Code
AbstractPushSender.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.push.sender;
20 
21 import java.util.Collection;
22 import java.util.function.Consumer;
23 import org.turro.action.Contacts;
24 import org.turro.action.IPushSender;
25 import org.turro.assistant.Assistant;
26 import org.turro.assistant.AssistantSet;
27 import org.turro.assistant.Assistants;
28 import org.turro.entities.Entities;
29 import org.turro.plugin.contacts.IContact;
30 import org.turro.security.SecurityGroup;
31 
36 public abstract class AbstractPushSender implements IPushSender {
37 
38  public final AssistantSet assistants = new AssistantSet();
39 
40  protected Consumer onStart, onCancel, onBuild, onFinish;
41 
42  @Override
44  addBySyndication(SecurityGroup.BRIGHTSIDE_ADMIN);
45  return this;
46  }
47 
48  @Override
49  public AbstractPushSender addBySyndication(String syndication) {
51  return this;
52  }
53 
54  @Override
55  public AbstractPushSender addByRole(String role) {
57  return this;
58  }
59 
60  @Override
61  public AbstractPushSender addByEntity(Object entity, Object data) {
62  addByEntity(entity, true, data);
63  return this;
64  }
65 
66  @Override
67  public AbstractPushSender addByEntity(Object entity, boolean deep, Object data) {
68  addByEntity(Entities.getController(entity).getPath(), deep, data);
69  return this;
70  }
71 
72  @Override
73  public AbstractPushSender addByEntity(String path, Object data) {
74  addByEntity(path, true, data);
75  return this;
76  }
77 
78  @Override
79  public AbstractPushSender addByEntity(String path, boolean deep, Object data) {
80  Assistants.addAssistants(path, true, assistants, data);
81  return this;
82  }
83 
84  @Override
86  assistants.addContact(contact, null);
87  return this;
88  }
89 
90  @Override
91  public AbstractPushSender addContacts(Collection<IContact> contacts) {
92  assistants.addContacts(contacts);
93  return this;
94  }
95 
96  @Override
98  this.assistants.add(assistant);
99  return this;
100  }
101 
102  @Override
104  for(Assistant assistant : assistants) {
105  this.assistants.add(assistant);
106  }
107  return this;
108  }
109 
110  @Override
111  public AbstractPushSender addUser(String name, String email) {
112  assistants.addUser(name, email, null);
113  return this;
114  }
115 
116  @Override
117  public AbstractPushSender onStart(Consumer command) {
118  onStart = command;
119  return this;
120  }
121 
122  @Override
123  public AbstractPushSender onCancel(Consumer command) {
124  onCancel = command;
125  return this;
126  }
127 
128  @Override
129  public AbstractPushSender onBuild(Consumer command) {
130  onBuild = command;
131  return this;
132  }
133 
134  @Override
135  public AbstractPushSender onFinish(Consumer command) {
136  onFinish = command;
137  return this;
138  }
139 
140  @Override
142  return assistants;
143  }
144 
145  /* Direct sending */
146 
147  @Override
148  public void send(String title, String message) {
149  doSend(title, message, null, onFinish);
150  }
151 
152  @Override
153  public void send(String title, String message, String link) {
154  doSend(title, message, link, onFinish);
155  }
156 
157  protected abstract void doSend(String title, String message, String link, Consumer onFinish);
158 
159 }
static List< IContact > getByRole(String role)
Definition: Contacts.java:134
static List< IContact > getBySyndication(String syndication)
Definition: Contacts.java:130
void addUser(String name, String email, Object relationEntity)
void addContacts(Collection< IContact > contacts)
void addContact(IContact contact, Object relationEntity)
static void addAssistants(String role, AssistantSet list, Object data)
Definition: Assistants.java:35
static IElephantEntity getController(String path)
Definition: Entities.java:78
AbstractPushSender onFinish(Consumer command)
AbstractPushSender addUser(String name, String email)
AbstractPushSender addBySyndication(String syndication)
AbstractPushSender addAssistant(Assistant assistant)
AbstractPushSender addByRole(String role)
AbstractPushSender onStart(Consumer command)
AbstractPushSender addByEntity(Object entity, Object data)
AbstractPushSender addAssistants(AssistantSet assistants)
AbstractPushSender addByEntity(String path, Object data)
AbstractPushSender addByEntity(Object entity, boolean deep, Object data)
AbstractPushSender onCancel(Consumer command)
void send(String title, String message, String link)
abstract void doSend(String title, String message, String link, Consumer onFinish)
AbstractPushSender addByEntity(String path, boolean deep, Object data)
AbstractPushSender addContacts(Collection< IContact > contacts)
AbstractPushSender onBuild(Consumer command)
AbstractPushSender addContact(IContact contact)
void send(String title, String message)