BrightSide Workbench Full Report + Source Code
Vendor.java
Go to the documentation of this file.
1 package org.turro.crm.entity;
2 
3 import java.util.HashSet;
4 import java.util.Set;
5 import javax.persistence.*;
6 import org.turro.string.Strings;
7 import org.turro.action.Contacts;
8 import org.turro.crm.db.CrmPU;
9 import org.turro.jpa.Dao;
10 import org.turro.jpa.entity.IDaoEntity;
11 import org.turro.plugin.contacts.IContact;
12 
17 @Entity
18 public class Vendor implements java.io.Serializable, IDaoEntity {
19  @Id
20  @GeneratedValue(strategy=GenerationType.IDENTITY)
21  @Column(name="IDENTIFIER")
22  private long id;
23 
24  private String name;
25 
26  private String idContact;
27 
28  @OneToMany(mappedBy = "vendor", fetch = FetchType.LAZY)
29  private Set<CustomerOwner> customerOwned = new HashSet<CustomerOwner>();
30 
31  @OneToMany(mappedBy = "vendor", fetch = FetchType.LAZY)
32  private Set<VendorProspect> vendorProspects = new HashSet<VendorProspect>();
33 
34  public Set<CustomerOwner> getCustomerOwned() {
35  Dao dao = new CrmPU();
36  if(id > 0 && dao.isNotLoaded(customerOwned)) {
37  customerOwned = dao.lazyLoader(Vendor.class, this, "customerOwned").customerOwned;
38  }
39  return customerOwned;
40  }
41 
42  public void setCustomerOwned(Set<CustomerOwner> customerOwned) {
43  this.customerOwned = customerOwned;
44  }
45 
46  public long getId() {
47  return id;
48  }
49 
50  public void setId(long id) {
51  this.id = id;
52  }
53 
54  public String getIdContact() {
55  return idContact;
56  }
57 
58  public void setIdContact(String idContact) {
59  this.idContact = idContact;
60  resetIContact();
62  }
63 
64  public String getName() {
65  return name;
66  }
67 
68  public void setName(String name) {
69  this.name = name;
70  }
71 
72  public Set<VendorProspect> getVendorProspects() {
73  Dao dao = new CrmPU();
74  if(id > 0 && dao.isNotLoaded(vendorProspects)) {
75  vendorProspects = dao.lazyLoader(Vendor.class, this, "vendorProspects").vendorProspects;
76  }
77  return vendorProspects;
78  }
79 
80  public void setVendorProspects(Set<VendorProspect> vendorProspects) {
81  this.vendorProspects = vendorProspects;
82  }
83 
84  /* IDaoEntity */
85 
86  @Override
87  public Object entityId() {
88  return id;
89  }
90 
91  @Override
92  public boolean isEmpty() {
93  return Strings.isBlank(idContact);
94  }
95 
98  private transient IContact _contact;
99 
101  if(_contact == null) {
102  _contact = Contacts.getContactById(idContact);
103  }
104  return _contact;
105  }
106 
107  public void setIContact(IContact contact) {
108  _contact = contact;
109  idContact = _contact != null ? _contact.getId() : null;
110  name = _contact != null ? _contact.getName() : null;
111  }
112 
113  private void resetIContact() {
114  _contact = null;
115  }
116 
117 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setName(String name)
Definition: Vendor.java:68
void setCustomerOwned(Set< CustomerOwner > customerOwned)
Definition: Vendor.java:42
void setIdContact(String idContact)
Definition: Vendor.java:58
Set< CustomerOwner > getCustomerOwned()
Definition: Vendor.java:34
Set< VendorProspect > getVendorProspects()
Definition: Vendor.java:72
void setVendorProspects(Set< VendorProspect > vendorProspects)
Definition: Vendor.java:80
void setIContact(IContact contact)
Definition: Vendor.java:107
boolean isNotLoaded(Object o, String attribute)
Definition: Dao.java:216