BrightSide Workbench Full Report + Source Code
CompanyParticipationCatcher.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.financials.db.FinancialsPU;
22 import org.turro.financials.entity.Company;
23 import org.turro.i18n.I_;
24 import org.turro.jpa.Dao;
25 import org.turro.path.Path;
26 import org.turro.plugin.contacts.IContact;
27 
34 
35  @Override
36  public String getDescription() {
37  return "BrightSide Business - " + I_.get("Company");
38  }
39 
40  @Override
41  public Dao createDao() {
42  return new FinancialsPU();
43  }
44 
45  @Override
46  public WhereClause getQuery(Path entityPath) {
47  if(!entityPath.isRoot() && "contact".equals(entityPath.getRoot())) {
48  WhereClause wc = new WhereClause();
49  wc.addClause("select distinct company from Company as company");
50  wc.addClause("where company.idContact = :id");
51  wc.addNamedValue("id", entityPath.getLastNode());
52  return wc;
53  }
54  return null;
55  }
56 
57  @Override
58  public boolean getCanDelete(Company v) {
59  return false;
60  }
61 
62  @Override
63  public String getDescription(Company v) {
64  return v.getName();
65  }
66 
67  @Override
68  public void doDelete(Company v) {
69  getDao().deleteObject(v);
70  }
71 
72  @Override
73  public void doShow(Company v) {
74  throw new UnsupportedOperationException("Not supported yet.");
75  }
76 
77  @Override
78  public void onChange(Object entity) {
79  if(entity instanceof IContact) {
80  IContact contact = (IContact) entity;
82  "update Company set name = ? " +
83  "where idContact = ?",
84  new Object[] { contact.getName(), contact.getId() });
85  }
86  }
87 
88  @Override
89  public void onDelete(Object entity) {
90  // do nothing
91  }
92 
93  @Override
94  public boolean getCanChangeFor(Company v) {
95  return false;
96  }
97 
98  @Override
99  public void doChangeFor(Company v, Path toPath) {
100  // do nothing
101  }
102 
103  @Override
104  public Object getReferringEntity(Company v) {
105  return v;
106  }
107 
108 }
109 
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