]> git.mxchange.org Git - addressbook-war.git/blob
28291f70d82dac937a729538c85eb6868ffb44be
[addressbook-war.git] /
1 /*
2  * Copyright (C) 2016 - 2022 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.addressbook.beans.business.basicdata;
18
19 import javax.ejb.EJB;
20 import javax.enterprise.context.RequestScoped;
21 import javax.enterprise.event.Event;
22 import javax.enterprise.inject.Any;
23 import javax.faces.FacesException;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import org.mxchange.addressbook.beans.BaseAddressbookBean;
27 import org.mxchange.jcontactsbusiness.events.basicdata.added.AdminAddedBusinessBasicDataEvent;
28 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
29 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataAlreadyAddedException;
30 import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
31 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
32 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
33 import org.mxchange.jcontactsbusiness.model.employee.Employable;
34 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
35 import org.mxchange.jcountry.model.data.Country;
36 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
37 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
38 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
39 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
40 import org.mxchange.jusercore.model.user.User;
41
42 /**
43  * An administrative business contact bean (controller)
44  * <p>
45  * @author Roland Häder<roland@mxchange.org>
46  */
47 @Named ("adminCompanyDataController")
48 @RequestScoped
49 public class AddressbookAdminBasicDataWebRequestBean extends BaseAddressbookBean implements AddressbookAdminBasicDataWebRequestController {
50
51         /**
52          * Serial number
53          */
54         private static final long serialVersionUID = 56_189_028_928_374L;
55
56         /**
57          * EJB for administrative purposes
58          */
59         @EJB (lookup = "java:global/addressbook-ejb/adminBasicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote")
60         private AdminBasicCompanyDataSessionBeanRemote adminBasicCompanyDataBean;
61
62         /**
63          * An event being fired when basic business data has been added
64          */
65         @Inject
66         @Any
67         private Event<ObservableAdminAddedBusinessBasicDataEvent> businessDataAddedEvent;
68
69         /**
70          * Comments for this company
71          */
72         private String companyComments;
73
74         /**
75          * An employee as contact person with this company
76          */
77         private Employable companyContactEmployee;
78
79         /**
80          * Companies (main) email address (example: info@company.example)
81          */
82         private String companyEmailAddress;
83
84         /**
85          * Company founder
86          */
87         private Employable companyFounder;
88
89         /**
90          * Headquarter data for this company
91          */
92         private Headquarter companyHeadQuarter;
93
94         /**
95          * Company name
96          */
97         private String companyName;
98
99         /**
100          * Company's road number
101          */
102         private String companyRoadNumber;
103
104         /**
105          * Company short name
106          */
107         private String companyShortName;
108
109         /**
110          * Tax number
111          */
112         private String companyTaxNumber;
113
114         /**
115          * Owning user instance (which this company is assigned to)
116          */
117         private User companyUserOwner;
118
119         /**
120          * Web site URL
121          */
122         private String companyWebsiteUrl;
123
124         /**
125          * Area code for fax number
126          */
127         private Integer faxAreaCode;
128
129         /**
130          * Country for fax number
131          */
132         private Country faxCountry;
133
134         /**
135          * Dial number for fax number
136          */
137         private Long faxNumber;
138
139         /**
140          * Area code for land-line number
141          */
142         private Integer landLineAreaCode;
143
144         /**
145          * Country for land-line number
146          */
147         private Country landLineCountry;
148
149         /**
150          * Dial number for land-line number
151          */
152         private Long landLineNumber;
153
154         /**
155          * Default constructor
156          */
157         public AddressbookAdminBasicDataWebRequestBean () {
158                 // Call super constructor
159                 super();
160         }
161
162         /**
163          * Adds a basic business data entry, if not yet found.
164          */
165         public void addBusinessBasicData () {
166                 // Check if company short name is set
167                 if (this.getCompanyShortName() == null) {
168                         // Is null
169                         throw new NullPointerException("this.companyShortName is null"); //NOI18N
170                 } else if (this.getCompanyShortName().isEmpty()) {
171                         // Is null
172                         throw new IllegalArgumentException("this.companyShortName is empty"); //NOI18N
173                 } else if ((this.getCompanyName() != null) && (this.getCompanyName().isEmpty())) {
174                         // Is null
175                         throw new IllegalArgumentException("this.companyName is set empty"); //NOI18N
176                 }
177
178                 // Prepare entity
179                 final BasicData basicData = new BusinessBasicData(this.getCompanyShortName());
180
181                 // Set all opther remaining data
182                 basicData.setCompanyComments(this.getCompanyComments());
183                 basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
184                 basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
185                 basicData.setCompanyFounder(this.getCompanyFounder());
186                 basicData.setCompanyHeadquarterData(this.getCompanyHeadQuarter());
187                 basicData.setCompanyName(this.getCompanyName());
188                 basicData.setCompanyRoadNumber(this.getCompanyRoadNumber());
189                 basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
190                 basicData.setCompanyUserOwner(this.getCompanyUserOwner());
191                 basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
192
193                 // Set logo instance
194                 // @TODO basicData.setCompanyLogo();
195                 // Init varibables
196                 DialableLandLineNumber landLine = null;
197                 DialableFaxNumber fax = null;
198
199                 // Are all 3 fields set?
200                 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
201                         // Initialize land number number instance
202                         landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
203                 }
204
205                 // Are all 3 fields set?
206                 if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
207                         // Initialzie fax number instance
208                         fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
209                 }
210
211                 // Don't set null or wrong references
212                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
213                         // Now the number must be given
214                         if (landLine.getPhoneAreaCode() == null) {
215                                 // Is null
216                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
217                         } else if (landLine.getPhoneAreaCode() < 1) {
218                                 // Abort here
219                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
220                         } else if (landLine.getPhoneNumber() == null) {
221                                 // Is null
222                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
223                         } else if (landLine.getPhoneNumber() < 1) {
224                                 // Abort here
225                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
226                         }
227
228                         // Set phone number
229                         basicData.setCompanyLandLineNumber(landLine);
230                 }
231
232                 // Don't set null or wrong references
233                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
234                         // Now the number must be given
235                         if (fax.getPhoneAreaCode() == null) {
236                                 // Is null
237                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
238                         } else if (fax.getPhoneAreaCode() < 1) {
239                                 // Abort here
240                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
241                         } else if (fax.getPhoneNumber() == null) {
242                                 // Is null
243                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
244                         } else if (fax.getPhoneNumber() < 1) {
245                                 // Abort here
246                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
247                         }
248
249                         // Set fax number
250                         basicData.setCompanyFaxNumber(fax);
251                 }
252
253                 // Init variable
254                 final BasicData updatedBasicData;
255
256                 // Now try to send to EJB and get an updated version back
257                 try {
258                         // Try it
259                         updatedBasicData = this.adminBasicCompanyDataBean.addBusinessBasicData(basicData);
260                 } catch (final BasicDataAlreadyAddedException e) {
261                         // Does already exist
262                         throw new FacesException(e);
263                 }
264
265                 // Fire event
266                 this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
267         }
268
269         /**
270          * Getter for comments
271          * <p>
272          * @return Comments
273          */
274         public String getCompanyComments () {
275                 return this.companyComments;
276         }
277
278         /**
279          * Setter for comments
280          * <p>
281          * @param companyComments Comments
282          */
283         public void setCompanyComments (final String companyComments) {
284                 this.companyComments = companyComments;
285         }
286
287         /**
288          * Getter for employee as contact person
289          * <p>
290          * @return Employable as contact person
291          */
292         public Employable getCompanyContactEmployee () {
293                 return this.companyContactEmployee;
294         }
295
296         /**
297          * Setter for employee as contact person
298          * <p>
299          * @param companyContactEmployee Employable as contact person
300          */
301         public void setCompanyContactEmployee (final Employable companyContactEmployee) {
302                 this.companyContactEmployee = companyContactEmployee;
303         }
304
305         /**
306          * Getter for company's (main) email address
307          * <p>
308          * @return Company's (main) email address
309          */
310         public String getCompanyEmailAddress () {
311                 return this.companyEmailAddress;
312         }
313
314         /**
315          * Setter for company's (main) email address
316          * <p>
317          * @param companyEmailAddress Company's (main) email address
318          */
319         public void setCompanyEmailAddress (final String companyEmailAddress) {
320                 this.companyEmailAddress = companyEmailAddress;
321         }
322
323         /**
324          * Getter for company founder
325          * <p>
326          * @return Company founder
327          */
328         public Employable getCompanyFounder () {
329                 return this.companyFounder;
330         }
331
332         /**
333          * Setter for company founder
334          * <p>
335          * @param companyFounder Company founder
336          */
337         public void setCompanyFounder (final Employable companyFounder) {
338                 this.companyFounder = companyFounder;
339         }
340
341         /**
342          * Getter for headquarter data
343          * <p>
344          * @return Headquarter data
345          */
346         public Headquarter getCompanyHeadQuarter () {
347                 return this.companyHeadQuarter;
348         }
349
350         /**
351          * Setter for headquarter data
352          * <p>
353          * @param companyHeadQuarter Headquarter data
354          */
355         public void setCompanyHeadQuarter (final Headquarter companyHeadQuarter) {
356                 this.companyHeadQuarter = companyHeadQuarter;
357         }
358
359         /**
360          * Getter for company name
361          * <p>
362          * @return Company name
363          */
364         public String getCompanyName () {
365                 return this.companyName;
366         }
367
368         /**
369          * Setter for company name
370          * <p>
371          * @param companyName Company name
372          */
373         public void setCompanyName (final String companyName) {
374                 this.companyName = companyName;
375         }
376
377         /**
378          * Getter for company's road number
379          * <p>
380          * @return Company's road number
381          */
382         public String getCompanyRoadNumber () {
383                 return this.companyRoadNumber;
384         }
385
386         /**
387          * Setter for company's road number
388          * <p>
389          * @param companyRoadNumber Company's road number
390          */
391         public void setCompanyRoadNumber (final String companyRoadNumber) {
392                 this.companyRoadNumber = companyRoadNumber;
393         }
394
395         /**
396          * Getter for company short name
397          * <p>
398          * @return Company short name
399          */
400         public String getCompanyShortName () {
401                 return this.companyShortName;
402         }
403
404         /**
405          * Setter for company short name
406          * <p>
407          * @param companyShortName Company short name
408          */
409         public void setCompanyShortName (final String companyShortName) {
410                 this.companyShortName = companyShortName;
411         }
412
413         /**
414          * Getter for company tax number
415          * <p>
416          * @return Company tax number
417          */
418         public String getCompanyTaxNumber () {
419                 return this.companyTaxNumber;
420         }
421
422         /**
423          * Setter for company tax number
424          * <p>
425          * @param companyTaxNumber Company tax number
426          */
427         public void setCompanyTaxNumber (final String companyTaxNumber) {
428                 this.companyTaxNumber = companyTaxNumber;
429         }
430
431         /**
432          * Getter for owning user instance
433          * <p>
434          * @return Owning user instance
435          */
436         public User getCompanyUserOwner () {
437                 return this.companyUserOwner;
438         }
439
440         /**
441          * Setter for owning user instance
442          * <p>
443          * @param companyUserOwner Owning user instance
444          */
445         public void setCompanyUserOwner (final User companyUserOwner) {
446                 this.companyUserOwner = companyUserOwner;
447         }
448
449         /**
450          * Getter for company web site URL
451          * <p>
452          * @return Company web site URL
453          */
454         public String getCompanyWebsiteUrl () {
455                 return this.companyWebsiteUrl;
456         }
457
458         /**
459          * Getter for company web site URL
460          * <p>
461          * @param companyWebsiteUrl Company web site URL
462          */
463         public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
464                 this.companyWebsiteUrl = companyWebsiteUrl;
465         }
466
467         /**
468          * Getter for fax number's area code
469          * <p>
470          * @return Fax number's area code
471          */
472         public Integer getFaxAreaCode () {
473                 return this.faxAreaCode;
474         }
475
476         /**
477          * Setter for fax number's area code
478          * <p>
479          * @param faxAreaCode Fax number's area code
480          */
481         public void setFaxAreaCode (final Integer faxAreaCode) {
482                 this.faxAreaCode = faxAreaCode;
483         }
484
485         /**
486          * Getter for fax's country instance
487          * <p>
488          * @return Fax' country instance
489          */
490         public Country getFaxCountry () {
491                 return this.faxCountry;
492         }
493
494         /**
495          * Setter for fax's country instance
496          * <p>
497          * @param faxCountry Fax' country instance
498          */
499         public void setFaxCountry (final Country faxCountry) {
500                 this.faxCountry = faxCountry;
501         }
502
503         /**
504          * Getter for fax number
505          * <p>
506          * @return Fax number
507          */
508         public Long getFaxNumber () {
509                 return this.faxNumber;
510         }
511
512         /**
513          * Setter for fax number
514          * <p>
515          * @param faxNumber Fax number
516          */
517         public void setFaxNumber (final Long faxNumber) {
518                 this.faxNumber = faxNumber;
519         }
520
521         /**
522          * Getter for land-line number's area code
523          * <p>
524          * @return Land-line number's area code
525          */
526         public Integer getLandLineAreaCode () {
527                 return this.landLineAreaCode;
528         }
529
530         /**
531          * Setter for land-line number's area code
532          * <p>
533          * @param landLineAreaCode Land-line number's area code
534          */
535         public void setLandLineAreaCode (final Integer landLineAreaCode) {
536                 this.landLineAreaCode = landLineAreaCode;
537         }
538
539         /**
540          * Getter for land-line number's country instance
541          * <p>
542          * @return Land-line number's country instance
543          */
544         public Country getLandLineCountry () {
545                 return this.landLineCountry;
546         }
547
548         /**
549          * Setter for land-line number's country instance
550          * <p>
551          * @param landLineCountry Land-line number's country instance
552          */
553         public void setLandLineCountry (final Country landLineCountry) {
554                 this.landLineCountry = landLineCountry;
555         }
556
557         /**
558          * Getter for land-line number
559          * <p>
560          * @return Land-line number
561          */
562         public Long getLandLineNumber () {
563                 return this.landLineNumber;
564         }
565
566         /**
567          * Setter for land-line number
568          * <p>
569          * @param landLineNumber Land-line number
570          */
571         public void setLandLineNumber (final Long landLineNumber) {
572                 this.landLineNumber = landLineNumber;
573         }
574
575 }