2 * Copyright (C) 2017 - 2020 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.jfinancials.beans.business.branchoffice.action;
19 import java.text.MessageFormat;
20 import java.util.ArrayList;
21 import java.util.Date;
22 import java.util.List;
23 import java.util.Objects;
25 import javax.enterprise.context.RequestScoped;
26 import javax.enterprise.event.Event;
27 import javax.enterprise.inject.Any;
28 import javax.faces.FacesException;
29 import javax.faces.application.FacesMessage;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import org.mxchange.jcontactsbusiness.events.branchoffice.added.AdminBranchOfficeAddedEvent;
33 import org.mxchange.jcontactsbusiness.events.branchoffice.added.ObservableAdminBranchOfficeAddedEvent;
34 import org.mxchange.jcontactsbusiness.events.branchoffice.updated.AdminBranchOfficeUpdatedEvent;
35 import org.mxchange.jcontactsbusiness.events.branchoffice.updated.ObservableAdminBranchOfficeUpdatedEvent;
36 import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException;
37 import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException;
38 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
39 import org.mxchange.jcontactsbusiness.model.branchoffice.AdminBranchOfficeSessionBeanRemote;
40 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
41 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
42 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
43 import org.mxchange.jcontactsbusiness.model.employee.Employable;
44 import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
45 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
46 import org.mxchange.jcoreee.dates.DayOfTheWeek;
47 import org.mxchange.jcountry.model.data.Country;
48 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
49 import org.mxchange.jfinancials.beans.business.branchoffice.list.FinancialsBranchOfficeListWebViewController;
50 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
51 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
52 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
53 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
54 import org.mxchange.jusercore.model.user.User;
57 * An administrative bean for branch offices
59 * @author Roland Häder<roland@mxchange.org>
61 @Named ("adminBranchOfficeActionController")
63 public class FinancialsAdminBranchOfficeActionWebRequestBean extends BaseFinancialsBean implements FinancialsAdminBranchOfficeActionWebRequestController {
66 * Opening times of this branch office
68 private static List<OpeningTime> branchOpeningTimes;
73 private static final long serialVersionUID = 5_028_697_360_471L;
76 * EJB for administrative purposes
78 @EJB (lookup = "java:global/jfinancials-ejb/adminBranchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.AdminBranchOfficeSessionBeanRemote")
79 private AdminBranchOfficeSessionBeanRemote adminBranchOfficeBean;
84 private String branchCity;
87 * Assigned company for this branch office
89 private BasicData branchCompany;
92 * Contact person in branch office
94 private Employable branchContactEmployee;
99 private Country branchCountry;
104 private String branchEmailAddress;
109 private Short branchHouseNumber;
112 * House number's extension (a,b,c,...)
114 private String branchHouseNumberExtension;
117 * Branch office's id number
119 private Long branchId;
124 private Short branchLastHouseNumber;
127 * Number of branch office
129 private Long branchNumber;
132 * An event being fired when a branch office has been successfully added
136 private Event<ObservableAdminBranchOfficeAddedEvent> branchOfficeAddedEvent;
139 * A list branch office controller (backing bean)
142 private FinancialsBranchOfficeListWebViewController branchOfficeListController;
145 * Owner/leader of branch office
147 private Employable branchOwnerEmployee;
152 private Short branchStore;
155 * Branch office street name
157 private String branchStreet;
162 private Short branchSuiteNumber;
165 * Owning user instance (which this branch office is assigned to)
167 private User branchUserOwner;
172 private Integer branchZipCode;
175 * Currently worked on branch office
177 private BranchOffice currentBranchOffice;
180 * Area code for fax number
182 private Integer faxAreaCode;
185 * Country for fax number
187 private Country faxCountry;
190 * Dial number for fax number
192 private Long faxNumber;
195 * Area code for land-line number
197 private Integer landLineAreaCode;
200 * Country for land-line number
202 private Country landLineCountry;
205 * Dial number for land-line number
207 private Long landLineNumber;
212 private DayOfTheWeek openingEndDay;
217 private Date openingEndTime;
222 private DayOfTheWeek openingStartDay;
227 private Date openingStartTime;
230 * Event being fired when an administrator has updated a branch office
234 private Event<ObservableAdminBranchOfficeUpdatedEvent> updatedBranchOfficeEvent;
237 * Default constructor
239 public FinancialsAdminBranchOfficeActionWebRequestBean () {
240 // Call super constructor
243 // Is the opening times list there?
244 if (null == branchOpeningTimes) {
246 branchOpeningTimes = new ArrayList<>(1);
251 * Adds branch office with all data from this backing bean. First this
252 * action method will validate if the branch office's address is already
253 * registered and if found, it will output a proper faces message.
255 public void addBranchOffice () {
257 final BranchOffice branchOffice = this.createBranchOffice();
259 // Is the branch office not created yet?
260 if (this.isBranchOfficeCreatedByRequiredData(branchOffice)) {
261 // Then show proper faces message
262 this.showFacesMessage("form-admin-add-branch-office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
266 // Delcare updated instance
267 final BranchOffice updatedOffice;
271 updatedOffice = this.adminBranchOfficeBean.addBranchOffice(branchOffice);
272 } catch (final BranchOfficeAlreadyAddedException ex) {
274 this.showFacesMessage("form-admin-add-branch-office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED", FacesMessage.SEVERITY_ERROR); //NOI18N
279 this.branchOfficeAddedEvent.fire(new AdminBranchOfficeAddedEvent(updatedOffice));
286 * Adds opening time to temporary list which will be sent along with the
287 * branch office data to the EJB.
289 public void addOpeningTime () {
290 // Validate all required fields
291 if (this.getOpeningEndDay() == null) {
293 throw new NullPointerException("this.openingEndDay is null"); //NOI18N
294 } else if (this.getOpeningEndTime() == null) {
296 throw new NullPointerException("this.openingEndTime is null"); //NOI18N
297 } else if (this.getOpeningStartDay() == null) {
299 throw new NullPointerException("this.openingStartDay is null"); //NOI18N
300 } else if (this.getOpeningStartTime() == null) {
302 throw new NullPointerException("this.openingStartTime is null"); //NOI18N
305 // Get opening time instance
306 final OpeningTime openingTime = this.createOpeningTimes();
309 if (this.isSameOpeningTimeFound(openingTime)) {
310 // Yes then abort here
311 this.showFacesMessage("form-admin-add-branch-opening-time:openingStartDay", "ADMIN_OPENING_TIME_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
315 // Add to temporary list
316 branchOpeningTimes.add(openingTime);
318 // Clear opening time fields
319 this.clearOpeningTime();
323 * Copies all current branch office's properties back to this bean.
325 public void copyAllBranchOfficeProperties () {
326 // Validate current product instance
327 if (this.getCurrentBranchOffice() == null) {
329 throw new NullPointerException("this.product is null"); //NOI18N
330 } else if (this.getCurrentBranchOffice().getBranchId() == null) {
332 throw new NullPointerException("this.product.branchId is null"); //NOI18N
333 } else if (this.getCurrentBranchOffice().getBranchId() < 1) {
335 throw new IllegalStateException(MessageFormat.format("this.product.branchId={0} is not valid.", this.getCurrentBranchOffice().getBranchId())); //NOI18N
338 // Now copy all fields
339 this.setBranchCity(this.getCurrentBranchOffice().getBranchCity());
340 this.setBranchCompany(this.getCurrentBranchOffice().getBranchCompany());
341 this.setBranchContactEmployee(this.getCurrentBranchOffice().getBranchContactEmployee());
342 this.setBranchCountry(this.getCurrentBranchOffice().getBranchCountry());
343 this.setBranchEmailAddress(this.getCurrentBranchOffice().getBranchEmailAddress());
344 this.setBranchHouseNumber(this.getCurrentBranchOffice().getBranchHouseNumber());
345 this.setBranchHouseNumberExtension(this.getCurrentBranchOffice().getBranchHouseNumberExtension());
346 this.setBranchId(this.getCurrentBranchOffice().getBranchId());
347 this.setBranchLastHouseNumber(this.getCurrentBranchOffice().getBranchLastHouseNumber());
348 this.setBranchNumber(this.getCurrentBranchOffice().getBranchNumber());
349 this.setBranchOpeningTimes(this.getCurrentBranchOffice().getBranchOpeningTimes());
350 this.setBranchOwnerEmployee(this.getCurrentBranchOffice().getBranchOwnerEmployee());
351 this.setBranchStore(this.getCurrentBranchOffice().getBranchStore());
352 this.setBranchStreet(this.getCurrentBranchOffice().getBranchStreet());
353 this.setBranchSuiteNumber(this.getCurrentBranchOffice().getBranchSuiteNumber());
354 this.setBranchUserOwner(this.getCurrentBranchOffice().getBranchUserOwner());
355 this.setBranchZipCode(this.getCurrentBranchOffice().getBranchZipCode());
363 public String getBranchCity () {
364 return this.branchCity;
370 * @param branchCity City
372 public void setBranchCity (final String branchCity) {
373 this.branchCity = branchCity;
377 * Getter for basic company data
379 * @return Basic company data
381 public BasicData getBranchCompany () {
382 return this.branchCompany;
386 * Setter for basic company data
388 * @param branchCompany Basic company data
390 public void setBranchCompany (final BasicData branchCompany) {
391 this.branchCompany = branchCompany;
395 * Getter for branch office contact person
397 * @return Branch office contact person
399 public Employable getBranchContactEmployee () {
400 return this.branchContactEmployee;
404 * Setter for branch office contact person
406 * @param branchContactEmployee Branch office contact person
408 public void setBranchContactEmployee (final Employable branchContactEmployee) {
409 this.branchContactEmployee = branchContactEmployee;
417 public Country getBranchCountry () {
418 return this.branchCountry;
424 * @param branchCountry Country
426 public void setBranchCountry (final Country branchCountry) {
427 this.branchCountry = branchCountry;
431 * Getter for email address
433 * @return Email address
435 public String getBranchEmailAddress () {
436 return this.branchEmailAddress;
440 * Getter for email address
442 * @param branchEmailAddress Email address
444 public void setBranchEmailAddress (final String branchEmailAddress) {
445 this.branchEmailAddress = branchEmailAddress;
449 * Getter for house number
451 * @return House number
453 public Short getBranchHouseNumber () {
454 return this.branchHouseNumber;
458 * Setter for house number
460 * @param branchHouseNumber House number
462 public void setBranchHouseNumber (final Short branchHouseNumber) {
463 this.branchHouseNumber = branchHouseNumber;
467 * Getter for house number's extension
469 * @return House number's extension
471 public String getBranchHouseNumberExtension () {
472 return this.branchHouseNumberExtension;
476 * Setter for house number's extension
478 * @param branchHouseNumberExtension House number's extension
480 public void setBranchHouseNumberExtension (final String branchHouseNumberExtension) {
481 this.branchHouseNumberExtension = branchHouseNumberExtension;
485 * Getter for branch office's id number
487 * @return Branch office's id number
489 public Long getBranchId () {
490 return this.branchId;
494 * Setter for branch office's id number
496 * @param branchId Branch office's id number
498 public void setBranchId (final Long branchId) {
499 this.branchId = branchId;
503 * Getter for last house number
505 * @return Last house number
507 public Short getBranchLastHouseNumber () {
508 return this.branchLastHouseNumber;
512 * Setter for last house number
514 * @param branchLastHouseNumber Last house number
516 public void setBranchLastHouseNumber (final Short branchLastHouseNumber) {
517 this.branchLastHouseNumber = branchLastHouseNumber;
521 * Getter for branch office number
523 * @return Branch office number
525 public Long getBranchNumber () {
526 return this.branchNumber;
530 * Setter for branch office number
532 * @param branchNumber Branch office number
534 public void setBranchNumber (final Long branchNumber) {
535 this.branchNumber = branchNumber;
539 * Getter for opening times of this branch office
541 * @return Opening times
543 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
544 public List<OpeningTime> getBranchOpeningTimes () {
545 return branchOpeningTimes;
549 * Setter for opening times of this branch office
551 * @param branchOpeningTimes Opening times
553 @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
554 public void setBranchOpeningTimes (final List<OpeningTime> branchOpeningTimes) {
555 FinancialsAdminBranchOfficeActionWebRequestBean.branchOpeningTimes = branchOpeningTimes;
559 * Getter for branch office contact person
561 * @return Branch office contact person
563 public Employable getBranchOwnerEmployee () {
564 return this.branchOwnerEmployee;
568 * Setter for branch office contact person
570 * @param branchOwnerEmployee Branch office contact person
572 public void setBranchOwnerEmployee (final Employable branchOwnerEmployee) {
573 this.branchOwnerEmployee = branchOwnerEmployee;
581 public Short getBranchStore () {
582 return this.branchStore;
588 * @param branchStore Store
590 public void setBranchStore (final Short branchStore) {
591 this.branchStore = branchStore;
595 * Getter for street name
597 * @return Street name
599 public String getBranchStreet () {
600 return this.branchStreet;
604 * Setter for street name
606 * @param branchStreet Street name
608 public void setBranchStreet (final String branchStreet) {
609 this.branchStreet = branchStreet;
613 * Getter for suite number
615 * @return Suite number
617 public Short getBranchSuiteNumber () {
618 return this.branchSuiteNumber;
622 * Setter for suite number
624 * @param branchSuiteNumber Suite number
626 public void setBranchSuiteNumber (final Short branchSuiteNumber) {
627 this.branchSuiteNumber = branchSuiteNumber;
631 * Getter for owning user instance
633 * @return Owning user instance
635 public User getBranchUserOwner () {
636 return this.branchUserOwner;
640 * Setter for owning user instance
642 * @param branchUserOwner Owning user instance
644 public void setBranchUserOwner (final User branchUserOwner) {
645 this.branchUserOwner = branchUserOwner;
649 * Getter for ZIP code\
653 public Integer getBranchZipCode () {
654 return this.branchZipCode;
658 * Setter for ZIP code\
660 * @param branchZipCode ZIP code
662 public void setBranchZipCode (final Integer branchZipCode) {
663 this.branchZipCode = branchZipCode;
667 * Getter for current branch office
669 * @return Current branch office
671 public BranchOffice getCurrentBranchOffice () {
672 return this.currentBranchOffice;
676 * Setter for current branch office
678 * @param currentBranchOffice Current branch office
680 public void setCurrentBranchOffice (final BranchOffice currentBranchOffice) {
681 this.currentBranchOffice = currentBranchOffice;
685 * Getter for fax number's area code
687 * @return Fax number's area code
689 public Integer getFaxAreaCode () {
690 return this.faxAreaCode;
694 * Setter for fax number's area code
696 * @param faxAreaCode Fax number's area code
698 public void setFaxAreaCode (final Integer faxAreaCode) {
699 this.faxAreaCode = faxAreaCode;
703 * Getter for fax's country instance
705 * @return Fax' country instance
707 public Country getFaxCountry () {
708 return this.faxCountry;
712 * Setter for fax's country instance
714 * @param faxCountry Fax' country instance
716 public void setFaxCountry (final Country faxCountry) {
717 this.faxCountry = faxCountry;
721 * Getter for fax number
725 public Long getFaxNumber () {
726 return this.faxNumber;
730 * Setter for fax number
732 * @param faxNumber Fax number
734 public void setFaxNumber (final Long faxNumber) {
735 this.faxNumber = faxNumber;
739 * Getter for land-line number's area code
741 * @return Land-line number's area code
743 public Integer getLandLineAreaCode () {
744 return this.landLineAreaCode;
748 * Setter for land-line number's area code
750 * @param landLineAreaCode Land-line number's area code
752 public void setLandLineAreaCode (final Integer landLineAreaCode) {
753 this.landLineAreaCode = landLineAreaCode;
757 * Getter for land-line number's country instance
759 * @return Land-line number's country instance
761 public Country getLandLineCountry () {
762 return this.landLineCountry;
766 * Setter for land-line number's country instance
768 * @param landLineCountry Land-line number's country instance
770 public void setLandLineCountry (final Country landLineCountry) {
771 this.landLineCountry = landLineCountry;
775 * Getter for land-line number
777 * @return Land-line number
779 public Long getLandLineNumber () {
780 return this.landLineNumber;
784 * Setter for land-line number
786 * @param landLineNumber Land-line number
788 public void setLandLineNumber (final Long landLineNumber) {
789 this.landLineNumber = landLineNumber;
793 * Getter for ending week day
795 * @return Ending week day
797 public DayOfTheWeek getOpeningEndDay () {
798 return this.openingEndDay;
802 * Setter for ending week day
804 * @param openingEndDay Ending week day
806 public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
807 this.openingEndDay = openingEndDay;
811 * Getter for ending time
813 * @return Ending time
815 @SuppressWarnings ("ReturnOfDateField")
816 public Date getOpeningEndTime () {
817 return this.openingEndTime;
821 * Getter for ending time
823 * @param openingEndTime Ending time
825 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
826 public void setOpeningEndTime (final Date openingEndTime) {
827 this.openingEndTime = openingEndTime;
831 * Getter for starting week day
833 * @return Starting week day
835 public DayOfTheWeek getOpeningStartDay () {
836 return this.openingStartDay;
840 * Getter for starting week day
842 * @param openingStartDay Starting week day
844 public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
845 this.openingStartDay = openingStartDay;
849 * Getter for starting time
851 * @return Starting time
853 @SuppressWarnings ("ReturnOfDateField")
854 public Date getOpeningStartTime () {
855 return this.openingStartTime;
859 * Getter for starting time
861 * @param openingStartTime Starting time
863 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
864 public void setOpeningStartTime (final Date openingStartTime) {
865 this.openingStartTime = openingStartTime;
869 * Updates currently worked on branch office data
871 * @return Redirection outcome
873 public String updateBranchOffice () {
875 if (this.getBranchId() == null) {
877 throw new NullPointerException("this.branchId is null"); //NOI18N
878 } else if (this.getBranchId() < 1) {
880 throw new IllegalStateException(MessageFormat.format("this.branchId={0} is not valid.", this.getBranchId())); //NOI18N
883 // Init instance with fresh data
884 final BranchOffice branchOffice = this.createBranchOffice();
886 // Does current (not updated) and just created (maybe updated) match?
887 if (Objects.equals(this.getCurrentBranchOffice(), branchOffice)) {
888 // Yes, then output message
889 this.showFacesMessage("form-admin-edit-branch-office:branchCompany", "ADMIN_BRANCH_OFFICE_NOT_UPDATED", FacesMessage.SEVERITY_WARN); //NOI18N
896 BranchOffices.copyBranchOfficeData(this.getCurrentBranchOffice(), branchOffice);
898 // Initialize updated instance
899 final BranchOffice updatedBranchOffice;
904 updatedBranchOffice = this.adminBranchOfficeBean.updateBranchOffice(branchOffice);
905 } catch (final BranchOfficeNotFoundException ex) {
907 throw new FacesException(ex);
911 this.updatedBranchOfficeEvent.fire(new AdminBranchOfficeUpdatedEvent(updatedBranchOffice));
913 // Redirect to list view
914 return "admin_list_branch_office"; //NOI18N
918 * Clears this bean data
920 private void clear () {
921 // Clear all branch office data
922 this.setBranchCity(null);
923 this.setBranchCompany(null);
924 this.setBranchContactEmployee(null);
925 this.setBranchCountry(null);
926 this.setBranchEmailAddress(null);
927 this.setBranchHouseNumber(null);
928 this.setBranchHouseNumberExtension(null);
929 this.setBranchLastHouseNumber(null);
930 this.setBranchNumber(null);
931 this.setBranchOwnerEmployee(null);
932 this.setBranchStore(null);
933 this.setBranchStreet(null);
934 this.setBranchSuiteNumber(null);
935 this.setBranchUserOwner(null);
936 this.setBranchZipCode(null);
938 // Opening times list
939 this.setBranchOpeningTimes(new ArrayList<OpeningTime>(1));
941 // Fax and land-line number
942 this.setFaxAreaCode(null);
943 this.setFaxCountry(null);
944 this.setFaxNumber(null);
945 this.setLandLineAreaCode(null);
946 this.setLandLineCountry(null);
947 this.setLandLineNumber(null);
949 // Extra-clear opening time
950 this.clearOpeningTime();
954 * Clears all opening time fields
956 private void clearOpeningTime () {
957 // Clear all opening time fields
958 this.setOpeningEndDay(null);
959 this.setOpeningEndTime(null);
960 this.setOpeningStartDay(null);
961 this.setOpeningStartTime(null);
965 * Prepares an instance of a BranchOffice object (entity) with all data from
966 * this bean. If a complete fax number or land-line number was provided, it
967 * will be set in the instance as well.
969 * @return An instance of a BranchOffice class (entity)
971 private BranchOffice createBranchOffice () {
972 // Create new branch office instance
973 final BranchOffice branchOffice = new BusinessBranchOffice(
974 this.getBranchCity(),
975 this.getBranchCompany(),
976 this.getBranchCountry(),
977 this.getBranchStreet(),
978 this.getBranchZipCode(),
979 this.getBranchHouseNumber()
982 // Add all other fields, too
983 branchOffice.setBranchId(this.getBranchId());
984 branchOffice.setBranchContactEmployee(this.getBranchContactEmployee());
985 branchOffice.setBranchEmailAddress(this.getBranchEmailAddress());
986 branchOffice.setBranchHouseNumberExtension(this.getBranchHouseNumberExtension());
987 branchOffice.setBranchLastHouseNumber(this.getBranchLastHouseNumber());
988 branchOffice.setBranchNumber(this.getBranchNumber());
989 branchOffice.setBranchOwnerEmployee(this.getBranchOwnerEmployee());
990 branchOffice.setBranchStore(this.getBranchStore());
991 branchOffice.setBranchSuiteNumber(this.getBranchSuiteNumber());
992 branchOffice.setBranchUserOwner(this.getBranchUserOwner());
995 DialableLandLineNumber landLine = null;
996 DialableFaxNumber fax = null;
998 // Are all required fields set?
999 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() != null && this.getLandLineNumber() != null) {
1000 // Initialize land-line instance
1001 landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1004 // Are all required fields set?
1005 if (this.getFaxAreaCode() != null && this.getFaxCountry() != null && this.getFaxNumber() != null) {
1006 // Initialize fax instance
1007 fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
1010 // Don't set null or wrong references
1011 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
1012 // Now the number must be given
1013 if (landLine.getPhoneAreaCode() == null) {
1015 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
1016 } else if (landLine.getPhoneAreaCode() < 1) {
1018 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
1019 } else if (landLine.getPhoneNumber() == null) {
1021 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
1022 } else if (landLine.getPhoneNumber() < 1) {
1024 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
1028 branchOffice.setBranchLandLineNumber(landLine);
1031 // Don't set null or wrong references
1032 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
1033 // Now the number must be given
1034 if (fax.getPhoneAreaCode() == null) {
1036 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
1037 } else if (fax.getPhoneAreaCode() < 1) {
1039 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
1040 } else if (fax.getPhoneNumber() == null) {
1042 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
1043 } else if (fax.getPhoneNumber() < 1) {
1045 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
1049 branchOffice.setBranchFaxNumber(fax);
1051 // Is the opening times list filled?
1052 if (!this.getBranchOpeningTimes().isEmpty()) {
1053 // Yes, then set in branch office, too
1054 branchOffice.setBranchOpeningTimes(this.getBranchOpeningTimes());
1057 // Return fully prepared instance
1058 return branchOffice;
1062 * Prepares an instance of a OpeningTimes object (entity) with all data from
1063 * this bean. If a complete fax number or land-line number was provided, it
1064 * will be set in the instance as well.
1066 * @return An instance of a OpeningTimes class (entity)
1068 private OpeningTime createOpeningTimes () {
1069 // Create new openingTime instance
1070 final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
1072 // Return fully prepared instance
1077 * Checks whether the given branch office's address is already found in
1078 * local cache. Please note that this method fully relies on the cache, so
1079 * you must always fire proper events that add/update/delete entries in
1082 * @param branchOffice Branch office to check it's address
1084 * @return Whether the address has been found
1086 private boolean isBranchOfficeCreatedByRequiredData (final BranchOffice branchOffice) {
1087 // Get full list from other bean
1088 final List<BranchOffice> branchOffices = this.branchOfficeListController.getAllBranchOffices();
1090 // Default is not found
1091 boolean isFound = false;
1093 // Now check each entry
1094 for (final BranchOffice bo : branchOffices) {
1096 if (BranchOffices.isSameAddress(bo, branchOffice)) {
1108 * Checks if given opening time is already added
1110 * @param openingTime Opening time to be checked
1112 * @return Whether it has been added already
1114 private boolean isSameOpeningTimeFound (final OpeningTime openingTime) {
1115 // Default is not found
1116 boolean isFound = false;
1118 // Loop through list
1119 for (final OpeningTime ot : this.getBranchOpeningTimes()) {
1121 if (Objects.equals(ot, openingTime)) {