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