BrightSide Workbench Full Report + Source Code
SaleProspect.java
Go to the documentation of this file.
1 package org.turro.crm.entity;
2 
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Date;
6 import java.util.HashSet;
7 import java.util.List;
8 import java.util.Set;
9 import javax.persistence.*;
10 import org.turro.string.Strings;
11 import org.turro.action.Contacts;
12 import org.turro.crm.db.CrmPU;
13 import org.turro.crm.zul.sale.ProspectStageWrapper;
14 import org.turro.crm.zul.sale.SaleActionSet;
15 import org.turro.jpa.Dao;
16 import org.turro.jpa.entity.IDaoEntity;
17 import org.turro.plugin.contacts.IContact;
18 
23 @Entity
24 public class SaleProspect implements java.io.Serializable, IDaoEntity {
25 
26  @Id
27  @GeneratedValue(strategy=GenerationType.IDENTITY)
28  @Column(name="IDENTIFIER")
29  private long id;
30 
31  @Lob
32  @Column(length=4096)
33  private String description;
34 
35  private double budget;
36 
37  private ProspectType type;
38 
39  private ProspectStage stage;
40 
41  @ManyToOne
42  private Customer customer;
43 
44  @Temporal(TemporalType.TIMESTAMP)
45  private java.util.Date prospectDate;
46 
47  @Temporal(TemporalType.TIMESTAMP)
48  private java.util.Date closingDate;
49 
50  @ManyToOne
51  private Campaign campaign;
52 
53  @OneToMany(mappedBy="saleProspect", fetch = FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
54  private Set<VendorProspect> vendorProspects = new HashSet<VendorProspect>();
55 
56  @ElementCollection(fetch=FetchType.EAGER)
57  private Set<String> attendees = new HashSet<String>();
58 
59  public Set<String> getAttendees() {
60  return attendees;
61  }
62 
63  public void setAttendees(Set<String> attendees) {
64  this.attendees = attendees;
65  }
66 
67  public double getBudget() {
68  return budget;
69  }
70 
71  public void setBudget(double budget) {
72  this.budget = budget;
73  }
74 
75  public Campaign getCampaign() {
76  return campaign;
77  }
78 
79  public void setCampaign(Campaign campaign) {
80  this.campaign = campaign;
81  }
82 
83  public Date getClosingDate() {
84  return closingDate;
85  }
86 
87  public void setClosingDate(Date closingDate) {
88  this.closingDate = closingDate;
89  }
90 
91  public Customer getCustomer() {
92  return customer;
93  }
94 
95  public void setCustomer(Customer customer) {
96  this.customer = customer;
97  }
98 
99  public String getDescription() {
100  return description;
101  }
102 
103  public void setDescription(String description) {
104  this.description = description;
105  }
106 
107  public long getId() {
108  return id;
109  }
110 
111  public void setId(long id) {
112  this.id = id;
113  }
114 
115  public Date getProspectDate() {
116  return prospectDate;
117  }
118 
119  public void setProspectDate(Date prospectDate) {
120  this.prospectDate = prospectDate;
121  }
122 
124  return stage;
125  }
126 
127  public void setStage(ProspectStage stage) {
128  this.stage = stage;
129  }
130 
132  return type;
133  }
134 
135  public void setType(ProspectType type) {
136  this.type = type;
137  }
138 
139  public Set<VendorProspect> getVendorProspects() {
140  return vendorProspects;
141  }
142 
143  public void setVendorProspects(Set<VendorProspect> vendorProspects) {
144  this.vendorProspects = vendorProspects;
145  }
146 
147  /* IDaoEntity */
148 
149  @Override
150  public Object entityId() {
151  return id;
152  }
153 
154  @Override
155  public boolean isEmpty() {
156  return Strings.isBlank(description) || customer == null;
157  }
158 
159  @Override
160  public Collection<Collection> collections() {
161  return List.of(vendorProspects);
162  }
163 
164  /* Helpers */
165 
166  public String getFullDescription() {
167  return Strings.truncateAndWarn(description, 50) +
168  (customer == null ? "" : " (" + customer.getName() + ")");
169  }
170 
172  return new SaleActionSet(this);
173  }
174 
177  return (set != null && !set.isEmpty()) ? set.last() : null;
178  }
179 
180  public Set<VendorProspect> getUpdatedVendorProspects() {
181  if(id > 0) {
182  Dao dao = new CrmPU();
183  return dao.lazyLoader(SaleProspect.class, this, "vendorProspects").vendorProspects;
184  }
185  return vendorProspects;
186  }
187 
189  return new ProspectStageWrapper(this, new Date());
190  }
191 
194  public Collection<IContact> getIAttendees() {
195  ArrayList<IContact> list = new ArrayList<IContact>();
196  for(String s : attendees) {
198  if(c.isValid()) list.add(c);
199  }
200  return list;
201  }
202 
203  public void setIAttendees(Collection<IContact> contacts) {
204  attendees.clear();
205  for(IContact c : contacts) {
206  if(c.isValid()) attendees.add(c.getId());
207  }
208  }
209 
210  public void addCustomerOwner(CustomerOwner customerOwner) {
211  VendorProspect vp = existsVendor(customerOwner.getVendor());
212  if(vp == null) {
213  vp = new VendorProspect();
214  vp.setSaleProspect(this);
215  vp.setVendor(customerOwner.getVendor());
216  getVendorProspects().add(vp);
217  }
218  vp.setComission(customerOwner.getComission());
219  vp.setAlert(customerOwner.getAlert());
220  }
221 
222  public void addCampaignVendor(CampaignVendor campaignVendor) {
223  VendorProspect vp = existsVendor(campaignVendor.getVendor());
224  if(vp == null) {
225  vp = new VendorProspect();
226  vp.setSaleProspect(this);
227  vp.setVendor(campaignVendor.getVendor());
228  getVendorProspects().add(vp);
229  }
230  vp.setComission(campaignVendor.getComission());
231  vp.setAlert(campaignVendor.getAlert());
232  }
233 
235  if(vendor != null) {
236  for(VendorProspect vp : vendorProspects) {
237  if(vp.getVendor() != null && vp.getVendor().getId() == vendor.getId()) {
238  return vp;
239  }
240  }
241  }
242  return null;
243  }
244 
245 }
static IContact getContactById(String id)
Definition: Contacts.java:72
Set< VendorProspect > getUpdatedVendorProspects()
void setStage(ProspectStage stage)
void setIAttendees(Collection< IContact > contacts)
void setClosingDate(Date closingDate)
void setCampaign(Campaign campaign)
void addCampaignVendor(CampaignVendor campaignVendor)
void setType(ProspectType type)
Collection< Collection > collections()
Set< VendorProspect > getVendorProspects()
void setCustomer(Customer customer)
void setDescription(String description)
VendorProspect existsVendor(Vendor vendor)
void setProspectDate(Date prospectDate)
Collection< IContact > getIAttendees()
void setVendorProspects(Set< VendorProspect > vendorProspects)
void setAttendees(Set< String > attendees)
ProspectStageWrapper getStageWrapper()
void addCustomerOwner(CustomerOwner customerOwner)
void setSaleProspect(SaleProspect saleProspect)
void setComission(Formula comission)