]> git.mxchange.org Git - jjobs-war.git/blob
4d622a310197a0a03b251cce6bece9db01785fc7
[jjobs-war.git] /
1 /*
2  * Copyright (C) 2017 - 2020 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (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 Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jjobs.beans.business.headquarter.action;
18
19 import java.util.ArrayList;
20 import java.util.Date;
21 import java.util.List;
22 import java.util.Objects;
23 import javax.ejb.EJB;
24 import javax.enterprise.context.RequestScoped;
25 import javax.enterprise.event.Event;
26 import javax.enterprise.inject.Any;
27 import javax.faces.application.FacesMessage;
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import org.mxchange.jcontactsbusiness.events.headquarter.added.HeadquarterAddedEvent;
31 import org.mxchange.jcontactsbusiness.events.headquarter.added.ObservableHeadquarterAddedEvent;
32 import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterAlreadyAddedException;
33 import org.mxchange.jcontactsbusiness.model.employee.Employable;
34 import org.mxchange.jcontactsbusiness.model.headquarter.AdminHeadquarterSessionBeanRemote;
35 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
36 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
37 import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
38 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
39 import org.mxchange.jcoreee.dates.DayOfTheWeek;
40 import org.mxchange.jcountry.model.data.Country;
41 import org.mxchange.jjobs.beans.BaseJobsBean;
42 import org.mxchange.jjobs.beans.business.headquarter.list.JobsHeadquarterListWebViewController;
43 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
44 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
47 import org.mxchange.jusercore.model.user.User;
48
49 /**
50  * An administrative action bean for headquarter
51  * <p>
52  * @author Roland Häder<roland@mxchange.org>
53  */
54 @Named ("adminHeadquarterActionController")
55 @RequestScoped
56 public class JobsAdminHeadquarterActionWebRequestBean extends BaseJobsBean implements JobsAdminHeadquarterActionWebRequestController {
57
58         /**
59          * Opening times of this headquarter
60          */
61         private static List<OpeningTime> headquarterOpeningTimes;
62
63         /**
64          * Serial number
65          */
66         private static final long serialVersionUID = 5_028_697_360_472L;
67
68         /**
69          * EJB for administrative purposes
70          */
71         @EJB (lookup = "java:global/jjobs-ejb/adminHeadquarter!org.mxchange.jcontactsbusiness.model.headquarter.AdminHeadquarterSessionBeanRemote")
72         private AdminHeadquarterSessionBeanRemote adminHeadquarterBean;
73
74         /**
75          * Area code for fax number
76          */
77         private Integer faxAreaCode;
78
79         /**
80          * Country for fax number
81          */
82         private Country faxCountry;
83
84         /**
85          * Dial number for fax number
86          */
87         private Long faxNumber;
88
89         /**
90          * An event being fired when a headquarter has been successfully added
91          */
92         @Inject
93         @Any
94         private Event<ObservableHeadquarterAddedEvent> headquarterAddedEvent;
95
96         /**
97          * City
98          */
99         private String headquarterCity;
100
101         /**
102          * Headquarter's company name
103          */
104         private String headquarterCompanyName;
105
106         /**
107          * Contact person in headquarter
108          */
109         private Employable headquarterContactEmployee;
110
111         /**
112          * Country
113          */
114         private Country headquarterCountry;
115
116         /**
117          * Email address
118          */
119         private String headquarterEmailAddress;
120
121         /**
122          * House number
123          */
124         private Short headquarterHouseNumber;
125
126         /**
127          * House number's extension
128          */
129         private String headquarterHouseNumberExtension;
130
131         /**
132          * Last house number
133          */
134         private Short headquarterLastHouseNumber;
135
136         /**
137          * A general headquarter controller (backing bean)
138          */
139         @Inject
140         private JobsHeadquarterListWebViewController headquarterListController;
141
142         /**
143          * Store
144          */
145         private Short headquarterStore;
146
147         /**
148          * Headquarter street name
149          */
150         private String headquarterStreet;
151
152         /**
153          * Suite number
154          */
155         private Short headquarterSuiteNumber;
156
157         /**
158          * Owning user instance (which this headquarter is assigned to)
159          */
160         private User headquarterUserOwner;
161
162         /**
163          * ZIP code
164          */
165         private Integer headquarterZipCode;
166
167         /**
168          * Area code for land-line number
169          */
170         private Integer landLineAreaCode;
171
172         /**
173          * Country for land-line number
174          */
175         private Country landLineCountry;
176
177         /**
178          * Dial number for land-line number
179          */
180         private Long landLineNumber;
181
182         /**
183          * Ending week day
184          */
185         private DayOfTheWeek openingEndDay;
186
187         /**
188          * Ending time
189          */
190         private Date openingEndTime;
191
192         /**
193          * Starting week day
194          */
195         private DayOfTheWeek openingStartDay;
196
197         /**
198          * Starting time
199          */
200         private Date openingStartTime;
201
202         /**
203          * Default constructor
204          */
205         public JobsAdminHeadquarterActionWebRequestBean () {
206                 // Call super constructor
207                 super();
208
209                 // Is the opening times list there?
210                 if (null == headquarterOpeningTimes) {
211                         // Init list
212                         headquarterOpeningTimes = new ArrayList<>(1);
213                 }
214         }
215
216         /**
217          * Adds headquarter with all data from this backing bean. First this action
218          * method will validate if the headquarter's address is already registered
219          * and if found, it will output a proper faces message.
220          */
221         public void addHeadquarter () {
222                 // Get instance
223                 final Headquarter headquarter = this.createHeadquarter();
224
225                 // Is the headquarter not created yet?
226                 if (this.headquarterListController.isHeadquarterCreatedByRequiredData(headquarter)) {
227                         // Then show proper faces message
228                         this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_HEADQUARTER_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
229                         return;
230                 }
231
232                 // Delcare updated instance
233                 final Headquarter updatedHeadquarter;
234
235                 try {
236                         // Try to call EJB
237                         updatedHeadquarter = this.adminHeadquarterBean.addHeadquarter(headquarter);
238                 } catch (final HeadquarterAlreadyAddedException ex) {
239                         // Output message
240                         this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_HEADQUARTER_ALREADY_CREATED", FacesMessage.SEVERITY_ERROR); //NOI18N
241                         return;
242                 }
243
244                 // Fire event
245                 this.headquarterAddedEvent.fire(new HeadquarterAddedEvent(updatedHeadquarter));
246
247                 // Clear this bean
248                 this.clear();
249         }
250
251         /**
252          * Adds opening time to temporary list which will be sent along with the
253          * headquarter data to the EJB.
254          */
255         public void addOpeningTime () {
256                 // Validate all required fields
257                 if (this.getOpeningEndDay() == null) {
258                         // Throw NPE
259                         throw new NullPointerException("this.openingEndDay is null"); //NOI18N
260                 } else if (this.getOpeningEndTime() == null) {
261                         // Throw NPE
262                         throw new NullPointerException("this.openingEndTime is null"); //NOI18N
263                 } else if (this.getOpeningStartDay() == null) {
264                         // Throw NPE
265                         throw new NullPointerException("this.openingStartDay is null"); //NOI18N
266                 } else if (this.getOpeningStartTime() == null) {
267                         // Throw NPE
268                         throw new NullPointerException("this.openingStartTime is null"); //NOI18N
269                 }
270
271                 // Get opening time instance
272                 final OpeningTime openingTime = this.createOpeningTimes();
273
274                 // Is same found?
275                 if (this.isSameOpeningTimeFound(openingTime)) {
276                         // Yes then abort here
277                         this.showFacesMessage("form-admin-add-headquarter-opening-time:openingStartDay", "ADMIN_OPENING_TIME_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
278                         return;
279                 }
280
281                 // Add to temporary list
282                 headquarterOpeningTimes.add(openingTime);
283
284                 // Clear opening time fields
285                 this.clearOpeningTime();
286         }
287
288         /**
289          * Getter for fax number's area code
290          * <p>
291          * @return Fax number's area code
292          */
293         public Integer getFaxAreaCode () {
294                 return this.faxAreaCode;
295         }
296
297         /**
298          * Setter for fax number's area code
299          * <p>
300          * @param faxAreaCode Fax number's area code
301          */
302         public void setFaxAreaCode (final Integer faxAreaCode) {
303                 this.faxAreaCode = faxAreaCode;
304         }
305
306         /**
307          * Getter for fax's country instance
308          * <p>
309          * @return Fax' country instance
310          */
311         public Country getFaxCountry () {
312                 return this.faxCountry;
313         }
314
315         /**
316          * Setter for fax's country instance
317          * <p>
318          * @param faxCountry Fax' country instance
319          */
320         public void setFaxCountry (final Country faxCountry) {
321                 this.faxCountry = faxCountry;
322         }
323
324         /**
325          * Getter for fax number
326          * <p>
327          * @return Fax number
328          */
329         public Long getFaxNumber () {
330                 return this.faxNumber;
331         }
332
333         /**
334          * Setter for fax number
335          * <p>
336          * @param faxNumber Fax number
337          */
338         public void setFaxNumber (final Long faxNumber) {
339                 this.faxNumber = faxNumber;
340         }
341
342         /**
343          * Getter for city
344          * <p>
345          * @return City
346          */
347         public String getHeadquarterCity () {
348                 return this.headquarterCity;
349         }
350
351         /**
352          * Setter for city
353          * <p>
354          * @param headquarterCity City
355          */
356         public void setHeadquarterCity (final String headquarterCity) {
357                 this.headquarterCity = headquarterCity;
358         }
359
360         /**
361          * Getter for headquarter's company name
362          * <p>
363          * @return Headquarter's company name
364          */
365         public String getHeadquarterCompanyName () {
366                 return this.headquarterCompanyName;
367         }
368
369         /**
370          * Setter for headquarter's company name
371          * <p>
372          * @param headquarterCompanyName Headquarter's company name
373          */
374         public void setHeadquarterCompanyName (final String headquarterCompanyName) {
375                 this.headquarterCompanyName = headquarterCompanyName;
376         }
377
378         /**
379          * Getter for headquarter contact person
380          * <p>
381          * @return Headquarter contact person
382          */
383         public Employable getHeadquarterContactEmployee () {
384                 return this.headquarterContactEmployee;
385         }
386
387         /**
388          * Setter for headquarter contact person
389          * <p>
390          * @param headquarterContactEmployee Headquarter contact person
391          */
392         public void setHeadquarterContactEmployee (final Employable headquarterContactEmployee) {
393                 this.headquarterContactEmployee = headquarterContactEmployee;
394         }
395
396         /**
397          * Getter for country
398          * <p>
399          * @return Country
400          */
401         public Country getHeadquarterCountry () {
402                 return this.headquarterCountry;
403         }
404
405         /**
406          * Setter for country
407          * <p>
408          * @param headquarterCountry Country
409          */
410         public void setHeadquarterCountry (final Country headquarterCountry) {
411                 this.headquarterCountry = headquarterCountry;
412         }
413
414         /**
415          * Getter for email address
416          * <p>
417          * @return Email address
418          */
419         public String getHeadquarterEmailAddress () {
420                 return this.headquarterEmailAddress;
421         }
422
423         /**
424          * Getter for email address
425          * <p>
426          * @param headquarterEmailAddress Email address
427          */
428         public void setHeadquarterEmailAddress (final String headquarterEmailAddress) {
429                 this.headquarterEmailAddress = headquarterEmailAddress;
430         }
431
432         /**
433          * Getter for house number
434          * <p>
435          * @return House number
436          */
437         public Short getHeadquarterHouseNumber () {
438                 return this.headquarterHouseNumber;
439         }
440
441         /**
442          * Setter for house number
443          * <p>
444          * @param headquarterHouseNumber House number
445          */
446         public void setHeadquarterHouseNumber (final Short headquarterHouseNumber) {
447                 this.headquarterHouseNumber = headquarterHouseNumber;
448         }
449
450         /**
451          * Getter for house number's extension
452          * <p>
453          * @return House number's extension
454          */
455         public String getHeadquarterHouseNumberExtension () {
456                 return this.headquarterHouseNumberExtension;
457         }
458
459         /**
460          * Setter for house number's extension
461          * <p>
462          * @param headquarterHouseNumberExtension House number's extension
463          */
464         public void setHeadquarterHouseNumberExtension (final String headquarterHouseNumberExtension) {
465                 this.headquarterHouseNumberExtension = headquarterHouseNumberExtension;
466         }
467
468         /**
469          * Getter for last house number
470          * <p>
471          * @return Last house number
472          */
473         public Short getHeadquarterLastHouseNumber () {
474                 return this.headquarterLastHouseNumber;
475         }
476
477         /**
478          * Setter for last house number
479          * <p>
480          * @param headquarterLastHouseNumber Last house number
481          */
482         public void setHeadquarterLastHouseNumber (final Short headquarterLastHouseNumber) {
483                 this.headquarterLastHouseNumber = headquarterLastHouseNumber;
484         }
485
486         /**
487          * Getter for opening times of this headquarter
488          * <p>
489          * @return Opening times
490          */
491         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
492         public List<OpeningTime> getHeadquarterOpeningTimes () {
493                 return headquarterOpeningTimes;
494         }
495
496         /**
497          * Setter for opening times of this headquarter
498          * <p>
499          * @param headquarterOpeningTimes Opening times
500          */
501         @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
502         public void setHeadquarterOpeningTimes (final List<OpeningTime> headquarterOpeningTimes) {
503                 JobsAdminHeadquarterActionWebRequestBean.headquarterOpeningTimes = headquarterOpeningTimes;
504         }
505
506         /**
507          * Getter for store
508          * <p>
509          * @return Store
510          */
511         public Short getHeadquarterStore () {
512                 return this.headquarterStore;
513         }
514
515         /**
516          * Setter for store
517          * <p>
518          * @param headquarterStore Store
519          */
520         public void setHeadquarterStore (final Short headquarterStore) {
521                 this.headquarterStore = headquarterStore;
522         }
523
524         /**
525          * Getter for street name
526          * <p>
527          * @return Street name
528          */
529         public String getHeadquarterStreet () {
530                 return this.headquarterStreet;
531         }
532
533         /**
534          * Setter for street name
535          * <p>
536          * @param headquarterStreet Street name
537          */
538         public void setHeadquarterStreet (final String headquarterStreet) {
539                 this.headquarterStreet = headquarterStreet;
540         }
541
542         /**
543          * Getter for suite number
544          * <p>
545          * @return Suite number
546          */
547         public Short getHeadquarterSuiteNumber () {
548                 return this.headquarterSuiteNumber;
549         }
550
551         /**
552          * Setter for suite number
553          * <p>
554          * @param headquarterSuiteNumber Suite number
555          */
556         public void setHeadquarterSuiteNumber (final Short headquarterSuiteNumber) {
557                 this.headquarterSuiteNumber = headquarterSuiteNumber;
558         }
559
560         /**
561          * Getter for owning user instance
562          * <p>
563          * @return Owning user instance
564          */
565         public User getHeadquarterUserOwner () {
566                 return this.headquarterUserOwner;
567         }
568
569         /**
570          * Setter for owning user instance
571          * <p>
572          * @param headquarterUserOwner Owning user instance
573          */
574         public void setHeadquarterUserOwner (final User headquarterUserOwner) {
575                 this.headquarterUserOwner = headquarterUserOwner;
576         }
577
578         /**
579          * Getter for ZIP code\
580          * <p>
581          * @return ZIP code
582          */
583         public Integer getHeadquarterZipCode () {
584                 return this.headquarterZipCode;
585         }
586
587         /**
588          * Setter for ZIP code\
589          * <p>
590          * @param headquarterZipCode ZIP code
591          */
592         public void setHeadquarterZipCode (final Integer headquarterZipCode) {
593                 this.headquarterZipCode = headquarterZipCode;
594         }
595
596         /**
597          * Getter for land-line number's area code
598          * <p>
599          * @return Land-line number's area code
600          */
601         public Integer getLandLineAreaCode () {
602                 return this.landLineAreaCode;
603         }
604
605         /**
606          * Setter for land-line number's area code
607          * <p>
608          * @param landLineAreaCode Land-line number's area code
609          */
610         public void setLandLineAreaCode (final Integer landLineAreaCode) {
611                 this.landLineAreaCode = landLineAreaCode;
612         }
613
614         /**
615          * Getter for land-line number's country instance
616          * <p>
617          * @return Land-line number's country instance
618          */
619         public Country getLandLineCountry () {
620                 return this.landLineCountry;
621         }
622
623         /**
624          * Setter for land-line number's country instance
625          * <p>
626          * @param landLineCountry Land-line number's country instance
627          */
628         public void setLandLineCountry (final Country landLineCountry) {
629                 this.landLineCountry = landLineCountry;
630         }
631
632         /**
633          * Getter for land-line number
634          * <p>
635          * @return Land-line number
636          */
637         public Long getLandLineNumber () {
638                 return this.landLineNumber;
639         }
640
641         /**
642          * Setter for land-line number
643          * <p>
644          * @param landLineNumber Land-line number
645          */
646         public void setLandLineNumber (final Long landLineNumber) {
647                 this.landLineNumber = landLineNumber;
648         }
649
650         /**
651          * Getter for ending week day
652          * <p>
653          * @return Ending week day
654          */
655         public DayOfTheWeek getOpeningEndDay () {
656                 return this.openingEndDay;
657         }
658
659         /**
660          * Setter for ending week day
661          * <p>
662          * @param openingEndDay Ending week day
663          */
664         public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
665                 this.openingEndDay = openingEndDay;
666         }
667
668         /**
669          * Getter for ending time
670          * <p>
671          * @return Ending time
672          */
673         @SuppressWarnings ("ReturnOfDateField")
674         public Date getOpeningEndTime () {
675                 return this.openingEndTime;
676         }
677
678         /**
679          * Getter for ending time
680          * <p>
681          * @param openingEndTime Ending time
682          */
683         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
684         public void setOpeningEndTime (final Date openingEndTime) {
685                 this.openingEndTime = openingEndTime;
686         }
687
688         /**
689          * Getter for starting week day
690          * <p>
691          * @return Starting week day
692          */
693         public DayOfTheWeek getOpeningStartDay () {
694                 return this.openingStartDay;
695         }
696
697         /**
698          * Getter for starting week day
699          * <p>
700          * @param openingStartDay Starting week day
701          */
702         public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
703                 this.openingStartDay = openingStartDay;
704         }
705
706         /**
707          * Getter for starting time
708          * <p>
709          * @return Starting time
710          */
711         @SuppressWarnings ("ReturnOfDateField")
712         public Date getOpeningStartTime () {
713                 return this.openingStartTime;
714         }
715
716         /**
717          * Getter for starting time
718          * <p>
719          * @param openingStartTime Starting time
720          */
721         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
722         public void setOpeningStartTime (final Date openingStartTime) {
723                 this.openingStartTime = openingStartTime;
724         }
725
726         /**
727          * Clears this bean data
728          */
729         private void clear () {
730                 // Clear all headquarter data
731                 this.setHeadquarterCity(null);
732                 this.setHeadquarterCompanyName(null);
733                 this.setHeadquarterContactEmployee(null);
734                 this.setHeadquarterCountry(null);
735                 this.setHeadquarterEmailAddress(null);
736                 this.setHeadquarterHouseNumber(null);
737                 this.setHeadquarterHouseNumberExtension(null);
738                 this.setHeadquarterLastHouseNumber(null);
739                 this.setHeadquarterStore(null);
740                 this.setHeadquarterStreet(null);
741                 this.setHeadquarterSuiteNumber(null);
742                 this.setHeadquarterUserOwner(null);
743                 this.setHeadquarterZipCode(null);
744                 this.setHeadquarterOpeningTimes(null);
745
746                 // Extra-clear opening time
747                 this.clearOpeningTime();
748         }
749
750         /**
751          * Clears all opening time fields
752          */
753         private void clearOpeningTime () {
754                 // Clear all opening time fields
755                 this.setOpeningEndDay(null);
756                 this.setOpeningEndTime(null);
757                 this.setOpeningStartDay(null);
758                 this.setOpeningStartTime(null);
759         }
760
761         /**
762          * Prepares an instance of a Headquarter object (entity) with all data from
763          * this bean. If a complete fax number or land-line number was provided, it
764          * will be set in the instance as well.
765          * <p>
766          * @return An instance of a Headquarter class (entity)
767          */
768         private Headquarter createHeadquarter () {
769                 // Create new headquarter instance
770                 final Headquarter headquarter = new BusinessHeadquarter(
771                                                   this.getHeadquarterCompanyName(),
772                                                   this.getHeadquarterCity(),
773                                                   this.getHeadquarterCountry(),
774                                                   this.getHeadquarterStreet(),
775                                                   this.getHeadquarterZipCode(),
776                                                   this.getHeadquarterHouseNumber()
777                                   );
778
779                 // Add all other fields, too
780                 headquarter.setHeadquarterContactEmployee(this.getHeadquarterContactEmployee());
781                 headquarter.setHeadquarterEmailAddress(this.getHeadquarterEmailAddress());
782                 headquarter.setHeadquarterHouseNumberExtension(this.getHeadquarterHouseNumberExtension());
783                 headquarter.setHeadquarterLastHouseNumber(this.getHeadquarterLastHouseNumber());
784                 headquarter.setHeadquarterStore(this.getHeadquarterStore());
785                 headquarter.setHeadquarterSuiteNumber(this.getHeadquarterSuiteNumber());
786                 headquarter.setHeadquarterUserOwner(this.getHeadquarterUserOwner());
787
788                 // Initialize variables
789                 DialableLandLineNumber landLine = null;
790                 DialableFaxNumber fax = null;
791
792                 // Are all fields set?
793                 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
794                         // Initialize instance
795                         landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
796                 }
797
798                 // Are all fields set?
799                 if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
800                         // Initialize instance
801                         fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
802                 }
803
804                 // Don't set null or wrong references
805                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
806                         // Now the number must be given
807                         if (landLine.getPhoneAreaCode() == null) {
808                                 // Is null
809                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
810                         } else if (landLine.getPhoneAreaCode() < 1) {
811                                 // Abort here
812                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
813                         } else if (landLine.getPhoneNumber() == null) {
814                                 // Is null
815                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
816                         } else if (landLine.getPhoneNumber() < 1) {
817                                 // Abort here
818                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
819                         }
820
821                         // Set phone number
822                         headquarter.setHeadquarterLandLineNumber(landLine);
823                 }
824
825                 // Don't set null or wrong references
826                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
827                         // Now the number must be given
828                         if (fax.getPhoneAreaCode() == null) {
829                                 // Is null
830                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
831                         } else if (fax.getPhoneAreaCode() < 1) {
832                                 // Abort here
833                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
834                         } else if (fax.getPhoneNumber() == null) {
835                                 // Is null
836                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
837                         } else if (fax.getPhoneNumber() < 1) {
838                                 // Abort here
839                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
840                         }
841
842                         // Set fax number
843                         headquarter.setHeadquarterFaxNumber(fax);
844                 }
845                 // Is the opening times list filled?
846                 if (!this.getHeadquarterOpeningTimes().isEmpty()) {
847                         // Yes, then set in headquarter, too
848                         headquarter.setHeadquarterOpeningTimes(this.getHeadquarterOpeningTimes());
849                 }
850
851                 // Return fully prepared instance
852                 return headquarter;
853         }
854
855         /**
856          * Prepares an instance of a OpeningTimes object (entity) with all data from
857          * this bean. If a complete fax number or land-line number was provided, it
858          * will be set in the instance as well.
859          * <p>
860          * @return An instance of a OpeningTimes class (entity)
861          */
862         private OpeningTime createOpeningTimes () {
863                 // Create new openingTime instance
864                 final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
865
866                 // Return fully prepared instance
867                 return openingTime;
868         }
869
870         /**
871          * Checks if given opening time is already added
872          * <p>
873          * @param openingTime Opening time to be checked
874          * <p>
875          * @return Whether it has been added already
876          */
877         private boolean isSameOpeningTimeFound (final OpeningTime openingTime) {
878                 // Default is not found
879                 boolean isFound = false;
880
881                 // Loop through list
882                 for (final OpeningTime ot : this.getHeadquarterOpeningTimes()) {
883                         // Check it
884                         if (Objects.equals(ot, openingTime)) {
885                                 // Found same match
886                                 isFound = true;
887                                 break;
888                         }
889                 }
890
891                 // Return it
892                 return isFound;
893         }
894
895 }