BrightSide Workbench Full Report + Source Code
PublicationParticipationCatcher.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.activity;
19 
20 import org.turro.elephant.db.WhereClause;
21 import org.turro.i18n.I_;
22 import org.turro.jpa.Dao;
23 import org.turro.path.Path;
24 import org.turro.plugin.contacts.IContact;
25 import org.turro.publication.db.PublicationPU;
26 import org.turro.publication.entity.Publication;
27 import org.turro.publication.zul.menu.PublicationMenu;
28 
33 @ParticipationCatcher
34 public class PublicationParticipationCatcher extends JpaParticipationCatcher<Publication> {
35 
36  @Override
37  public String getDescription() {
38  return "BrightSide Publications - " + I_.get("Author");
39  }
40 
41  @Override
42  public Dao createDao() {
43  return new PublicationPU();
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 publication from Publication as publication");
51  wc.addClause("where publication.idContact = :id");
52  wc.addNamedValue("id", entityPath.getLastNode());
53  return wc;
54  }
55  return null;
56  }
57 
58  @Override
59  public boolean getCanDelete(Publication v) {
60  return false;
61  }
62 
63  @Override
64  public String getDescription(Publication v) {
65  return v.getTitle();
66  }
67 
68  @Override
69  public void doDelete(Publication v) {
70  getDao().deleteObject(v);
71  }
72 
73  @Override
74  public void doShow(Publication v) {
76  }
77 
78  @Override
79  public void onChange(Object entity) {
80  if(entity instanceof IContact) {
81  IContact contact = (IContact) entity;
82  // do nothing
83  }
84  }
85 
86  @Override
87  public void onDelete(Object entity) {
88  // do nothing
89  }
90 
91  @Override
92  public boolean getCanChangeFor(Publication v) {
93  return true;
94  }
95 
96  @Override
97  public void doChangeFor(Publication v, Path toPath) {
98  if(v != null && !toPath.isRoot() && "contact".equals(toPath.getRoot())) {
99  WhereClause wc = new WhereClause();
100  wc.addClause("update Publication");
101  wc.addClause("set idContact = :to");
102  wc.addClause("where idContact = :from");
103  wc.addNamedValue("to", toPath.getLastNode());
104  wc.addNamedValue("from", v.getIdContact());
105  getDao().executeUpdate(wc);
106  }
107  }
108 
109  @Override
110  public Object getReferringEntity(Publication v) {
111  return v;
112  }
113 
114 }
void addNamedValue(String name, Object value)
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