BrightSide Workbench Full Report + Source Code
org.turro.mail.queue.QueueManager Class Reference

Public Member Functions

MailItem addToQueue (NotificationCategory category, IContact contact, MailMessage mmt, String reason, String poolName)
 
MailItem addToQueue (NotificationCategory category, IContact contact, String subject, String message, String reason, String poolName)
 
void checkConfiguration (IContact contact, String idCategory, QueuePeriod queuePeriod)
 
void setPeriod (IContact contact, String idCategory, QueuePeriod queuePeriod, boolean override)
 
void subscribeDefaults (ConstraintKeys keys)
 
QueueOptions getConfiguration (IContact contact, String idCategory)
 
QueueOptions configQueue (QueueOptions qo)
 
boolean contactWants (IContact contact, String idCategory)
 
boolean contactMayWant (IContact contact, String idCategory)
 
List< MailItemgetPending (QueuePeriod period)
 
ContactMap getContactMap (List< MailItem > list)
 
void removeUniquesFor (String idCategory, String idContact)
 
void removeMails (QueuePeriod period, String idContact, String idCategory)
 
void removeContactMails (String idContact)
 
void removeWithoutOptions ()
 
void removeOldsByPeriod ()
 
void removeOptions (String idCategory)
 
void setPeriodToAll (String idCategory, QueuePeriod period)
 
void checkConstraints (String idCategory)
 
Collection< QueueOptionsgetSubcribers (String idCategory)
 
Collection< Long > getSubcribersId (String idCategory)
 
void createBulk ()
 
void removeMail (MailItem mi)
 
void removeOptions (QueueOptions qo)
 
Collection< QueueOptionsgetSubcribersByRoot (String root)
 

Static Public Member Functions

static void send (IConstructor constructor, QueuePeriod period)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 48 of file QueueManager.java.

Member Function Documentation

◆ addToQueue() [1/2]

MailItem org.turro.mail.queue.QueueManager.addToQueue ( NotificationCategory  category,
IContact  contact,
MailMessage  mmt,
String  reason,
String  poolName 
)

Definition at line 67 of file QueueManager.java.

68  {
69  if(contact.isWebUser()) {
70  MailItem mi = new MailItem();
71  mi.setIdCategory(category.getIdCategory());
72  mi.setCategory(category.getCategory());
73  mi.setDescription(category.getDescription());
74  mi.setIContact(contact);
75  mi.setItemDate(mmt.getSentDate());
76  mi.setSubject(mmt.getSubject());
77  mi.setMessage(mmt.getMessage());
78  mi.setReason(cleanSubject(reason));
79  mi.setPoolName(poolName);
80  if(category.isUnique()) {
81  removeUniquesFor(category.getIdCategory(), contact.getId());
82  }
83  checkConfiguration(contact, category.getIdCategory(), category.getDefaultPeriod());
84  return getDao().saveObject(mi);
85  }
86  return null;
87  }
void checkConfiguration(IContact contact, String idCategory, QueuePeriod queuePeriod)
void removeUniquesFor(String idCategory, String idContact)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addToQueue() [2/2]

MailItem org.turro.mail.queue.QueueManager.addToQueue ( NotificationCategory  category,
IContact  contact,
String  subject,
String  message,
String  reason,
String  poolName 
)

Definition at line 89 of file QueueManager.java.

90  {
91  if(contact.isWebUser()) {
92  MailItem mi = new MailItem();
93  mi.setIdCategory(category.getIdCategory());
94  mi.setCategory(category.getCategory());
95  mi.setDescription(category.getDescription());
96  mi.setIContact(contact);
97  mi.setItemDate(new Date());
98  mi.setSubject(subject);
99  mi.setMessage(message);
100  mi.setReason(cleanSubject(reason));
101  mi.setPoolName(poolName);
102  if(category.isUnique()) {
103  removeUniquesFor(category.getIdCategory(), contact.getId());
104  }
105  checkConfiguration(contact, category.getIdCategory(), category.getDefaultPeriod());
106  return getDao().saveObject(mi);
107  }
108  return null;
109  }

