2 * Copyright (C) 2016, 2017 Roland Häder
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.Calendar;
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.CompanyEmployee;
40 import org.mxchange.jcontactsbusiness.model.employee.Employee;
41 import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData;
42 import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
43 import org.mxchange.jcontactsbusiness.model.logo.BusinessLogo;
44 import org.mxchange.jcontactsbusiness.model.logo.CompanyLogo;
45 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
47 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
49 import org.mxchange.jusercore.model.user.LoginUser;
50 import org.mxchange.jusercore.model.user.User;
53 * A POJO for business basic data
55 * @author Roland Häder<roland@mxchange.org>
57 @Entity (name = "company_basic_data")
58 @Table (name = "company_basic_data")
61 @NamedQuery (name = "AllBusinessData", query = "SELECT b FROM company_basic_data AS b ORDER BY b.basicDataId"),
62 @NamedQuery (name = "SearchBusinessDataById", query = "SELECT b FROM company_basic_data AS b WHERE b.basicDataId = :basicDataId")
65 @SuppressWarnings ("PersistenceUnitPresent")
66 public class CompanyBasicData implements BusinessBasicData {
72 private static final long serialVersionUID = 470_375_172_748_691L;
78 @Column (name = "company_data_id", nullable = false, updatable = false)
79 @GeneratedValue (strategy = GenerationType.IDENTITY)
80 private Long basicDataId;
83 * Reference to company branch offices
86 private List<BranchOffice> brancheOffices;
92 @Column (name = "company_comments")
93 private String companyComments;
96 * Reference to contact person
98 @JoinColumn (name = "company_contact_employee_id")
99 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
100 private Employee companyContactEmployee;
103 * Timestamp when this entry has been created
105 @Basic (optional = false)
106 @Temporal (TemporalType.TIMESTAMP)
107 @Column (name = "company_entry_created", nullable = false, updatable = false)
108 private Calendar companyCreated;
111 * Company's main email address (example: info@company.com)
113 @Column (name = "company_email_address", length = 100)
114 private String companyEmailAddress;
117 * Company's main fax numbers: +ccxxxxxxxxxx
119 @JoinColumn (name = "company_fax_number_id")
120 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
121 private DialableFaxNumber companyFaxNumber;
124 * Reference to CEO "employee"
126 @JoinColumn (name = "company_founder_id")
127 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
128 private Employee companyFounder;
131 * Reference to headquarters data
133 @JoinColumn (name = "company_headquarters_data_id")
134 @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL)
135 private HeadquartersData companyHeadQuartersData;
138 * Company's main phone number: +ccxxxxxxxxxx
140 @JoinColumn (name = "company_landline_number_id")
141 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
142 private DialableLandLineNumber companyLandLineNumber;
145 * Id number of company logo
147 @JoinColumn (name = "company_logo_id")
148 @OneToOne (targetEntity = CompanyLogo.class, cascade = CascadeType.ALL)
149 private BusinessLogo companyLogo;
154 @Basic (optional = false)
155 @Column (name = "company_name", length = 100, nullable = false, unique = true)
156 private String companyName;
161 @Column (name = "company_tax_number", length = 30)
162 private String companyTaxNumber;
165 * User owner instance
167 @JoinColumn (name = "company_owner_user_id")
168 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
169 private User companyUserOwner;
172 * URL for company website
174 @Column (name = "company_website_url")
175 private String companyWebsiteUrl;
178 * Default constructor, required for JPA
180 public CompanyBasicData () {
184 * Constructor with company name
186 * @param companyName Company name
188 public CompanyBasicData (final String companyName) {
189 // First, validate all parameter
190 if (companyName == null) {
192 throw new NullPointerException("companyName is null"); //NOI18N
193 } else if (companyName.isEmpty()) {
195 throw new IllegalArgumentException("companyName is empty"); //NOI18N
199 this.companyName = companyName;
203 public boolean equals (final Object object) {
204 if (null == object) {
206 } else if (this.getClass() != object.getClass()) {
210 final BusinessBasicData other = (BusinessBasicData) object;
212 if (!Objects.equals(this.getBasicDataId(), other.getBasicDataId())) {
214 } else if (!Objects.equals(this.getCompanyName(), other.getCompanyName())) {
216 } else if (!Objects.equals(this.getCompanyHeadQuartersData(), other.getCompanyHeadQuartersData())) {
218 } else if (!Objects.equals(this.getCompanyContactEmployee(), other.getCompanyContactEmployee())) {
220 } else if (!Objects.equals(this.getCompanyFounder(), other.getCompanyFounder())) {
228 public Long getBasicDataId () {
229 return this.basicDataId;
233 public void setBasicDataId (final Long basicDataId) {
234 this.basicDataId = basicDataId;
238 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
239 public List<BranchOffice> getBrancheOffices () {
240 return this.brancheOffices;
244 @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
245 public void setBrancheOffices (final List<BranchOffice> brancheOffices) {
246 this.brancheOffices = brancheOffices;
250 public String getCompanyComments () {
251 return this.companyComments;
255 public void setCompanyComments (final String companyComments) {
256 this.companyComments = companyComments;
260 public Employee getCompanyContactEmployee () {
261 return this.companyContactEmployee;
265 public void setCompanyContactEmployee (final Employee companyContactEmployee) {
266 this.companyContactEmployee = companyContactEmployee;
270 @SuppressWarnings ("ReturnOfDateField")
271 public Calendar getCompanyCreated () {
272 return this.companyCreated;
276 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
277 public void setCompanyCreated (final Calendar companyCreated) {
278 this.companyCreated = companyCreated;
282 public String getCompanyEmailAddress () {
283 return this.companyEmailAddress;
287 public void setCompanyEmailAddress (final String companyEmailAddress) {
288 this.companyEmailAddress = companyEmailAddress;
292 public DialableFaxNumber getCompanyFaxNumber () {
293 return this.companyFaxNumber;
297 public void setCompanyFaxNumber (final DialableFaxNumber companyFaxNumber) {
298 this.companyFaxNumber = companyFaxNumber;
302 public Employee getCompanyFounder () {
303 return this.companyFounder;
307 public void setCompanyFounder (final Employee companyFounder) {
308 this.companyFounder = companyFounder;
312 public HeadquartersData getCompanyHeadQuartersData () {
313 return this.companyHeadQuartersData;
317 public void setCompanyHeadQuartersData (final HeadquartersData companyHeadQuartersData) {
318 this.companyHeadQuartersData = companyHeadQuartersData;
322 public DialableLandLineNumber getCompanyLandLineNumber () {
323 return this.companyLandLineNumber;
327 public void setCompanyLandLineNumber (final DialableLandLineNumber companyLandLineNumber) {
328 this.companyLandLineNumber = companyLandLineNumber;
332 public BusinessLogo getCompanyLogo () {
333 return this.companyLogo;
337 public void setCompanyLogo (final BusinessLogo companyLogoId) {
338 this.companyLogo = companyLogoId;
342 public String getCompanyName () {
343 return this.companyName;
347 public void setCompanyName (final String companyName) {
348 this.companyName = companyName;
352 public String getCompanyTaxNumber () {
353 return this.companyTaxNumber;
357 public void setCompanyTaxNumber (final String companyTaxNumber) {
358 this.companyTaxNumber = companyTaxNumber;
362 public User getCompanyUserOwner () {
363 return this.companyUserOwner;
367 public void setCompanyUserOwner (final User companyUserOwner) {
368 this.companyUserOwner = companyUserOwner;
372 public String getCompanyWebsiteUrl () {
373 return this.companyWebsiteUrl;
377 public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
378 this.companyWebsiteUrl = companyWebsiteUrl;
382 public int hashCode () {
385 hash = 37 * hash + Objects.hashCode(this.getBasicDataId());
386 hash = 37 * hash + Objects.hashCode(this.getCompanyName());
387 hash = 37 * hash + Objects.hashCode(this.getCompanyHeadQuartersData());
388 hash = 37 * hash + Objects.hashCode(this.getCompanyContactEmployee());
389 hash = 37 * hash + Objects.hashCode(this.getCompanyFounder());