BrightSide Workbench Full Report + Source Code
InTouchParticipationCatcher.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.InTouch;
22 import org.turro.contacts.db.ContactsPU;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.entities.Entities;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.Dao;
27 import org.turro.path.Path;
28 
33 @ParticipationCatcher
35 
36  @Override
37  public String getDescription() {
38  return "BrightSide Contacts - " + I_.get("In touch");
39  }
40 
41  @Override
42  public Dao createDao() {
43  return new ContactsPU();
44  }
45 
46  @Override
47  public WhereClause getQuery(Path entityPath) {
48  if(!entityPath.isRoot() && "contact".equals(entityPath.getRoot())) {
49  WhereClause wc = new WhereClause();
50  wc.addClause("select distinct a from InTouch as a");
51  wc.addClause("where a.contact.id = :idc");
52  wc.addNamedValue("idc", entityPath.getLastNode());
53  wc.addClause("or a.address.contact.id = :idp");
54  wc.addNamedValue("idp", entityPath.getLastNode());
55  wc.addClause("or a.path = :path");
56  wc.addNamedValue("path", entityPath.getPath());
57  return wc;
58  }
59  return null;
60  }
61 
62  @Override
63  public boolean getCanDelete(InTouch v) {
64  return true;
65  }
66 
67  @Override
68  public String getDescription(InTouch v) {
69  return Entities.getController(v.getName()).getName();
70  }
71 
72  @Override
73  public void doDelete(InTouch v) {
74  getDao().deleteObject(v);
75  }
76 
77  @Override
78  public void doShow(InTouch v) {
79  // nothing to show?
80  }
81 
82  @Override
83  public void onChange(Object entity) {
84  // do nothing
85  }
86 
87  @Override
88  public void onDelete(Object entity) {
89  // do nothing
90  }
91 
92  @Override
93  public boolean getCanChangeFor(InTouch v) {
94  return false;
95  }
96 
97  @Override
98  public void doChangeFor(InTouch v, Path toPath) {
99  // do nothing
100  }
101 
102  @Override
103  public Object getReferringEntity(InTouch v) {
104  return Entities.getController(v.getPath()).getEntity();
105  }
106 
107 }
108 
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
Definition: Entities.java:78
static String get(String msg)
Definition: I_.java:41
void deleteObject(Object obj)
Definition: Dao.java:162