]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java
Updated copyright year
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / basicdata / BusinessBasicData.java
1 /*
2  * Copyright (C) 2016 - 2020 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.apache.commons.lang3.StringUtils;
39 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
40 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
41 import org.mxchange.jcontactsbusiness.model.employee.Employable;
42 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
43 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
44 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters;
45 import org.mxchange.jcontactsbusiness.model.logo.BusinessLogo;
46 import org.mxchange.jcontactsbusiness.model.logo.Logo;
47 import org.mxchange.jcoreutils.Comparables;
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         @Column (name = "company_name", unique = true)
157         private String companyName;
158
159         /**
160          * Short company name
161          */
162         @Basic (optional = false)
163         @Column (name = "company_short_name", length = 100, nullable = false, unique = true)
164         private String companyShortName;
165
166         /**
167          * Tax number
168          */
169         @Column (name = "company_tax_number", length = 30)
170         private String companyTaxNumber;
171
172         /**
173          * User owner instance
174          */
175         @JoinColumn (name = "company_owner_user_id")
176         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
177         private User companyUserOwner;
178
179         /**
180          * URL for company website
181          */
182         @Column (name = "company_website_url")
183         private String companyWebsiteUrl;
184
185         /**
186          * Default constructor, required for JPA
187          */
188         public BusinessBasicData () {
189         }
190
191         /**
192          * Constructor with company short name
193          * <p>
194          * @param companyShortName Company short name
195          */
196         public BusinessBasicData (final String companyShortName) {
197                 // First, validate all parameter
198                 if (companyShortName == null) {
199                         // Is null
200                         throw new NullPointerException("companyShortName is null"); //NOI18N
201                 } else if (companyShortName.isEmpty()) {
202                         // Is null
203                         throw new IllegalArgumentException("companyShortName is empty"); //NOI18N
204                 }
205
206                 // Set company short name
207                 this.companyShortName = companyShortName;
208         }
209
210         @Override
211         public int compareTo (final BasicData basicData) {
212                 // Check parameter on null-reference and equality to this
213                 if (null == basicData) {
214                         // Should not happen
215                         throw new NullPointerException("basicData is null"); //NOI18N
216                 } else if (basicData.equals(this)) {
217                         // Same object
218                         return 0;
219                 }
220
221                 // Init comparators
222                 final int comparators[] = {
223                         // First compare company short name
224                         this.getCompanyShortName().compareToIgnoreCase(basicData.getCompanyShortName()),
225                         // ... 2nd compare company name
226                         StringUtils.compareIgnoreCase(this.getCompanyName(), basicData.getCompanyName()),
227                         // ... next tax number
228                         StringUtils.compareIgnoreCase(this.getCompanyTaxNumber(), basicData.getCompanyTaxNumber()),
229                         // ... and email address
230                         StringUtils.compareIgnoreCase(this.getCompanyEmailAddress(), basicData.getCompanyEmailAddress()),
231                         // ... head quarter data
232                         Headquarters.compare(this.getCompanyHeadquarterData(), basicData.getCompanyHeadquarterData())
233                 };
234
235                 // Check all values
236                 final int comparison = Comparables.checkAll(comparators);
237
238                 // Return value
239                 return comparison;
240         }
241
242         @Override
243         public boolean equals (final Object object) {
244                 if (null == object) {
245                         return false;
246                 } else if (this.getClass() != object.getClass()) {
247                         return false;
248                 }
249
250                 final BasicData other = (BasicData) object;
251
252                 if (!Objects.equals(this.getBasicDataId(), other.getBasicDataId())) {
253                         return false;
254                 } else if (!Objects.equals(this.getCompanyShortName(), other.getCompanyShortName())) {
255                         return false;
256                 } else if (!Objects.equals(this.getCompanyName(), other.getCompanyName())) {
257                         return false;
258                 }
259
260                 return true;
261         }
262
263         @Override
264         public Long getBasicDataId () {
265                 return this.basicDataId;
266         }
267
268         @Override
269         public void setBasicDataId (final Long basicDataId) {
270                 this.basicDataId = basicDataId;
271         }
272
273         @Override
274         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
275         public List<BranchOffice> getBrancheOffices () {
276                 return this.brancheOffices;
277         }
278
279         @Override
280         @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
281         public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
282                 this.brancheOffices = brancheOffices;
283         }
284
285         @Override
286         public String getCompanyComments () {
287                 return this.companyComments;
288         }
289
290         @Override
291         public void setCompanyComments (final String companyComments) {
292                 this.companyComments = companyComments;
293         }
294
295         @Override
296         public Employable getCompanyContactEmployee () {
297                 return this.companyContactEmployee;
298         }
299
300         @Override
301         public void setCompanyContactEmployee (final Employable companyContactEmployee) {
302                 this.companyContactEmployee = companyContactEmployee;
303         }
304
305         @Override
306         @SuppressWarnings ("ReturnOfDateField")
307         public Date getCompanyCreated () {
308                 return this.companyCreated;
309         }
310
311         @Override
312         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
313         public void setCompanyCreated (final Date companyCreated) {
314                 this.companyCreated = companyCreated;
315         }
316
317         @Override
318         public String getCompanyEmailAddress () {
319                 return this.companyEmailAddress;
320         }
321
322         @Override
323         public void setCompanyEmailAddress (final String companyEmailAddress) {
324                 this.companyEmailAddress = companyEmailAddress;
325         }
326
327         @Override
328         public DialableFaxNumber getCompanyFaxNumber () {
329                 return this.companyFaxNumber;
330         }
331
332         @Override
333         public void setCompanyFaxNumber (final DialableFaxNumber companyFaxNumber) {
334                 this.companyFaxNumber = companyFaxNumber;
335         }
336
337         @Override
338         public Employable getCompanyFounder () {
339                 return this.companyFounder;
340         }
341
342         @Override
343         public void setCompanyFounder (final Employable companyFounder) {
344                 this.companyFounder = companyFounder;
345         }
346
347         @Override
348         public Headquarter getCompanyHeadquarterData () {
349                 return this.companyHeadquarterData;
350         }
351
352         @Override
353         public void setCompanyHeadquarterData (final Headquarter companyHeadquarterData) {
354                 this.companyHeadquarterData = companyHeadquarterData;
355         }
356
357         @Override
358         public DialableLandLineNumber getCompanyLandLineNumber () {
359                 return this.companyLandLineNumber;
360         }
361
362         @Override
363         public void setCompanyLandLineNumber (final DialableLandLineNumber companyLandLineNumber) {
364                 this.companyLandLineNumber = companyLandLineNumber;
365         }
366
367         @Override
368         public Logo getCompanyLogo () {
369                 return this.companyLogo;
370         }
371
372         @Override
373         public void setCompanyLogo (final Logo companyLogoId) {
374                 this.companyLogo = companyLogoId;
375         }
376
377         @Override
378         public String getCompanyName () {
379                 return this.companyName;
380         }
381
382         @Override
383         public void setCompanyName (final String companyName) {
384                 this.companyName = companyName;
385         }
386
387         @Override
388         public String getCompanyShortName () {
389                 return this.companyShortName;
390         }
391
392         @Override
393         public void setCompanyShortName (final String companyShortName) {
394                 this.companyShortName = companyShortName;
395         }
396
397         @Override
398         public String getCompanyTaxNumber () {
399                 return this.companyTaxNumber;
400         }
401
402         @Override
403         public void setCompanyTaxNumber (final String companyTaxNumber) {
404                 this.companyTaxNumber = companyTaxNumber;
405         }
406
407         @Override
408         public User getCompanyUserOwner () {
409                 return this.companyUserOwner;
410         }
411
412         @Override
413         public void setCompanyUserOwner (final User companyUserOwner) {
414                 this.companyUserOwner = companyUserOwner;
415         }
416
417         @Override
418         public String getCompanyWebsiteUrl () {
419                 return this.companyWebsiteUrl;
420         }
421
422         @Override
423         public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
424                 this.companyWebsiteUrl = companyWebsiteUrl;
425         }
426
427         @Override
428         public int hashCode () {
429                 int hash = 3;
430
431                 hash = 37 * hash + Objects.hashCode(this.getBasicDataId());
432                 hash = 37 * hash + Objects.hashCode(this.getCompanyShortName());
433                 hash = 37 * hash + Objects.hashCode(this.getCompanyName());
434
435                 return hash;
436         }
437
438 }