BrightSide Workbench Full Report + Source Code
IssueParticipationCatcher.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.Issue;
22 import org.turro.dossier.entity.IssueParticipant;
23 import org.turro.dossier.entity.IssueParticipantRole;
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 IssueParticipationCatcher extends JpaParticipationCatcher<IssueParticipant> {
38 
39  @Override
40  public String getDescription() {
41  return "BrightSide Dossiers - " + I_.get("Issue");
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 iparticipant from IssueParticipant as iparticipant");
54  wc.addClause("where iparticipant.idContact = :id");
55  wc.addNamedValue("id", entityPath.getLastNode());
56  return wc;
57  }
58  return null;
59  }
60 
61  @Override
62  public boolean getCanDelete(IssueParticipant v) {
63  return IssueParticipantRole.ISSUE_ASSISTANT.equals(v.getRole());
64  }
65 
66  @Override
67  public String getDescription(IssueParticipant v) {
68  return v.getIssue().getDescription() + Chars.forward().spaced() + I_.byKey(v.getRole().toString());
69  }
70 
71  @Override
72  public void doDelete(IssueParticipant v) {
73  Issue i = v.getIssue();
74  i.getParticipants().remove(v);
75  getDao().saveObject(i);
76  }
77 
78  @Override
79  public void doShow(IssueParticipant v) {
81  }
82 
83  @Override
84  public void onChange(Object entity) {
85  if(entity instanceof IContact) {
86  IContact contact = (IContact) entity;
88  "update IssueParticipant 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(IssueParticipant v) {
101  return true;
102  }
103 
104  @Override
105  public void doChangeFor(IssueParticipant v, Path toPath) {
106  if(v != null && !toPath.isRoot() && "contact".equals(toPath.getRoot())) {
107  WhereClause wc = new WhereClause();
108  wc.addClause("update IssueParticipant");
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
119  return v.getIssue();
120  }
121 
122 }
void doChangeFor(IssueParticipant v, Path toPath)
Set< IssueParticipant > getParticipants()
Definition: Issue.java:114
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