]> git.mxchange.org Git - jfinancials-war.git/blob
d69a8e639e8af92625d00f856b136c0f1214fa02
[jfinancials-war.git] /
1 /*
2  * Copyright (C) 2017, 2018 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          * <p>
220          * @return Redirect outcome
221          */
222         public String addHeadquarter () {
223                 // Get instance
224                 final Headquarter headquarter = this.createHeadquarter();
225
226                 // Is the headquarter not created yet?
227                 if (this.isHeadquarterCreatedByRequiredData(headquarter)) {
228                         // Then show proper faces message
229                         this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_HEADQUARTER_ALREADY_CREATED"); //NOI18N
230                         return ""; //NOI18N
231                 }
232
233                 // Delcare updated instance
234                 final Headquarter updatedHeadquarter;
235
236                 try {
237                         // Try to call EJB
238                         updatedHeadquarter = this.adminHeadquarterBean.addHeadquarter(headquarter);
239                 } catch (final HeadquarterAlreadyAddedException ex) {
240                         // Output message
241                         this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_HEADQUARTER_ALREADY_CREATED"); //NOI18N
242                         return ""; //NOI18N
243                 }
244
245                 // Fire event
246                 this.headquarterAddedEvent.fire(new HeadquarterAddedEvent(updatedHeadquarter));
247
248                 // Clear this bean
249                 this.clear();
250
251                 // Redirect to list
252                 return "admin_list_headquarter"; //NOI18N
253         }
254
255         /**
256          * Adds opening time to temporary list which will be sent along with the
257          * headquarter data to the EJB.
258          */
259         public void addOpeningTime () {
260                 // Validate all required fields
261                 if (this.getOpeningEndDay() == null) {
262                         // Throw NPE
263                         throw new NullPointerException("this.openingEndDay is null"); //NOI18N
264                 } else if (this.getOpeningEndTime() == null) {
265                         // Throw NPE
266                         throw new NullPointerException("this.openingEndTime is null"); //NOI18N
267                 } else if (this.getOpeningStartDay() == null) {
268                         // Throw NPE
269                         throw new NullPointerException("this.openingStartDay is null"); //NOI18N
270                 } else if (this.getOpeningStartTime() == null) {
271                         // Throw NPE
272                         throw new NullPointerException("this.openingStartTime is null"); //NOI18N
273                 }
274
275                 // Get opening time instance
276                 final OpeningTime openingTime = this.createOpeningTimes();
277
278                 // Is same found?
279                 if (this.isSameOpeningTimeFound(openingTime)) {
280                         // Yes then abort here
281                         this.showFacesMessage("form-admin-add-headquarter-opening-time:openingStartDay", "ADMIN_OPENING_TIME_ALREADY_CREATED"); //NOI18N
282                         return;
283                 }
284
285                 // Add to temporary list
286                 headquarterOpeningTimes.add(openingTime);
287
288                 // Clear opening time fields
289                 this.clearOpeningTime();
290         }
291
292         /**
293          * Getter for fax number's area code
294          * <p>
295          * @return Fax number's area code
296          */
297         public Integer getFaxAreaCode () {
298                 return this.faxAreaCode;
299         }
300
301         /**
302          * Setter for fax number's area code
303          * <p>
304          * @param faxAreaCode Fax number's area code
305          */
306         public void setFaxAreaCode (final Integer faxAreaCode) {
307                 this.faxAreaCode = faxAreaCode;
308         }
309
310         /**
311          * Getter for fax's country instance
312          * <p>
313          * @return Fax' country instance
314          */
315         public Country getFaxCountry () {
316                 return this.faxCountry;
317         }
318
319         /**
320          * Setter for fax's country instance
321          * <p>
322          * @param faxCountry Fax' country instance
323          */
324         public void setFaxCountry (final Country faxCountry) {
325                 this.faxCountry = faxCountry;
326         }
327
328         /**
329          * Getter for fax number
330          * <p>
331          * @return Fax number
332          */
333         public Long getFaxNumber () {
334                 return this.faxNumber;
335         }
336
337         /**
338          * Setter for fax number
339          * <p>
340          * @param faxNumber Fax number
341          */
342         public void setFaxNumber (final Long faxNumber) {
343                 this.faxNumber = faxNumber;
344         }
345
346         /**
347          * Getter for city
348          * <p>
349          * @return City
350          */
351         public String getHeadquarterCity () {
352                 return this.headquarterCity;
353         }
354
355         /**
356          * Setter for city
357          * <p>
358          * @param headquarterCity City
359          */
360         public void setHeadquarterCity (final String headquarterCity) {
361                 this.headquarterCity = headquarterCity;
362         }
363
364         /**
365          * Getter for headquarter's company name
366          * <p>
367          * @return Headquarter's company name
368          */
369         public String getHeadquarterCompanyName () {
370                 return this.headquarterCompanyName;
371         }
372
373         /**
374          * Setter for headquarter's company name
375          * <p>
376          * @param headquarterCompanyName Headquarter's company name
377          */
378         public void setHeadquarterCompanyName (final String headquarterCompanyName) {
379                 this.headquarterCompanyName = headquarterCompanyName;
380         }
381
382         /**
383          * Getter for headquarter contact person
384          * <p>
385          * @return Headquarter contact person
386          */
387         public Employable getHeadquarterContactEmployee () {
388                 return this.headquarterContactEmployee;
389         }
390
391         /**
392          * Setter for headquarter contact person
393          * <p>
394          * @param headquarterContactEmployee Headquarter contact person
395          */
396         public void setHeadquarterContactEmployee (final Employable headquarterContactEmployee) {
397                 this.headquarterContactEmployee = headquarterContactEmployee;
398         }
399
400         /**
401          * Getter for country
402          * <p>
403          * @return Country
404          */
405         public Country getHeadquarterCountry () {
406                 return this.headquarterCountry;
407         }
408
409         /**
410          * Setter for country
411          * <p>
412          * @param headquarterCountry Country
413          */
414         public void setHeadquarterCountry (final Country headquarterCountry) {
415                 this.headquarterCountry = headquarterCountry;
416         }
417
418         /**
419          * Getter for email address
420          * <p>
421          * @return Email address
422          */
423         public String getHeadquarterEmailAddress () {
424                 return this.headquarterEmailAddress;
425         }
426
427         /**
428          * Getter for email address
429          * <p>
430          * @param headquarterEmailAddress Email address
431          */
432         public void setHeadquarterEmailAddress (final String headquarterEmailAddress) {
433                 this.headquarterEmailAddress = headquarterEmailAddress;
434         }
435
436         /**
437          * Getter for house number
438          * <p>
439          * @return House number
440          */
441         public Short getHeadquarterHouseNumber () {
442                 return this.headquarterHouseNumber;
443         }
444
445         /**
446          * Setter for house number
447          * <p>
448          * @param headquarterHouseNumber House number
449          */
450         public void setHeadquarterHouseNumber (final Short headquarterHouseNumber) {
451                 this.headquarterHouseNumber = headquarterHouseNumber;
452         }
453
454         /**
455          * Getter for house number's extension
456          * <p>
457          * @return House number's extension
458          */
459         public String getHeadquarterHouseNumberExtension () {
460                 return this.headquarterHouseNumberExtension;
461         }
462
463         /**
464          * Setter for house number's extension
465          * <p>
466          * @param headquarterHouseNumberExtension House number's extension
467          */
468         public void setHeadquarterHouseNumberExtension (final String headquarterHouseNumberExtension) {
469                 this.headquarterHouseNumberExtension = headquarterHouseNumberExtension;
470         }
471
472         /**
473          * Getter for last house number
474          * <p>
475          * @return Last house number
476          */
477         public Short getHeadquarterLastHouseNumber () {
478                 return this.headquarterLastHouseNumber;
479         }
480
481         /**
482          * Setter for last house number
483          * <p>
484          * @param headquarterLastHouseNumber Last house number
485          */
486         public void setHeadquarterLastHouseNumber (final Short headquarterLastHouseNumber) {
487                 this.headquarterLastHouseNumber = headquarterLastHouseNumber;
488         }
489
490         /**
491          * Getter for opening times of this headquarter
492          * <p>
493          * @return Opening times
494          */
495         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
496         public List<OpeningTime> getHeadquarterOpeningTimes () {
497                 return headquarterOpeningTimes;
498         }
499
500         /**
501          * Setter for opening times of this headquarter
502          * <p>
503          * @param headquarterOpeningTimes Opening times
504          */
505         @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
506         public void setHeadquarterOpeningTimes (final List<OpeningTime> headquarterOpeningTimes) {
507                 FinancialsAdminHeadquarterWebRequestBean.headquarterOpeningTimes = headquarterOpeningTimes;
508         }
509
510         /**
511          * Getter for store
512          * <p>
513          * @return Store
514          */
515         public Short getHeadquarterStore () {
516                 return this.headquarterStore;
517         }
518
519         /**
520          * Setter for store
521          * <p>
522          * @param headquarterStore Store
523          */
524         public void setHeadquarterStore (final Short headquarterStore) {
525                 this.headquarterStore = headquarterStore;
526         }
527
528         /**
529          * Getter for street name
530          * <p>
531          * @return Street name
532          */
533         public String getHeadquarterStreet () {
534                 return this.headquarterStreet;
535         }
536
537         /**
538          * Setter for street name
539          * <p>
540          * @param headquarterStreet Street name
541          */
542         public void setHeadquarterStreet (final String headquarterStreet) {
543                 this.headquarterStreet = headquarterStreet;
544         }
545
546         /**
547          * Getter for suite number
548          * <p>
549          * @return Suite number
550          */
551         public Short getHeadquarterSuiteNumber () {
552                 return this.headquarterSuiteNumber;
553         }
554
555         /**
556          * Setter for suite number
557          * <p>
558          * @param headquarterSuiteNumber Suite number
559          */
560         public void setHeadquarterSuiteNumber (final Short headquarterSuiteNumber) {
561                 this.headquarterSuiteNumber = headquarterSuiteNumber;
562         }
563
564         /**
565          * Getter for owning user instance
566          * <p>
567          * @return Owning user instance
568          */
569         public User getHeadquarterUserOwner () {
570                 return this.headquarterUserOwner;
571         }
572
573         /**
574          * Setter for owning user instance
575          * <p>
576          * @param headquarterUserOwner Owning user instance
577          */
578         public void setHeadquarterUserOwner (final User headquarterUserOwner) {
579                 this.headquarterUserOwner = headquarterUserOwner;
580         }
581
582         /**
583          * Getter for ZIP code\
584          * <p>
585          * @return ZIP code
586          */
587         public Integer getHeadquarterZipCode () {
588                 return this.headquarterZipCode;
589         }
590
591         /**
592          * Setter for ZIP code\
593          * <p>
594          * @param headquarterZipCode ZIP code
595          */
596         public void setHeadquarterZipCode (final Integer headquarterZipCode) {
597                 this.headquarterZipCode = headquarterZipCode;
598         }
599
600         /**
601          * Getter for land-line number's area code
602          * <p>
603          * @return Land-line number's area code
604          */
605         public Integer getLandLineAreaCode () {
606                 return this.landLineAreaCode;
607         }
608
609         /**
610          * Setter for land-line number's area code
611          * <p>
612          * @param landLineAreaCode Land-line number's area code
613          */
614         public void setLandLineAreaCode (final Integer landLineAreaCode) {
615                 this.landLineAreaCode = landLineAreaCode;
616         }
617
618         /**
619          * Getter for land-line number's country instance
620          * <p>
621          * @return Land-line number's country instance
622          */
623         public Country getLandLineCountry () {
624                 return this.landLineCountry;
625         }
626
627         /**
628          * Setter for land-line number's country instance
629          * <p>
630          * @param landLineCountry Land-line number's country instance
631          */
632         public void setLandLineCountry (final Country landLineCountry) {
633                 this.landLineCountry = landLineCountry;
634         }
635
636         /**
637          * Getter for land-line number
638          * <p>
639          * @return Land-line number
640          */
641         public Long getLandLineNumber () {
642                 return this.landLineNumber;
643         }
644
645         /**
646          * Setter for land-line number
647          * <p>
648          * @param landLineNumber Land-line number
649          */
650         public void setLandLineNumber (final Long landLineNumber) {
651                 this.landLineNumber = landLineNumber;
652         }
653
654         /**
655          * Getter for ending week day
656          * <p>
657          * @return Ending week day
658          */
659         public DayOfTheWeek getOpeningEndDay () {
660                 return this.openingEndDay;
661         }
662
663         /**
664          * Setter for ending week day
665          * <p>
666          * @param openingEndDay Ending week day
667          */
668         public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
669                 this.openingEndDay = openingEndDay;
670         }
671
672         /**
673          * Getter for ending time
674          * <p>
675          * @return Ending time
676          */
677         @SuppressWarnings ("ReturnOfDateField")
678         public Date getOpeningEndTime () {
679                 return this.openingEndTime;
680         }
681
682         /**
683          * Getter for ending time
684          * <p>
685          * @param openingEndTime Ending time
686          */
687         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
688         public void setOpeningEndTime (final Date openingEndTime) {
689                 this.openingEndTime = openingEndTime;
690         }
691
692         /**
693          * Getter for starting week day
694          * <p>
695          * @return Starting week day
696          */
697         public DayOfTheWeek getOpeningStartDay () {
698                 return this.openingStartDay;
699         }
700
701         /**
702          * Getter for starting week day
703          * <p>
704          * @param openingStartDay Starting week day
705          */
706         public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
707                 this.openingStartDay = openingStartDay;
708         }
709
710         /**
711          * Getter for starting time
712          * <p>
713          * @return Starting time
714          */
715         @SuppressWarnings ("ReturnOfDateField")
716         public Date getOpeningStartTime () {
717                 return this.openingStartTime;
718         }
719
720         /**
721          * Getter for starting time
722          * <p>
723          * @param openingStartTime Starting time
724          */
725         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
726         public void setOpeningStartTime (final Date openingStartTime) {
727                 this.openingStartTime = openingStartTime;
728         }
729
730         /**
731          * Clears this bean data
732          */
733         private void clear () {
734                 // Clear all headquarter data
735                 this.setHeadquarterCity(null);
736                 this.setHeadquarterCompanyName(null);
737                 this.setHeadquarterContactEmployee(null);
738                 this.setHeadquarterCountry(null);
739                 this.setHeadquarterEmailAddress(null);
740                 this.setHeadquarterHouseNumber(null);
741                 this.setHeadquarterHouseNumberExtension(null);
742                 this.setHeadquarterLastHouseNumber(null);
743                 this.setHeadquarterStore(null);
744                 this.setHeadquarterStreet(null);
745                 this.setHeadquarterSuiteNumber(null);
746                 this.setHeadquarterUserOwner(null);
747                 this.setHeadquarterZipCode(null);
748                 this.setHeadquarterOpeningTimes(null);
749
750                 // Extra-clear opening time
751                 this.clearOpeningTime();
752         }
753
754         /**
755          * Clears all opening time fields
756          */
757         private void clearOpeningTime () {
758                 // Clear all opening time fields
759                 this.setOpeningEndDay(null);
760                 this.setOpeningEndTime(null);
761                 this.setOpeningStartDay(null);
762                 this.setOpeningStartTime(null);
763         }
764
765         /**
766          * Prepares an instance of a Headquarter object (entity) with all data from
767          * this bean. If a complete fax number or land-line number was provided, it
768          * will be set in the instance as well.
769          * <p>
770          * @return An instance of a Headquarter class (entity)
771          */
772         private Headquarter createHeadquarter () {
773                 // Create new headquarter instance
774                 final Headquarter headquarter = new BusinessHeadquarter(this.getHeadquarterCompanyName(), this.getHeadquarterCity(), this.getHeadquarterCountry(), this.getHeadquarterStreet(), this.getHeadquarterZipCode(), this.getHeadquarterHouseNumber());
775
776                 // Add all other fields, too
777                 headquarter.setHeadquarterContactEmployee(this.getHeadquarterContactEmployee());
778                 headquarter.setHeadquarterEmailAddress(this.getHeadquarterEmailAddress());
779                 headquarter.setHeadquarterHouseNumberExtension(this.getHeadquarterHouseNumberExtension());
780                 headquarter.setHeadquarterLastHouseNumber(this.getHeadquarterLastHouseNumber());
781                 headquarter.setHeadquarterStore(this.getHeadquarterStore());
782                 headquarter.setHeadquarterSuiteNumber(this.getHeadquarterSuiteNumber());
783                 headquarter.setHeadquarterUserOwner(this.getHeadquarterUserOwner());
784
785                 // Generate phone number
786                 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
787                 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
788
789                 // Don't set null or wrong references
790                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
791                         // Now the number must be given
792                         if (landLine.getPhoneAreaCode() == null) {
793                                 // Is null
794                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
795                         } else if (landLine.getPhoneAreaCode() < 1) {
796                                 // Abort here
797                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
798                         } else if (landLine.getPhoneNumber() == null) {
799                                 // Is null
800                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
801                         } else if (landLine.getPhoneNumber() < 1) {
802                                 // Abort here
803                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
804                         }
805
806                         // Set phone number
807                         headquarter.setHeadquarterLandLineNumber(landLine);
808                 }
809
810                 // Don't set null or wrong references
811                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
812                         // Now the number must be given
813                         if (fax.getPhoneAreaCode() == null) {
814                                 // Is null
815                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
816                         } else if (fax.getPhoneAreaCode() < 1) {
817                                 // Abort here
818                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
819                         } else if (fax.getPhoneNumber() == null) {
820                                 // Is null
821                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
822                         } else if (fax.getPhoneNumber() < 1) {
823                                 // Abort here
824                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
825                         }
826
827                         // Set fax number
828                         headquarter.setHeadquarterFaxNumber(fax);
829                 }
830                 // Is the opening times list filled?
831                 if (!this.getHeadquarterOpeningTimes().isEmpty()) {
832                         // Yes, then set in headquarter, too
833                         headquarter.setHeadquarterOpeningTimes(this.getHeadquarterOpeningTimes());
834                 }
835
836                 // Return fully prepared instance
837                 return headquarter;
838         }
839
840         /**
841          * Prepares an instance of a OpeningTimes object (entity) with all data from
842          * this bean. If a complete fax number or land-line number was provided, it
843          * will be set in the instance as well.
844          * <p>
845          * @return An instance of a OpeningTimes class (entity)
846          */
847         private OpeningTime createOpeningTimes () {
848                 // Create new openingTime instance
849                 final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
850
851                 // Return fully prepared instance
852                 return openingTime;
853         }
854
855         /**
856          * Checks whether the given headquarter' address is already found in local
857          * cache. Please note that this method fully relies on the cache, so you
858          * must always fire proper events that add/update/delete entries in cache.
859          * <p>
860          * @param headquarter Headquarter to check it's address
861          * <p>
862          * @return Whether the address has been found
863          */
864         private boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter) {
865                 // Get full list from other bean
866                 final List<Headquarter> allHeadquarter = this.headquarterController.allHeadquarter();
867
868                 // Default is not found
869                 boolean isFound = false;
870
871                 // Now check each entry
872                 for (final Headquarter hq : allHeadquarter) {
873                         // Is same address?
874                         if (Headquarters.isSameAddress(hq, headquarter)) {
875                                 // Found one
876                                 isFound = true;
877                                 break;
878                         }
879                 }
880
881                 // Return flag
882                 return isFound;
883         }
884
885         /**
886          * Checks if given opening time is already added
887          * <p>
888          * @param openingTime Opening time to be checked
889          * <p>
890          * @return Whether it has been added already
891          */
892         private boolean isSameOpeningTimeFound (final OpeningTime openingTime) {
893                 // Default is not found
894                 boolean isFound = false;
895
896                 // Loop through list
897                 for (final OpeningTime ot : this.getHeadquarterOpeningTimes()) {
898                         // Check it
899                         if (Objects.equals(ot, openingTime)) {
900                                 // Found same match
901                                 isFound = true;
902                                 break;
903                         }
904                 }
905
906                 // Return it
907                 return isFound;
908         }
909
910 }