BrightSide Workbench Full Report + Source Code
SendableActivityCatcher.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.amic.util.date.DateFormats;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.db.ElephantPU;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.elephant.entities.db.Sendable;
26 import org.turro.jpa.Dao;
27 import org.turro.path.Path;
28 
33 public class SendableActivityCatcher extends JpaParticipationCatcher<Sendable> {
34 
35  @Override
36  public String getDescription() {
37  return "Sendable";
38  }
39 
40  @Override
41  public Dao createDao() {
42  return new ElephantPU();
43  }
44 
45  @Override
46  public WhereClause getQuery(Path entityPath) {
47  if(!entityPath.isRoot() && "contact".equals(entityPath.getRoot())) {
48  WhereClause wc = new WhereClause();
49  wc.addClause("select distinct s from Sendable as s");
50  wc.addClause("where s.entityPath = :path");
51  wc.addNamedValue("path", entityPath.getPath());
52  return wc;
53  }
54  return null;
55  }
56 
57  @Override
58  public boolean getCanDelete(Sendable v) {
59  return true;
60  }
61 
62  @Override
63  public String getDescription(Sendable v) {
64  return v != null ? DateFormats.format(v.getSchedule(), "MEDIUM", Application.getUsedLocale()) : "";
65  }
66 
67  @Override
68  public void doDelete(Sendable v) {
69  getDao().deleteObject(v);
70  }
71 
72  @Override
73  public void doShow(Sendable v) {
74  // do nothing
75  }
76 
77  @Override
78  public void onChange(Object entity) {
79  // do nothing
80  }
81 
82  @Override
83  public void onDelete(Object entity) {
84  // do nothing
85  }
86 
87  @Override
88  public boolean getCanChangeFor(Sendable v) {
89  return true;
90  }
91 
92  @Override
93  public void doChangeFor(Sendable v, Path toPath) {
94  if(v != null && !toPath.isRoot()) {
95  WhereClause wc = new WhereClause();
96  wc.addClause("update Sendable");
97  wc.addClause("set entityPath = :to");
98  wc.addClause("where entityPath = :from");
99  wc.addNamedValue("to", toPath.getPath());
100  wc.addNamedValue("from", v.getEntityPath());
101  getDao().executeUpdate(wc);
102  }
103  }
104 
105  @Override
106  public Object getReferringEntity(Sendable v) {
107  return v.getEntity();
108  }
109 
110 }
void addNamedValue(String name, Object value)
void deleteObject(Object obj)
Definition: Dao.java:162
int executeUpdate(String query)
Definition: Dao.java:463