◆ checkConfiguration()

void org.turro.mail.queue.QueueManager.checkConfiguration ( IContact  contact,
String  idCategory,
QueuePeriod  queuePeriod 
)

Definition at line 111 of file QueueManager.java.

111  {
112  QueueOptions qo = getConfiguration(contact, idCategory);
113  if(qo == null) {
114  qo = new QueueOptions();
115  qo.setIdCategory(idCategory);
116  qo.setIdContact(contact.getId());
117  qo.setPeriod(queuePeriod);
118  qo.setSingleMail(true);
119  configQueue(qo);
120  }
121  }
QueueOptions configQueue(QueueOptions qo)
QueueOptions getConfiguration(IContact contact, String idCategory)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkConstraints()

void org.turro.mail.queue.QueueManager.checkConstraints ( String  idCategory)

Definition at line 290 of file QueueManager.java.

290  {
291  NotificationCategory nc = Notifications.getCategory(idCategory);
292  if(nc.getConstraints().isRestricted()) {
293  List<QueueOptions> toDelete = new ArrayList<>();
294  SqlClause.select("o").from("QueueOptions o")
295  .where().equal("o.idCategory", idCategory)
296  .dao(getDao())
297  .resultList(QueueOptions.class)
298  .forEach(o -> {
299  IContact contact = Contacts.getContactById(o.getIdContact());
300  if(contact.isValid()) {
301  ConstraintKeys keys = ConstraintKeys.from(contact);
302  if(!nc.strongBond(keys)) {
303  toDelete.add(o);
304  //removeOptions(getConfiguration(keys.contact(), nc.getIdCategory()));
305  }
306  } else {
307  toDelete.add(o);
308  }
309  });
310  getDao().deleteCollection(toDelete);
311  }
312  }
void deleteCollection(Collection objs)
Definition: Dao.java:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ configQueue()

QueueOptions org.turro.mail.queue.QueueManager.configQueue ( QueueOptions  qo)

Definition at line 156 of file QueueManager.java.

156  {
157  return getDao().saveObject(qo);
158  }
Here is the caller graph for this function:

◆ contactMayWant()

boolean org.turro.mail.queue.QueueManager.contactMayWant ( IContact  contact,
String  idCategory 
)

Definition at line 165 of file QueueManager.java.

