BrightSide Workbench Full Report + Source Code
GenericElephantNotification.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 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 java.util.EnumSet;
23 import org.turro.action.queue.IElephantNotification;
24 import org.turro.action.queue.NotificationCategory;
25 import org.turro.action.queue.NotificationRole;
26 import org.turro.action.queue.QueuePeriod;
27 import org.turro.annotation.ElephantNotification;
28 import org.turro.elephant.entities.db.QueueOptions;
29 import org.turro.plugin.contacts.IContact;
30 
35 @ElephantNotification
37 
38  @Override
39  public Collection<NotificationCategory> getCategories() {
40  NotificationCategoryMap map = initCategories(this);
41  return map.values();
42  }
43 
44  @Override
45  public Collection<NotificationCategory> getAllCategories() {
47  map.putAll(initCategories(this));
48  map.putAll(_private);
49  return map.values();
50  }
51 
52  @Override
53  public Collection<String> getCategoryIds() {
54  NotificationCategoryMap map = initCategories(this);
55  return map.keySet();
56  }
57 
58  @Override
59  public Collection<String> getAllCategoryIds() {
61  map.putAll(initCategories(this));
62  map.putAll(_private);
63  return map.keySet();
64  }
65 
66  @Override
67  public NotificationCategory getCategory(String id) {
69  map.putAll(initCategories(this));
70  map.putAll(_private);
71  return map.get(id);
72  }
73 
74  @Override
75  public QueuePeriod period(String idCategory, IContact contact) {
76  QueueManager qm = new QueueManager();
77  QueueOptions qo = qm.getConfiguration(contact, idCategory);
78  return qo != null ? qo.getPeriod() : null;
79  }
80 
81  @Override
82  public void subscribe(String idCategory, IContact contact, QueuePeriod period) {
83  QueueManager qm = new QueueManager();
84  qm.setPeriod(contact, idCategory, period, true);
85  }
86 
87  @Override
88  public void subscribeIfNot(String idCategory, IContact contact, QueuePeriod period) {
89  QueueManager qm = new QueueManager();
90  qm.setPeriod(contact, idCategory, period, false);
91  }
92 
93  @Override
94  public void removeAll(String idCategory) {
95  QueueManager qm = new QueueManager();
96  qm.removeOptions(idCategory);
97  }
98 
99  @Override
100  public void periodToAll(String idCategory, QueuePeriod period) {
101  QueueManager qm = new QueueManager();
102  qm.setPeriodToAll(idCategory, period);
103  }
104 
105  @Override
106  public void checkConstraints(String idCategory) {
107  //
108  }
109 
110  @Override
111  public void reset() {
112  // do nothing
113  }
114 
115  /* Categories */
116 
117  private static NotificationCategoryMap _categories, _private;
118 
119  public static final String
120  GENERIC_NOTIFICATION = "/elephant",
121  SYSTEM_NOTIFICATION = "/system";
122 
123  private static NotificationCategoryMap initCategories(IElephantNotification en) {
124  if(_categories == null) {
125  _categories = new NotificationCategoryMap();
126  _categories.addCategory(GENERIC_NOTIFICATION,
127  "Site notifications", "Includes generic notifications from de web site in contexts where you participate, such as accepted comments.",
128  EnumSet.range(QueuePeriod.DONT_SEND, QueuePeriod.MONTHLY),
129  false, QueuePeriod.DAILY, en, NotificationRole.NOTIF_OBSERVER, null, true);
130  _private = new NotificationCategoryMap();
131  _private.addCategory(SYSTEM_NOTIFICATION,
132  "System notification", "dSystemNotification",
133  EnumSet.range(QueuePeriod.DONT_SEND, QueuePeriod.DAILY),
134  false, QueuePeriod.AS_GENERATED, en, NotificationRole.NOTIF_OBSERVER, null, false);
135  }
136  return _categories;
137  }
138 
139 }
140 
void periodToAll(String idCategory, QueuePeriod period)
QueuePeriod period(String idCategory, IContact contact)
void subscribe(String idCategory, IContact contact, QueuePeriod period)
void subscribeIfNot(String idCategory, IContact contact, QueuePeriod period)
NotificationCategory addCategory(String id, String name, String description, EnumSet< QueuePeriod > allowedPeriods, boolean unique, QueuePeriod defaultPeriod, IElephantNotification notification, NotificationRole role, Set< NotificationConstraint > constraints, boolean publishable)
void setPeriod(IContact contact, String idCategory, QueuePeriod queuePeriod, boolean override)
QueueOptions getConfiguration(IContact contact, String idCategory)
void setPeriodToAll(String idCategory, QueuePeriod period)
void removeOptions(String idCategory)