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