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