]> 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.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;
49
50 /**
51  * A POJO for company branch offices
52  * <p>
53  * @author Roland Häder<roland@mxchange.org>
54  */
55 @Entity (name = "company_branch_offices")
56 @Table (name = "company_branch_offices")
57 @NamedQueries ({
58         @NamedQuery (name = "AllBranchOffices", query = "SELECT bo FROM company_branch_offices AS bo ORDER BY bo.branchId ASC")
59 })
60 @SuppressWarnings ("PersistenceUnitPresent")
61 public class CompanyBranchOffice implements BranchOffice {
62
63         /**
64          * Serial number
65          */
66         @Transient
67         private static final long serialVersionUID = 47_957_817_276_871_852L;
68
69         /**
70          * Branch office's city name
71          */
72         @Basic (optional = false)
73         @Column (name = "branch_city", length = 100, nullable = false)
74         private String branchCity;
75
76         /**
77          * Company that has this branch office
78          */
79         @JoinColumn (name = "branch_company_id", nullable = false, updatable = false)
80         @OneToOne (targetEntity = CompanyBasicData.class, optional = false, cascade = CascadeType.REFRESH)
81         private BusinessBasicData branchCompany;
82
83         /**
84          * Reference to contact person
85          */
86         @JoinColumn (name = "branch_contact_employee_id")
87         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.REFRESH)
88         private Employee branchContactEmployee;
89
90         /**
91          * Branch office's country code
92          */
93         @JoinColumn (name = "branch_country_id", nullable = false)
94         @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
95         private Country branchCountry;
96
97         /**
98          * Timestamp when this entry has been created
99          */
100         @Basic (optional = false)
101         @Temporal (TemporalType.TIMESTAMP)
102         @Column (name = "branch_entry_created", nullable = false, updatable = false)
103         private Calendar branchCreated;
104
105         /**
106          * Branch office's main email address (example: branch-name@company.com)
107          */
108         @Column (name = "branch_email_address", length = 100)
109         private String branchEmailAddress;
110
111         /**
112          * Branch office's main fax number: +ccxxxxxxxxxx
113          */
114         @JoinColumn (name = "branch_fax_number_id")
115         @OneToOne (targetEntity = FaxNumber.class, cascade = CascadeType.ALL)
116         private DialableFaxNumber branchFaxNumber;
117
118         /**
119          * Branch office's house number
120          */
121         @Basic (optional = false)
122         @Column (name = "branch_house_number", length = 3, nullable = false)
123         private Short branchHouseNumber;
124
125         /**
126          * Id number
127          */
128         @Id
129         @GeneratedValue (strategy = GenerationType.IDENTITY)
130         @Column (name = "branch_id", nullable = false, updatable = false)
131         private Long branchId;
132
133         /**
134          * Branch office's main land-line number: +ccxxxxxxxxxx
135          */
136         @JoinColumn (name = "branch_landline_number_id")
137         @OneToOne (targetEntity = LandLineNumber.class, cascade = CascadeType.ALL)
138         private DialableLandLineNumber branchLandLineNumber;
139
140         /**
141          * Branch office's store (if multiple-store building)
142          */
143         @Column (name = "branch_store", length = 3)
144         private Short branchStore;
145
146         /**
147          * Branch office's street name
148          */
149         @Basic (optional = false)
150         @Column (name = "branch_street", length = 100, nullable = false)
151         private String branchStreet;
152
153         /**
154          * Branch office's suite number (if applyable)
155          */
156         @Column (name = "branch_suite_number", length = 4)
157         private Short branchSuiteNumber;
158
159         /**
160          * User owner instance
161          */
162         @JoinColumn (name = "branch_user_id")
163         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
164         private User branchUserOwner;
165
166         /**
167          * Branch office's ZIP code
168          */
169         @Basic (optional = false)
170         @Column (name = "branch_zip_code", length = 6, nullable = false)
171         private Integer branchZipCode;
172
173         /**
174          * Default constructor for JPA
175          */
176         public CompanyBranchOffice () {
177         }
178
179         /**
180          * Constructor with all required fields. This constructor may throw
181          * exceptions when one parameter is not valid or NULL.
182          * <p>
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
189          */
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
192                 this();
193
194                 // Check all parameter
195                 if (null == branchCity) {
196                         // Throw NPE
197                         throw new NullPointerException("branchCity is null"); //NOI18N
198                 } else if (branchCity.isEmpty()) {
199                         // Throw IAE
200                         throw new IllegalArgumentException("branchCity is empty"); //NOI18N
201                 } else if (null == branchCompany) {
202                         // Throw NPE
203                         throw new NullPointerException("branchCompany is null"); //NOI18N
204                 } else if (branchCompany.getBasicDataId() == null) {
205                         // Throw NPE again
206                         throw new NullPointerException("branchCompany.basicDataId is null"); //NOI18N
207                 } else if (branchCompany.getBasicDataId() < 1) {
208                         // Throw IAE again
209                         throw new IllegalArgumentException(MessageFormat.format("branchCompany.basicDataId={0} is invalid", branchCompany.getBasicDataId())); //NOI18N
210                 } else if (null == branchCountry) {
211                         // Throw NPE again
212                         throw new NullPointerException("branchCountry is null"); //NOI18N
213                 } else if (branchCountry.getCountryId() == null) {
214                         // Throw NPE again
215                         throw new NullPointerException("branchCountry.countryId is null"); //NOI18N
216                 } else if (branchCountry.getCountryId() < 1) {
217                         // Throw IAE again
218                         throw new IllegalArgumentException(MessageFormat.format("branchCountry.countryId={0} is invalid", branchCountry.getCountryId())); //NOI18N
219                 } else if (null == branchStreet) {
220                         // Throw NPE
221                         throw new NullPointerException("branchStreet is null"); //NOI18N
222                 } else if (branchStreet.isEmpty()) {
223                         // Throw IAE
224                         throw new IllegalArgumentException("branchStreet is empty"); //NOI18N
225                 } else if (null == branchZipCode) {
226                         // Throw NPE
227                         throw new NullPointerException("branchZipCode is null"); //NOI18N
228                 } else if (branchZipCode < 1) {
229                         // Throw IAE
230                         throw new IllegalArgumentException(MessageFormat.format("branchZipCode={0} is out of range.", branchZipCode)); //NOI18N
231                 } else if (null == branchHouseNumber) {
232                         // Throw NPE
233                         throw new NullPointerException("branchHouseNumber is null"); //NOI18N
234                 } else if (branchHouseNumber < 1) {
235                         // Throw IAE
236                         throw new IllegalArgumentException(MessageFormat.format("branchHouseNumber={0} is out of range.", branchHouseNumber)); //NOI18N
237                 }
238
239                 // Set all fields
240                 this.branchCity = branchCity;
241                 this.branchCompany = branchCompany;
242                 this.branchCountry = branchCountry;
243                 this.branchStreet = branchStreet;
244                 this.branchZipCode = branchZipCode;
245                 this.branchHouseNumber = branchHouseNumber;
246         }
247
248         @Override
249         public boolean equals (final Object object) {
250                 if (null == object) {
251                         return false;
252                 } else if (this.getClass() != object.getClass()) {
253                         return false;
254                 }
255
256                 final BranchOffice other = (BranchOffice) object;
257
258                 if (!Objects.equals(this.getBranchId(), other.getBranchId())) {
259                         return false;
260                 } else if (!Objects.equals(this.getBranchCity(), other.getBranchCity())) {
261                         return false;
262                 } else if (!Objects.equals(this.getBranchCountry(), other.getBranchCountry())) {
263                         return false;
264                 } else if (!Objects.equals(this.getBranchHouseNumber(), other.getBranchHouseNumber())) {
265                         return false;
266                 } else if (!Objects.equals(this.getBranchStore(), other.getBranchStore())) {
267                         return false;
268                 } else if (!Objects.equals(this.getBranchStreet(), other.getBranchStreet())) {
269                         return false;
270                 } else if (!Objects.equals(this.getBranchSuiteNumber(), other.getBranchSuiteNumber())) {
271                         return false;
272                 } else if (!Objects.equals(this.getBranchZipCode(), other.getBranchZipCode())) {
273                         return false;
274                 }
275
276                 return true;
277         }
278
279         @Override
280         public String getBranchCity () {
281                 return this.branchCity;
282         }
283
284         @Override
285         public void setBranchCity (final String branchCity) {
286                 this.branchCity = branchCity;
287         }
288
289         @Override
290         public BusinessBasicData getBranchCompany () {
291                 return this.branchCompany;
292         }
293
294         @Override
295         public void setBranchCompany (final BusinessBasicData branchCompany) {
296                 this.branchCompany = branchCompany;
297         }
298
299         @Override
300         public Employee getBranchContactEmployee () {
301                 return this.branchContactEmployee;
302         }
303
304         @Override
305         public void setBranchContactEmployee (final Employee branchContactEmployee) {
306                 this.branchContactEmployee = branchContactEmployee;
307         }
308
309         @Override
310         public Country getBranchCountry () {
311                 return this.branchCountry;
312         }
313
314         @Override
315         public void setBranchCountry (final Country branchCountry) {
316                 this.branchCountry = branchCountry;
317         }
318
319         @Override
320         @SuppressWarnings ("ReturnOfDateField")
321         public Calendar getBranchCreated () {
322                 return this.branchCreated;
323         }
324
325         @Override
326         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
327         public void setBranchCreated (final Calendar branchCreated) {
328                 this.branchCreated = branchCreated;
329         }
330
331         @Override
332         public String getBranchEmailAddress () {
333                 return this.branchEmailAddress;
334         }
335
336         @Override
337         public void setBranchEmailAddress (final String branchEmailAddress) {
338                 this.branchEmailAddress = branchEmailAddress;
339         }
340
341         @Override
342         public DialableFaxNumber getBranchFaxNumber () {
343                 return this.branchFaxNumber;
344         }
345
346         @Override
347         public void setBranchFaxNumber (final DialableFaxNumber branchFaxNumber) {
348                 this.branchFaxNumber = branchFaxNumber;
349         }
350
351         @Override
352         public Short getBranchHouseNumber () {
353                 return this.branchHouseNumber;
354         }
355
356         @Override
357         public void setBranchHouseNumber (final Short branchHouseNumber) {
358                 this.branchHouseNumber = branchHouseNumber;
359         }
360
361         @Override
362         public Long getBranchId () {
363                 return this.branchId;
364         }
365
366         @Override
367         public void setBranchId (final Long branchId) {
368                 this.branchId = branchId;
369         }
370
371         @Override
372         public DialableLandLineNumber getBranchLandLineNumber () {
373                 return this.branchLandLineNumber;
374         }
375
376         @Override
377         public void setBranchLandLineNumber (final DialableLandLineNumber branchLandLineNumber) {
378                 this.branchLandLineNumber = branchLandLineNumber;
379         }
380
381         @Override
382         public Short getBranchStore () {
383                 return this.branchStore;
384         }
385
386         @Override
387         public void setBranchStore (final Short branchStore) {
388                 this.branchStore = branchStore;
389         }
390
391         @Override
392         public String getBranchStreet () {
393                 return this.branchStreet;
394         }
395
396         @Override
397         public void setBranchStreet (final String branchStreet) {
398                 this.branchStreet = branchStreet;
399         }
400
401         @Override
402         public Short getBranchSuiteNumber () {
403                 return this.branchSuiteNumber;
404         }
405
406         @Override
407         public void setBranchSuiteNumber (final Short branchSuiteNumber) {
408                 this.branchSuiteNumber = branchSuiteNumber;
409         }
410
411         @Override
412         public User getBranchUserOwner () {
413                 return this.branchUserOwner;
414         }
415
416         @Override
417         public void setBranchUserOwner (final User branchUserOwner) {
418                 this.branchUserOwner = branchUserOwner;
419         }
420
421         @Override
422         public Integer getBranchZipCode () {
423                 return this.branchZipCode;
424         }
425
426         @Override
427         public void setBranchZipCode (final Integer branchZipCode) {
428                 this.branchZipCode = branchZipCode;
429         }
430
431         @Override
432         public int hashCode () {
433                 int hash = 7;
434
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());
443
444                 return hash;
445         }
446
447 }