BrightSide Workbench Full Report + Source Code
ContractParticipationCatcher.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 java.util.List;
21 import org.turro.elephant.db.WhereClause;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.Contract;
24 import org.turro.financials.menu.FinancialsMenu;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.Dao;
27 import org.turro.path.Path;
28 import org.turro.plugin.contacts.IContact;
29 
34 @ParticipationCatcher
35 public class ContractParticipationCatcher extends JpaParticipationCatcher<Contract> {
36 
37  @Override
38  public String getDescription() {
39  return "BrightSide Financials - " + I_.get("Contract");
40  }
41 
42  @Override
43  public Dao createDao() {
44  return new FinancialsPU();
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 contract from Contract as contract");
52  wc.addClause("left join contract.participants as participant");
53  wc.addClause("where contract.contractor = :id");
54  wc.addNamedValue("id", entityPath.getLastNode());
55  wc.addClause("or participant.idContact = :id2");
56  wc.addNamedValue("id2", entityPath.getLastNode());
57  wc.addClause("order by contract.id");
58  return wc;
59  }
60  return null;
61  }
62 
63  @Override
64  public boolean getCanDelete(Contract v) {
65  return false;
66  }
67 
68  @Override
69  public String getDescription(Contract v) {
70  return v.getName();
71  }
72 
73  @Override
74  public void doDelete(Contract v) {
75  getDao().deleteObject(v);
76  }
77 
78  @Override
79  public void doShow(Contract v) {
81  }
82 
83  @Override
84  public void onChange(Object entity) {
85  if(entity instanceof IContact) {
86  IContact contact = (IContact) entity;
87  List<Contract> contracts = getDao().getResultList(
88  "select c from Contract c where c.contractor = ?",
89  new Object[] { contact.getId() });
90  for(Contract contract : contracts) {
92  "update Contract set name = ? " +
93  "where id = ?",
94  new Object[] { contract.getFullDescription(), contract.getId() });
95  }
97  "update ContractParticipant set name = ? " +
98  "where idContact = ?",
99  new Object[] { contact.getName(), contact.getId() });
100  }
101  }
102 
103  @Override
104  public void onDelete(Object entity) {
105  // do nothing
106  }
107 
108  @Override
109  public boolean getCanChangeFor(Contract v) {
110  return false;
111  }
112 
113  @Override
114  public void doChangeFor(Contract v, Path toPath) {
115  // do nothing
116  }
117 
118  @Override
119  public Object getReferringEntity(Contract v) {
120  return v;
121  }
122 
123 }
124 
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