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