BrightSide Workbench Full Report + Source Code
ContractRelations.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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 
19 package org.turro.financials.model.contract;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.ContractParticipant;
26 import org.turro.plugin.contacts.IContactRelation;
27 import org.turro.plugin.contacts.IContactRelationSolver;
28 import org.turro.plugin.contacts.ContactRelationSolver;
29 
34 @ContactRelationSolver
35 public class ContractRelations implements IContactRelationSolver {
36 
37  @Override
38  public boolean isDirect() {
39  return false;
40  }
41 
42  @Override
43  public List<IContactRelation> getRelations(String idContact) {
44  List<IContactRelation> list = new ArrayList<>();
45  list.addAll(getBusiness(idContact));
46  list.addAll(getWorkers(idContact));
47  return list;
48  }
49 
50  @Override
51  public List<IContactRelation> getBusiness(String idContact) {
52  List<IContactRelation> list = new ArrayList<>();
53  WhereClause wc = new WhereClause();
54  wc.addClause("select cp from ContractParticipant as cp");
55  wc.addClause("where cp.idContact = :idContact");
56  wc.addNamedValue("idContact", idContact);
57  for(ContractParticipant cp : new FinancialsPU().getResultList(ContractParticipant.class, wc)) {
58  if(!cp.isEmpty()) {
59  list.add(new ContactRelationAdapter(true, cp));
60  }
61  }
62  return list;
63  }
64 
65  @Override
66  public List<IContactRelation> getWorkers(String idContact) {
67  List<IContactRelation> list = new ArrayList<>();
68  WhereClause wc = new WhereClause();
69  wc.addClause("select cp from ContractParticipant as cp");
70  wc.addClause("where cp.contract.contractor = :idContact");
71  wc.addNamedValue("idContact", idContact);
72  for(ContractParticipant cp : new FinancialsPU().getResultList(ContractParticipant.class, wc)) {
73  if(!cp.isEmpty()) {
74  list.add(new ContactRelationAdapter(false, cp));
75  }
76  }
77  return list;
78  }
79 
80 }
void addNamedValue(String name, Object value)
List< IContactRelation > getWorkers(String idContact)
List< IContactRelation > getRelations(String idContact)
List< IContactRelation > getBusiness(String idContact)