BrightSide Workbench Full Report + Source Code
SaleAction.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.Iterator;
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.contacts.Address;
13 import org.turro.contacts.db.ContactsPU;
14 import org.turro.jpa.entity.IDaoEntity;
15 import org.turro.plugin.contacts.IContact;
16 import org.turro.util.CompareUtil;
17 
22 @Entity
23 public class SaleAction implements java.io.Serializable, IDaoEntity, Comparable<SaleAction> {
24 
25  public static final int SA_PENDING = 0, SA_DONE = 1, SA_CANCELLED = 2;
26 
27  @Id
28  @GeneratedValue(strategy=GenerationType.IDENTITY)
29  @Column(name="IDENTIFIER")
30  private long id;
31 
32  @Temporal(TemporalType.TIMESTAMP)
33  private java.util.Date actionDate;
34 
35  @Temporal(TemporalType.TIMESTAMP)
36  private java.util.Date finalDate;
37 
38  @Lob
39  @Column(length=4096)
40  private String comment;
41 
42  @ManyToMany(fetch = FetchType.EAGER, targetEntity = TouchPoint.class)
43  private Set<TouchPoint> touchPoints = new HashSet<TouchPoint>();
44 
45  @ManyToOne
46  private VendorProspect vendorProspect;
47 
48  private int status;
49 
50  @ElementCollection(fetch=FetchType.EAGER)
51  private Set<String> attendees = new HashSet<String>();
52 
53  @ElementCollection(fetch=FetchType.EAGER)
54  private Set<String> actionType = new HashSet<String>();
55 
56  private String addressId;
57 
58  public Date getActionDate() {
59  return actionDate;
60  }
61 
62  public void setActionDate(Date actionDate) {
63  this.actionDate = actionDate;
64  }
65 
66  public Set<String> getActionType() {
67  return actionType;
68  }
69 
70  public void setActionType(Set<String> actionType) {
71  this.actionType = actionType;
72  }
73 
74  public String getAddressId() {
75  return addressId;
76  }
77 
78  public void setAddressId(String addressId) {
79  this.addressId = addressId;
80  }
81 
82  public Set<String> getAttendees() {
83  return attendees;
84  }
85 
86  public void setAttendees(Set<String> attendees) {
87  this.attendees = attendees;
88  }
89 
90  public String getComment() {
91  return comment;
92  }
93 
94  public void setComment(String comment) {
95  this.comment = comment;
96  }
97 
98  public Date getFinalDate() {
99  return finalDate;
100  }
101 
102  public void setFinalDate(Date finalDate) {
103  this.finalDate = finalDate;
104  }
105 
106  public long getId() {
107  return id;
108  }
109 
110  public void setId(long id) {
111  this.id = id;
112  }
113 
114  public int getStatus() {
115  return status;
116  }
117 
118  public void setStatus(int status) {
119  this.status = status;
120  }
121 
122  public Set<TouchPoint> getTouchPoints() {
123  return touchPoints;
124  }
125 
126  public void setTouchPoints(Set<TouchPoint> touchPoints) {
127  this.touchPoints = touchPoints;
128  }
129 
131  return vendorProspect;
132  }
133 
134  public void setVendorProspect(VendorProspect vendorProspect) {
135  this.vendorProspect = vendorProspect;
136  }
137 
138  /* Comparable */
139 
140  @Override
141  public int compareTo(SaleAction o) {
142  return CompareUtil.compare(actionDate, o.actionDate);
143  }
144 
145  /* IDaoEntity */
146 
147  @Override
148  public Object entityId() {
149  return id;
150  }
151 
152  @Override
153  public boolean isEmpty() {
154  return actionDate == null ||
155  finalDate == null ||
156  actionDate.after(finalDate) ||
157  Strings.isBlank(comment) ||
158  vendorProspect == null ||
159  actionType.isEmpty();
160  }
161 
162  @Override
163  public void removeEmpties() {
164  IDaoEntity.super.removeEmpties();
165  Iterator<String> it = attendees.iterator();
166  while(it.hasNext()) {
167  if(Strings.isBlank(it.next())) {
168  it.remove();
169  }
170  }
171  }
172 
173 
174  /* Helpers */
175 
176  public boolean isOverdue(Date now) {
177  return actionDate != null &&
178  actionDate.after(now);
179  }
180 
181  public void checkDate() {
182  if(actionDate == null) {
183  actionDate = new Date();
184  finalDate = new Date();
185  }
186  if(CompareUtil.compare(actionDate, finalDate) > 0) {
187  finalDate.setTime(actionDate.getTime());
188  }
189  }
190 
193  public Collection<IContact> getIAttendees() {
194  ArrayList<IContact> list = new ArrayList<>();
195  for(String s : attendees) {
197  if(c.isValid()) list.add(c);
198  }
199  return list;
200  }
201 
202  public void setIAttendees(Collection<IContact> contacts) {
203  attendees.clear();
204  for(IContact c : contacts) {
205  if(c.isValid()) attendees.add(c.getId());
206  }
207  }
208 
209  public Address getAddress() {
210  return (!Strings.isBlank(addressId) ?
211  new ContactsPU().find(Address.class, addressId) : null);
212  }
213 
214  public void setAddress(Address address) {
215  addressId = (address != null ? address.getId() : null);
216  }
217 
218  public Set<TouchPoint> getProcessTouchPoints() {
219  HashSet<TouchPoint> hs = new HashSet<TouchPoint>();
220  for(TouchPoint tp : getTouchPoints()) {
221  if(!tp.isEndsSale()) {
222  hs.add(tp);
223  }
224  }
225  return hs;
226  }
227 
228  public void setProcessTouchPoints(Set<TouchPoint> stp) {
229  Iterator<TouchPoint> it = getTouchPoints().iterator();
230  while(it.hasNext()) {
231  if(!it.next().isEndsSale()) {
232  it.remove();
233  }
234  }
235  getTouchPoints().addAll(stp);
236  }
237 
239  for(TouchPoint tp : getTouchPoints()) {
240  if(tp.isEndsSale()) {
241  return tp;
242  }
243  }
244  return null;
245  }
246 
247  public void setEndingTouchPoint(TouchPoint tp) {
248  Iterator<TouchPoint> it = getTouchPoints().iterator();
249  while(it.hasNext()) {
250  if(it.next().isEndsSale()) {
251  it.remove();
252  }
253  }
254  if(tp != null) {
255  getTouchPoints().add(tp);
256  }
257  }
258 
259 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setActionType(Set< String > actionType)
Definition: SaleAction.java:70
void setAddressId(String addressId)
Definition: SaleAction.java:78
void setEndingTouchPoint(TouchPoint tp)
void setIAttendees(Collection< IContact > contacts)
void setAttendees(Set< String > attendees)
Definition: SaleAction.java:86
VendorProspect getVendorProspect()
Set< TouchPoint > getProcessTouchPoints()
Collection< IContact > getIAttendees()
void setVendorProspect(VendorProspect vendorProspect)
void setComment(String comment)
Definition: SaleAction.java:94
void setFinalDate(Date finalDate)
void setProcessTouchPoints(Set< TouchPoint > stp)
void setActionDate(Date actionDate)
Definition: SaleAction.java:62
Set< TouchPoint > getTouchPoints()
void setTouchPoints(Set< TouchPoint > touchPoints)
void setAddress(Address address)