BrightSide Workbench Full Report + Source Code
AttendeeParticipationCatcher.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.contacts.Attendee;
22 import org.turro.contacts.db.ContactsPU;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.jpa.Dao;
25 import org.turro.path.Path;
26 
31 @ParticipationCatcher
32 public class AttendeeParticipationCatcher extends JpaParticipationCatcher<Attendee> {
33 
34  @Override
35  public String getDescription() {
36  return "BrightSide Contacts - Attendee";
37  }
38 
39  @Override
40  public Dao createDao() {
41  return new ContactsPU();
42  }
43 
44  @Override
45  public WhereClause getQuery(Path entityPath) {
46  WhereClause wc = new WhereClause();
47  wc.addClause("select distinct a from Attendee as a");
48  wc.addClause("where a.contact.id = :id");
49  wc.addNamedValue("id", entityPath.getLastNode());
50  return wc;
51  }
52 
53  @Override
54  public boolean getCanDelete(Attendee v) {
55  return true;
56  }
57 
58  @Override
59  public String getDescription(Attendee v) {
60  return v.getConvocation().getName();
61  }
62 
63  @Override
64  public void doDelete(Attendee v) {
65  // Using SQL because has cascading attributes in Convocation
66  WhereClause wc = new WhereClause();
67  wc.addClause("delete from Attendee where id = :id");
68  wc.addNamedValue("id", v.getId());
69  getDao().executeUpdate(wc);
70  }
71 
72  @Override
73  public void doShow(Attendee v) {
74  // nothing to show?
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(Attendee v) {
89  return false;
90  }
91 
92  @Override
93  public void doChangeFor(Attendee v, Path toPath) {
94  // do nothing
95  }
96 
97  @Override
98  public Object getReferringEntity(Attendee v) {
99  return v.getConvocation();
100  }
101 
102 }
103 
104 
Convocation getConvocation()
Definition: Attendee.java:63
void addNamedValue(String name, Object value)
int executeUpdate(String query)
Definition: Dao.java:463