]> git.mxchange.org Git - jfinancials-war.git/blob
dbfb419c7916e16c6c5d54fe644ee5c5a6acbc28
[jfinancials-war.git] /
1 /*
2  * Copyright (C) 2016 - 2020 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'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 FinancialsAdminBasicDataWebRequestBean () {
158                 // Call super constructor
159                 super();
160         }
161
162         /**
163          * Adds a basic business data entry, if not yet found.
164          * <p>
165          */
166         public void addBusinessBasicData () {
167                 // Check if company short name is set
168                 if (this.getCompanyShortName() == null) {
169                         // Is null
170                         throw new NullPointerException("this.companyShortName is null"); //NOI18N
171                 } else if (this.getCompanyShortName().isEmpty()) {
172                         // Is null
173                         throw new IllegalArgumentException("this.companyShortName is empty"); //NOI18N
174                 } else if ((this.getCompanyName() != null) && (this.getCompanyName().isEmpty())) {
175                         // Is null
176                         throw new IllegalArgumentException("this.companyName is set empty"); //NOI18N
177                 }
178
179                 // Prepare entity
180                 final BasicData basicData = new BusinessBasicData(this.getCompanyShortName());
181
182                 // Set all opther remaining data
183                 basicData.setCompanyComments(this.getCompanyComments());
184                 basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
185                 basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
186                 basicData.setCompanyFounder(this.getCompanyFounder());
187                 basicData.setCompanyHeadquarterData(this.getCompanyHeadQuarter());
188                 basicData.setCompanyName(this.getCompanyName());
189                 basicData.setCompanyRoadNumber(this.getCompanyRoadNumber());
190                 basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
191                 basicData.setCompanyUserOwner(this.getCompanyUserOwner());
192                 basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
193
194                 // Set logo instance
195                 // @TODO basicData.setCompanyLogo();
196                 // Init varibables
197                 DialableLandLineNumber landLine = null;
198                 DialableFaxNumber fax = null;
199
200                 // Are all 3 fields set?
201                 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() != null && this.getLandLineNumber() != null) {
202                         // Initialize land number number instance
203                         landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
204                 }
205
206                 // Are all 3 fields set?
207                 if (this.getFaxAreaCode() != null && this.getFaxCountry() != null && this.getFaxNumber() != null) {
208                         // Initialzie fax number instance
209                         fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
210                 }
211
212                 // Don't set null or wrong references
213                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
214                         // Now the number must be given
215                         if (landLine.getPhoneAreaCode() == null) {
216                                 // Is null
217                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
218                         } else if (landLine.getPhoneAreaCode() < 1) {
219                                 // Abort here
220                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
221                         } else if (landLine.getPhoneNumber() == null) {
222                                 // Is null
223                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
224                         } else if (landLine.getPhoneNumber() < 1) {
225                                 // Abort here
226                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
227                         }
228
229                         // Set phone number
230                         basicData.setCompanyLandLineNumber(landLine);
231                 }
232
233                 // Don't set null or wrong references
234                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
235                         // Now the number must be given
236                         if (fax.getPhoneAreaCode() == null) {
237                                 // Is null
238                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
239                         } else if (fax.getPhoneAreaCode() < 1) {
240                                 // Abort here
241                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
242                         } else if (fax.getPhoneNumber() == null) {
243                                 // Is null
244                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
245                         } else if (fax.getPhoneNumber() < 1) {
246                                 // Abort here
247                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
248                         }
249
250                         // Set fax number
251                         basicData.setCompanyFaxNumber(fax);
252                 }
253
254                 // Init variable
255                 final BasicData updatedBasicData;
256
257                 // Now try to send to EJB and get an updated version back
258                 try {
259                         // Try it
260                         updatedBasicData = this.adminBasicCompanyDataBean.addBusinessBasicData(basicData);
261                 } catch (final BasicDataAlreadyAddedException e) {
262                         // Does already exist
263                         throw new FacesException(e);
264                 }
265
266                 // Fire event
267                 this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
268         }
269
270         /**
271          * Getter for comments
272          * <p>
273          * @return Comments
274          */
275         public String getCompanyComments () {
276                 return this.companyComments;
277         }
278
279         /**
280          * Setter for comments
281          * <p>
282          * @param companyComments Comments
283          */
284         public void setCompanyComments (final String companyComments) {
285                 this.companyComments = companyComments;
286         }
287
288         /**
289          * Getter for employee as contact person
290          * <p>
291          * @return Employable as contact person
292          */
293         public Employable getCompanyContactEmployee () {
294                 return this.companyContactEmployee;
295         }
296
297         /**
298          * Setter for employee as contact person
299          * <p>
300          * @param companyContactEmployee Employable as contact person
301          */
302         public void setCompanyContactEmployee (final Employable companyContactEmployee) {
303                 this.companyContactEmployee = companyContactEmployee;
304         }
305
306         /**
307          * Getter for company's (main) email address
308          * <p>
309          * @return Company's (main) email address
310          */
311         public String getCompanyEmailAddress () {
312                 return this.companyEmailAddress;
313         }
314
315         /**
316          * Setter for company's (main) email address
317          * <p>
318          * @param companyEmailAddress Company's (main) email address
319          */
320         public void setCompanyEmailAddress (final String companyEmailAddress) {
321                 this.companyEmailAddress = companyEmailAddress;
322         }
323
324         /**
325          * Getter for company founder
326          * <p>
327          * @return Company founder
328          */
329         public Employable getCompanyFounder () {
330                 return this.companyFounder;
331         }
332
333         /**
334          * Setter for company founder
335          * <p>
336          * @param companyFounder Company founder
337          */
338         public void setCompanyFounder (final Employable companyFounder) {
339                 this.companyFounder = companyFounder;
340         }
341
342         /**
343          * Getter for headquarter data
344          * <p>
345          * @return Headquarter data
346          */
347         public Headquarter getCompanyHeadQuarter () {
348                 return this.companyHeadQuarter;
349         }
350
351         /**
352          * Setter for headquarter data
353          * <p>
354          * @param companyHeadQuarter Headquarter data
355          */
356         public void setCompanyHeadQuarter (final Headquarter companyHeadQuarter) {
357                 this.companyHeadQuarter = companyHeadQuarter;
358         }
359
360         /**
361          * Getter for company name
362          * <p>
363          * @return Company name
364          */
365         public String getCompanyName () {
366                 return this.companyName;
367         }
368
369         /**
370          * Setter for company name
371          * <p>
372          * @param companyName Company name
373          */
374         public void setCompanyName (final String companyName) {
375                 this.companyName = companyName;
376         }
377
378         /**
379          * Getter for company's road number
380          * <p>
381          * @return Company's road number
382          */
383         public String getCompanyRoadNumber () {
384                 return this.companyRoadNumber;
385         }
386
387         /**
388          * Setter for company's road number
389          * <p>
390          * @param companyRoadNumber Company's road number
391          */
392         public void setCompanyRoadNumber (final String companyRoadNumber) {
393                 this.companyRoadNumber = companyRoadNumber;
394         }
395
396         /**
397          * Getter for company short name
398          * <p>
399          * @return Company short name
400          */
401         public String getCompanyShortName () {
402                 return this.companyShortName;
403         }
404
405         /**
406          * Setter for company short name
407          * <p>
408          * @param companyShortName Company short name
409          */
410         public void setCompanyShortName (final String companyShortName) {
411                 this.companyShortName = companyShortName;
412         }
413
414         /**
415          * Getter for company tax number
416          * <p>
417          * @return Company tax number
418          */
419         public String getCompanyTaxNumber () {
420                 return this.companyTaxNumber;
421         }
422
423         /**
424          * Setter for company tax number
425          * <p>
426          * @param companyTaxNumber Company tax number
427          */
428         public void setCompanyTaxNumber (final String companyTaxNumber) {
429                 this.companyTaxNumber = companyTaxNumber;
430         }
431
432         /**
433          * Getter for owning user instance
434          * <p>
435          * @return Owning user instance
436          */
437         public User getCompanyUserOwner () {
438                 return this.companyUserOwner;
439         }
440
441         /**
442          * Setter for owning user instance
443          * <p>
444          * @param companyUserOwner Owning user instance
445          */
446         public void setCompanyUserOwner (final User companyUserOwner) {
447                 this.companyUserOwner = companyUserOwner;
448         }
449
450         /**
451          * Getter for company web site URL
452          * <p>
453          * @return Company web site URL
454          */
455         public String getCompanyWebsiteUrl () {
456                 return this.companyWebsiteUrl;
457         }
458
459         /**
460          * Getter for company web site URL
461          * <p>
462          * @param companyWebsiteUrl Company web site URL
463          */
464         public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
465                 this.companyWebsiteUrl = companyWebsiteUrl;
466         }
467
468         /**
469          * Getter for fax number's area code
470          * <p>
471          * @return Fax number's area code
472          */
473         public Integer getFaxAreaCode () {
474                 return this.faxAreaCode;
475         }
476
477         /**
478          * Setter for fax number's area code
479          * <p>
480          * @param faxAreaCode Fax number's area code
481          */
482         public void setFaxAreaCode (final Integer faxAreaCode) {
483                 this.faxAreaCode = faxAreaCode;
484         }
485
486         /**
487          * Getter for fax's country instance
488          * <p>
489          * @return Fax' country instance
490          */
491         public Country getFaxCountry () {
492                 return this.faxCountry;
493         }
494
495         /**
496          * Setter for fax's country instance
497          * <p>
498          * @param faxCountry Fax' country instance
499          */
500         public void setFaxCountry (final Country faxCountry) {
501                 this.faxCountry = faxCountry;
502         }
503
504         /**
505          * Getter for fax number
506          * <p>
507          * @return Fax number
508          */
509         public Long getFaxNumber () {
510                 return this.faxNumber;
511         }
512
513         /**
514          * Setter for fax number
515          * <p>
516          * @param faxNumber Fax number
517          */
518         public void setFaxNumber (final Long faxNumber) {
519                 this.faxNumber = faxNumber;
520         }
521
522         /**
523          * Getter for land-line number's area code
524          * <p>
525          * @return Land-line number's area code
526          */
527         public Integer getLandLineAreaCode () {
528                 return this.landLineAreaCode;
529         }
530
531         /**
532          * Setter for land-line number's area code
533          * <p>
534          * @param landLineAreaCode Land-line number's area code
535          */
536         public void setLandLineAreaCode (final Integer landLineAreaCode) {
537                 this.landLineAreaCode = landLineAreaCode;
538         }
539
540         /**
541          * Getter for land-line number's country instance
542          * <p>
543          * @return Land-line number's country instance
544          */
545         public Country getLandLineCountry () {
546                 return this.landLineCountry;
547         }
548
549         /**
550          * Setter for land-line number's country instance
551          * <p>
552          * @param landLineCountry Land-line number's country instance
553          */
554         public void setLandLineCountry (final Country landLineCountry) {
555                 this.landLineCountry = landLineCountry;
556         }
557
558         /**
559          * Getter for land-line number
560          * <p>
561          * @return Land-line number
562          */
563         public Long getLandLineNumber () {
564                 return this.landLineNumber;
565         }
566
567         /**
568          * Setter for land-line number
569          * <p>
570          * @param landLineNumber Land-line number
571          */
572         public void setLandLineNumber (final Long landLineNumber) {
573                 this.landLineNumber = landLineNumber;
574         }
575
576 }