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.Date;
21 import java.util.List;
22 import java.util.Objects;
23 import javax.persistence.Basic;
24 import javax.persistence.CascadeType;
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.JoinTable;
32 import javax.persistence.ManyToMany;
33 import javax.persistence.NamedQueries;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.OneToOne;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
39 import javax.persistence.Transient;
40 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
41 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
42 import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
43 import org.mxchange.jcontactsbusiness.model.employee.Employable;
44 import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
45 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
46 import org.mxchange.jcountry.model.data.Country;
47 import org.mxchange.jcountry.model.data.CountryData;
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 company branch offices
58 * @author Roland Häder<roland@mxchange.org>
60 @Entity (name = "company_branch_offices")
61 @Table (name = "company_branch_offices")
64 @NamedQuery (name = "AllBranchOffices", query = "SELECT bo FROM company_branch_offices AS bo ORDER BY bo.branchId ASC"),
65 @NamedQuery (name = "SearchBranchOfficeById", query = "SELECT bo FROM company_branch_offices AS bo WHERE bo.branchId = :branchOfficeId")
68 @SuppressWarnings ("PersistenceUnitPresent")
69 public class BusinessBranchOffice implements BranchOffice {
75 private static final long serialVersionUID = 47_957_817_276_871_852L;
78 * Branch office's city name
80 @Basic (optional = false)
81 @Column (name = "branch_city", length = 100, nullable = false)
82 private String branchCity;
85 * Company that has this branch office
87 @JoinColumn (name = "branch_company_id", nullable = false, updatable = false)
88 @OneToOne (targetEntity = BusinessBasicData.class, optional = false, cascade = CascadeType.REFRESH)
89 private BasicData branchCompany;
92 * Reference to contact person
94 @JoinColumn (name = "branch_contact_employee_id", referencedColumnName = "employee_id")
95 @OneToOne (targetEntity = BusinessEmployee.class, cascade = CascadeType.REFRESH)
96 private Employable branchContactEmployee;
99 * Branch office's country code
101 @JoinColumn (name = "branch_country_id", referencedColumnName = "country_id", nullable = false)
102 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
103 private Country branchCountry;
106 * Timestamp when this entry has been created
108 @Basic (optional = false)
109 @Temporal (TemporalType.TIMESTAMP)
110 @Column (name = "branch_entry_created", nullable = false, updatable = false)
111 private Date branchCreated;
114 * Branch office's main email address (example: branch-name@company.com)
116 @Column (name = "branch_email_address", length = 100)
117 private String branchEmailAddress;
120 * Branch office's main fax number: +ccxxxxxxxxxx
122 @JoinColumn (name = "branch_fax_number_id", referencedColumnName = "fax_id")
123 @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
124 private DialableFaxNumber branchFaxNumber;
127 * Branch office's house number
129 @Basic (optional = false)
130 @Column (name = "branch_house_number", length = 3, nullable = false)
131 private Short branchHouseNumber;
137 @GeneratedValue (strategy = GenerationType.IDENTITY)
138 @Column (name = "branch_id", nullable = false, updatable = false)
139 private Long branchId;
142 * Branch office's main land-line number: +ccxxxxxxxxxx
144 @JoinColumn (name = "branch_landline_number_id", referencedColumnName = "landline_id")
145 @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
146 private DialableLandLineNumber branchLandLineNumber;
149 * Numer of this branch office
151 @Column (name = "branch_number")
152 private Long branchNumber;
155 * Opening times for this branch office
157 @JoinTable (name = "branch_opening_times", joinColumns = @JoinColumn(name = "branch_opening_id", referencedColumnName = "branch_id"), inverseJoinColumns = @JoinColumn(name = "opening_branch_id", referencedColumnName = "opening_times_id"))
158 @ManyToMany (targetEntity = BusinessOpeningTime.class, cascade = CascadeType.ALL)
159 private List<OpeningTime> branchOpeningTimes;
162 * Reference to branch office owner (for example some franchise supermarkets
163 * will have an owning person (here generally referred as "employee") who
164 * will own one or more branch offices.
166 @JoinColumn (name = "branch_owner_employee_id", referencedColumnName = "employee_id")
167 @OneToOne (targetEntity = BusinessEmployee.class, cascade = CascadeType.REFRESH)
168 private Employable branchOwnerEmployee;
171 * Branch office's store (if multiple-store building)
173 @Column (name = "branch_store", length = 3)
174 private Short branchStore;
177 * Branch office's street name
179 @Basic (optional = false)
180 @Column (name = "branch_street", length = 100, nullable = false)
181 private String branchStreet;
184 * Branch office's suite number (if applyable)
186 @Column (name = "branch_suite_number", length = 4)
187 private Short branchSuiteNumber;
190 * User owner instance
192 @JoinColumn (name = "branch_user_id", referencedColumnName = "user_id")
193 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
194 private User branchUserOwner;
197 * Branch office's ZIP code
199 @Basic (optional = false)
200 @Column (name = "branch_zip_code", length = 6, nullable = false)
201 private Integer branchZipCode;
204 * Default constructor for JPA
206 public BusinessBranchOffice () {
210 * Constructor with all required fields. This constructor may throw
211 * exceptions when one parameter is not valid or NULL.
213 * @param branchCity Branch office's city
214 * @param branchCompany Branch office's assigned company
215 * @param branchCountry Branch office's country
216 * @param branchStreet Branch office's street
217 * @param branchZipCode Branch office's ZIP code
218 * @param branchHouseNumber Branch office's house number
220 public BusinessBranchOffice (final String branchCity, final BasicData branchCompany, final Country branchCountry, final String branchStreet, final Integer branchZipCode, final Short branchHouseNumber) {
221 // Call other constructor
224 // Check all parameter
225 if (null == branchCity) {
227 throw new NullPointerException("branchCity is null"); //NOI18N
228 } else if (branchCity.isEmpty()) {
230 throw new IllegalArgumentException("branchCity is empty"); //NOI18N
231 } else if (null == branchCompany) {
233 throw new NullPointerException("branchCompany is null"); //NOI18N
234 } else if (branchCompany.getBasicDataId() == null) {
236 throw new NullPointerException("branchCompany.basicDataId is null"); //NOI18N
237 } else if (branchCompany.getBasicDataId() < 1) {
239 throw new IllegalArgumentException(MessageFormat.format("branchCompany.basicDataId={0} is invalid", branchCompany.getBasicDataId())); //NOI18N
240 } else if (null == branchCountry) {
242 throw new NullPointerException("branchCountry is null"); //NOI18N
243 } else if (branchCountry.getCountryId() == null) {
245 throw new NullPointerException("branchCountry.countryId is null"); //NOI18N
246 } else if (branchCountry.getCountryId() < 1) {
248 throw new IllegalArgumentException(MessageFormat.format("branchCountry.countryId={0} is invalid", branchCountry.getCountryId())); //NOI18N
249 } else if (null == branchStreet) {
251 throw new NullPointerException("branchStreet is null"); //NOI18N
252 } else if (branchStreet.isEmpty()) {
254 throw new IllegalArgumentException("branchStreet is empty"); //NOI18N
255 } else if (null == branchZipCode) {
257 throw new NullPointerException("branchZipCode is null"); //NOI18N
258 } else if (branchZipCode < 1) {
260 throw new IllegalArgumentException(MessageFormat.format("branchZipCode={0} is out of range.", branchZipCode)); //NOI18N
261 } else if (null == branchHouseNumber) {
263 throw new NullPointerException("branchHouseNumber is null"); //NOI18N
264 } else if (branchHouseNumber < 1) {
266 throw new IllegalArgumentException(MessageFormat.format("branchHouseNumber={0} is out of range.", branchHouseNumber)); //NOI18N
270 this.branchCity = branchCity;
271 this.branchCompany = branchCompany;
272 this.branchCountry = branchCountry;
273 this.branchStreet = branchStreet;
274 this.branchZipCode = branchZipCode;
275 this.branchHouseNumber = branchHouseNumber;
279 public boolean equals (final Object object) {
280 if (null == object) {
282 } else if (this.getClass() != object.getClass()) {
286 final BranchOffice other = (BranchOffice) object;
288 if (!Objects.equals(this.getBranchId(), other.getBranchId())) {
290 } else if (!Objects.equals(this.getBranchCity(), other.getBranchCity())) {
292 } else if (!Objects.equals(this.getBranchCountry(), other.getBranchCountry())) {
294 } else if (!Objects.equals(this.getBranchHouseNumber(), other.getBranchHouseNumber())) {
296 } else if (!Objects.equals(this.getBranchNumber(), other.getBranchNumber())) {
298 } else if (!Objects.equals(this.getBranchStore(), other.getBranchStore())) {
300 } else if (!Objects.equals(this.getBranchStreet(), other.getBranchStreet())) {
302 } else if (!Objects.equals(this.getBranchSuiteNumber(), other.getBranchSuiteNumber())) {
304 } else if (!Objects.equals(this.getBranchZipCode(), other.getBranchZipCode())) {
312 public String getBranchCity () {
313 return this.branchCity;
317 public void setBranchCity (final String branchCity) {
318 this.branchCity = branchCity;
322 public BasicData getBranchCompany () {
323 return this.branchCompany;
327 public void setBranchCompany (final BasicData branchCompany) {
328 this.branchCompany = branchCompany;
332 public Employable getBranchContactEmployee () {
333 return this.branchContactEmployee;
337 public void setBranchContactEmployee (final Employable branchContactEmployee) {
338 this.branchContactEmployee = branchContactEmployee;
342 public Country getBranchCountry () {
343 return this.branchCountry;
347 public void setBranchCountry (final Country branchCountry) {
348 this.branchCountry = branchCountry;
352 @SuppressWarnings ("ReturnOfDateField")
353 public Date getBranchCreated () {
354 return this.branchCreated;
358 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
359 public void setBranchCreated (final Date branchCreated) {
360 this.branchCreated = branchCreated;
364 public String getBranchEmailAddress () {
365 return this.branchEmailAddress;
369 public void setBranchEmailAddress (final String branchEmailAddress) {
370 this.branchEmailAddress = branchEmailAddress;
374 public DialableFaxNumber getBranchFaxNumber () {
375 return this.branchFaxNumber;
379 public void setBranchFaxNumber (final DialableFaxNumber branchFaxNumber) {
380 this.branchFaxNumber = branchFaxNumber;
384 public Short getBranchHouseNumber () {
385 return this.branchHouseNumber;
389 public void setBranchHouseNumber (final Short branchHouseNumber) {
390 this.branchHouseNumber = branchHouseNumber;
394 public Long getBranchId () {
395 return this.branchId;
399 public void setBranchId (final Long branchId) {
400 this.branchId = branchId;
404 public DialableLandLineNumber getBranchLandLineNumber () {
405 return this.branchLandLineNumber;
409 public void setBranchLandLineNumber (final DialableLandLineNumber branchLandLineNumber) {
410 this.branchLandLineNumber = branchLandLineNumber;
414 public Long getBranchNumber () {
415 return this.branchNumber;
419 public void setBranchNumber (final Long branchNumber) {
420 this.branchNumber = branchNumber;
424 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
425 public List<OpeningTime> getBranchOpeningTimes () {
426 return this.branchOpeningTimes;
430 @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
431 public void setBranchOpeningTimes (final List<OpeningTime> branchOpeningTimes) {
432 this.branchOpeningTimes = branchOpeningTimes;
436 public Employable getBranchOwnerEmployee () {
437 return this.branchOwnerEmployee;
441 public void setBranchOwnerEmployee (final Employable branchOwnerEmployee) {
442 this.branchOwnerEmployee = branchOwnerEmployee;
446 public Short getBranchStore () {
447 return this.branchStore;
451 public void setBranchStore (final Short branchStore) {
452 this.branchStore = branchStore;
456 public String getBranchStreet () {
457 return this.branchStreet;
461 public void setBranchStreet (final String branchStreet) {
462 this.branchStreet = branchStreet;
466 public Short getBranchSuiteNumber () {
467 return this.branchSuiteNumber;
471 public void setBranchSuiteNumber (final Short branchSuiteNumber) {
472 this.branchSuiteNumber = branchSuiteNumber;
476 public User getBranchUserOwner () {
477 return this.branchUserOwner;
481 public void setBranchUserOwner (final User branchUserOwner) {
482 this.branchUserOwner = branchUserOwner;
486 public Integer getBranchZipCode () {
487 return this.branchZipCode;
491 public void setBranchZipCode (final Integer branchZipCode) {
492 this.branchZipCode = branchZipCode;
496 public int hashCode () {
499 hash = 53 * hash + Objects.hashCode(this.getBranchId());
500 hash = 53 * hash + Objects.hashCode(this.getBranchCity());
501 hash = 53 * hash + Objects.hashCode(this.getBranchCountry());
502 hash = 53 * hash + Objects.hashCode(this.getBranchNumber());
503 hash = 53 * hash + Objects.hashCode(this.getBranchHouseNumber());
504 hash = 53 * hash + Objects.hashCode(this.getBranchStore());
505 hash = 53 * hash + Objects.hashCode(this.getBranchStreet());
506 hash = 53 * hash + Objects.hashCode(this.getBranchSuiteNumber());
507 hash = 53 * hash + Objects.hashCode(this.getBranchZipCode());