BrightSide Workbench Full Report + Source Code
MailParticipationCatcher.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.activity;
20 
21 import org.turro.action.queue.NotificationCategory;
22 import org.turro.action.queue.Notifications;
23 import org.turro.elephant.db.ElephantPU;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.elephant.entities.db.QueueOptions;
26 import org.turro.i18n.I_;
27 import org.turro.jpa.Dao;
28 import org.turro.mail.queue.QueueManager;
29 import org.turro.path.Path;
30 
35 @ParticipationCatcher
36 public class MailParticipationCatcher extends JpaParticipationCatcher<QueueOptions> {
37 
38  @Override
39  public String getDescription() {
40  return "Elephant Mail";
41  }
42 
43  @Override
44  public Dao createDao() {
45  return new ElephantPU();
46  }
47 
48  @Override
49  public WhereClause getQuery(Path entityPath) {
50  if(!entityPath.isRoot() && "contact".equals(entityPath.getRoot())) {
51  WhereClause wc = new WhereClause();
52  wc.addClause("select distinct opt from QueueOptions as opt");
53  wc.addClause("where opt.idContact = :id");
54  wc.addNamedValue("id", entityPath.getLastNode());
55  return wc;
56  }
57  return null;
58  }
59 
60  @Override
61  public boolean getCanDelete(QueueOptions v) {
62  return true;
63  }
64 
65  @Override
66  public String getDescription(QueueOptions v) {
68  return (nc != null ? I_.get(nc.getCategory()) + " " : "") + I_.byKey(v.getPeriod().toString());
69  }
70 
71  @Override
72  public void doDelete(QueueOptions v) {
73  QueueManager qm = new QueueManager();
75  getDao().deleteObject(v);
76  }
77 
78  @Override
79  public void doShow(QueueOptions v) {
80  // do nothing
81  }
82 
83  @Override
84  public void onChange(Object entity) {
85  // do nothing
86  }
87 
88  @Override
89  public void onDelete(Object entity) {
90  // do nothing
91  }
92 
93  @Override
94  public boolean getCanChangeFor(QueueOptions v) {
95  return true;
96  }
97 
98  @Override
99  public void doChangeFor(QueueOptions v, Path toPath) {
100  if(v != null && !toPath.isRoot() && "contact".equals(toPath.getRoot())) {
101  WhereClause wc = new WhereClause();
102  wc.addClause("update QueueOptions");
103  wc.addClause("set idContact = :to");
104  wc.addClause("where idContact = :from");
105  wc.addNamedValue("to", toPath.getLastNode());
106  wc.addNamedValue("from", v.getIdContact());
107  getDao().executeUpdate(wc);
108  }
109  }
110 
111  @Override
112  public Object getReferringEntity(QueueOptions v) {
113  return null;
114  }
115 
116 }
static NotificationCategory getCategory(String id)
void addNamedValue(String name, Object value)
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41
void deleteObject(Object obj)
Definition: Dao.java:162
int executeUpdate(String query)
Definition: Dao.java:463
void removeContactMails(String idContact)