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;
100 * Company's road number
102 private String companyRoadNumber;
107 private String companyShortName;
112 private String companyTaxNumber;
115 * Owning user instance (which this company is assigned to)
117 private User companyUserOwner;
122 private String companyWebsiteUrl;
125 * Area code for fax number
127 private Integer faxAreaCode;
130 * Country for fax number
132 private Country faxCountry;
135 * Dial number for fax number
137 private Long faxNumber;
140 * Area code for land-line number
142 private Integer landLineAreaCode;
145 * Country for land-line number
147 private Country landLineCountry;
150 * Dial number for land-line number
152 private Long landLineNumber;
155 * Default constructor
157 public FinancialsAdminBasicDataWebRequestBean () {
158 // Call super constructor
163 * Adds a basic business data entry, if not yet found.
166 public void addBusinessBasicData () {
167 // Check if company short name is set
168 if (this.getCompanyShortName() == null) {
170 throw new NullPointerException("this.companyShortName is null"); //NOI18N
171 } else if (this.getCompanyShortName().isEmpty()) {
173 throw new IllegalArgumentException("this.companyShortName is empty"); //NOI18N
174 } else if ((this.getCompanyName() != null) && (this.getCompanyName().isEmpty())) {
176 throw new IllegalArgumentException("this.companyName is set empty"); //NOI18N
180 final BasicData basicData = new BusinessBasicData(this.getCompanyShortName());
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());
195 // @TODO basicData.setCompanyLogo();
197 DialableLandLineNumber landLine = null;
198 DialableFaxNumber fax = null;
200 // Are all 3 fields set?
201 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
202 // Initialize land number number instance
203 landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
206 // Are all 3 fields set?
207 if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
208 // Initialzie fax number instance
209 fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
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) {
217 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
218 } else if (landLine.getPhoneAreaCode() < 1) {
220 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
221 } else if (landLine.getPhoneNumber() == null) {
223 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
224 } else if (landLine.getPhoneNumber() < 1) {
226 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
230 basicData.setCompanyLandLineNumber(landLine);
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) {
238 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
239 } else if (fax.getPhoneAreaCode() < 1) {
241 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
242 } else if (fax.getPhoneNumber() == null) {
244 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
245 } else if (fax.getPhoneNumber() < 1) {
247 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
251 basicData.setCompanyFaxNumber(fax);
255 final BasicData updatedBasicData;
257 // Now try to send to EJB and get an updated version back
260 updatedBasicData = this.adminBasicCompanyDataBean.addBusinessBasicData(basicData);
261 } catch (final BasicDataAlreadyAddedException e) {
262 // Does already exist
263 throw new FacesException(e);
267 this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
271 * Getter for comments
275 public String getCompanyComments () {
276 return this.companyComments;
280 * Setter for comments
282 * @param companyComments Comments
284 public void setCompanyComments (final String companyComments) {
285 this.companyComments = companyComments;
289 * Getter for employee as contact person
291 * @return Employable as contact person
293 public Employable getCompanyContactEmployee () {
294 return this.companyContactEmployee;
298 * Setter for employee as contact person
300 * @param companyContactEmployee Employable as contact person
302 public void setCompanyContactEmployee (final Employable companyContactEmployee) {
303 this.companyContactEmployee = companyContactEmployee;
307 * Getter for company's (main) email address
309 * @return Company's (main) email address
311 public String getCompanyEmailAddress () {
312 return this.companyEmailAddress;
316 * Setter for company's (main) email address
318 * @param companyEmailAddress Company's (main) email address
320 public void setCompanyEmailAddress (final String companyEmailAddress) {
321 this.companyEmailAddress = companyEmailAddress;
325 * Getter for company founder
327 * @return Company founder
329 public Employable getCompanyFounder () {
330 return this.companyFounder;
334 * Setter for company founder
336 * @param companyFounder Company founder
338 public void setCompanyFounder (final Employable companyFounder) {
339 this.companyFounder = companyFounder;
343 * Getter for headquarter data
345 * @return Headquarter data
347 public Headquarter getCompanyHeadQuarter () {
348 return this.companyHeadQuarter;
352 * Setter for headquarter data
354 * @param companyHeadQuarter Headquarter data
356 public void setCompanyHeadQuarter (final Headquarter companyHeadQuarter) {
357 this.companyHeadQuarter = companyHeadQuarter;
361 * Getter for company name
363 * @return Company name
365 public String getCompanyName () {
366 return this.companyName;
370 * Setter for company name
372 * @param companyName Company name
374 public void setCompanyName (final String companyName) {
375 this.companyName = companyName;
379 * Getter for company's road number
381 * @return Company's road number
383 public String getCompanyRoadNumber () {
384 return this.companyRoadNumber;
388 * Setter for company's road number
390 * @param companyRoadNumber Company's road number
392 public void setCompanyRoadNumber (final String companyRoadNumber) {
393 this.companyRoadNumber = companyRoadNumber;
397 * Getter for company short name
399 * @return Company short name
401 public String getCompanyShortName () {
402 return this.companyShortName;
406 * Setter for company short name
408 * @param companyShortName Company short name
410 public void setCompanyShortName (final String companyShortName) {
411 this.companyShortName = companyShortName;
415 * Getter for company tax number
417 * @return Company tax number
419 public String getCompanyTaxNumber () {
420 return this.companyTaxNumber;
424 * Setter for company tax number
426 * @param companyTaxNumber Company tax number
428 public void setCompanyTaxNumber (final String companyTaxNumber) {
429 this.companyTaxNumber = companyTaxNumber;
433 * Getter for owning user instance
435 * @return Owning user instance
437 public User getCompanyUserOwner () {
438 return this.companyUserOwner;
442 * Setter for owning user instance
444 * @param companyUserOwner Owning user instance
446 public void setCompanyUserOwner (final User companyUserOwner) {
447 this.companyUserOwner = companyUserOwner;
451 * Getter for company web site URL
453 * @return Company web site URL
455 public String getCompanyWebsiteUrl () {
456 return this.companyWebsiteUrl;
460 * Getter for company web site URL
462 * @param companyWebsiteUrl Company web site URL
464 public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
465 this.companyWebsiteUrl = companyWebsiteUrl;
469 * Getter for fax number's area code
471 * @return Fax number's area code
473 public Integer getFaxAreaCode () {
474 return this.faxAreaCode;
478 * Setter for fax number's area code
480 * @param faxAreaCode Fax number's area code
482 public void setFaxAreaCode (final Integer faxAreaCode) {
483 this.faxAreaCode = faxAreaCode;
487 * Getter for fax's country instance
489 * @return Fax' country instance
491 public Country getFaxCountry () {
492 return this.faxCountry;
496 * Setter for fax's country instance
498 * @param faxCountry Fax' country instance
500 public void setFaxCountry (final Country faxCountry) {
501 this.faxCountry = faxCountry;
505 * Getter for fax number
509 public Long getFaxNumber () {
510 return this.faxNumber;
514 * Setter for fax number
516 * @param faxNumber Fax number
518 public void setFaxNumber (final Long faxNumber) {
519 this.faxNumber = faxNumber;
523 * Getter for land-line number's area code
525 * @return Land-line number's area code
527 public Integer getLandLineAreaCode () {
528 return this.landLineAreaCode;
532 * Setter for land-line number's area code
534 * @param landLineAreaCode Land-line number's area code
536 public void setLandLineAreaCode (final Integer landLineAreaCode) {
537 this.landLineAreaCode = landLineAreaCode;
541 * Getter for land-line number's country instance
543 * @return Land-line number's country instance
545 public Country getLandLineCountry () {
546 return this.landLineCountry;
550 * Setter for land-line number's country instance
552 * @param landLineCountry Land-line number's country instance
554 public void setLandLineCountry (final Country landLineCountry) {
555 this.landLineCountry = landLineCountry;
559 * Getter for land-line number
561 * @return Land-line number
563 public Long getLandLineNumber () {
564 return this.landLineNumber;
568 * Setter for land-line number
570 * @param landLineNumber Land-line number
572 public void setLandLineNumber (final Long landLineNumber) {
573 this.landLineNumber = landLineNumber;