]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookAdminBusinessDataWebRequestBean.java
Please cherry-pick:
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / business / basicdata / AddressbookAdminBusinessDataWebRequestBean.java
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.BasicCompanyDataAlreadyAddedException;
30 import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
31 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
32 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
33 import org.mxchange.jcontactsbusiness.model.employee.Employee;
34 import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
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 AddressbookAdminBusinessDataWebRequestBean extends BaseAddressbookBean implements AddressbookAdminBusinessDataWebRequestController {
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 Employee 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 Employee companyFounder;
88
89         /**
90          * Head quarter data for this company
91          */
92         private HeadquartersData companyHeadQuarters;
93
94         /**
95          * Company name
96          */
97         private String companyName;
98
99         /**
100          * Tax number
101          */
102         private String companyTaxNumber;
103
104         /**
105          * Owning user instance (which this company is assigned to)
106          */
107         private User companyUserOwner;
108
109         /**
110          * Web site URL
111          */
112         private String companyWebsiteUrl;
113
114         /**
115          * Area code for fax number
116          */
117         private Integer faxAreaCode;
118
119         /**
120          * Country for fax number
121          */
122         private Country faxCountry;
123
124         /**
125          * Dial number for fax number
126          */
127         private Long faxNumber;
128
129         /**
130          * Area code for land-line number
131          */
132         private Integer landLineAreaCode;
133
134         /**
135          * Country for land-line number
136          */
137         private Country landLineCountry;
138
139         /**
140          * Dial number for land-line number
141          */
142         private Long landLineNumber;
143
144         /**
145          * Default constructor
146          */
147         public AddressbookAdminBusinessDataWebRequestBean () {
148                 // Call super constructor
149                 super();
150         }
151
152         /**
153          * Adds a basic business data entry, if not yet found.
154          * <p>
155          * @return Redirect outcome
156          */
157         public String addBusinessBasicData () {
158                 // First, validate all parameter
159                 if (this.getCompanyName() == null) {
160                         // Is null
161                         throw new NullPointerException("this.companyName is null"); //NOI18N
162                 } else if (this.getCompanyName().isEmpty()) {
163                         // Is null
164                         throw new IllegalArgumentException("this.companyName is empty"); //NOI18N
165                 }
166
167                 // Prepare entity
168                 BusinessBasicData basicData = new CompanyBasicData(this.getCompanyName());
169
170                 // Set all opther remaining data
171                 basicData.setCompanyComments(this.getCompanyComments());
172                 basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
173                 basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
174                 basicData.setCompanyFounder(this.getCompanyFounder());
175                 basicData.setCompanyHeadQuartersData(this.getCompanyHeadQuarters());
176                 basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
177                 basicData.setCompanyUserOwner(this.getCompanyUserOwner());
178                 basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
179
180                 // Set logo instance
181                 // @TODO basicData.setCompanyLogo();
182                 // Generate phone number
183                 DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
184                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
185
186                 // Don't set null or wrong references
187                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
188                         // Now the number must be given
189                         if (landLine.getPhoneAreaCode() == null) {
190                                 // Is null
191                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
192                         } else if (landLine.getPhoneAreaCode() < 1) {
193                                 // Abort here
194                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
195                         } else if (landLine.getPhoneNumber() == null) {
196                                 // Is null
197                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
198                         } else if (landLine.getPhoneNumber() < 1) {
199                                 // Abort here
200                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
201                         }
202
203                         // Set phone number
204                         basicData.setCompanyLandLineNumber(landLine);
205                 }
206
207                 // Don't set null or wrong references
208                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
209                         // Now the number must be given
210                         if (fax.getPhoneAreaCode() == null) {
211                                 // Is null
212                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
213                         } else if (fax.getPhoneAreaCode() < 1) {
214                                 // Abort here
215                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
216                         } else if (fax.getPhoneNumber() == null) {
217                                 // Is null
218                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
219                         } else if (fax.getPhoneNumber() < 1) {
220                                 // Abort here
221                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
222                         }
223
224                         // Set fax number
225                         basicData.setCompanyFaxNumber(fax);
226                 }
227
228                 // Now try to send to EJB and get an updated version back
229                 try {
230                         // Try it
231                         BusinessBasicData updatedBasicData = this.adminBasicCompanyDataBean.addCompanyBasicData(basicData);
232
233                         // Fire event
234                         this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
235                 } catch (final BasicCompanyDataAlreadyAddedException e) {
236                         // Does already exist
237                         throw new FacesException(e);
238                 }
239
240                 // Continue to list again
241                 return "admin_list_basic_company_data"; //NOI18N
242         }
243
244         /**
245          * Getter for comments
246          * <p>
247          * @return Comments
248          */
249         public String getCompanyComments () {
250                 return this.companyComments;
251         }
252
253         /**
254          * Setter for comments
255          * <p>
256          * @param companyComments Comments
257          */
258         public void setCompanyComments (final String companyComments) {
259                 this.companyComments = companyComments;
260         }
261
262         /**
263          * Getter for employee as contact person
264          * <p>
265          * @return Employee as contact person
266          */
267         public Employee getCompanyContactEmployee () {
268                 return this.companyContactEmployee;
269         }
270
271         /**
272          * Setter for employee as contact person
273          * <p>
274          * @param companyContactEmployee Employee as contact person
275          */
276         public void setCompanyContactEmployee (final Employee companyContactEmployee) {
277                 this.companyContactEmployee = companyContactEmployee;
278         }
279
280         /**
281          * Getter for company's (main) email address
282          * <p>
283          * @return Company's (main) email address
284          */
285         public String getCompanyEmailAddress () {
286                 return this.companyEmailAddress;
287         }
288
289         /**
290          * Setter for company's (main) email address
291          * <p>
292          * @param companyEmailAddress Company's (main) email address
293          */
294         public void setCompanyEmailAddress (final String companyEmailAddress) {
295                 this.companyEmailAddress = companyEmailAddress;
296         }
297
298         /**
299          * Getter for company founder
300          * <p>
301          * @return Company founder
302          */
303         public Employee getCompanyFounder () {
304                 return this.companyFounder;
305         }
306
307         /**
308          * Setter for company founder
309          * <p>
310          * @param companyFounder Company founder
311          */
312         public void setCompanyFounder (final Employee companyFounder) {
313                 this.companyFounder = companyFounder;
314         }
315
316         /**
317          * Getter for headquarters data
318          * <p>
319          * @return Headquarters data
320          */
321         public HeadquartersData getCompanyHeadQuarters () {
322                 return this.companyHeadQuarters;
323         }
324
325         /**
326          * Setter for headquarters data
327          * <p>
328          * @param companyHeadQuarters Headquarters data
329          */
330         public void setCompanyHeadQuarters (final HeadquartersData companyHeadQuarters) {
331                 this.companyHeadQuarters = companyHeadQuarters;
332         }
333
334         /**
335          * Getter for company name
336          * <p>
337          * @return Company name
338          */
339         public String getCompanyName () {
340                 return this.companyName;
341         }
342
343         /**
344          * Setter for company name
345          * <p>
346          * @param companyName Company name
347          */
348         public void setCompanyName (final String companyName) {
349                 this.companyName = companyName;
350         }
351
352         /**
353          * Getter for company tax number
354          * <p>
355          * @return Company tax number
356          */
357         public String getCompanyTaxNumber () {
358                 return this.companyTaxNumber;
359         }
360
361         /**
362          * Setter for company tax number
363          * <p>
364          * @param companyTaxNumber Company tax number
365          */
366         public void setCompanyTaxNumber (final String companyTaxNumber) {
367                 this.companyTaxNumber = companyTaxNumber;
368         }
369
370         /**
371          * Getter for owning user instance
372          * <p>
373          * @return Owning user instance
374          */
375         public User getCompanyUserOwner () {
376                 return this.companyUserOwner;
377         }
378
379         /**
380          * Setter for owning user instance
381          * <p>
382          * @param companyUserOwner Owning user instance
383          */
384         public void setCompanyUserOwner (final User companyUserOwner) {
385                 this.companyUserOwner = companyUserOwner;
386         }
387
388         /**
389          * Getter for company web site URL
390          * <p>
391          * @return Company web site URL
392          */
393         public String getCompanyWebsiteUrl () {
394                 return this.companyWebsiteUrl;
395         }
396
397         /**
398          * Getter for company web site URL
399          * <p>
400          * @param companyWebsiteUrl Company web site URL
401          */
402         public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
403                 this.companyWebsiteUrl = companyWebsiteUrl;
404         }
405
406         /**
407          * Getter for fax number's area code
408          * <p>
409          * @return Fax number's area code
410          */
411         public Integer getFaxAreaCode () {
412                 return this.faxAreaCode;
413         }
414
415         /**
416          * Setter for fax number's area code
417          * <p>
418          * @param faxAreaCode Fax number's area code
419          */
420         public void setFaxAreaCode (final Integer faxAreaCode) {
421                 this.faxAreaCode = faxAreaCode;
422         }
423
424         /**
425          * Getter for fax's country instance
426          * <p>
427          * @return Fax' country instance
428          */
429         public Country getFaxCountry () {
430                 return this.faxCountry;
431         }
432
433         /**
434          * Setter for fax's country instance
435          * <p>
436          * @param faxCountry Fax' country instance
437          */
438         public void setFaxCountry (final Country faxCountry) {
439                 this.faxCountry = faxCountry;
440         }
441
442         /**
443          * Getter for fax number
444          * <p>
445          * @return Fax number
446          */
447         public Long getFaxNumber () {
448                 return this.faxNumber;
449         }
450
451         /**
452          * Setter for fax number
453          * <p>
454          * @param faxNumber Fax number
455          */
456         public void setFaxNumber (final Long faxNumber) {
457                 this.faxNumber = faxNumber;
458         }
459
460         /**
461          * Getter for land-line number's area code
462          * <p>
463          * @return Land-line number's area code
464          */
465         public Integer getLandLineAreaCode () {
466                 return this.landLineAreaCode;
467         }
468
469         /**
470          * Setter for land-line number's area code
471          * <p>
472          * @param landLineAreaCode Land-line number's area code
473          */
474         public void setLandLineAreaCode (final Integer landLineAreaCode) {
475                 this.landLineAreaCode = landLineAreaCode;
476         }
477
478         /**
479          * Getter for land-line number's country instance
480          * <p>
481          * @return Land-line number's country instance
482          */
483         public Country getLandLineCountry () {
484                 return this.landLineCountry;
485         }
486
487         /**
488          * Setter for land-line number's country instance
489          * <p>
490          * @param landLineCountry Land-line number's country instance
491          */
492         public void setLandLineCountry (final Country landLineCountry) {
493                 this.landLineCountry = landLineCountry;
494         }
495
496         /**
497          * Getter for land-line number
498          * <p>
499          * @return Land-line number
500          */
501         public Long getLandLineNumber () {
502                 return this.landLineNumber;
503         }
504
505         /**
506          * Setter for land-line number
507          * <p>
508          * @param landLineNumber Land-line number
509          */
510         public void setLandLineNumber (final Long landLineNumber) {
511                 this.landLineNumber = landLineNumber;
512         }
513
514 }