2 * Copyright (C) 2016 - 2018 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 companyTaxNumber;
105 * Owning user instance (which this company is assigned to)
107 private User companyUserOwner;
112 private String companyWebsiteUrl;
115 * Area code for fax number
117 private Integer faxAreaCode;
120 * Country for fax number
122 private Country faxCountry;
125 * Dial number for fax number
127 private Long faxNumber;
130 * Area code for land-line number
132 private Integer landLineAreaCode;
135 * Country for land-line number
137 private Country landLineCountry;
140 * Dial number for land-line number
142 private Long landLineNumber;
145 * Default constructor
147 public FinancialsAdminBasicDataWebRequestBean () {
148 // Call super constructor
153 * Adds a basic business data entry, if not yet found.
156 public void addBusinessBasicData () {
157 // First, validate all parameter
158 if (this.getCompanyName() == null) {
160 throw new NullPointerException("this.companyName is null"); //NOI18N
161 } else if (this.getCompanyName().isEmpty()) {
163 throw new IllegalArgumentException("this.companyName is empty"); //NOI18N
167 BasicData basicData = new BusinessBasicData(this.getCompanyName());
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());
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());
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) {
190 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
191 } else if (landLine.getPhoneAreaCode() < 1) {
193 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
194 } else if (landLine.getPhoneNumber() == null) {
196 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
197 } else if (landLine.getPhoneNumber() < 1) {
199 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
203 basicData.setCompanyLandLineNumber(landLine);
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) {
211 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
212 } else if (fax.getPhoneAreaCode() < 1) {
214 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
215 } else if (fax.getPhoneNumber() == null) {
217 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
218 } else if (fax.getPhoneNumber() < 1) {
220 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
224 basicData.setCompanyFaxNumber(fax);
227 // Now try to send to EJB and get an updated version back
230 final BasicData updatedBasicData = this.adminBasicCompanyDataBean.addBusinessBasicData(basicData);
233 this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
234 } catch (final BasicDataAlreadyAddedException e) {
235 // Does already exist
236 throw new FacesException(e);
241 * Getter for comments
245 public String getCompanyComments () {
246 return this.companyComments;
250 * Setter for comments
252 * @param companyComments Comments
254 public void setCompanyComments (final String companyComments) {
255 this.companyComments = companyComments;
259 * Getter for employee as contact person
261 * @return Employable as contact person
263 public Employable getCompanyContactEmployee () {
264 return this.companyContactEmployee;
268 * Setter for employee as contact person
270 * @param companyContactEmployee Employable as contact person
272 public void setCompanyContactEmployee (final Employable companyContactEmployee) {
273 this.companyContactEmployee = companyContactEmployee;
277 * Getter for company's (main) email address
279 * @return Company's (main) email address
281 public String getCompanyEmailAddress () {
282 return this.companyEmailAddress;
286 * Setter for company's (main) email address
288 * @param companyEmailAddress Company's (main) email address
290 public void setCompanyEmailAddress (final String companyEmailAddress) {
291 this.companyEmailAddress = companyEmailAddress;
295 * Getter for company founder
297 * @return Company founder
299 public Employable getCompanyFounder () {
300 return this.companyFounder;
304 * Setter for company founder
306 * @param companyFounder Company founder
308 public void setCompanyFounder (final Employable companyFounder) {
309 this.companyFounder = companyFounder;
313 * Getter for headquarter data
315 * @return Headquarter data
317 public Headquarter getCompanyHeadQuarter () {
318 return this.companyHeadQuarter;
322 * Setter for headquarter data
324 * @param companyHeadQuarter Headquarter data
326 public void setCompanyHeadQuarter (final Headquarter companyHeadQuarter) {
327 this.companyHeadQuarter = companyHeadQuarter;
331 * Getter for company name
333 * @return Company name
335 public String getCompanyName () {
336 return this.companyName;
340 * Setter for company name
342 * @param companyName Company name
344 public void setCompanyName (final String companyName) {
345 this.companyName = companyName;
349 * Getter for company tax number
351 * @return Company tax number
353 public String getCompanyTaxNumber () {
354 return this.companyTaxNumber;
358 * Setter for company tax number
360 * @param companyTaxNumber Company tax number
362 public void setCompanyTaxNumber (final String companyTaxNumber) {
363 this.companyTaxNumber = companyTaxNumber;
367 * Getter for owning user instance
369 * @return Owning user instance
371 public User getCompanyUserOwner () {
372 return this.companyUserOwner;
376 * Setter for owning user instance
378 * @param companyUserOwner Owning user instance
380 public void setCompanyUserOwner (final User companyUserOwner) {
381 this.companyUserOwner = companyUserOwner;
385 * Getter for company web site URL
387 * @return Company web site URL
389 public String getCompanyWebsiteUrl () {
390 return this.companyWebsiteUrl;
394 * Getter for company web site URL
396 * @param companyWebsiteUrl Company web site URL
398 public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
399 this.companyWebsiteUrl = companyWebsiteUrl;
403 * Getter for fax number's area code
405 * @return Fax number's area code
407 public Integer getFaxAreaCode () {
408 return this.faxAreaCode;
412 * Setter for fax number's area code
414 * @param faxAreaCode Fax number's area code
416 public void setFaxAreaCode (final Integer faxAreaCode) {
417 this.faxAreaCode = faxAreaCode;
421 * Getter for fax's country instance
423 * @return Fax' country instance
425 public Country getFaxCountry () {
426 return this.faxCountry;
430 * Setter for fax's country instance
432 * @param faxCountry Fax' country instance
434 public void setFaxCountry (final Country faxCountry) {
435 this.faxCountry = faxCountry;
439 * Getter for fax number
443 public Long getFaxNumber () {
444 return this.faxNumber;
448 * Setter for fax number
450 * @param faxNumber Fax number
452 public void setFaxNumber (final Long faxNumber) {
453 this.faxNumber = faxNumber;
457 * Getter for land-line number's area code
459 * @return Land-line number's area code
461 public Integer getLandLineAreaCode () {
462 return this.landLineAreaCode;
466 * Setter for land-line number's area code
468 * @param landLineAreaCode Land-line number's area code
470 public void setLandLineAreaCode (final Integer landLineAreaCode) {
471 this.landLineAreaCode = landLineAreaCode;
475 * Getter for land-line number's country instance
477 * @return Land-line number's country instance
479 public Country getLandLineCountry () {
480 return this.landLineCountry;
484 * Setter for land-line number's country instance
486 * @param landLineCountry Land-line number's country instance
488 public void setLandLineCountry (final Country landLineCountry) {
489 this.landLineCountry = landLineCountry;
493 * Getter for land-line number
495 * @return Land-line number
497 public Long getLandLineNumber () {
498 return this.landLineNumber;
502 * Setter for land-line number
504 * @param landLineNumber Land-line number
506 public void setLandLineNumber (final Long landLineNumber) {
507 this.landLineNumber = landLineNumber;