165  {
166  QueueOptions qo = getConfiguration(contact, idCategory);
167  return qo == null || !QueuePeriod.DONT_SEND.equals(qo.getPeriod());
168  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ contactWants()

boolean org.turro.mail.queue.QueueManager.contactWants ( IContact  contact,
String  idCategory 
)

Definition at line 160 of file QueueManager.java.

160  {
161  QueueOptions qo = getConfiguration(contact, idCategory);
162  return qo != null && !QueuePeriod.DONT_SEND.equals(qo.getPeriod());
163  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBulk()

void org.turro.mail.queue.QueueManager.createBulk ( )

Definition at line 330 of file QueueManager.java.

330  {
331 // IContact contact = Contacts.getContactByEmail("lluis@turro.org");
332 // if(contact != null && contact.isWebUser()) {
333 // QueueOptions qo = new QueueOptions();
334 // qo.setIdCategory("/myissues");
335 // qo.setIdContact(contact.getId());
336 // qo.setPeriod(QueuePeriod.AS_GENERATED);
337 // qo.setSingleMail(true);
338 // configQueue(qo);
339 // MailItem mi = new MailItem();
340 // mi.setIdCategory("/myissues");
341 // mi.setIContact(contact);
342 // mi.setDescription("cosa");
343 // mi.setCategory("My issues");
344 // mi.setItemDate(new Date());
345 // mi.setMessage("Message");
346 // mi.setSubject("Subject");
347 // mi.setPoolName("Dossier");
348 // addToQueue(mi);
349 // }
350  }

◆ getConfiguration()

QueueOptions org.turro.mail.queue.QueueManager.getConfiguration ( IContact  contact,
String  idCategory 
)

Definition at line 146 of file QueueManager.java.

146  {
147  WhereClause wc = new WhereClause();
148  wc.addClause("select o from QueueOptions o");
149  wc.addClause("where o.idContact = :idContact");
150  wc.addClause("and o.idCategory = :idCategory");
151  wc.addNamedValue("idContact", contact.getId());
152  wc.addNamedValue("idCategory", idCategory);
153  return (QueueOptions) getDao().getSingleResultOrNull(wc);
154  }
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContactMap()

ContactMap org.turro.mail.queue.QueueManager.getContactMap ( List< MailItem list)

Definition at line 181 of file QueueManager.java.

181  {
182  ContactMap cm = new ContactMap();
183  for(MailItem mi : list) {
184  cm.addMailItem(mi);
185  }
186  return cm;
187  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPending()

List<MailItem> org.turro.mail.queue.QueueManager.getPending ( QueuePeriod  period)

Definition at line 170 of file QueueManager.java.

170  {
171  WhereClause wc = new WhereClause();
172  wc.addClause("select m from MailItem m, QueueOptions o");
173  wc.addClause("where o.period = :period");
174  wc.addClause("and m.idContact = o.idContact");
175  wc.addClause("and m.idCategory = o.idCategory");
176  wc.addClause("order by m.idContact, m.idCategory");
177  wc.addNamedValue("period", period);
178  return getDao().getResultList(wc);
179  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSubcribers()

Collection<QueueOptions> org.turro.mail.queue.QueueManager.getSubcribers ( String  idCategory)

Definition at line 314 of file QueueManager.java.

314  {
315  WhereClause wc = new WhereClause();
316  wc.addClause("select o from QueueOptions o");
317  wc.addClause("where o.idCategory = :category");
318  wc.addNamedValue("category", idCategory);
319  return getDao().getResultList(wc);
320  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSubcribersByRoot()

Collection<QueueOptions> org.turro.mail.queue.QueueManager.getSubcribersByRoot ( String  root)

Definition at line 371 of file QueueManager.java.

371  {
372  WhereClause wc = new WhereClause();
373  wc.addClause("select o from QueueOptions o");
374  wc.addClause("where o.idCategory like :category");
375  wc.addNamedValue("category", root + "/%");
376  return getDao().getResultList(wc);
377  }
Here is the call graph for this function:

◆ getSubcribersId()

Collection<Long> org.turro.mail.queue.QueueManager.getSubcribersId ( String  idCategory)

Definition at line 322 of file QueueManager.java.

322  {
323  WhereClause wc = new WhereClause();
324  wc.addClause("select o.id from QueueOptions o");
325  wc.addClause("where o.idCategory = :category");
326  wc.addNamedValue("category", idCategory);
327  return getDao().getResultList(wc);
328  }
Here is the call graph for this function:

◆ removeContactMails()

void org.turro.mail.queue.QueueManager.removeContactMails ( String  idContact)

Definition at line 216 of file QueueManager.java.

216  {
217  WhereClause wc = new WhereClause();
218  wc.addClause("delete from MailItem m");
219  wc.addClause("where m.idContact = :contact");
220  wc.addNamedValue("contact", idContact);
221  getDao().executeUpdate(wc);
222  }
int executeUpdate(String query)
Definition: Dao.java:463
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeMail()

void org.turro.mail.queue.QueueManager.removeMail ( MailItem  mi)

Definition at line 352 of file QueueManager.java.

352  {
353  getDao().deleteObject(mi);
354  }
void deleteObject(Object obj)
Definition: Dao.java:162

◆ removeMails()

void org.turro.mail.queue.QueueManager.removeMails ( QueuePeriod  period,
String  idContact,
String  idCategory 
)

Definition at line 199 of file QueueManager.java.

199  {
200  WhereClause wc = new WhereClause();
201  wc.addClause("delete from MailItem m");
202  wc.addClause("where m.idContact = :contact");
203  wc.addClause("and m.idCategory = :category");
204  wc.addClause("and exists (");
205  wc.addClause("select o from QueueOptions o");
206  wc.addClause("where o.period = :period");
207  wc.addClause("and m.idContact = o.idContact");
208  wc.addClause("and m.idCategory = o.idCategory");
209  wc.addClause(")");
210  wc.addNamedValue("contact", idContact);
211  wc.addNamedValue("category", idCategory);
212  wc.addNamedValue("period", period);
213  getDao().executeUpdate(wc);
214  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeOldsByPeriod()

void org.turro.mail.queue.QueueManager.removeOldsByPeriod ( )

Definition at line 235 of file QueueManager.java.

235  {
236  WhereClause wc = new WhereClause();
237  wc.addClause("delete from MailItem m");
238  wc.addClause("where exists (");
239  wc.addClause("select o from QueueOptions o");
240  wc.addClause("where m.idContact = o.idContact");
241  wc.addClause("and m.idCategory = o.idCategory");
242  wc.addClause("and (");
243  wc.addClause("o.period = :dontSend");
244  wc.addClause("or (o.period = :asGenerated and m.itemDate < :oneDay)");
245  wc.addClause("or (o.period = :daily and m.itemDate < :oneDay)");
246  wc.addClause("or (o.period = :weekly and m.itemDate < :oneWeek)");
247  wc.addClause("or (o.period = :fortnightly and m.itemDate < :twoWeeks)");
248  wc.addClause("or (o.period = :monthly and m.itemDate < :oneMonth)");
249  wc.addClause("or (o.period = :quarterly and m.itemDate < :threeMonths)");
250  wc.addClause("or (o.period = :everySix and m.itemDate < :sixMonths)");
251  wc.addClause("or (o.period = :yearly and m.itemDate < :oneYear)");
252  wc.addClause("))");
253  wc.addNamedValue("dontSend", QueuePeriod.DONT_SEND);
254  wc.addNamedValue("asGenerated", QueuePeriod.AS_GENERATED);
255  wc.addNamedValue("daily", QueuePeriod.DAILY);
256  wc.addNamedValue("oneDay", new CheckDate().addDays(-2).getDate());
257  wc.addNamedValue("weekly", QueuePeriod.WEEKLY);
258  wc.addNamedValue("oneWeek", new CheckDate().addWeeks(-1).addDays(-2).getDate());
259  wc.addNamedValue("fortnightly", QueuePeriod.FORTNIGHTLY);
260  wc.addNamedValue("twoWeeks", new CheckDate().addWeeks(-2).addDays(-2).getDate());
261  wc.addNamedValue("monthly", QueuePeriod.MONTHLY);
262  wc.addNamedValue("oneMonth", new CheckDate().addMonths(-1).addDays(-2).getDate());
263  wc.addNamedValue("quarterly", QueuePeriod.QUARTERLY);
264  wc.addNamedValue("threeMonths", new CheckDate().addMonths(-3).addDays(-2).getDate());
265  wc.addNamedValue("everySix", QueuePeriod.EVERY_SIX_MONTHS);
266  wc.addNamedValue("sixMonths", new CheckDate().addMonths(-6).addDays(-2).getDate());
267  wc.addNamedValue("yearly", QueuePeriod.YEARLY);
268  wc.addNamedValue("oneYear", new CheckDate().addYears(-1).addDays(-2).getDate());
269  getDao().executeUpdate(wc);
270  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeOptions() [1/2]

void org.turro.mail.queue.QueueManager.removeOptions ( QueueOptions  qo)

Definition at line 356 of file QueueManager.java.

356  {
357  if(qo != null) getDao().deleteObject(qo);
358  }

◆ removeOptions() [2/2]

void org.turro.mail.queue.QueueManager.removeOptions ( String  idCategory)

Definition at line 272 of file QueueManager.java.

272  {
273  WhereClause wc = new WhereClause();
274  wc.addClause("delete from QueueOptions o");
275  wc.addClause("where o.idCategory = :category");
276  wc.addNamedValue("category", idCategory);
277  getDao().executeUpdate(wc);
278  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeUniquesFor()

void org.turro.mail.queue.QueueManager.removeUniquesFor ( String  idCategory,
String  idContact 
)

Definition at line 189 of file QueueManager.java.

189  {
190  WhereClause wc = new WhereClause();
191  wc.addClause("delete from MailItem m");
192  wc.addClause("where m.idContact = :contact");
193  wc.addClause("and m.idCategory = :category");
194  wc.addNamedValue("contact", idContact);
195  wc.addNamedValue("category", idCategory);
196  getDao().executeUpdate(wc);
197  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeWithoutOptions()

void org.turro.mail.queue.QueueManager.removeWithoutOptions ( )

Definition at line 224 of file QueueManager.java.

224  {
225  WhereClause wc = new WhereClause();
226  wc.addClause("delete from MailItem m");
227  wc.addClause("where not exists (");
228  wc.addClause("select o from QueueOptions o");
229  wc.addClause("where m.idContact = o.idContact");
230  wc.addClause("and m.idCategory = o.idCategory");
231  wc.addClause(")");
232  getDao().executeUpdate(wc);
233  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

static void org.turro.mail.queue.QueueManager.send ( IConstructor  constructor,
QueuePeriod  period 
)
static

Definition at line 50 of file QueueManager.java.

50  {
51  boolean lockAcquired = QUEUEMANAGER_LOCK.tryLock();
52  if(lockAcquired) {
53  try {
54  QueueManager qm = new QueueManager();
55  qm.removeWithoutOptions();
56  qm.removeOldsByPeriod();
57  ContactMap cm = qm.getContactMap(qm.getPending(period));
58  for(String idContact : cm.keySet()) {
59  new ContactQueueSender(constructor, qm, period, cm.get(idContact)).send();
60  }
61  } finally {
62  QUEUEMANAGER_LOCK.unlock();
63  }
64  }
65  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPeriod()

void org.turro.mail.queue.QueueManager.setPeriod ( IContact  contact,
String  idCategory,
QueuePeriod  queuePeriod,
boolean  override 
)

Definition at line 123 of file QueueManager.java.

123  {
124  QueueOptions qo = getConfiguration(contact, idCategory);
125  if(qo != null && !override) return;
126  if(qo == null) {
127  qo = new QueueOptions();
128  qo.setIdCategory(idCategory);
129  qo.setIdContact(contact.getId());
130  qo.setSingleMail(true);
131  }
132  qo.setPeriod(queuePeriod);
133  configQueue(qo);
134  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPeriodToAll()

void org.turro.mail.queue.QueueManager.setPeriodToAll ( String  idCategory,
QueuePeriod  period 
)

Definition at line 280 of file QueueManager.java.

280  {
281  WhereClause wc = new WhereClause();
282  wc.addClause("update QueueOptions o");
283  wc.addClause("set o.period = :period");
284  wc.addClause("where o.idCategory = :category");
285  wc.addNamedValue("period", period);
286  wc.addNamedValue("category", idCategory);
287  getDao().executeUpdate(wc);
288  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ subscribeDefaults()

void org.turro.mail.queue.QueueManager.subscribeDefaults ( ConstraintKeys  keys)

Definition at line 136 of file QueueManager.java.

136  {
137  for(NotificationCategory nc : Notifications.getCategories()) {
138  if(nc.wideBond(keys)) {
139  checkConfiguration(keys.contact(), nc.getIdCategory(), nc.getDefaultPeriod());
140  } else if(!nc.strongBond(keys)) {
141  removeOptions(getConfiguration(keys.contact(), nc.getIdCategory()));
142  }
143  }
144  }
void removeOptions(String idCategory)
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: