BrightSide Workbench Full Report + Source Code
CategoryParticipationCatcher.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.dossier.db.DossierPU;
21 import org.turro.dossier.entity.Category;
22 import org.turro.dossier.entity.CategoryParticipant;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.i18n.I_;
25 import org.turro.jpa.Dao;
26 import org.turro.path.Path;
27 import org.turro.plugin.contacts.IContact;
28 import org.turro.util.Chars;
29 
34 @ParticipationCatcher
35 public class CategoryParticipationCatcher extends JpaParticipationCatcher<CategoryParticipant> {
36 
37  @Override
38  public String getDescription() {
39  return "BrightSide Dossiers - " + I_.get("Category");
40  }
41 
42  @Override
43  public Dao createDao() {
44  return new DossierPU();
45  }
46 
47  @Override
48  public WhereClause getQuery(Path entityPath) {
49  if(!entityPath.isRoot() && "contact".equals(entityPath.getRoot())) {
50  WhereClause wc = new WhereClause();
51  wc.addClause("select distinct cparticipant from CategoryParticipant as cparticipant");
52  wc.addClause("where cparticipant.idContact = :id");
53  wc.addNamedValue("id", entityPath.getLastNode());
54  return wc;
55  }
56  return null;
57  }
58 
59  @Override
60  public boolean getCanDelete(CategoryParticipant v) {
61  return true;
62  }
63 
64  @Override
66  return v.getCategory().getFullDescription() + Chars.forward().spaced() + I_.byKey(v.getRole().toString());
67  }
68 
69  @Override
70  public void doDelete(CategoryParticipant v) {
71  Category c = v.getCategory();
72  c.getParticipants().remove(v);
73  getDao().saveObject(c);
74  }
75 
76  @Override
77  public void doShow(CategoryParticipant v) {
78  throw new UnsupportedOperationException("Not supported yet.");
79  }
80 
81  @Override
82  public void onChange(Object entity) {
83  if(entity instanceof IContact) {
84  IContact contact = (IContact) entity;
86  "update CategoryParticipant set name = ? " +
87  "where idContact = ?",
88  new Object[] { contact.getName(), contact.getId() });
89  }
90  }
91 
92  @Override
93  public void onDelete(Object entity) {
94  // do nothing
95  }
96 
97  @Override
99  return true;
100  }
101 
102  @Override
103  public void doChangeFor(CategoryParticipant v, Path toPath) {
104  if(v != null && !toPath.isRoot() && "contact".equals(toPath.getRoot())) {
105  WhereClause wc = new WhereClause();
106  wc.addClause("update CategoryParticipant");
107  wc.addClause("set idContact = :to");
108  wc.addClause("where idContact = :from");
109  wc.addNamedValue("to", toPath.getLastNode());
110  wc.addNamedValue("from", v.getIdContact());
111  getDao().executeUpdate(wc);
112  }
113  }
114 
115  @Override
117  return v.getCategory();
118  }
119 
120 }
void doChangeFor(CategoryParticipant v, Path toPath)
Set< CategoryParticipant > getParticipants()
Definition: Category.java:116
void addNamedValue(String name, Object value)
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41
int executeUpdate(String query)
Definition: Dao.java:463