]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java
Continued:
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / basicdata / BusinessBasicData.java
1 /*
2  * Copyright (C) 2016 - 2018 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontactsbusiness.model.basicdata;
18
19 import java.util.Date;
20 import java.util.List;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.Lob;
31 import javax.persistence.NamedQueries;
32 import javax.persistence.NamedQuery;
33 import javax.persistence.OneToOne;
34 import javax.persistence.Table;
35 import javax.persistence.Temporal;
36 import javax.persistence.TemporalType;
37 import javax.persistence.Transient;
38 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
39 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
40 import org.mxchange.jcontactsbusiness.model.employee.Employable;
41 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
42 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
43 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters;
44 import org.mxchange.jcontactsbusiness.model.logo.BusinessLogo;
45 import org.mxchange.jcontactsbusiness.model.logo.Logo;
46 import org.mxchange.jcoreee.utils.Comparables;
47 import org.mxchange.jcoreee.utils.StringUtils;
48 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jusercore.model.user.LoginUser;
53 import org.mxchange.jusercore.model.user.User;
54
55 /**
56  * A POJO for business basic data
57  * <p>
58  * @author Roland Häder<roland@mxchange.org>
59  */
60 @Entity (name = "company_basic_data")
61 @Table (name = "company_basic_data")
62 @NamedQueries (
63                 {
64                         @NamedQuery (name = "AllBusinessData", query = "SELECT b FROM company_basic_data AS b ORDER BY b.basicDataId"),
65                 }
66 )
67 @SuppressWarnings ("PersistenceUnitPresent")
68 public class BusinessBasicData implements BasicData {
69
70         /**
71          * Serial number
72          */
73         @Transient
74         private static final long serialVersionUID = 470_375_172_748_691L;
75
76         /**
77          * Id number
78          */
79         @Id
80         @Column (name = "company_data_id", nullable = false, updatable = false)
81         @GeneratedValue (strategy = GenerationType.IDENTITY)
82         private Long basicDataId;
83
84         /**
85          * Reference to company branch offices
86          */
87         @Transient
88         private List<BranchOffice> brancheOffices;
89
90         /**
91          * Comments (any)
92          */
93         @Lob
94         @Column (name = "company_comments")
95         private String companyComments;
96
97         /**
98          * Reference to contact person
99          */
100         @JoinColumn (name = "company_contact_employee_id")
101         @OneToOne (targetEntity = BusinessEmployee.class, cascade = CascadeType.REFRESH)
102         private Employable companyContactEmployee;
103
104         /**
105          * Timestamp when this entry has been created
106          */
107         @Basic (optional = false)
108         @Temporal (TemporalType.TIMESTAMP)
109         @Column (name = "company_entry_created", nullable = false, updatable = false)
110         private Date companyCreated;
111
112         /**
113          * Company's main email address (example: info@company.com)
114          */
115         @Column (name = "company_email_address", length = 100)
116         private String companyEmailAddress;
117
118         /**
119          * Company's main fax numbers: +ccxxxxxxxxxx
120          */
121         @JoinColumn (name = "company_fax_number_id")
122         @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
123         private DialableFaxNumber companyFaxNumber;
124
125         /**
126          * Reference to CEO "employee"
127          */
128         @JoinColumn (name = "company_founder_id")
129         @OneToOne (targetEntity = BusinessEmployee.class, cascade = CascadeType.REFRESH)
130         private Employable companyFounder;
131
132         /**
133          * Reference to headquarter data
134          */
135         @JoinColumn (name = "company_headquarter_data_id")
136         @OneToOne (targetEntity = BusinessHeadquarter.class, cascade = CascadeType.REFRESH)
137         private Headquarter companyHeadquarterData;
138
139         /**
140          * Company's main phone number: +ccxxxxxxxxxx
141          */
142         @JoinColumn (name = "company_landline_number_id")
143         @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
144         private DialableLandLineNumber companyLandLineNumber;
145
146         /**
147          * Id number of company logo
148          */
149         @JoinColumn (name = "company_logo_id")
150         @OneToOne (targetEntity = BusinessLogo.class, cascade = CascadeType.REFRESH)
151         private Logo companyLogo;
152
153         /**
154          * Company name
155          */
156         @Basic (optional = false)
157         @Column (name = "company_name", length = 100, nullable = false, unique = true)
158         private String companyName;
159
160         /**
161          * Tax number
162          */
163         @Column (name = "company_tax_number", length = 30)
164         private String companyTaxNumber;
165
166         /**
167          * User owner instance
168          */
169         @JoinColumn (name = "company_owner_user_id")
170         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
171         private User companyUserOwner;
172
173         /**
174          * URL for company website
175          */
176         @Column (name = "company_website_url")
177         private String companyWebsiteUrl;
178
179         /**
180          * Default constructor, required for JPA
181          */
182         public BusinessBasicData () {
183         }
184
185         /**
186          * Constructor with company name
187          * <p>
188          * @param companyName Company name
189          */
190         public BusinessBasicData (final String companyName) {
191                 // First, validate all parameter
192                 if (companyName == null) {
193                         // Is null
194                         throw new NullPointerException("companyName is null"); //NOI18N
195                 } else if (companyName.isEmpty()) {
196                         // Is null
197                         throw new IllegalArgumentException("companyName is empty"); //NOI18N
198                 }
199
200                 // Set company name
201                 this.companyName = companyName;
202         }
203
204         @Override
205         public int compareTo (final BasicData basicData) {
206                 // For performance reasons
207                 if (null == basicData) {
208                         // Should not happen
209                         throw new NullPointerException("basicData is null"); //NOI18N
210                 } else if (Objects.equals(this, basicData)) {
211                         // Same object
212                         return 0;
213                 }
214
215                 // Init comparators
216                 final int comparators[] = {
217                         // First compare company name
218                         this.getCompanyName().compareToIgnoreCase(basicData.getCompanyName()),
219                         // ... next tax number
220                         StringUtils.compareToIgnoreCase(this.getCompanyTaxNumber(), basicData.getCompanyTaxNumber()),
221                         // ... and email address
222                         StringUtils.compareToIgnoreCase(this.getCompanyEmailAddress(), basicData.getCompanyEmailAddress()),
223                         // ... head quarter data
224                         Headquarters.compare(this.getCompanyHeadquarterData(), basicData.getCompanyHeadquarterData())
225                 };
226
227                 // Check all values
228                 final int comparison = Comparables.checkAll(comparators);
229
230                 // Return value
231                 return comparison;
232         }
233
234         @Override
235         public boolean equals (final Object object) {
236                 if (null == object) {
237                         return false;
238                 } else if (this.getClass() != object.getClass()) {
239                         return false;
240                 }
241
242                 final BasicData other = (BasicData) object;
243
244                 if (!Objects.equals(this.getBasicDataId(), other.getBasicDataId())) {
245                         return false;
246                 } else if (!Objects.equals(this.getCompanyName(), other.getCompanyName())) {
247                         return false;
248                 }
249
250                 return true;
251         }
252
253         @Override
254         public Long getBasicDataId () {
255                 return this.basicDataId;
256         }
257
258         @Override
259         public void setBasicDataId (final Long basicDataId) {
260                 this.basicDataId = basicDataId;
261         }
262
263         @Override
264         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
265         public List<BranchOffice> getBrancheOffices () {
266                 return this.brancheOffices;
267         }
268
269         @Override
270         @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
271         public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
272                 this.brancheOffices = brancheOffices;
273         }
274
275         @Override
276         public String getCompanyComments () {
277                 return this.companyComments;
278         }
279
280         @Override
281         public void setCompanyComments (final String companyComments) {
282                 this.companyComments = companyComments;
283         }
284
285         @Override
286         public Employable getCompanyContactEmployee () {
287                 return this.companyContactEmployee;
288         }
289
290         @Override
291         public void setCompanyContactEmployee (final Employable companyContactEmployee) {
292                 this.companyContactEmployee = companyContactEmployee;
293         }
294
295         @Override
296         @SuppressWarnings ("ReturnOfDateField")
297         public Date getCompanyCreated () {
298                 return this.companyCreated;
299         }
300
301         @Override
302         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
303         public void setCompanyCreated (final Date companyCreated) {
304                 this.companyCreated = companyCreated;
305         }
306
307         @Override
308         public String getCompanyEmailAddress () {
309                 return this.companyEmailAddress;
310         }
311
312         @Override
313         public void setCompanyEmailAddress (final String companyEmailAddress) {
314                 this.companyEmailAddress = companyEmailAddress;
315         }
316
317         @Override
318         public DialableFaxNumber getCompanyFaxNumber () {
319                 return this.companyFaxNumber;
320         }
321
322         @Override
323         public void setCompanyFaxNumber (final DialableFaxNumber companyFaxNumber) {
324                 this.companyFaxNumber = companyFaxNumber;
325         }
326
327         @Override
328         public Employable getCompanyFounder () {
329                 return this.companyFounder;
330         }
331
332         @Override
333         public void setCompanyFounder (final Employable companyFounder) {
334                 this.companyFounder = companyFounder;
335         }
336
337         @Override
338         public Headquarter getCompanyHeadquarterData () {
339                 return this.companyHeadquarterData;
340         }
341
342         @Override
343         public void setCompanyHeadquarterData (final Headquarter companyHeadquarterData) {
344                 this.companyHeadquarterData = companyHeadquarterData;
345         }
346
347         @Override
348         public DialableLandLineNumber getCompanyLandLineNumber () {
349                 return this.companyLandLineNumber;
350         }
351
352         @Override
353         public void setCompanyLandLineNumber (final DialableLandLineNumber companyLandLineNumber) {
354                 this.companyLandLineNumber = companyLandLineNumber;
355         }
356
357         @Override
358         public Logo getCompanyLogo () {
359                 return this.companyLogo;
360         }
361
362         @Override
363         public void setCompanyLogo (final Logo companyLogoId) {
364                 this.companyLogo = companyLogoId;
365         }
366
367         @Override
368         public String getCompanyName () {
369                 return this.companyName;
370         }
371
372         @Override
373         public void setCompanyName (final String companyName) {
374                 this.companyName = companyName;
375         }
376
377         @Override
378         public String getCompanyTaxNumber () {
379                 return this.companyTaxNumber;
380         }
381
382         @Override
383         public void setCompanyTaxNumber (final String companyTaxNumber) {
384                 this.companyTaxNumber = companyTaxNumber;
385         }
386
387         @Override
388         public User getCompanyUserOwner () {
389                 return this.companyUserOwner;
390         }
391
392         @Override
393         public void setCompanyUserOwner (final User companyUserOwner) {
394                 this.companyUserOwner = companyUserOwner;
395         }
396
397         @Override
398         public String getCompanyWebsiteUrl () {
399                 return this.companyWebsiteUrl;
400         }
401
402         @Override
403         public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
404                 this.companyWebsiteUrl = companyWebsiteUrl;
405         }
406
407         @Override
408         public int hashCode () {
409                 int hash = 3;
410
411                 hash = 37 * hash + Objects.hashCode(this.getBasicDataId());
412                 hash = 37 * hash + Objects.hashCode(this.getCompanyName());
413
414                 return hash;
415         }
416
417 }