]> git.mxchange.org Git - jfinancials-war.git/blob
994215aea820e97c3d6ebf2c256ffeef42ed5967
[jfinancials-war.git] /
1 /*
2  * Copyright (C) 2017 Roland Häder
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.headquarter;
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.SessionScoped;
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.headquarter.added.HeadquarterAddedEvent;
30 import org.mxchange.jcontactsbusiness.events.headquarter.added.ObservableHeadquarterAddedEvent;
31 import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterAlreadyAddedException;
32 import org.mxchange.jcontactsbusiness.model.employee.Employable;
33 import org.mxchange.jcontactsbusiness.model.headquarter.AdminHeadquarterSessionBeanRemote;
34 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
35 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
36 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters;
37 import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
38 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
39 import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek;
40 import org.mxchange.jcountry.model.data.Country;
41 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
42 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
43 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
44 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
45 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
46 import org.mxchange.jusercore.model.user.User;
47
48 /**
49  * An administrative bean for headquarter
50  * <p>
51  * @author Roland Häder<roland@mxchange.org>
52  */
53 @Named ("adminHeadquarterController")
54 @SessionScoped
55 public class FinancialsAdminHeadquarterWebRequestBean extends BaseFinancialsBean implements FinancialsAdminHeadquarterWebRequestController {
56
57         /**
58          * Opening times of this headquarter
59          */
60         private static List<OpeningTime> headquarterOpeningTimes;
61
62         /**
63          * Serial number
64          */
65         private static final long serialVersionUID = 5_028_697_360_462L;
66
67         /**
68          * EJB for administrative purposes
69          */
70         @EJB (lookup = "java:global/jfinancials-ejb/adminHeadquarter!org.mxchange.jcontactsbusiness.model.headquarter.AdminHeadquarterSessionBeanRemote")
71         private AdminHeadquarterSessionBeanRemote adminHeadquarterBean;
72
73         /**
74          * Area code for fax number
75          */
76         private Integer faxAreaCode;
77
78         /**
79          * Country for fax number
80          */
81         private Country faxCountry;
82
83         /**
84          * Dial number for fax number
85          */
86         private Long faxNumber;
87
88         /**
89          * An event being fired when a headquarter has been successfully added
90          */
91         @Inject
92         @Any
93         private Event<ObservableHeadquarterAddedEvent> headquarterAddedEvent;
94
95         /**
96          * City
97          */
98         private String headquarterCity;
99
100         /**
101          * Contact person in headquarter
102          */
103         private Employable headquarterContactEmployee;
104
105         /**
106          * A general headquarter controller (backing bean)
107          */
108         @Inject
109         private FinancialsHeadquarterWebRequestController headquarterController;
110
111         /**
112          * Country
113          */
114         private Country headquarterCountry;
115
116         /**
117          * Email address
118          */
119         private String headquarterEmailAddress;
120
121         /**
122          * House number
123          */
124         private Short headquarterHouseNumber;
125
126         /**
127          * Store
128          */
129         private Short headquarterStore;
130
131         /**
132          * Headquarter street name
133          */
134         private String headquarterStreet;
135
136         /**
137          * Suite number
138          */
139         private Short headquarterSuiteNumber;
140
141         /**
142          * Owning user instance (which this headquarter is assigned to)
143          */
144         private User headquarterUserOwner;
145
146         /**
147          * ZIP code
148          */
149         private Integer headquarterZipCode;
150
151         /**
152          * Area code for land-line number
153          */
154         private Integer landLineAreaCode;
155
156         /**
157          * Country for land-line number
158          */
159         private Country landLineCountry;
160
161         /**
162          * Dial number for land-line number
163          */
164         private Long landLineNumber;
165
166         /**
167          * Ending week day
168          */
169         private DayOfTheWeek openingEndDay;
170
171         /**
172          * Ending time
173          */
174         private Date openingEndTime;
175
176         /**
177          * Starting week day
178          */
179         private DayOfTheWeek openingStartDay;
180
181         /**
182          * Starting time
183          */
184         private Date openingStartTime;
185
186         /**
187          * Default constructor
188          */
189         public FinancialsAdminHeadquarterWebRequestBean () {
190                 // Call super constructor
191                 super();
192
193                 // Is the opening times list there?
194                 if (null == headquarterOpeningTimes) {
195                         // Init list
196                         headquarterOpeningTimes = new ArrayList<>(1);
197                 }
198         }
199
200         /**
201          * Adds headquarter with all data from this backing bean. First this action
202          * method will validate if the headquarter's address is already registered
203          * and if found, it will output a proper faces message.
204          * <p>
205          * @return Redirect outcome
206          */
207         public String addHeadquarter () {
208                 // Get instance
209                 final Headquarter headquarter = this.createHeadquarter();
210
211                 // Is the headquarter not created yet?
212                 if (this.isHeadquarterCreatedByRequiredData(headquarter)) {
213                         // Then show proper faces message
214                         this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED"); //NOI18N
215                         return ""; //NOI18N
216                 }
217
218                 // Delcare updated instance
219                 final Headquarter updatedHeadquarter;
220
221                 try {
222                         // Try to call EJB
223                         updatedHeadquarter = this.adminHeadquarterBean.addHeadquarter(headquarter);
224                 } catch (final HeadquarterAlreadyAddedException ex) {
225                         // Output message
226                         this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED"); //NOI18N
227                         return ""; //NOI18N
228                 }
229
230                 // Fire event
231                 this.headquarterAddedEvent.fire(new HeadquarterAddedEvent(updatedHeadquarter));
232
233                 // Clear this bean
234                 this.clear();
235
236                 // Redirect to list
237                 return "admin_list_headquarter_office"; //NOI18N
238         }
239
240         /**
241          * Adds opening time to temporary list which will be sent along with the
242          * headquarter data to the EJB.
243          */
244         public void addOpeningTime () {
245                 // Validate all required fields
246                 if (this.getOpeningEndDay() == null) {
247                         // Throw NPE
248                         throw new NullPointerException("this.openingEndDay is null"); //NOI18N
249                 } else if (this.getOpeningEndTime() == null) {
250                         // Throw NPE
251                         throw new NullPointerException("this.openingEndTime is null"); //NOI18N
252                 } else if (this.getOpeningStartDay() == null) {
253                         // Throw NPE
254                         throw new NullPointerException("this.openingStartDay is null"); //NOI18N
255                 } else if (this.getOpeningStartTime() == null) {
256                         // Throw NPE
257                         throw new NullPointerException("this.openingStartTime is null"); //NOI18N
258                 }
259
260                 // Get opening time instance
261                 final OpeningTime openingTime = this.createOpeningTimes();
262
263                 // Is same found?
264                 if (this.isSameOpeningTimeFound(openingTime)) {
265                         // Yes then abort here
266                         this.showFacesMessage("form-admin-add-headquarter-opening-time:openingStartDay", "ADMIN_OPENING_TIME_ALREADY_CREATED"); //NOI18N
267                         return;
268                 }
269
270                 // Add to temporary list
271                 headquarterOpeningTimes.add(openingTime);
272
273                 // Clear opening time fields
274                 this.clearOpeningTime();
275         }
276
277         /**
278          * Getter for fax number's area code
279          * <p>
280          * @return Fax number's area code
281          */
282         public Integer getFaxAreaCode () {
283                 return this.faxAreaCode;
284         }
285
286         /**
287          * Setter for fax number's area code
288          * <p>
289          * @param faxAreaCode Fax number's area code
290          */
291         public void setFaxAreaCode (final Integer faxAreaCode) {
292                 this.faxAreaCode = faxAreaCode;
293         }
294
295         /**
296          * Getter for fax's country instance
297          * <p>
298          * @return Fax' country instance
299          */
300         public Country getFaxCountry () {
301                 return this.faxCountry;
302         }
303
304         /**
305          * Setter for fax's country instance
306          * <p>
307          * @param faxCountry Fax' country instance
308          */
309         public void setFaxCountry (final Country faxCountry) {
310                 this.faxCountry = faxCountry;
311         }
312
313         /**
314          * Getter for fax number
315          * <p>
316          * @return Fax number
317          */
318         public Long getFaxNumber () {
319                 return this.faxNumber;
320         }
321
322         /**
323          * Setter for fax number
324          * <p>
325          * @param faxNumber Fax number
326          */
327         public void setFaxNumber (final Long faxNumber) {
328                 this.faxNumber = faxNumber;
329         }
330
331         /**
332          * Getter for city
333          * <p>
334          * @return City
335          */
336         public String getHeadquarterCity () {
337                 return this.headquarterCity;
338         }
339
340         /**
341          * Setter for city
342          * <p>
343          * @param headquarterCity City
344          */
345         public void setHeadquarterCity (final String headquarterCity) {
346                 this.headquarterCity = headquarterCity;
347         }
348
349         /**
350          * Getter for headquarter contact person
351          * <p>
352          * @return Headquarter contact person
353          */
354         public Employable getHeadquarterContactEmployee () {
355                 return this.headquarterContactEmployee;
356         }
357
358         /**
359          * Setter for headquarter contact person
360          * <p>
361          * @param headquarterContactEmployee Headquarter contact person
362          */
363         public void setHeadquarterContactEmployee (final Employable headquarterContactEmployee) {
364                 this.headquarterContactEmployee = headquarterContactEmployee;
365         }
366
367         /**
368          * Getter for country
369          * <p>
370          * @return Country
371          */
372         public Country getHeadquarterCountry () {
373                 return this.headquarterCountry;
374         }
375
376         /**
377          * Setter for country
378          * <p>
379          * @param headquarterCountry Country
380          */
381         public void setHeadquarterCountry (final Country headquarterCountry) {
382                 this.headquarterCountry = headquarterCountry;
383         }
384
385         /**
386          * Getter for email address
387          * <p>
388          * @return Email address
389          */
390         public String getHeadquarterEmailAddress () {
391                 return this.headquarterEmailAddress;
392         }
393
394         /**
395          * Getter for email address
396          * <p>
397          * @param headquarterEmailAddress Email address
398          */
399         public void setHeadquarterEmailAddress (final String headquarterEmailAddress) {
400                 this.headquarterEmailAddress = headquarterEmailAddress;
401         }
402
403         /**
404          * Getter for house number
405          * <p>
406          * @return House number
407          */
408         public Short getHeadquarterHouseNumber () {
409                 return this.headquarterHouseNumber;
410         }
411
412         /**
413          * Setter for house number
414          * <p>
415          * @param headquarterHouseNumber House number
416          */
417         public void setHeadquarterHouseNumber (final Short headquarterHouseNumber) {
418                 this.headquarterHouseNumber = headquarterHouseNumber;
419         }
420
421         /**
422          * Getter for opening times of this headquarter
423          * <p>
424          * @return Opening times
425          */
426         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
427         public List<OpeningTime> getHeadquarterOpeningTimes () {
428                 return headquarterOpeningTimes;
429         }
430
431         /**
432          * Setter for opening times of this headquarter
433          * <p>
434          * @param headquarterOpeningTimes Opening times
435          */
436         @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
437         public void setHeadquarterOpeningTimes (final List<OpeningTime> headquarterOpeningTimes) {
438                 FinancialsAdminHeadquarterWebRequestBean.headquarterOpeningTimes = headquarterOpeningTimes;
439         }
440
441         /**
442          * Getter for store
443          * <p>
444          * @return Store
445          */
446         public Short getHeadquarterStore () {
447                 return this.headquarterStore;
448         }
449
450         /**
451          * Setter for store
452          * <p>
453          * @param headquarterStore Store
454          */
455         public void setHeadquarterStore (final Short headquarterStore) {
456                 this.headquarterStore = headquarterStore;
457         }
458
459         /**
460          * Getter for street name
461          * <p>
462          * @return Street name
463          */
464         public String getHeadquarterStreet () {
465                 return this.headquarterStreet;
466         }
467
468         /**
469          * Setter for street name
470          * <p>
471          * @param headquarterStreet Street name
472          */
473         public void setHeadquarterStreet (final String headquarterStreet) {
474                 this.headquarterStreet = headquarterStreet;
475         }
476
477         /**
478          * Getter for suite number
479          * <p>
480          * @return Suite number
481          */
482         public Short getHeadquarterSuiteNumber () {
483                 return this.headquarterSuiteNumber;
484         }
485
486         /**
487          * Setter for suite number
488          * <p>
489          * @param headquarterSuiteNumber Suite number
490          */
491         public void setHeadquarterSuiteNumber (final Short headquarterSuiteNumber) {
492                 this.headquarterSuiteNumber = headquarterSuiteNumber;
493         }
494
495         /**
496          * Getter for owning user instance
497          * <p>
498          * @return Owning user instance
499          */
500         public User getHeadquarterUserOwner () {
501                 return this.headquarterUserOwner;
502         }
503
504         /**
505          * Setter for owning user instance
506          * <p>
507          * @param headquarterUserOwner Owning user instance
508          */
509         public void setHeadquarterUserOwner (final User headquarterUserOwner) {
510                 this.headquarterUserOwner = headquarterUserOwner;
511         }
512
513         /**
514          * Getter for ZIP code\
515          * <p>
516          * @return ZIP code
517          */
518         public Integer getHeadquarterZipCode () {
519                 return this.headquarterZipCode;
520         }
521
522         /**
523          * Setter for ZIP code\
524          * <p>
525          * @param headquarterZipCode ZIP code
526          */
527         public void setHeadquarterZipCode (final Integer headquarterZipCode) {
528                 this.headquarterZipCode = headquarterZipCode;
529         }
530
531         /**
532          * Getter for land-line number's area code
533          * <p>
534          * @return Land-line number's area code
535          */
536         public Integer getLandLineAreaCode () {
537                 return this.landLineAreaCode;
538         }
539
540         /**
541          * Setter for land-line number's area code
542          * <p>
543          * @param landLineAreaCode Land-line number's area code
544          */
545         public void setLandLineAreaCode (final Integer landLineAreaCode) {
546                 this.landLineAreaCode = landLineAreaCode;
547         }
548
549         /**
550          * Getter for land-line number's country instance
551          * <p>
552          * @return Land-line number's country instance
553          */
554         public Country getLandLineCountry () {
555                 return this.landLineCountry;
556         }
557
558         /**
559          * Setter for land-line number's country instance
560          * <p>
561          * @param landLineCountry Land-line number's country instance
562          */
563         public void setLandLineCountry (final Country landLineCountry) {
564                 this.landLineCountry = landLineCountry;
565         }
566
567         /**
568          * Getter for land-line number
569          * <p>
570          * @return Land-line number
571          */
572         public Long getLandLineNumber () {
573                 return this.landLineNumber;
574         }
575
576         /**
577          * Setter for land-line number
578          * <p>
579          * @param landLineNumber Land-line number
580          */
581         public void setLandLineNumber (final Long landLineNumber) {
582                 this.landLineNumber = landLineNumber;
583         }
584
585         /**
586          * Getter for ending week day
587          * <p>
588          * @return Ending week day
589          */
590         public DayOfTheWeek getOpeningEndDay () {
591                 return this.openingEndDay;
592         }
593
594         /**
595          * Setter for ending week day
596          * <p>
597          * @param openingEndDay Ending week day
598          */
599         public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
600                 this.openingEndDay = openingEndDay;
601         }
602
603         /**
604          * Getter for ending time
605          * <p>
606          * @return Ending time
607          */
608         @SuppressWarnings ("ReturnOfDateField")
609         public Date getOpeningEndTime () {
610                 return this.openingEndTime;
611         }
612
613         /**
614          * Getter for ending time
615          * <p>
616          * @param openingEndTime Ending time
617          */
618         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
619         public void setOpeningEndTime (final Date openingEndTime) {
620                 this.openingEndTime = openingEndTime;
621         }
622
623         /**
624          * Getter for starting week day
625          * <p>
626          * @return Starting week day
627          */
628         public DayOfTheWeek getOpeningStartDay () {
629                 return this.openingStartDay;
630         }
631
632         /**
633          * Getter for starting week day
634          * <p>
635          * @param openingStartDay Starting week day
636          */
637         public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
638                 this.openingStartDay = openingStartDay;
639         }
640
641         /**
642          * Getter for starting time
643          * <p>
644          * @return Starting time
645          */
646         @SuppressWarnings ("ReturnOfDateField")
647         public Date getOpeningStartTime () {
648                 return this.openingStartTime;
649         }
650
651         /**
652          * Getter for starting time
653          * <p>
654          * @param openingStartTime Starting time
655          */
656         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
657         public void setOpeningStartTime (final Date openingStartTime) {
658                 this.openingStartTime = openingStartTime;
659         }
660
661         /**
662          * Clears this bean data
663          */
664         private void clear () {
665                 // Clear all headquarter data
666                 this.setHeadquarterCity(null);
667                 this.setHeadquarterContactEmployee(null);
668                 this.setHeadquarterCountry(null);
669                 this.setHeadquarterEmailAddress(null);
670                 this.setHeadquarterHouseNumber(null);
671                 this.setHeadquarterStore(null);
672                 this.setHeadquarterStreet(null);
673                 this.setHeadquarterSuiteNumber(null);
674                 this.setHeadquarterUserOwner(null);
675                 this.setHeadquarterZipCode(null);
676                 this.setHeadquarterOpeningTimes(null);
677
678                 // Extra-clear opening time
679                 this.clearOpeningTime();
680         }
681
682         /**
683          * Clears all opening time fields
684          */
685         private void clearOpeningTime () {
686                 // Clear all opening time fields
687                 this.setOpeningEndDay(null);
688                 this.setOpeningEndTime(null);
689                 this.setOpeningStartDay(null);
690                 this.setOpeningStartTime(null);
691         }
692
693         /**
694          * Prepares an instance of a Headquarter object (entity) with all data from
695          * this bean. If a complete fax number or land-line number was provided, it
696          * will be set in the instance as well.
697          * <p>
698          * @return An instance of a Headquarter class (entity)
699          */
700         private Headquarter createHeadquarter () {
701                 // Create new headquarter instance
702                 final Headquarter headquarter = new BusinessHeadquarter(this.getHeadquarterCity(), this.getHeadquarterCountry(), this.getHeadquarterStreet(), this.getHeadquarterZipCode(), this.getHeadquarterHouseNumber());
703
704                 // Add all other fields, too
705                 headquarter.setHeadquarterContactEmployee(this.getHeadquarterContactEmployee());
706                 headquarter.setHeadquarterEmailAddress(this.getHeadquarterEmailAddress());
707                 headquarter.setHeadquarterStore(this.getHeadquarterStore());
708                 headquarter.setHeadquarterSuiteNumber(this.getHeadquarterSuiteNumber());
709                 headquarter.setHeadquarterUserOwner(this.getHeadquarterUserOwner());
710
711                 // Generate phone number
712                 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
713                 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
714
715                 // Don't set null or wrong references
716                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
717                         // Now the number must be given
718                         if (landLine.getPhoneAreaCode() == null) {
719                                 // Is null
720                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
721                         } else if (landLine.getPhoneAreaCode() < 1) {
722                                 // Abort here
723                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
724                         } else if (landLine.getPhoneNumber() == null) {
725                                 // Is null
726                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
727                         } else if (landLine.getPhoneNumber() < 1) {
728                                 // Abort here
729                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
730                         }
731
732                         // Set phone number
733                         headquarter.setHeadquarterLandLineNumber(landLine);
734                 }
735
736                 // Don't set null or wrong references
737                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
738                         // Now the number must be given
739                         if (fax.getPhoneAreaCode() == null) {
740                                 // Is null
741                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
742                         } else if (fax.getPhoneAreaCode() < 1) {
743                                 // Abort here
744                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
745                         } else if (fax.getPhoneNumber() == null) {
746                                 // Is null
747                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
748                         } else if (fax.getPhoneNumber() < 1) {
749                                 // Abort here
750                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
751                         }
752
753                         // Set fax number
754                         headquarter.setHeadquarterFaxNumber(fax);
755                 }
756                 // Is the opening times list filled?
757                 if (!this.getHeadquarterOpeningTimes().isEmpty()) {
758                         // Yes, then set in headquarter, too
759                         headquarter.setHeadquarterOpeningTimes(this.getHeadquarterOpeningTimes());
760                 }
761
762                 // Return fully prepared instance
763                 return headquarter;
764         }
765
766         /**
767          * Prepares an instance of a OpeningTimes object (entity) with all data from
768          * this bean. If a complete fax number or land-line number was provided, it
769          * will be set in the instance as well.
770          * <p>
771          * @return An instance of a OpeningTimes class (entity)
772          */
773         private OpeningTime createOpeningTimes () {
774                 // Create new openingTime instance
775                 final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
776
777                 // Return fully prepared instance
778                 return openingTime;
779         }
780
781         /**
782          * Checks whether the given headquarter' address is already found in local
783          * cache. Please note that this method fully relies on the cache, so you
784          * must always fire proper events that add/update/delete entries in cache.
785          * <p>
786          * @param headquarter Headquarter to check it's address
787          * <p>
788          * @return Whether the address has been found
789          */
790         private boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter) {
791                 // Get full list from other bean
792                 final List<Headquarter> allHeadquarter = this.headquarterController.allHeadquarter();
793
794                 // Default is not found
795                 boolean isFound = false;
796
797                 // Now check each entry
798                 for (final Headquarter hq : allHeadquarter) {
799                         // Is same address?
800                         if (Headquarters.isSameAddress(hq, headquarter)) {
801                                 // Found one
802                                 isFound = true;
803                                 break;
804                         }
805                 }
806
807                 // Return flag
808                 return isFound;
809         }
810
811         /**
812          * Checks if given opening time is already added
813          * <p>
814          * @param openingTime Opening time to be checked
815          * <p>
816          * @return Whether it has been added already
817          */
818         private boolean isSameOpeningTimeFound (final OpeningTime openingTime) {
819                 // Default is not found
820                 boolean isFound = false;
821
822                 // Loop through list
823                 for (final OpeningTime ot : this.getHeadquarterOpeningTimes()) {
824                         // Check it
825                         if (Objects.equals(ot, openingTime)) {
826                                 // Found same match
827                                 isFound = true;
828                                 break;
829                         }
830                 }
831
832                 // Return it
833                 return isFound;
834         }
835
836 }