]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/branchoffice/CompanyBranchOffice.java
Continued:
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / branchoffice / CompanyBranchOffice.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
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.branchoffice;
18
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.BusinessBasicData;
41 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
42 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee;
43 import org.mxchange.jcontactsbusiness.model.employee.Employee;
44 import org.mxchange.jcontactsbusiness.model.opening_times.BusinessOpeningTimes;
45 import org.mxchange.jcontactsbusiness.model.opening_times.OpeningTimes;
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;
54
55 /**
56  * A POJO for company branch offices
57  * <p>
58  * @author Roland Häder<roland@mxchange.org>
59  */
60 @Entity (name = "company_branch_offices")
61 @Table (name = "company_branch_offices")
62 @NamedQueries (
63                 {
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")
66                 }
67 )
68 @SuppressWarnings ("PersistenceUnitPresent")
69 public class CompanyBranchOffice implements BranchOffice {
70
71         /**
72          * Serial number
73          */
74         @Transient
75         private static final long serialVersionUID = 47_957_817_276_871_852L;
76
77         /**
78          * Branch office's city name
79          */
80         @Basic (optional = false)
81         @Column (name = "branch_city", length = 100, nullable = false)
82         private String branchCity;
83
84         /**
85          * Company that has this branch office
86          */
87         @JoinColumn (name = "branch_company_id", nullable = false, updatable = false)
88         @OneToOne (targetEntity = CompanyBasicData.class, optional = false, cascade = CascadeType.REFRESH)
89         private BusinessBasicData branchCompany;
90
91         /**
92          * Reference to contact person
93          */
94         @JoinColumn (name = "branch_contact_employee_id", referencedColumnName = "employee_id")
95         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.REFRESH)
96         private Employee branchContactEmployee;
97
98         /**
99          * Branch office's country code
100          */
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;
104
105         /**
106          * Timestamp when this entry has been created
107          */
108         @Basic (optional = false)
109         @Temporal (TemporalType.TIMESTAMP)
110         @Column (name = "branch_entry_created", nullable = false, updatable = false)
111         private Date branchCreated;
112
113         /**
114          * Branch office's main email address (example: branch-name@company.com)
115          */
116         @Column (name = "branch_email_address", length = 100)
117         private String branchEmailAddress;
118
119         /**
120          * Branch office's main fax number: +ccxxxxxxxxxx
121          */
122         @JoinColumn (name = "branch_fax_number_id", referencedColumnName = "fax_id")
123         @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
124         private DialableFaxNumber branchFaxNumber;
125
126         /**
127          * Branch office's house number
128          */
129         @Basic (optional = false)
130         @Column (name = "branch_house_number", length = 3, nullable = false)
131         private Short branchHouseNumber;
132
133         /**
134          * Id number
135          */
136         @Id
137         @GeneratedValue (strategy = GenerationType.IDENTITY)
138         @Column (name = "branch_id", nullable = false, updatable = false)
139         private Long branchId;
140
141         /**
142          * Branch office's main land-line number: +ccxxxxxxxxxx
143          */
144         @JoinColumn (name = "branch_landline_number_id", referencedColumnName = "landline_id")
145         @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
146         private DialableLandLineNumber branchLandLineNumber;
147
148         /**
149          * Numer of this branch office
150          */
151         @Column (name = "branch_number")
152         private Long branchNumber;
153
154         /**
155          * Opening times for this branch office
156          */
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 = BusinessOpeningTimes.class, cascade = CascadeType.REFRESH)
159         private List<OpeningTimes> branchOpeningTimes;
160
161         /**
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.
165          */
166         @JoinColumn (name = "branch_owner_employee_id", referencedColumnName = "employee_id")
167         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.REFRESH)
168         private Employee branchOwnerEmployee;
169
170         /**
171          * Branch office's store (if multiple-store building)
172          */
173         @Column (name = "branch_store", length = 3)
174         private Short branchStore;
175
176         /**
177          * Branch office's street name
178          */
179         @Basic (optional = false)
180         @Column (name = "branch_street", length = 100, nullable = false)
181         private String branchStreet;
182
183         /**
184          * Branch office's suite number (if applyable)
185          */
186         @Column (name = "branch_suite_number", length = 4)
187         private Short branchSuiteNumber;
188
189         /**
190          * User owner instance
191          */
192         @JoinColumn (name = "branch_user_id", referencedColumnName = "user_id")
193         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
194         private User branchUserOwner;
195
196         /**
197          * Branch office's ZIP code
198          */
199         @Basic (optional = false)
200         @Column (name = "branch_zip_code", length = 6, nullable = false)
201         private Integer branchZipCode;
202
203         /**
204          * Default constructor for JPA
205          */
206         public CompanyBranchOffice () {
207         }
208
209         /**
210          * Constructor with all required fields. This constructor may throw
211          * exceptions when one parameter is not valid or NULL.
212          * <p>
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
219          */
220         public CompanyBranchOffice (final String branchCity, final BusinessBasicData branchCompany, final Country branchCountry, final String branchStreet, final Integer branchZipCode, final Short branchHouseNumber) {
221                 // Call other constructor
222                 this();
223
224                 // Check all parameter
225                 if (null == branchCity) {
226                         // Throw NPE
227                         throw new NullPointerException("branchCity is null"); //NOI18N
228                 } else if (branchCity.isEmpty()) {
229                         // Throw IAE
230                         throw new IllegalArgumentException("branchCity is empty"); //NOI18N
231                 } else if (null == branchCompany) {
232                         // Throw NPE
233                         throw new NullPointerException("branchCompany is null"); //NOI18N
234                 } else if (branchCompany.getBasicDataId() == null) {
235                         // Throw NPE again
236                         throw new NullPointerException("branchCompany.basicDataId is null"); //NOI18N
237                 } else if (branchCompany.getBasicDataId() < 1) {
238                         // Throw IAE again
239                         throw new IllegalArgumentException(MessageFormat.format("branchCompany.basicDataId={0} is invalid", branchCompany.getBasicDataId())); //NOI18N
240                 } else if (null == branchCountry) {
241                         // Throw NPE again
242                         throw new NullPointerException("branchCountry is null"); //NOI18N
243                 } else if (branchCountry.getCountryId() == null) {
244                         // Throw NPE again
245                         throw new NullPointerException("branchCountry.countryId is null"); //NOI18N
246                 } else if (branchCountry.getCountryId() < 1) {
247                         // Throw IAE again
248                         throw new IllegalArgumentException(MessageFormat.format("branchCountry.countryId={0} is invalid", branchCountry.getCountryId())); //NOI18N
249                 } else if (null == branchStreet) {
250                         // Throw NPE
251                         throw new NullPointerException("branchStreet is null"); //NOI18N
252                 } else if (branchStreet.isEmpty()) {
253                         // Throw IAE
254                         throw new IllegalArgumentException("branchStreet is empty"); //NOI18N
255                 } else if (null == branchZipCode) {
256                         // Throw NPE
257                         throw new NullPointerException("branchZipCode is null"); //NOI18N
258                 } else if (branchZipCode < 1) {
259                         // Throw IAE
260                         throw new IllegalArgumentException(MessageFormat.format("branchZipCode={0} is out of range.", branchZipCode)); //NOI18N
261                 } else if (null == branchHouseNumber) {
262                         // Throw NPE
263                         throw new NullPointerException("branchHouseNumber is null"); //NOI18N
264                 } else if (branchHouseNumber < 1) {
265                         // Throw IAE
266                         throw new IllegalArgumentException(MessageFormat.format("branchHouseNumber={0} is out of range.", branchHouseNumber)); //NOI18N
267                 }
268
269                 // Set all fields
270                 this.branchCity = branchCity;
271                 this.branchCompany = branchCompany;
272                 this.branchCountry = branchCountry;
273                 this.branchStreet = branchStreet;
274                 this.branchZipCode = branchZipCode;
275                 this.branchHouseNumber = branchHouseNumber;
276         }
277
278         @Override
279         public boolean equals (final Object object) {
280                 if (null == object) {
281                         return false;
282                 } else if (this.getClass() != object.getClass()) {
283                         return false;
284                 }
285
286                 final BranchOffice other = (BranchOffice) object;
287
288                 if (!Objects.equals(this.getBranchId(), other.getBranchId())) {
289                         return false;
290                 } else if (!Objects.equals(this.getBranchCity(), other.getBranchCity())) {
291                         return false;
292                 } else if (!Objects.equals(this.getBranchCountry(), other.getBranchCountry())) {
293                         return false;
294                 } else if (!Objects.equals(this.getBranchHouseNumber(), other.getBranchHouseNumber())) {
295                         return false;
296                 } else if (!Objects.equals(this.getBranchNumber(), other.getBranchNumber())) {
297                         return false;
298                 } else if (!Objects.equals(this.getBranchStore(), other.getBranchStore())) {
299                         return false;
300                 } else if (!Objects.equals(this.getBranchStreet(), other.getBranchStreet())) {
301                         return false;
302                 } else if (!Objects.equals(this.getBranchSuiteNumber(), other.getBranchSuiteNumber())) {
303                         return false;
304                 } else if (!Objects.equals(this.getBranchZipCode(), other.getBranchZipCode())) {
305                         return false;
306                 }
307
308                 return true;
309         }
310
311         @Override
312         public String getBranchCity () {
313                 return this.branchCity;
314         }
315
316         @Override
317         public void setBranchCity (final String branchCity) {
318                 this.branchCity = branchCity;
319         }
320
321         @Override
322         public BusinessBasicData getBranchCompany () {
323                 return this.branchCompany;
324         }
325
326         @Override
327         public void setBranchCompany (final BusinessBasicData branchCompany) {
328                 this.branchCompany = branchCompany;
329         }
330
331         @Override
332         public Employee getBranchContactEmployee () {
333                 return this.branchContactEmployee;
334         }
335
336         @Override
337         public void setBranchContactEmployee (final Employee branchContactEmployee) {
338                 this.branchContactEmployee = branchContactEmployee;
339         }
340
341         @Override
342         public Country getBranchCountry () {
343                 return this.branchCountry;
344         }
345
346         @Override
347         public void setBranchCountry (final Country branchCountry) {
348                 this.branchCountry = branchCountry;
349         }
350
351         @Override
352         @SuppressWarnings ("ReturnOfDateField")
353         public Date getBranchCreated () {
354                 return this.branchCreated;
355         }
356
357         @Override
358         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
359         public void setBranchCreated (final Date branchCreated) {
360                 this.branchCreated = branchCreated;
361         }
362
363         @Override
364         public String getBranchEmailAddress () {
365                 return this.branchEmailAddress;
366         }
367
368         @Override
369         public void setBranchEmailAddress (final String branchEmailAddress) {
370                 this.branchEmailAddress = branchEmailAddress;
371         }
372
373         @Override
374         public DialableFaxNumber getBranchFaxNumber () {
375                 return this.branchFaxNumber;
376         }
377
378         @Override
379         public void setBranchFaxNumber (final DialableFaxNumber branchFaxNumber) {
380                 this.branchFaxNumber = branchFaxNumber;
381         }
382
383         @Override
384         public Short getBranchHouseNumber () {
385                 return this.branchHouseNumber;
386         }
387
388         @Override
389         public void setBranchHouseNumber (final Short branchHouseNumber) {
390                 this.branchHouseNumber = branchHouseNumber;
391         }
392
393         @Override
394         public Long getBranchId () {
395                 return this.branchId;
396         }
397
398         @Override
399         public void setBranchId (final Long branchId) {
400                 this.branchId = branchId;
401         }
402
403         @Override
404         public DialableLandLineNumber getBranchLandLineNumber () {
405                 return this.branchLandLineNumber;
406         }
407
408         @Override
409         public void setBranchLandLineNumber (final DialableLandLineNumber branchLandLineNumber) {
410                 this.branchLandLineNumber = branchLandLineNumber;
411         }
412
413         @Override
414         public Long getBranchNumber () {
415                 return this.branchNumber;
416         }
417
418         @Override
419         public void setBranchNumber (final Long branchNumber) {
420                 this.branchNumber = branchNumber;
421         }
422
423         @Override
424         public List<OpeningTimes> getBranchOpeningTimes () {
425                 return this.branchOpeningTimes;
426         }
427
428         @Override
429         public void setBranchOpeningTimes (final List<OpeningTimes> branchOpeningTimes) {
430                 this.branchOpeningTimes = branchOpeningTimes;
431         }
432
433         @Override
434         public Employee getBranchOwnerEmployee () {
435                 return this.branchOwnerEmployee;
436         }
437
438         @Override
439         public void setBranchOwnerEmployee (final Employee branchOwnerEmployee) {
440                 this.branchOwnerEmployee = branchOwnerEmployee;
441         }
442
443         @Override
444         public Short getBranchStore () {
445                 return this.branchStore;
446         }
447
448         @Override
449         public void setBranchStore (final Short branchStore) {
450                 this.branchStore = branchStore;
451         }
452
453         @Override
454         public String getBranchStreet () {
455                 return this.branchStreet;
456         }
457
458         @Override
459         public void setBranchStreet (final String branchStreet) {
460                 this.branchStreet = branchStreet;
461         }
462
463         @Override
464         public Short getBranchSuiteNumber () {
465                 return this.branchSuiteNumber;
466         }
467
468         @Override
469         public void setBranchSuiteNumber (final Short branchSuiteNumber) {
470                 this.branchSuiteNumber = branchSuiteNumber;
471         }
472
473         @Override
474         public User getBranchUserOwner () {
475                 return this.branchUserOwner;
476         }
477
478         @Override
479         public void setBranchUserOwner (final User branchUserOwner) {
480                 this.branchUserOwner = branchUserOwner;
481         }
482
483         @Override
484         public Integer getBranchZipCode () {
485                 return this.branchZipCode;
486         }
487
488         @Override
489         public void setBranchZipCode (final Integer branchZipCode) {
490                 this.branchZipCode = branchZipCode;
491         }
492
493         @Override
494         public int hashCode () {
495                 int hash = 7;
496
497                 hash = 53 * hash + Objects.hashCode(this.getBranchId());
498                 hash = 53 * hash + Objects.hashCode(this.getBranchCity());
499                 hash = 53 * hash + Objects.hashCode(this.getBranchCountry());
500                 hash = 53 * hash + Objects.hashCode(this.getBranchNumber());
501                 hash = 53 * hash + Objects.hashCode(this.getBranchHouseNumber());
502                 hash = 53 * hash + Objects.hashCode(this.getBranchStore());
503                 hash = 53 * hash + Objects.hashCode(this.getBranchStreet());
504                 hash = 53 * hash + Objects.hashCode(this.getBranchSuiteNumber());
505                 hash = 53 * hash + Objects.hashCode(this.getBranchZipCode());
506
507                 return hash;
508         }
509
510 }