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