BrightSide Workbench Full Report + Source Code
ProductFilter.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.financials.product;
19 
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.List;
23 import org.turro.string.Strings;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.financials.db.FinancialsPU;
26 import org.turro.financials.entity.Product;
27 import org.turro.jpa.Dao;
28 import org.turro.plugin.filter.IFilterValue;
29 
34 public class ProductFilter {
35 
36  public ProductFilter() {
37  }
38 
39  public Collection<Product> getProducts(List<IFilterValue> values) {
40  Dao dao = new FinancialsPU();
41  try {
42  WhereClause wc = createCriteria(values);
43  if(!Strings.isEmpty(wc.getClause())) {
44  return dao.getResultList(wc, 300);
45  } else {
46  return Collections.EMPTY_LIST;
47  }
48  } finally {
49  dao.close();
50  }
51  }
52 
53 // public void checkGroup(Grid grid, Contract contract) {
54 // if("ctc.contractDefinition.id".equals(mainOrderField)) {
55 // if(lastContract == 0 || lastContract != contract.getContractDefinition().getId()) {
56 // lastContract = contract.getContractDefinition().getId();
57 // Group group = new GroupExtended(contract.getContractDefinition().getName());
58 // group.setOpen(false);
59 // grid.getRows().appendChild(group);
60 // }
61 // } else if("ctc.contractor".equals(mainOrderField)) {
62 // if(lastContact == null || !lastContact.equals(contract.getContractor())) {
63 // lastContact = contract.getContractor();
64 // Group group = new GroupExtended(contract.getIContractor().getName());
65 // group.setOpen(false);
66 // grid.getRows().appendChild(group);
67 // }
68 // }
69 // }
70 
71  private WhereClause createCriteria(List<IFilterValue> values) {
72  WhereClause wc = new WhereClause();
73  wc.addClause("select prod from Product as prod");
74  wc.addClause("where 1=1");
75  for(IFilterValue v : values) {
76  v.addConstraint(wc);
77  }
78  wc.addClause("order by prod.description, prod.productCode, prod.id");
79  return wc;
80  }
81 
82 }
Collection< Product > getProducts(List< IFilterValue > values)
void close()
Definition: Dao.java:71