BrightSide Workbench Full Report + Source Code
Campaign.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.crm.entity;
20 
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26 import javax.persistence.CascadeType;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.FetchType;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.GenerationType;
32 import javax.persistence.Id;
33 import javax.persistence.Lob;
34 import javax.persistence.OneToMany;
35 import javax.persistence.Temporal;
36 import javax.persistence.TemporalType;
37 import org.turro.string.Strings;
38 import org.turro.contacts.organigram.TargetArray;
39 import org.turro.jpa.entity.IDaoEntity;
40 import org.turro.plugin.GenericObject;
41 
46 @Entity
47 public class Campaign implements java.io.Serializable, IDaoEntity {
48 
49  @Id
50  @GeneratedValue(strategy=GenerationType.IDENTITY)
51  @Column(name="IDENTIFIER")
52  private long id;
53 
54  @Lob
55  @Column(length=4096)
56  private String description;
57 
58  @Lob
59  @Column(name="targets")
60  private byte[] targets;
61 
62  @Temporal(TemporalType.TIMESTAMP)
63  private java.util.Date campaignDate;
64 
65  @Temporal(TemporalType.TIMESTAMP)
66  private java.util.Date closingDate;
67 
68  @OneToMany(mappedBy="campaign", fetch = FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
69  private Set<CampaignVendor> campaignVendors = new HashSet<CampaignVendor>();
70 
71  @OneToMany(mappedBy="campaign", fetch = FetchType.EAGER, cascade=CascadeType.ALL, orphanRemoval=true)
72  private Set<SaleProspect> saleProspects = new HashSet<SaleProspect>();
73 
74  public long getId() {
75  return id;
76  }
77 
78  public void setId(long id) {
79  this.id = id;
80  }
81 
82  public String getDescription() {
83  return description;
84  }
85 
86  public void setDescription(String description) {
87  this.description = description;
88  }
89 
90  public Date getCampaignDate() {
91  return campaignDate;
92  }
93 
94  public void setCampaignDate(Date campaignDate) {
95  this.campaignDate = campaignDate;
96  }
97 
98  public Date getClosingDate() {
99  return closingDate;
100  }
101 
102  public void setClosingDate(Date closingDate) {
103  this.closingDate = closingDate;
104  }
105 
106  public Set<CampaignVendor> getCampaignVendors() {
107  return campaignVendors;
108  }
109 
110  public void setCampaignVendors(Set<CampaignVendor> campaignVendors) {
111  this.campaignVendors = campaignVendors;
112  }
113 
114  public Set<SaleProspect> getSaleProspects() {
115  return saleProspects;
116  }
117 
118  public void setSaleProspects(Set<SaleProspect> saleProspects) {
119  this.saleProspects = saleProspects;
120  }
121 
122  public byte[] getTargets() {
123  return targets;
124  }
125 
126  public void setTargets(byte[] targets) {
127  this.targets = targets;
128  }
129 
130  /* IDaoEntity */
131 
132  @Override
133  public Object entityId() {
134  return id;
135  }
136 
137  @Override
138  public boolean isEmpty() {
139  return Strings.isBlank(description);
140  }
141 
142  @Override
143  public Collection<Collection> collections() {
144  return List.of(campaignVendors);
145  }
146 
147  /* Helpers */
148 
150  for(SaleProspect sp : saleProspects) {
151  if(sp.getCustomer().getId() == customer.getId()) {
152  return sp;
153  }
154  }
155  return null;
156  }
157 
158  /* Targets */
159 
161  if(targets == null) {
162  return new TargetArray();
163  }
164  GenericObject go = new GenericObject();
165  go.bytesToObject(targets);
166  return (TargetArray) go.getObject();
167  }
168 
169  public void setTargetArray(TargetArray targetArray) {
170  if(targetArray == null) {
171  targets = null;
172  return;
173  }
174  GenericObject go = new GenericObject();
175  go.setObject(targetArray);
176  targets = go.objectToBytes();
177  }
178 
179 }
void setCampaignDate(Date campaignDate)
Definition: Campaign.java:94
void setCampaignVendors(Set< CampaignVendor > campaignVendors)
Definition: Campaign.java:110
void setTargetArray(TargetArray targetArray)
Definition: Campaign.java:169
void setTargets(byte[] targets)
Definition: Campaign.java:126
SaleProspect customerExists(Customer customer)
Definition: Campaign.java:149
Collection< Collection > collections()
Definition: Campaign.java:143
void setClosingDate(Date closingDate)
Definition: Campaign.java:102
Set< CampaignVendor > getCampaignVendors()
Definition: Campaign.java:106
Set< SaleProspect > getSaleProspects()
Definition: Campaign.java:114
void setSaleProspects(Set< SaleProspect > saleProspects)
Definition: Campaign.java:118
void setDescription(String description)
Definition: Campaign.java:86