]> git.mxchange.org Git - jfinancials-war.git/blob - src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsAdminBasicDataWebRequestBean.java
Please cherry-pick:
[jfinancials-war.git] / src / java / org / mxchange / jfinancials / beans / business / basicdata / FinancialsAdminBasicDataWebRequestBean.java
1 /*
2  * Copyright (C) 2016 - 2018 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jfinancials.beans.business.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.jcontactsbusiness.events.basicdata.added.AdminAddedBusinessBasicDataEvent;
27 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
28 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataAlreadyAddedException;
29 import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
30 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
31 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
32 import org.mxchange.jcontactsbusiness.model.employee.Employable;
33 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
34 import org.mxchange.jcountry.model.data.Country;
35 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
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 ("adminBasicCompanyDataController")
48 @RequestScoped
49 public class FinancialsAdminBasicDataWebRequestBean extends BaseFinancialsBean implements FinancialsAdminBasicDataWebRequestController {
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/jfinancials-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 short name
101          */
102         private String companyShortName;
103
104         /**
105          * Tax number
106          */
107         private String companyTaxNumber;
108
109         /**
110          * Owning user instance (which this company is assigned to)
111          */
112         private User companyUserOwner;
113
114         /**
115          * Web site URL
116          */
117         private String companyWebsiteUrl;
118
119         /**
120          * Area code for fax number
121          */
122         private Integer faxAreaCode;
123
124         /**
125          * Country for fax number
126          */
127         private Country faxCountry;
128
129         /**
130          * Dial number for fax number
131          */
132         private Long faxNumber;
133
134         /**
135          * Area code for land-line number
136          */
137         private Integer landLineAreaCode;
138
139         /**
140          * Country for land-line number
141          */
142         private Country landLineCountry;
143
144         /**
145          * Dial number for land-line number
146          */
147         private Long landLineNumber;
148
149         /**
150          * Default constructor
151          */
152         public FinancialsAdminBasicDataWebRequestBean () {
153                 // Call super constructor
154                 super();
155         }
156
157         /**
158          * Adds a basic business data entry, if not yet found.
159          * <p>
160          */
161         public void addBusinessBasicData () {
162                 // Check if company short name is set
163                 if (this.getCompanyShortName() == null) {
164                         // Is null
165                         throw new NullPointerException("this.companyShortName is null"); //NOI18N
166                 } else if (this.getCompanyShortName().isEmpty()) {
167                         // Is null
168                         throw new IllegalArgumentException("this.companyShortName is empty"); //NOI18N
169                 }
170
171                 // Prepare entity
172                 BasicData basicData = new BusinessBasicData(this.getCompanyShortName());
173
174                 // Set all opther remaining data
175                 basicData.setCompanyComments(this.getCompanyComments());
176                 basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
177                 basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
178                 basicData.setCompanyFounder(this.getCompanyFounder());
179                 basicData.setCompanyHeadquarterData(this.getCompanyHeadQuarter());
180                 basicData.setCompanyName(this.getCompanyName());
181                 basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
182                 basicData.setCompanyUserOwner(this.getCompanyUserOwner());
183                 basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
184
185                 // Set logo instance
186                 // @TODO basicData.setCompanyLogo();
187                 // Generate phone number
188                 DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
189                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
190
191                 // Don't set null or wrong references
192                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
193                         // Now the number must be given
194                         if (landLine.getPhoneAreaCode() == null) {
195                                 // Is null
196                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
197                         } else if (landLine.getPhoneAreaCode() < 1) {
198                                 // Abort here
199                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
200                         } else if (landLine.getPhoneNumber() == null) {
201                                 // Is null
202                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
203                         } else if (landLine.getPhoneNumber() < 1) {
204                                 // Abort here
205                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
206                         }
207
208                         // Set phone number
209                         basicData.setCompanyLandLineNumber(landLine);
210                 }
211
212                 // Don't set null or wrong references
213                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
214                         // Now the number must be given
215                         if (fax.getPhoneAreaCode() == null) {
216                                 // Is null
217                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
218                         } else if (fax.getPhoneAreaCode() < 1) {
219                                 // Abort here
220                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
221                         } else if (fax.getPhoneNumber() == null) {
222                                 // Is null
223                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
224                         } else if (fax.getPhoneNumber() < 1) {
225                                 // Abort here
226                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
227                         }
228
229                         // Set fax number
230                         basicData.setCompanyFaxNumber(fax);
231                 }
232
233                 // Now try to send to EJB and get an updated version back
234                 try {
235                         // Try it
236                         final BasicData updatedBasicData = this.adminBasicCompanyDataBean.addBusinessBasicData(basicData);
237
238                         // Fire event
239                         this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
240                 } catch (final BasicDataAlreadyAddedException e) {
241                         // Does already exist
242                         throw new FacesException(e);
243                 }
244         }
245
246         /**
247          * Getter for comments
248          * <p>
249          * @return Comments
250          */
251         public String getCompanyComments () {
252                 return this.companyComments;
253         }
254
255         /**
256          * Setter for comments
257          * <p>
258          * @param companyComments Comments
259          */
260         public void setCompanyComments (final String companyComments) {
261                 this.companyComments = companyComments;
262         }
263
264         /**
265          * Getter for employee as contact person
266          * <p>
267          * @return Employable as contact person
268          */
269         public Employable getCompanyContactEmployee () {
270                 return this.companyContactEmployee;
271         }
272
273         /**
274          * Setter for employee as contact person
275          * <p>
276          * @param companyContactEmployee Employable as contact person
277          */
278         public void setCompanyContactEmployee (final Employable companyContactEmployee) {
279                 this.companyContactEmployee = companyContactEmployee;
280         }
281
282         /**
283          * Getter for company's (main) email address
284          * <p>
285          * @return Company's (main) email address
286          */
287         public String getCompanyEmailAddress () {
288                 return this.companyEmailAddress;
289         }
290
291         /**
292          * Setter for company's (main) email address
293          * <p>
294          * @param companyEmailAddress Company's (main) email address
295          */
296         public void setCompanyEmailAddress (final String companyEmailAddress) {
297                 this.companyEmailAddress = companyEmailAddress;
298         }
299
300         /**
301          * Getter for company founder
302          * <p>
303          * @return Company founder
304          */
305         public Employable getCompanyFounder () {
306                 return this.companyFounder;
307         }
308
309         /**
310          * Setter for company founder
311          * <p>
312          * @param companyFounder Company founder
313          */
314         public void setCompanyFounder (final Employable companyFounder) {
315                 this.companyFounder = companyFounder;
316         }
317
318         /**
319          * Getter for headquarter data
320          * <p>
321          * @return Headquarter data
322          */
323         public Headquarter getCompanyHeadQuarter () {
324                 return this.companyHeadQuarter;
325         }
326
327         /**
328          * Setter for headquarter data
329          * <p>
330          * @param companyHeadQuarter Headquarter data
331          */
332         public void setCompanyHeadQuarter (final Headquarter companyHeadQuarter) {
333                 this.companyHeadQuarter = companyHeadQuarter;
334         }
335
336         /**
337          * Getter for company name
338          * <p>
339          * @return Company name
340          */
341         public String getCompanyName () {
342                 return this.companyName;
343         }
344
345         /**
346          * Setter for company name
347          * <p>
348          * @param companyName Company name
349          */
350         public void setCompanyName (final String companyName) {
351                 this.companyName = companyName;
352         }
353
354         /**
355          * Getter for company short name
356          * <p>
357          * @return Company short name
358          */
359         public String getCompanyShortName () {
360                 return this.companyShortName;
361         }
362
363         /**
364          * Setter for company short name
365          * <p>
366          * @param companyShortName Company short name
367          */
368         public void setCompanyShortName (final String companyShortName) {
369                 this.companyShortName = companyShortName;
370         }
371
372         /**
373          * Getter for company tax number
374          * <p>
375          * @return Company tax number
376          */
377         public String getCompanyTaxNumber () {
378                 return this.companyTaxNumber;
379         }
380
381         /**
382          * Setter for company tax number
383          * <p>
384          * @param companyTaxNumber Company tax number
385          */
386         public void setCompanyTaxNumber (final String companyTaxNumber) {
387                 this.companyTaxNumber = companyTaxNumber;
388         }
389
390         /**
391          * Getter for owning user instance
392          * <p>
393          * @return Owning user instance
394          */
395         public User getCompanyUserOwner () {
396                 return this.companyUserOwner;
397         }
398
399         /**
400          * Setter for owning user instance
401          * <p>
402          * @param companyUserOwner Owning user instance
403          */
404         public void setCompanyUserOwner (final User companyUserOwner) {
405                 this.companyUserOwner = companyUserOwner;
406         }
407
408         /**
409          * Getter for company web site URL
410          * <p>
411          * @return Company web site URL
412          */
413         public String getCompanyWebsiteUrl () {
414                 return this.companyWebsiteUrl;
415         }
416
417         /**
418          * Getter for company web site URL
419          * <p>
420          * @param companyWebsiteUrl Company web site URL
421          */
422         public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
423                 this.companyWebsiteUrl = companyWebsiteUrl;
424         }
425
426         /**
427          * Getter for fax number's area code
428          * <p>
429          * @return Fax number's area code
430          */
431         public Integer getFaxAreaCode () {
432                 return this.faxAreaCode;
433         }
434
435         /**
436          * Setter for fax number's area code
437          * <p>
438          * @param faxAreaCode Fax number's area code
439          */
440         public void setFaxAreaCode (final Integer faxAreaCode) {
441                 this.faxAreaCode = faxAreaCode;
442         }
443
444         /**
445          * Getter for fax's country instance
446          * <p>
447          * @return Fax' country instance
448          */
449         public Country getFaxCountry () {
450                 return this.faxCountry;
451         }
452
453         /**
454          * Setter for fax's country instance
455          * <p>
456          * @param faxCountry Fax' country instance
457          */
458         public void setFaxCountry (final Country faxCountry) {
459                 this.faxCountry = faxCountry;
460         }
461
462         /**
463          * Getter for fax number
464          * <p>
465          * @return Fax number
466          */
467         public Long getFaxNumber () {
468                 return this.faxNumber;
469         }
470
471         /**
472          * Setter for fax number
473          * <p>
474          * @param faxNumber Fax number
475          */
476         public void setFaxNumber (final Long faxNumber) {
477                 this.faxNumber = faxNumber;
478         }
479
480         /**
481          * Getter for land-line number's area code
482          * <p>
483          * @return Land-line number's area code
484          */
485         public Integer getLandLineAreaCode () {
486                 return this.landLineAreaCode;
487         }
488
489         /**
490          * Setter for land-line number's area code
491          * <p>
492          * @param landLineAreaCode Land-line number's area code
493          */
494         public void setLandLineAreaCode (final Integer landLineAreaCode) {
495                 this.landLineAreaCode = landLineAreaCode;
496         }
497
498         /**
499          * Getter for land-line number's country instance
500          * <p>
501          * @return Land-line number's country instance
502          */
503         public Country getLandLineCountry () {
504                 return this.landLineCountry;
505         }
506
507         /**
508          * Setter for land-line number's country instance
509          * <p>
510          * @param landLineCountry Land-line number's country instance
511          */
512         public void setLandLineCountry (final Country landLineCountry) {
513                 this.landLineCountry = landLineCountry;
514         }
515
516         /**
517          * Getter for land-line number
518          * <p>
519          * @return Land-line number
520          */
521         public Long getLandLineNumber () {
522                 return this.landLineNumber;
523         }
524
525         /**
526          * Setter for land-line number
527          * <p>
528          * @param landLineNumber Land-line number
529          */
530         public void setLandLineNumber (final Long landLineNumber) {
531                 this.landLineNumber = landLineNumber;
532         }
533
534 }