2 * Copyright (C) 2016, 2017 Roland Häder
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.addressbook.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.addressbook.beans.BaseAddressbookController;
27 import org.mxchange.jcontactsbusiness.model.basicdata.AdminBusinessDataSessionBeanRemote;
28 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
29 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
30 import org.mxchange.jcontactsbusiness.model.employee.Employee;
31 import org.mxchange.jcontactsbusiness.events.basicdata.added.AdminAddedBusinessBasicDataEvent;
32 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
33 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataAlreadyAddedException;
34 import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
35 import org.mxchange.jcountry.model.data.Country;
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 ("adminCompanyDataController")
49 public class AddressbookAdminBusinessDataWebRequestBean extends BaseAddressbookController implements AddressbookAdminBusinessDataWebRequestController {
54 private static final long serialVersionUID = 56_189_028_928_374L;
57 * EJB for administrative purposes
59 @EJB (lookup = "java:global/addressbook-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote")
60 private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
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 Employee companyContactEmployee;
80 * Companies (main) email address (example: info@company.example)
82 private String companyEmailAddress;
87 private Employee companyFounder;
90 * Head quarter data for this company
92 private HeadquartersData companyHeadQuarters;
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 AddressbookAdminBusinessDataWebRequestBean () {
148 // Call super constructor
153 * Adds a basic business data entry, if not yet found.
155 * @return Redirect outcome
157 public String addBusinessBasicData () {
158 // First, validate all parameter
159 if (this.getCompanyName() == null) {
161 throw new NullPointerException("this.companyName is null"); //NOI18N
162 } else if (this.getCompanyName().isEmpty()) {
164 throw new IllegalArgumentException("this.companyName is empty"); //NOI18N
168 BusinessBasicData basicData = new CompanyBasicData(this.getCompanyName());
170 // Set all opther remaining data
171 basicData.setCompanyComments(this.getCompanyComments());
172 basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
173 basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
174 basicData.setCompanyFounder(this.getCompanyFounder());
175 basicData.setCompanyHeadQuartersData(this.getCompanyHeadQuarters());
176 basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
177 basicData.setCompanyUserOwner(this.getCompanyUserOwner());
178 basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
181 // @TODO basicData.setCompanyLogo();
182 // Generate phone number
183 DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
184 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
186 // Don't set null or wrong references
187 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
188 // Now the number must be given
189 if (landLine.getPhoneAreaCode() == null) {
191 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
192 } else if (landLine.getPhoneAreaCode() < 1) {
194 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
195 } else if (landLine.getPhoneNumber() == null) {
197 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
198 } else if (landLine.getPhoneNumber() < 1) {
200 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
204 basicData.setCompanyLandLineNumber(landLine);
207 // Don't set null or wrong references
208 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
209 // Now the number must be given
210 if (fax.getPhoneAreaCode() == null) {
212 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
213 } else if (fax.getPhoneAreaCode() < 1) {
215 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
216 } else if (fax.getPhoneNumber() == null) {
218 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
219 } else if (fax.getPhoneNumber() < 1) {
221 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
225 basicData.setCompanyFaxNumber(fax);
228 // Now try to send to EJB and get an updated version back
231 BusinessBasicData updatedBasicData = this.adminBusinessDataBean.addCompanyBasicData(basicData);
234 this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
235 } catch (final BusinessDataAlreadyAddedException e) {
236 // Does already exist
237 throw new FacesException(e);
240 // Continue to list again
241 return "admin_list_business_contacts"; //NOI18N
245 * Getter for comments
249 public String getCompanyComments () {
250 return this.companyComments;
254 * Setter for comments
256 * @param companyComments Comments
258 public void setCompanyComments (final String companyComments) {
259 this.companyComments = companyComments;
263 * Getter for employee as contact person
265 * @return Employee as contact person
267 public Employee getCompanyContactEmployee () {
268 return this.companyContactEmployee;
272 * Setter for employee as contact person
274 * @param companyContactEmployee Employee as contact person
276 public void setCompanyContactEmployee (final Employee companyContactEmployee) {
277 this.companyContactEmployee = companyContactEmployee;
281 * Getter for company's (main) email address
283 * @return Company's (main) email address
285 public String getCompanyEmailAddress () {
286 return this.companyEmailAddress;
290 * Setter for company's (main) email address
292 * @param companyEmailAddress Company's (main) email address
294 public void setCompanyEmailAddress (final String companyEmailAddress) {
295 this.companyEmailAddress = companyEmailAddress;
299 * Getter for company founder
301 * @return Company founder
303 public Employee getCompanyFounder () {
304 return this.companyFounder;
308 * Setter for company founder
310 * @param companyFounder Company founder
312 public void setCompanyFounder (final Employee companyFounder) {
313 this.companyFounder = companyFounder;
317 * Getter for headquarters data
319 * @return Headquarters data
321 public HeadquartersData getCompanyHeadQuarters () {
322 return this.companyHeadQuarters;
326 * Setter for headquarters data
328 * @param companyHeadQuarters Headquarters data
330 public void setCompanyHeadQuarters (final HeadquartersData companyHeadQuarters) {
331 this.companyHeadQuarters = companyHeadQuarters;
335 * Getter for company name
337 * @return Company name
339 public String getCompanyName () {
340 return this.companyName;
344 * Setter for company name
346 * @param companyName Company name
348 public void setCompanyName (final String companyName) {
349 this.companyName = companyName;
353 * Getter for company tax number
355 * @return Company tax number
357 public String getCompanyTaxNumber () {
358 return this.companyTaxNumber;
362 * Setter for company tax number
364 * @param companyTaxNumber Company tax number
366 public void setCompanyTaxNumber (final String companyTaxNumber) {
367 this.companyTaxNumber = companyTaxNumber;
371 * Getter for owning user instance
373 * @return Owning user instance
375 public User getCompanyUserOwner () {
376 return this.companyUserOwner;
380 * Setter for owning user instance
382 * @param companyUserOwner Owning user instance
384 public void setCompanyUserOwner (final User companyUserOwner) {
385 this.companyUserOwner = companyUserOwner;
389 * Getter for company web site URL
391 * @return Company web site URL
393 public String getCompanyWebsiteUrl () {
394 return this.companyWebsiteUrl;
398 * Getter for company web site URL
400 * @param companyWebsiteUrl Company web site URL
402 public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
403 this.companyWebsiteUrl = companyWebsiteUrl;
407 * Getter for fax number's area code
409 * @return Fax number's area code
411 public Integer getFaxAreaCode () {
412 return this.faxAreaCode;
416 * Setter for fax number's area code
418 * @param faxAreaCode Fax number's area code
420 public void setFaxAreaCode (final Integer faxAreaCode) {
421 this.faxAreaCode = faxAreaCode;
425 * Getter for fax's country instance
427 * @return Fax' country instance
429 public Country getFaxCountry () {
430 return this.faxCountry;
434 * Setter for fax's country instance
436 * @param faxCountry Fax' country instance
438 public void setFaxCountry (final Country faxCountry) {
439 this.faxCountry = faxCountry;
443 * Getter for fax number
447 public Long getFaxNumber () {
448 return this.faxNumber;
452 * Setter for fax number
454 * @param faxNumber Fax number
456 public void setFaxNumber (final Long faxNumber) {
457 this.faxNumber = faxNumber;
461 * Getter for land-line number's area code
463 * @return Land-line number's area code
465 public Integer getLandLineAreaCode () {
466 return this.landLineAreaCode;
470 * Setter for land-line number's area code
472 * @param landLineAreaCode Land-line number's area code
474 public void setLandLineAreaCode (final Integer landLineAreaCode) {
475 this.landLineAreaCode = landLineAreaCode;
479 * Getter for land-line number's country instance
481 * @return Land-line number's country instance
483 public Country getLandLineCountry () {
484 return this.landLineCountry;
488 * Setter for land-line number's country instance
490 * @param landLineCountry Land-line number's country instance
492 public void setLandLineCountry (final Country landLineCountry) {
493 this.landLineCountry = landLineCountry;
497 * Getter for land-line number
499 * @return Land-line number
501 public Long getLandLineNumber () {
502 return this.landLineNumber;
506 * Setter for land-line number
508 * @param landLineNumber Land-line number
510 public void setLandLineNumber (final Long landLineNumber) {
511 this.landLineNumber = landLineNumber;