2 * Copyright (C) 2016 - 2020 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.jfinancials.beans.business.basicdata;
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;
43 * An administrative business contact bean (controller)
45 * @author Roland Häder<roland@mxchange.org>
47 @Named ("adminBasicCompanyDataController")
49 public class FinancialsAdminBasicDataWebRequestBean extends BaseFinancialsBean implements FinancialsAdminBasicDataWebRequestController {
54 private static final long serialVersionUID = 56_189_028_928_374L;
57 * EJB for administrative purposes
59 @EJB (lookup = "java:global/jfinancials-ejb/adminBasicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote")
60 private AdminBasicCompanyDataSessionBeanRemote adminBasicCompanyDataBean;
63 * An event being fired when basic business data has been added
67 private Event<ObservableAdminAddedBusinessBasicDataEvent> businessDataAddedEvent;
70 * Comments for this company
72 private String companyComments;
75 * An employee as contact person with this company
77 private Employable companyContactEmployee;
80 * Companies (main) email address (example: info@company.example)
82 private String companyEmailAddress;
87 private Employable companyFounder;
90 * Headquarter data for this company
92 private Headquarter companyHeadQuarter;
97 private String companyName;
102 private String companyShortName;
107 private String companyTaxNumber;
110 * Owning user instance (which this company is assigned to)
112 private User companyUserOwner;
117 private String companyWebsiteUrl;
120 * Area code for fax number
122 private Integer faxAreaCode;
125 * Country for fax number
127 private Country faxCountry;
130 * Dial number for fax number
132 private Long faxNumber;
135 * Area code for land-line number
137 private Integer landLineAreaCode;
140 * Country for land-line number
142 private Country landLineCountry;
145 * Dial number for land-line number
147 private Long landLineNumber;
150 * Default constructor
152 public FinancialsAdminBasicDataWebRequestBean () {
153 // Call super constructor
158 * Adds a basic business data entry, if not yet found.
161 public void addBusinessBasicData () {
162 // Check if company short name is set
163 if (this.getCompanyShortName() == null) {
165 throw new NullPointerException("this.companyShortName is null"); //NOI18N
166 } else if (this.getCompanyShortName().isEmpty()) {
168 throw new IllegalArgumentException("this.companyShortName is empty"); //NOI18N
169 } else if ((this.getCompanyName() != null) && (this.getCompanyName().isEmpty())) {
171 throw new IllegalArgumentException("this.companyName is set empty"); //NOI18N
175 final BasicData basicData = new BusinessBasicData(this.getCompanyShortName());
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());
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());
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) {
199 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
200 } else if (landLine.getPhoneAreaCode() < 1) {
202 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
203 } else if (landLine.getPhoneNumber() == null) {
205 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
206 } else if (landLine.getPhoneNumber() < 1) {
208 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
212 basicData.setCompanyLandLineNumber(landLine);
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) {
220 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
221 } else if (fax.getPhoneAreaCode() < 1) {
223 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
224 } else if (fax.getPhoneNumber() == null) {
226 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
227 } else if (fax.getPhoneNumber() < 1) {
229 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
233 basicData.setCompanyFaxNumber(fax);
236 // Now try to send to EJB and get an updated version back
239 final BasicData updatedBasicData = this.adminBasicCompanyDataBean.addBusinessBasicData(basicData);
242 this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
243 } catch (final BasicDataAlreadyAddedException e) {
244 // Does already exist
245 throw new FacesException(e);
250 * Getter for comments
254 public String getCompanyComments () {
255 return this.companyComments;
259 * Setter for comments
261 * @param companyComments Comments
263 public void setCompanyComments (final String companyComments) {
264 this.companyComments = companyComments;
268 * Getter for employee as contact person
270 * @return Employable as contact person
272 public Employable getCompanyContactEmployee () {
273 return this.companyContactEmployee;
277 * Setter for employee as contact person
279 * @param companyContactEmployee Employable as contact person
281 public void setCompanyContactEmployee (final Employable companyContactEmployee) {
282 this.companyContactEmployee = companyContactEmployee;
286 * Getter for company's (main) email address
288 * @return Company's (main) email address
290 public String getCompanyEmailAddress () {
291 return this.companyEmailAddress;
295 * Setter for company's (main) email address
297 * @param companyEmailAddress Company's (main) email address
299 public void setCompanyEmailAddress (final String companyEmailAddress) {
300 this.companyEmailAddress = companyEmailAddress;
304 * Getter for company founder
306 * @return Company founder
308 public Employable getCompanyFounder () {
309 return this.companyFounder;
313 * Setter for company founder
315 * @param companyFounder Company founder
317 public void setCompanyFounder (final Employable companyFounder) {
318 this.companyFounder = companyFounder;
322 * Getter for headquarter data
324 * @return Headquarter data
326 public Headquarter getCompanyHeadQuarter () {
327 return this.companyHeadQuarter;
331 * Setter for headquarter data
333 * @param companyHeadQuarter Headquarter data
335 public void setCompanyHeadQuarter (final Headquarter companyHeadQuarter) {
336 this.companyHeadQuarter = companyHeadQuarter;
340 * Getter for company name
342 * @return Company name
344 public String getCompanyName () {
345 return this.companyName;
349 * Setter for company name
351 * @param companyName Company name
353 public void setCompanyName (final String companyName) {
354 this.companyName = companyName;
358 * Getter for company short name
360 * @return Company short name
362 public String getCompanyShortName () {
363 return this.companyShortName;
367 * Setter for company short name
369 * @param companyShortName Company short name
371 public void setCompanyShortName (final String companyShortName) {
372 this.companyShortName = companyShortName;
376 * Getter for company tax number
378 * @return Company tax number
380 public String getCompanyTaxNumber () {
381 return this.companyTaxNumber;
385 * Setter for company tax number
387 * @param companyTaxNumber Company tax number
389 public void setCompanyTaxNumber (final String companyTaxNumber) {
390 this.companyTaxNumber = companyTaxNumber;
394 * Getter for owning user instance
396 * @return Owning user instance
398 public User getCompanyUserOwner () {
399 return this.companyUserOwner;
403 * Setter for owning user instance
405 * @param companyUserOwner Owning user instance
407 public void setCompanyUserOwner (final User companyUserOwner) {
408 this.companyUserOwner = companyUserOwner;
412 * Getter for company web site URL
414 * @return Company web site URL
416 public String getCompanyWebsiteUrl () {
417 return this.companyWebsiteUrl;
421 * Getter for company web site URL
423 * @param companyWebsiteUrl Company web site URL
425 public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
426 this.companyWebsiteUrl = companyWebsiteUrl;
430 * Getter for fax number's area code
432 * @return Fax number's area code
434 public Integer getFaxAreaCode () {
435 return this.faxAreaCode;
439 * Setter for fax number's area code
441 * @param faxAreaCode Fax number's area code
443 public void setFaxAreaCode (final Integer faxAreaCode) {
444 this.faxAreaCode = faxAreaCode;
448 * Getter for fax's country instance
450 * @return Fax' country instance
452 public Country getFaxCountry () {
453 return this.faxCountry;
457 * Setter for fax's country instance
459 * @param faxCountry Fax' country instance
461 public void setFaxCountry (final Country faxCountry) {
462 this.faxCountry = faxCountry;
466 * Getter for fax number
470 public Long getFaxNumber () {
471 return this.faxNumber;
475 * Setter for fax number
477 * @param faxNumber Fax number
479 public void setFaxNumber (final Long faxNumber) {
480 this.faxNumber = faxNumber;
484 * Getter for land-line number's area code
486 * @return Land-line number's area code
488 public Integer getLandLineAreaCode () {
489 return this.landLineAreaCode;
493 * Setter for land-line number's area code
495 * @param landLineAreaCode Land-line number's area code
497 public void setLandLineAreaCode (final Integer landLineAreaCode) {
498 this.landLineAreaCode = landLineAreaCode;
502 * Getter for land-line number's country instance
504 * @return Land-line number's country instance
506 public Country getLandLineCountry () {
507 return this.landLineCountry;
511 * Setter for land-line number's country instance
513 * @param landLineCountry Land-line number's country instance
515 public void setLandLineCountry (final Country landLineCountry) {
516 this.landLineCountry = landLineCountry;
520 * Getter for land-line number
522 * @return Land-line number
524 public Long getLandLineNumber () {
525 return this.landLineNumber;
529 * Setter for land-line number
531 * @param landLineNumber Land-line number
533 public void setLandLineNumber (final Long landLineNumber) {
534 this.landLineNumber = landLineNumber;