2 * Copyright (C) 2016 - 2018 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.jcontactsbusiness.model.basicdata;
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;
56 * A POJO for business basic data
58 * @author Roland Häder<roland@mxchange.org>
60 @Entity (name = "company_basic_data")
61 @Table (name = "company_basic_data")
64 @NamedQuery (name = "AllBusinessData", query = "SELECT b FROM company_basic_data AS b ORDER BY b.basicDataId"),
67 @SuppressWarnings ("PersistenceUnitPresent")
68 public class BusinessBasicData implements BasicData {
74 private static final long serialVersionUID = 470_375_172_748_691L;
80 @Column (name = "company_data_id", nullable = false, updatable = false)
81 @GeneratedValue (strategy = GenerationType.IDENTITY)
82 private Long basicDataId;
85 * Reference to company branch offices
88 private List<BranchOffice> brancheOffices;
94 @Column (name = "company_comments")
95 private String companyComments;
98 * Reference to contact person
100 @JoinColumn (name = "company_contact_employee_id")
101 @OneToOne (targetEntity = BusinessEmployee.class, cascade = CascadeType.REFRESH)
102 private Employable companyContactEmployee;
105 * Timestamp when this entry has been created
107 @Basic (optional = false)
108 @Temporal (TemporalType.TIMESTAMP)
109 @Column (name = "company_entry_created", nullable = false, updatable = false)
110 private Date companyCreated;
113 * Company's main email address (example: info@company.com)
115 @Column (name = "company_email_address", length = 100)
116 private String companyEmailAddress;
119 * Company's main fax numbers: +ccxxxxxxxxxx
121 @JoinColumn (name = "company_fax_number_id")
122 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
123 private DialableFaxNumber companyFaxNumber;
126 * Reference to CEO "employee"
128 @JoinColumn (name = "company_founder_id")
129 @OneToOne (targetEntity = BusinessEmployee.class, cascade = CascadeType.REFRESH)
130 private Employable companyFounder;
133 * Reference to headquarter data
135 @JoinColumn (name = "company_headquarter_data_id")
136 @OneToOne (targetEntity = BusinessHeadquarter.class, cascade = CascadeType.REFRESH)
137 private Headquarter companyHeadquarterData;
140 * Company's main phone number: +ccxxxxxxxxxx
142 @JoinColumn (name = "company_landline_number_id")
143 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
144 private DialableLandLineNumber companyLandLineNumber;
147 * Id number of company logo
149 @JoinColumn (name = "company_logo_id")
150 @OneToOne (targetEntity = BusinessLogo.class, cascade = CascadeType.REFRESH)
151 private Logo companyLogo;
156 @Basic (optional = false)
157 @Column (name = "company_name", length = 100, nullable = false, unique = true)
158 private String companyName;
163 @Column (name = "company_tax_number", length = 30)
164 private String companyTaxNumber;
167 * User owner instance
169 @JoinColumn (name = "company_owner_user_id")
170 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
171 private User companyUserOwner;
174 * URL for company website
176 @Column (name = "company_website_url")
177 private String companyWebsiteUrl;
180 * Default constructor, required for JPA
182 public BusinessBasicData () {
186 * Constructor with company name
188 * @param companyName Company name
190 public BusinessBasicData (final String companyName) {
191 // First, validate all parameter
192 if (companyName == null) {
194 throw new NullPointerException("companyName is null"); //NOI18N
195 } else if (companyName.isEmpty()) {
197 throw new IllegalArgumentException("companyName is empty"); //NOI18N
201 this.companyName = companyName;
205 public int compareTo (final BasicData basicData) {
206 // For performance reasons
207 if (null == basicData) {
209 throw new NullPointerException("basicData is null"); //NOI18N
210 } else if (Objects.equals(this, basicData)) {
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())
228 final int comparison = Comparables.checkAll(comparators);
235 public boolean equals (final Object object) {
236 if (null == object) {
238 } else if (this.getClass() != object.getClass()) {
242 final BasicData other = (BasicData) object;
244 if (!Objects.equals(this.getBasicDataId(), other.getBasicDataId())) {
246 } else if (!Objects.equals(this.getCompanyName(), other.getCompanyName())) {
254 public Long getBasicDataId () {
255 return this.basicDataId;
259 public void setBasicDataId (final Long basicDataId) {
260 this.basicDataId = basicDataId;
264 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
265 public List<BranchOffice> getBrancheOffices () {
266 return this.brancheOffices;
270 @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
271 public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
272 this.brancheOffices = brancheOffices;
276 public String getCompanyComments () {
277 return this.companyComments;
281 public void setCompanyComments (final String companyComments) {
282 this.companyComments = companyComments;
286 public Employable getCompanyContactEmployee () {
287 return this.companyContactEmployee;
291 public void setCompanyContactEmployee (final Employable companyContactEmployee) {
292 this.companyContactEmployee = companyContactEmployee;
296 @SuppressWarnings ("ReturnOfDateField")
297 public Date getCompanyCreated () {
298 return this.companyCreated;
302 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
303 public void setCompanyCreated (final Date companyCreated) {
304 this.companyCreated = companyCreated;
308 public String getCompanyEmailAddress () {
309 return this.companyEmailAddress;
313 public void setCompanyEmailAddress (final String companyEmailAddress) {
314 this.companyEmailAddress = companyEmailAddress;
318 public DialableFaxNumber getCompanyFaxNumber () {
319 return this.companyFaxNumber;
323 public void setCompanyFaxNumber (final DialableFaxNumber companyFaxNumber) {
324 this.companyFaxNumber = companyFaxNumber;
328 public Employable getCompanyFounder () {
329 return this.companyFounder;
333 public void setCompanyFounder (final Employable companyFounder) {
334 this.companyFounder = companyFounder;
338 public Headquarter getCompanyHeadquarterData () {
339 return this.companyHeadquarterData;
343 public void setCompanyHeadquarterData (final Headquarter companyHeadquarterData) {
344 this.companyHeadquarterData = companyHeadquarterData;
348 public DialableLandLineNumber getCompanyLandLineNumber () {
349 return this.companyLandLineNumber;
353 public void setCompanyLandLineNumber (final DialableLandLineNumber companyLandLineNumber) {
354 this.companyLandLineNumber = companyLandLineNumber;
358 public Logo getCompanyLogo () {
359 return this.companyLogo;
363 public void setCompanyLogo (final Logo companyLogoId) {
364 this.companyLogo = companyLogoId;
368 public String getCompanyName () {
369 return this.companyName;
373 public void setCompanyName (final String companyName) {
374 this.companyName = companyName;
378 public String getCompanyTaxNumber () {
379 return this.companyTaxNumber;
383 public void setCompanyTaxNumber (final String companyTaxNumber) {
384 this.companyTaxNumber = companyTaxNumber;
388 public User getCompanyUserOwner () {
389 return this.companyUserOwner;
393 public void setCompanyUserOwner (final User companyUserOwner) {
394 this.companyUserOwner = companyUserOwner;
398 public String getCompanyWebsiteUrl () {
399 return this.companyWebsiteUrl;
403 public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
404 this.companyWebsiteUrl = companyWebsiteUrl;
408 public int hashCode () {
411 hash = 37 * hash + Objects.hashCode(this.getBasicDataId());
412 hash = 37 * hash + Objects.hashCode(this.getCompanyName());