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.branchoffice;
19 import java.text.MessageFormat;
20 import java.util.Calendar;
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.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
37 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
38 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
39 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee;
40 import org.mxchange.jcontactsbusiness.model.employee.Employee;
41 import org.mxchange.jcountry.data.Country;
42 import org.mxchange.jcountry.data.CountryData;
43 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
44 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
45 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
46 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
47 import org.mxchange.jusercore.model.user.LoginUser;
48 import org.mxchange.jusercore.model.user.User;
51 * A POJO for company branch offices
53 * @author Roland Häder<roland@mxchange.org>
55 @Entity (name = "company_branch_offices")
56 @Table (name = "company_branch_offices")
58 @NamedQuery (name = "AllBranchOffices", query = "SELECT bo FROM company_branch_offices AS bo ORDER BY bo.branchId ASC")
60 @SuppressWarnings ("PersistenceUnitPresent")
61 public class CompanyBranchOffice implements BranchOffice {
67 private static final long serialVersionUID = 47_957_817_276_871_852L;
70 * Branch office's city name
72 @Basic (optional = false)
73 @Column (name = "branch_city", length = 100, nullable = false)
74 private String branchCity;
77 * Company that has this branch office
79 @JoinColumn (name = "branch_company_id", nullable = false, updatable = false)
80 @OneToOne (targetEntity = CompanyBasicData.class, optional = false, cascade = CascadeType.REFRESH)
81 private BusinessBasicData branchCompany;
84 * Reference to contact person
86 @JoinColumn (name = "branch_contact_employee_id")
87 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.REFRESH)
88 private Employee branchContactEmployee;
91 * Branch office's country code
93 @JoinColumn (name = "branch_country_id", nullable = false)
94 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
95 private Country branchCountry;
98 * Timestamp when this entry has been created
100 @Basic (optional = false)
101 @Temporal (TemporalType.TIMESTAMP)
102 @Column (name = "branch_entry_created", nullable = false, updatable = false)
103 private Calendar branchCreated;
106 * Branch office's main email address (example: branch-name@company.com)
108 @Column (name = "branch_email_address", length = 100)
109 private String branchEmailAddress;
112 * Branch office's main fax number: +ccxxxxxxxxxx
114 @JoinColumn (name = "branch_fax_number_id")
115 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
116 private DialableFaxNumber branchFaxNumber;
119 * Branch office's house number
121 @Basic (optional = false)
122 @Column (name = "branch_house_number", length = 3, nullable = false)
123 private Short branchHouseNumber;
129 @GeneratedValue (strategy = GenerationType.IDENTITY)
130 @Column (name = "branch_id", nullable = false, updatable = false)
131 private Long branchId;
134 * Branch office's main land-line number: +ccxxxxxxxxxx
136 @JoinColumn (name = "branch_landline_number_id")
137 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
138 private DialableLandLineNumber branchLandLineNumber;
141 * Branch office's store (if multiple-store building)
143 @Column (name = "branch_store", length = 3)
144 private Short branchStore;
147 * Branch office's street name
149 @Basic (optional = false)
150 @Column (name = "branch_street", length = 100, nullable = false)
151 private String branchStreet;
154 * Branch office's suite number (if applyable)
156 @Column (name = "branch_suite_number", length = 4)
157 private Short branchSuiteNumber;
160 * User owner instance
162 @JoinColumn (name = "branch_user_id")
163 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
164 private User branchUserOwner;
167 * Branch office's ZIP code
169 @Basic (optional = false)
170 @Column (name = "branch_zip_code", length = 6, nullable = false)
171 private Integer branchZipCode;
174 * Default constructor for JPA
176 public CompanyBranchOffice () {
180 * Constructor with all required fields. This constructor may throw
181 * exceptions when one parameter is not valid or NULL.
183 * @param branchCity Branch office's city
184 * @param branchCompany Branch office's assigned company
185 * @param branchCountry Branch office's country
186 * @param branchStreet Branch office's street
187 * @param branchZipCode Branch office's ZIP code
188 * @param branchHouseNumber Branch office's house number
190 public CompanyBranchOffice (final String branchCity, final BusinessBasicData branchCompany, final Country branchCountry, final String branchStreet, final Integer branchZipCode, final Short branchHouseNumber) {
191 // Call other constructor
194 // Check all parameter
195 if (null == branchCity) {
197 throw new NullPointerException("branchCity is null"); //NOI18N
198 } else if (branchCity.isEmpty()) {
200 throw new IllegalArgumentException("branchCity is empty"); //NOI18N
201 } else if (null == branchCompany) {
203 throw new NullPointerException("branchCompany is null"); //NOI18N
204 } else if (branchCompany.getBasicDataId() == null) {
206 throw new NullPointerException("branchCompany.basicDataId is null"); //NOI18N
207 } else if (branchCompany.getBasicDataId() < 1) {
209 throw new IllegalArgumentException(MessageFormat.format("branchCompany.basicDataId={0} is invalid", branchCompany.getBasicDataId())); //NOI18N
210 } else if (null == branchCountry) {
212 throw new NullPointerException("branchCountry is null"); //NOI18N
213 } else if (branchCountry.getCountryId() == null) {
215 throw new NullPointerException("branchCountry.countryId is null"); //NOI18N
216 } else if (branchCountry.getCountryId() < 1) {
218 throw new IllegalArgumentException(MessageFormat.format("branchCountry.countryId={0} is invalid", branchCountry.getCountryId())); //NOI18N
219 } else if (null == branchStreet) {
221 throw new NullPointerException("branchStreet is null"); //NOI18N
222 } else if (branchStreet.isEmpty()) {
224 throw new IllegalArgumentException("branchStreet is empty"); //NOI18N
225 } else if (null == branchZipCode) {
227 throw new NullPointerException("branchZipCode is null"); //NOI18N
228 } else if (branchZipCode < 1) {
230 throw new IllegalArgumentException(MessageFormat.format("branchZipCode={0} is out of range.", branchZipCode)); //NOI18N
231 } else if (null == branchHouseNumber) {
233 throw new NullPointerException("branchHouseNumber is null"); //NOI18N
234 } else if (branchHouseNumber < 1) {
236 throw new IllegalArgumentException(MessageFormat.format("branchHouseNumber={0} is out of range.", branchHouseNumber)); //NOI18N
240 this.branchCity = branchCity;
241 this.branchCompany = branchCompany;
242 this.branchCountry = branchCountry;
243 this.branchStreet = branchStreet;
244 this.branchZipCode = branchZipCode;
245 this.branchHouseNumber = branchHouseNumber;
249 public boolean equals (final Object object) {
250 if (null == object) {
252 } else if (this.getClass() != object.getClass()) {
256 final BranchOffice other = (BranchOffice) object;
258 if (!Objects.equals(this.getBranchId(), other.getBranchId())) {
260 } else if (!Objects.equals(this.getBranchCity(), other.getBranchCity())) {
262 } else if (!Objects.equals(this.getBranchCountry(), other.getBranchCountry())) {
264 } else if (!Objects.equals(this.getBranchHouseNumber(), other.getBranchHouseNumber())) {
266 } else if (!Objects.equals(this.getBranchStore(), other.getBranchStore())) {
268 } else if (!Objects.equals(this.getBranchStreet(), other.getBranchStreet())) {
270 } else if (!Objects.equals(this.getBranchSuiteNumber(), other.getBranchSuiteNumber())) {
272 } else if (!Objects.equals(this.getBranchZipCode(), other.getBranchZipCode())) {
280 public String getBranchCity () {
281 return this.branchCity;
285 public void setBranchCity (final String branchCity) {
286 this.branchCity = branchCity;
290 public BusinessBasicData getBranchCompany () {
291 return this.branchCompany;
295 public void setBranchCompany (final BusinessBasicData branchCompany) {
296 this.branchCompany = branchCompany;
300 public Employee getBranchContactEmployee () {
301 return this.branchContactEmployee;
305 public void setBranchContactEmployee (final Employee branchContactEmployee) {
306 this.branchContactEmployee = branchContactEmployee;
310 public Country getBranchCountry () {
311 return this.branchCountry;
315 public void setBranchCountry (final Country branchCountry) {
316 this.branchCountry = branchCountry;
320 @SuppressWarnings ("ReturnOfDateField")
321 public Calendar getBranchCreated () {
322 return this.branchCreated;
326 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
327 public void setBranchCreated (final Calendar branchCreated) {
328 this.branchCreated = branchCreated;
332 public String getBranchEmailAddress () {
333 return this.branchEmailAddress;
337 public void setBranchEmailAddress (final String branchEmailAddress) {
338 this.branchEmailAddress = branchEmailAddress;
342 public DialableFaxNumber getBranchFaxNumber () {
343 return this.branchFaxNumber;
347 public void setBranchFaxNumber (final DialableFaxNumber branchFaxNumber) {
348 this.branchFaxNumber = branchFaxNumber;
352 public Short getBranchHouseNumber () {
353 return this.branchHouseNumber;
357 public void setBranchHouseNumber (final Short branchHouseNumber) {
358 this.branchHouseNumber = branchHouseNumber;
362 public Long getBranchId () {
363 return this.branchId;
367 public void setBranchId (final Long branchId) {
368 this.branchId = branchId;
372 public DialableLandLineNumber getBranchLandLineNumber () {
373 return this.branchLandLineNumber;
377 public void setBranchLandLineNumber (final DialableLandLineNumber branchLandLineNumber) {
378 this.branchLandLineNumber = branchLandLineNumber;
382 public Short getBranchStore () {
383 return this.branchStore;
387 public void setBranchStore (final Short branchStore) {
388 this.branchStore = branchStore;
392 public String getBranchStreet () {
393 return this.branchStreet;
397 public void setBranchStreet (final String branchStreet) {
398 this.branchStreet = branchStreet;
402 public Short getBranchSuiteNumber () {
403 return this.branchSuiteNumber;
407 public void setBranchSuiteNumber (final Short branchSuiteNumber) {
408 this.branchSuiteNumber = branchSuiteNumber;
412 public User getBranchUserOwner () {
413 return this.branchUserOwner;
417 public void setBranchUserOwner (final User branchUserOwner) {
418 this.branchUserOwner = branchUserOwner;
422 public Integer getBranchZipCode () {
423 return this.branchZipCode;
427 public void setBranchZipCode (final Integer branchZipCode) {
428 this.branchZipCode = branchZipCode;
432 public int hashCode () {
435 hash = 53 * hash + Objects.hashCode(this.getBranchId());
436 hash = 53 * hash + Objects.hashCode(this.getBranchCity());
437 hash = 53 * hash + Objects.hashCode(this.getBranchCountry());
438 hash = 53 * hash + Objects.hashCode(this.getBranchHouseNumber());
439 hash = 53 * hash + Objects.hashCode(this.getBranchStore());
440 hash = 53 * hash + Objects.hashCode(this.getBranchStreet());
441 hash = 53 * hash + Objects.hashCode(this.getBranchSuiteNumber());
442 hash = 53 * hash + Objects.hashCode(this.getBranchZipCode());