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