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