]> git.mxchange.org Git - jfinancials-war.git/blob
78826580d7de0c83d46823e32845535039eeaccb
[jfinancials-war.git] /
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
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.annotation.PostConstruct;
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.faces.view.facelets.FaceletException;
25 import javax.inject.Inject;
26 import javax.inject.Named;
27 import javax.naming.Context;
28 import javax.naming.InitialContext;
29 import javax.naming.NamingException;
30 import org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote;
31 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
32 import org.mxchange.jcontactsbusiness.basicdata.CompanyBasicData;
33 import org.mxchange.jcontactsbusiness.employee.Employee;
34 import org.mxchange.jcontactsbusiness.events.basicdata.added.BusinessBasicDataAddedEvent;
35 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableBusinessBasicDataAddedEvent;
36 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataAlreadyAddedException;
37 import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData;
38 import org.mxchange.jcountry.data.Country;
39 import org.mxchange.jfinancials.beans.BaseFinancialsController;
40 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
41 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
42 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
43 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
44 import org.mxchange.jusercore.model.user.User;
45
46 /**
47  * An administrative business contact bean (controller)
48  * <p>
49  * @author Roland Häder<roland@mxchange.org>
50  */
51 @Named ("adminCompanyDataController")
52 @RequestScoped
53 public class FinancialsAdminBusinessDataWebRequestBean extends BaseFinancialsController implements FinancialsAdminBusinessDataWebRequestController {
54
55         /**
56          * Serial number
57          */
58         private static final long serialVersionUID = 56_189_028_928_374L;
59
60         /**
61          * Remote contact bean
62          */
63         private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
64
65         /**
66          * An event being fired when basic business data has been added
67          */
68         @Inject
69         @Any
70         private Event<ObservableBusinessBasicDataAddedEvent> businessDataAddedEvent;
71
72         /**
73          * Comments for this company
74          */
75         private String companyComments;
76
77         /**
78          * An employee as contact person with this company
79          */
80         private Employee companyContactEmployee;
81
82         /**
83          * Companies (main) email address (example: info@company.example)
84          */
85         private String companyEmailAddress;
86
87         /**
88          * Company founder
89          */
90         private Employee companyFounder;
91
92         /**
93          * Head quarter data for this company
94          */
95         private HeadquartersData companyHeadQuarters;
96
97         /**
98          * Company name
99          */
100         private String companyName;
101
102         /**
103          * Tax number
104          */
105         private String companyTaxNumber;
106
107         /**
108          * Owning user instance (which this company is assigned to)
109          */
110         private User companyUserOwner;
111
112         /**
113          * Web site URL
114          */
115         private String companyWebsiteUrl;
116
117         /**
118          * Area code for fax number
119          */
120         private Integer faxAreaCode;
121
122         /**
123          * Country for fax number
124          */
125         private Country faxCountry;
126
127         /**
128          * Dial number for fax number
129          */
130         private Long faxNumber;
131
132         /**
133          * Area code for land-line number
134          */
135         private Integer landLineAreaCode;
136
137         /**
138          * Country for land-line number
139          */
140         private Country landLineCountry;
141
142         /**
143          * Dial number for land-line number
144          */
145         private Long landLineNumber;
146
147         /**
148          * Default constructor
149          */
150         public FinancialsAdminBusinessDataWebRequestBean () {
151                 // Call super constructor
152                 super();
153         }
154
155         /**
156          * Adds a basic business data entry, if not yet found.
157          * <p>
158          * @return Redirect outcome
159          */
160         public String addBusinessBasicData () {
161                 // First, validate all parameter
162                 if (this.getCompanyName() == null) {
163                         // Is null
164                         throw new NullPointerException("this.companyName is null"); //NOI18N
165                 } else if (this.getCompanyName().isEmpty()) {
166                         // Is null
167                         throw new IllegalArgumentException("this.companyName is empty"); //NOI18N
168                 }
169
170                 // Prepare entity
171                 BusinessBasicData basicData = new CompanyBasicData(this.getCompanyName());
172
173                 // Set all opther remaining data
174                 basicData.setCompanyComments(this.getCompanyComments());
175                 basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
176                 basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
177                 basicData.setCompanyFounder(this.getCompanyFounder());
178                 basicData.setCompanyHeadQuartersData(this.getCompanyHeadQuarters());
179                 basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
180                 basicData.setCompanyUserOwner(this.getCompanyUserOwner());
181                 basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
182
183                 // Set logo instance
184                 // @TODO basicData.setCompanyLogo();
185                 // Generate phone number
186                 DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
187                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
188
189                 // Don't set null or wrong references
190                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
191                         // Now the number must be given
192                         if (landLine.getPhoneAreaCode() == null) {
193                                 // Is null
194                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
195                         } else if (landLine.getPhoneAreaCode() < 1) {
196                                 // Abort here
197                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
198                         } else if (landLine.getPhoneNumber() == null) {
199                                 // Is null
200                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
201                         } else if (landLine.getPhoneNumber() < 1) {
202                                 // Abort here
203                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
204                         }
205
206                         // Set phone number
207                         basicData.setCompanyLandLineNumber(landLine);
208                 }
209
210                 // Don't set null or wrong references
211                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
212                         // Now the number must be given
213                         if (fax.getPhoneAreaCode() == null) {
214                                 // Is null
215                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
216                         } else if (fax.getPhoneAreaCode() < 1) {
217                                 // Abort here
218                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
219                         } else if (fax.getPhoneNumber() == null) {
220                                 // Is null
221                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
222                         } else if (fax.getPhoneNumber() < 1) {
223                                 // Abort here
224                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
225                         }
226
227                         // Set fax number
228                         basicData.setCompanyFaxNumber(fax);
229                 }
230
231                 // Now try to send to EJB and get an updated version back
232                 try {
233                         // Try it
234                         BusinessBasicData updatedBasicData = this.adminBusinessDataBean.addCompanyBasicData(basicData);
235
236                         // Fire event
237                         this.businessDataAddedEvent.fire(new BusinessBasicDataAddedEvent(updatedBasicData));
238                 } catch (final BusinessDataAlreadyAddedException e) {
239                         // Does already exist
240                         throw new FacesException(e);
241                 }
242
243                 // Continue to list again
244                 return "admin_list_business_contacts"; //NOI18N
245         }
246
247         /**
248          * Getter for comments
249          * <p>
250          * @return Comments
251          */
252         public String getCompanyComments () {
253                 return this.companyComments;
254         }
255
256         /**
257          * Setter for comments
258          * <p>
259          * @param companyComments Comments
260          */
261         public void setCompanyComments (final String companyComments) {
262                 this.companyComments = companyComments;
263         }
264
265         /**
266          * Getter for employee as contact person
267          * <p>
268          * @return Employee as contact person
269          */
270         public Employee getCompanyContactEmployee () {
271                 return this.companyContactEmployee;
272         }
273
274         /**
275          * Setter for employee as contact person
276          * <p>
277          * @param companyContactEmployee Employee as contact person
278          */
279         public void setCompanyContactEmployee (final Employee companyContactEmployee) {
280                 this.companyContactEmployee = companyContactEmployee;
281         }
282
283         /**
284          * Getter for company's (main) email address
285          * <p>
286          * @return Company's (main) email address
287          */
288         public String getCompanyEmailAddress () {
289                 return this.companyEmailAddress;
290         }
291
292         /**
293          * Setter for company's (main) email address
294          * <p>
295          * @param companyEmailAddress Company's (main) email address
296          */
297         public void setCompanyEmailAddress (final String companyEmailAddress) {
298                 this.companyEmailAddress = companyEmailAddress;
299         }
300
301         /**
302          * Getter for company founder
303          * <p>
304          * @return Company founder
305          */
306         public Employee getCompanyFounder () {
307                 return this.companyFounder;
308         }
309
310         /**
311          * Setter for company founder
312          * <p>
313          * @param companyFounder Company founder
314          */
315         public void setCompanyFounder (final Employee companyFounder) {
316                 this.companyFounder = companyFounder;
317         }
318
319         /**
320          * Getter for headquarters data
321          * <p>
322          * @return Headquarters data
323          */
324         public HeadquartersData getCompanyHeadQuarters () {
325                 return this.companyHeadQuarters;
326         }
327
328         /**
329          * Setter for headquarters data
330          * <p>
331          * @param companyHeadQuarters Headquarters data
332          */
333         public void setCompanyHeadQuarters (final HeadquartersData companyHeadQuarters) {
334                 this.companyHeadQuarters = companyHeadQuarters;
335         }
336
337         /**
338          * Getter for company name
339          * <p>
340          * @return Company name
341          */
342         public String getCompanyName () {
343                 return this.companyName;
344         }
345
346         /**
347          * Setter for company name
348          * <p>
349          * @param companyName Company name
350          */
351         public void setCompanyName (final String companyName) {
352                 this.companyName = companyName;
353         }
354
355         /**
356          * Getter for company tax number
357          * <p>
358          * @return Company tax number
359          */
360         public String getCompanyTaxNumber () {
361                 return this.companyTaxNumber;
362         }
363
364         /**
365          * Setter for company tax number
366          * <p>
367          * @param companyTaxNumber Company tax number
368          */
369         public void setCompanyTaxNumber (final String companyTaxNumber) {
370                 this.companyTaxNumber = companyTaxNumber;
371         }
372
373         /**
374          * Getter for owning user instance
375          * <p>
376          * @return Owning user instance
377          */
378         public User getCompanyUserOwner () {
379                 return this.companyUserOwner;
380         }
381
382         /**
383          * Setter for owning user instance
384          * <p>
385          * @param companyUserOwner Owning user instance
386          */
387         public void setCompanyUserOwner (final User companyUserOwner) {
388                 this.companyUserOwner = companyUserOwner;
389         }
390
391         /**
392          * Getter for company web site URL
393          * <p>
394          * @return Company web site URL
395          */
396         public String getCompanyWebsiteUrl () {
397                 return this.companyWebsiteUrl;
398         }
399
400         /**
401          * Getter for company web site URL
402          * <p>
403          * @param companyWebsiteUrl Company web site URL
404          */
405         public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
406                 this.companyWebsiteUrl = companyWebsiteUrl;
407         }
408
409         /**
410          * Getter for fax number's area code
411          * <p>
412          * @return Fax number's area code
413          */
414         public Integer getFaxAreaCode () {
415                 return this.faxAreaCode;
416         }
417
418         /**
419          * Setter for fax number's area code
420          * <p>
421          * @param faxAreaCode Fax number's area code
422          */
423         public void setFaxAreaCode (final Integer faxAreaCode) {
424                 this.faxAreaCode = faxAreaCode;
425         }
426
427         /**
428          * Getter for fax's country instance
429          * <p>
430          * @return Fax' country instance
431          */
432         public Country getFaxCountry () {
433                 return this.faxCountry;
434         }
435
436         /**
437          * Setter for fax's country instance
438          * <p>
439          * @param faxCountry Fax' country instance
440          */
441         public void setFaxCountry (final Country faxCountry) {
442                 this.faxCountry = faxCountry;
443         }
444
445         /**
446          * Getter for fax number
447          * <p>
448          * @return Fax number
449          */
450         public Long getFaxNumber () {
451                 return this.faxNumber;
452         }
453
454         /**
455          * Setter for fax number
456          * <p>
457          * @param faxNumber Fax number
458          */
459         public void setFaxNumber (final Long faxNumber) {
460                 this.faxNumber = faxNumber;
461         }
462
463         /**
464          * Getter for land-line number's area code
465          * <p>
466          * @return Land-line number's area code
467          */
468         public Integer getLandLineAreaCode () {
469                 return this.landLineAreaCode;
470         }
471
472         /**
473          * Setter for land-line number's area code
474          * <p>
475          * @param landLineAreaCode Land-line number's area code
476          */
477         public void setLandLineAreaCode (final Integer landLineAreaCode) {
478                 this.landLineAreaCode = landLineAreaCode;
479         }
480
481         /**
482          * Getter for land-line number's country instance
483          * <p>
484          * @return Land-line number's country instance
485          */
486         public Country getLandLineCountry () {
487                 return this.landLineCountry;
488         }
489
490         /**
491          * Setter for land-line number's country instance
492          * <p>
493          * @param landLineCountry Land-line number's country instance
494          */
495         public void setLandLineCountry (final Country landLineCountry) {
496                 this.landLineCountry = landLineCountry;
497         }
498
499         /**
500          * Getter for land-line number
501          * <p>
502          * @return Land-line number
503          */
504         public Long getLandLineNumber () {
505                 return this.landLineNumber;
506         }
507
508         /**
509          * Setter for land-line number
510          * <p>
511          * @param landLineNumber Land-line number
512          */
513         public void setLandLineNumber (final Long landLineNumber) {
514                 this.landLineNumber = landLineNumber;
515         }
516
517         /**
518          * Post-initialization of this class
519          */
520         @PostConstruct
521         public void init () {
522                 // Try it
523                 try {
524                         // Get initial context
525                         Context context = new InitialContext();
526
527                         // Try to lookup
528                         this.adminBusinessDataBean = (AdminBusinessDataSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote"); //NOI18N
529                 } catch (final NamingException e) {
530                         // Throw again
531                         throw new FaceletException(e);
532                 }
533         }
534
535 }