BrightSide Workbench Full Report + Source Code
CustomerResults.java
Go to the documentation of this file.
1 package org.turro.crm.search;
2 
3 import org.turro.auth.Authentication;
4 import org.turro.crm.db.CrmPU;
5 import org.turro.elephant.context.Application;
6 import org.turro.elephant.db.SQLHelper;
7 import org.turro.elephant.db.WhereClause;
8 import org.turro.jpa.Dao;
9 import org.turro.plugin.contacts.IContact;
10 import org.zkoss.lang.Strings;
11 
16 public class CustomerResults {
17 
18  private Application app = Application.getApplication();
19 
20  private boolean ckOthers;
21  private String customerValue = "*";
22  private IContact byParticipant;
23 
24  public CustomerResults() {
25  }
26 
27  public java.util.List getCustomerList() {
28  Dao dao = new CrmPU();
29  return dao.getResultList(createCriteria());
30  }
31 
33  WhereClause wc = new WhereClause();
34 
35  wc.addClause("select distinct customer");
36  wc.addClause("from Customer as customer");
37  wc.addClause("left outer join customer.ownedBy ownedBy");
38  wc.addClause("where 1=1");
39 
40  if(Strings.isEmpty(customerValue) || (ckOthers && !app.isInRole("customer:all"))) {
41  wc.addClause("order by customer.name");
42  return wc;
43  }
44 
45  if(byParticipant == null) {
46  byParticipant = Authentication.getIContact();
47  }
48 
49  wc = SQLHelper.getWhereClause(wc, new String[] {
50  "customer.name"
51  }, (customerValue == null ? "" : customerValue.replaceAll("\\*", "%")));
52 
53  if(!(ckOthers && app.isInRole("customer:all"))) {
54  wc.addClause("and (");
55 
56  wc.addClause("ownedBy.vendor.idContact = :idOwner");
57  wc.addNamedValue("idOwner", byParticipant.getId());
58 
59  wc.addClause("or exists (");
60 
61  wc.addClause(
62  "select vp from VendorProspect as vp where vendor.idContact = :idVendor " +
63  "and vp.saleProspect.customer = customer"
64  );
65  wc.addNamedValue("idVendor", byParticipant.getId());
66 
67  wc.addClause("))");
68  }
69 
70  wc.addClause("order by customer.name");
71 
72  return wc;
73  }
74 
76  return byParticipant;
77  }
78 
79  public void setByParticipant(IContact byParticipant) {
80  this.byParticipant = byParticipant;
81  }
82 
83  public boolean isCkOthers() {
84  return ckOthers;
85  }
86 
87  public void setCkOthers(boolean ckOthers) {
88  this.ckOthers = ckOthers;
89  }
90 
91  public String getCustomerValue() {
92  return customerValue;
93  }
94 
95  public void setCustomerValue(String customerValue) {
96  this.customerValue = customerValue;
97  }
98 
99 }
void setCustomerValue(String customerValue)
void setByParticipant(IContact byParticipant)
static WhereClause getWhereClause(String[] fields, String value)
Definition: SQLHelper.java:64
void addNamedValue(String name, Object value)