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