BrightSide Workbench Full Report + Source Code
DossierElephantNotification.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.dossier.util;
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.mail.queue.NotificationCategoryMap;
30 import org.turro.mail.queue.QueueManager;
31 import org.turro.plugin.contacts.IContact;
32 
37 @ElephantNotification
39 
40  @Override
41  public Collection<NotificationCategory> getCategories() {
42  NotificationCategoryMap map = initCategories(this);
43  return map.values();
44  }
45 
46  @Override
47  public Collection<NotificationCategory> getAllCategories() {
48  return getCategories();
49  }
50 
51  @Override
52  public Collection<String> getCategoryIds() {
53  NotificationCategoryMap map = initCategories(this);
54  return map.keySet();
55  }
56 
57  @Override
58  public Collection<String> getAllCategoryIds() {
59  return getCategoryIds();
60  }
61 
62  @Override
63  public NotificationCategory getCategory(String id) {
64  NotificationCategoryMap map = initCategories(this);
65  return map.get(id);
66  }
67 
68  @Override
69  public QueuePeriod period(String idCategory, IContact contact) {
70  QueueManager qm = new QueueManager();
71  QueueOptions qo = qm.getConfiguration(contact, idCategory);
72  return qo != null ? qo.getPeriod() : null;
73  }
74 
75  @Override
76  public void subscribe(String idCategory, IContact contact, QueuePeriod period) {
77  QueueManager qm = new QueueManager();
78  qm.setPeriod(contact, idCategory, period, true);
79  }
80 
81  @Override
82  public void subscribeIfNot(String idCategory, IContact contact, QueuePeriod period) {
83  QueueManager qm = new QueueManager();
84  qm.setPeriod(contact, idCategory, period, false);
85  }
86 
87  @Override
88  public void removeAll(String idCategory) {
89  QueueManager qm = new QueueManager();
90  qm.removeOptions(idCategory);
91  }
92 
93  @Override
94  public void periodToAll(String idCategory, QueuePeriod period) {
95  QueueManager qm = new QueueManager();
96  qm.setPeriodToAll(idCategory, period);
97  }
98 
99  @Override
100  public void checkConstraints(String idCategory) {
101  //
102  }
103 
104  @Override
105  public void reset() {
106  // do nothing
107  }
108 
109  /* Categories */
110 
111  private static NotificationCategoryMap _categories;
112 
113  public static final String
114  PROJECT_NOTIFICATION = "/project",
115  DOSSIER_NOTIFICATION = "/dossier",
116  MY_ISSUES_NOTIFICATION = "/my-issues";
117 
118  private static NotificationCategoryMap initCategories(IElephantNotification en) {
119  if(_categories == null) {
120  _categories = new NotificationCategoryMap();
121  _categories.addCategory(PROJECT_NOTIFICATION,
122  "Project notification", "Project generated notifications",
123  EnumSet.range(QueuePeriod.DONT_SEND, QueuePeriod.MONTHLY),
125  null, true);
126  _categories.addCategory(DOSSIER_NOTIFICATION,
127  "Dossier notification", "Dossier generated notifications",
128  EnumSet.range(QueuePeriod.DONT_SEND, QueuePeriod.MONTHLY),
130  null, true);
131  _categories.addCategory(MY_ISSUES_NOTIFICATION,
132  "My issues notifier", "Current workload, composed by pending issues.",
133  EnumSet.range(QueuePeriod.DONT_SEND, QueuePeriod.MONTHLY),
135  null, true);
136  }
137  return _categories;
138  }
139 
140 }
void periodToAll(String idCategory, QueuePeriod period)
void subscribe(String idCategory, IContact contact, QueuePeriod period)
void subscribeIfNot(String idCategory, IContact contact, QueuePeriod period)
QueuePeriod period(String idCategory, IContact contact)
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)