BrightSide Workbench Full Report + Source Code
Customer.java
Go to the documentation of this file.
1 package org.turro.crm.entity;
2 
3 import java.util.Collection;
4 import java.util.HashSet;
5 import java.util.List;
6 import java.util.Set;
7 import javax.persistence.*;
8 import org.turro.string.Strings;
9 import org.turro.action.Contacts;
10 import org.turro.jpa.entity.IDaoEntity;
11 import org.turro.plugin.contacts.IContact;
12 
17 @Entity
18 public class Customer implements java.io.Serializable, IDaoEntity {
19 
20  @Id
21  @GeneratedValue(strategy=GenerationType.IDENTITY)
22  @Column(name="IDENTIFIER")
23  private long id;
24 
25  private String name;
26 
27  private String idContact;
28 
29  @JoinTable(name="Customer_ActivitySector")
30  @ManyToMany(fetch = FetchType.EAGER, targetEntity = ActivitySector.class)
31  private Set<ActivitySector> activitySectors = new HashSet<ActivitySector>();
32 
33  @JoinTable(name="Customer_CustomerSector")
34  @ManyToMany(fetch = FetchType.EAGER, targetEntity = ActivitySector.class)
35  private Set<ActivitySector> customerSectors = new HashSet<ActivitySector>();
36 
37  @ManyToMany(fetch = FetchType.EAGER, targetEntity = Technology.class)
38  private Set<Technology> technologies = new HashSet<Technology>();
39 
40  @OneToMany(mappedBy = "customer", fetch = FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
41  private Set<CustomerOwner> ownedBy = new HashSet<CustomerOwner>();
42 
43  @OneToMany(mappedBy = "customer", fetch = FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
44  private Set<SaleProspect> saleProspects = new HashSet<SaleProspect>();
45 
46  public Set<ActivitySector> getActivitySectors() {
47  return activitySectors;
48  }
49 
50  public void setActivitySectors(Set<ActivitySector> activitySectors) {
51  this.activitySectors = activitySectors;
52  }
53 
54  public Set<ActivitySector> getCustomerSectors() {
55  return customerSectors;
56  }
57 
58  public void setCustomerSectors(Set<ActivitySector> customerSectors) {
59  this.customerSectors = customerSectors;
60  }
61 
62  public long getId() {
63  return id;
64  }
65 
66  public void setId(long id) {
67  this.id = id;
68  }
69 
70  public String getIdContact() {
71  return idContact;
72  }
73 
74  public void setIdContact(String idContact) {
75  this.idContact = idContact;
76  resetIContact();
78  }
79 
80  public String getName() {
81  return name;
82  }
83 
84  public void setName(String name) {
85  this.name = name;
86  }
87 
88  public Set<CustomerOwner> getOwnedBy() {
89  return ownedBy;
90  }
91 
92  public void setOwnedBy(Set<CustomerOwner> ownedBy) {
93  this.ownedBy = ownedBy;
94  }
95 
96  public Set<SaleProspect> getSaleProspects() {
97  return saleProspects;
98  }
99 
100  public void setSaleProspects(Set<SaleProspect> saleProspects) {
101  this.saleProspects = saleProspects;
102  }
103 
104  public Set<Technology> getTechnologies() {
105  return technologies;
106  }
107 
108  public void setTechnologies(Set<Technology> technologies) {
109  this.technologies = technologies;
110  }
111 
112  /* IDaoEntity */
113 
114  @Override
115  public Object entityId() {
116  return id;
117  }
118 
119  @Override
120  public boolean isEmpty() {
121  return Strings.isBlank(idContact);
122  }
123 
124  @Override
125  public Collection<Collection> collections() {
126  return List.of(ownedBy);
127  }
128 
131  private transient IContact _contact;
132 
134  if(_contact == null) {
135  _contact = Contacts.getContactById(idContact);
136  }
137  return _contact;
138  }
139 
140  public void setIContact(IContact contact) {
141  _contact = contact;
142  idContact = _contact != null ? _contact.getId() : null;
143  name = _contact != null ? _contact.getName() : null;
144  }
145 
146  private void resetIContact() {
147  _contact = null;
148  }
149 
150 }
static IContact getContactById(String id)
Definition: Contacts.java:72
Set< ActivitySector > getActivitySectors()
Definition: Customer.java:46
void setOwnedBy(Set< CustomerOwner > ownedBy)
Definition: Customer.java:92
Set< CustomerOwner > getOwnedBy()
Definition: Customer.java:88
void setCustomerSectors(Set< ActivitySector > customerSectors)
Definition: Customer.java:58
Set< SaleProspect > getSaleProspects()
Definition: Customer.java:96
Set< Technology > getTechnologies()
Definition: Customer.java:104
Set< ActivitySector > getCustomerSectors()
Definition: Customer.java:54
void setIContact(IContact contact)
Definition: Customer.java:140
void setName(String name)
Definition: Customer.java:84
Collection< Collection > collections()
Definition: Customer.java:125
void setTechnologies(Set< Technology > technologies)
Definition: Customer.java:108
void setSaleProspects(Set< SaleProspect > saleProspects)
Definition: Customer.java:100
void setIdContact(String idContact)
Definition: Customer.java:74
void setActivitySectors(Set< ActivitySector > activitySectors)
Definition: Customer.java:50