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.pizzaapplication.beans.business.basicdata;
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.AdminAddedBusinessBasicDataEvent;
35 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
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.jphone.phonenumbers.fax.DialableFaxNumber;
40 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
41 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
42 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
43 import org.mxchange.jusercore.model.user.User;
44 import org.mxchange.pizzaapplication.beans.BasePizzaController;
47 * An administrative business contact bean (controller)
49 * @author Roland Häder<roland@mxchange.org>
51 @Named ("adminCompanyDataController")
53 public class PizzaAdminBusinessDataWebRequestBean extends BasePizzaController implements PizzaAdminBusinessDataWebRequestController {
58 private static final long serialVersionUID = 56_189_028_928_374L;
63 private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
66 * An event being fired when basic business data has been added
70 private Event<ObservableAdminAddedBusinessBasicDataEvent> businessDataAddedEvent;
73 * Comments for this company
75 private String companyComments;
78 * An employee as contact person with this company
80 private Employee companyContactEmployee;
83 * Companies (main) email address (example: info@company.example)
85 private String companyEmailAddress;
90 private Employee companyFounder;
93 * Head quarter data for this company
95 private HeadquartersData companyHeadQuarters;
100 private String companyName;
105 private String companyTaxNumber;
108 * Owning user instance (which this company is assigned to)
110 private User companyUserOwner;
115 private String companyWebsiteUrl;
118 * Area code for fax number
120 private Integer faxAreaCode;
123 * Country for fax number
125 private Country faxCountry;
128 * Dial number for fax number
130 private Long faxNumber;
133 * Area code for land-line number
135 private Integer landLineAreaCode;
138 * Country for land-line number
140 private Country landLineCountry;
143 * Dial number for land-line number
145 private Long landLineNumber;
148 * Default constructor
150 public PizzaAdminBusinessDataWebRequestBean () {
151 // Call super constructor
156 * Adds a basic business data entry, if not yet found.
158 * @return Redirect outcome
160 public String addBusinessBasicData () {
161 // First, validate all parameter
162 if (this.getCompanyName() == null) {
164 throw new NullPointerException("this.companyName is null"); //NOI18N
165 } else if (this.getCompanyName().isEmpty()) {
167 throw new IllegalArgumentException("this.companyName is empty"); //NOI18N
171 BusinessBasicData basicData = new CompanyBasicData(this.getCompanyName());
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());
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());
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) {
194 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
195 } else if (landLine.getPhoneAreaCode() < 1) {
197 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
198 } else if (landLine.getPhoneNumber() == null) {
200 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
201 } else if (landLine.getPhoneNumber() < 1) {
203 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
207 basicData.setCompanyLandLineNumber(landLine);
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) {
215 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
216 } else if (fax.getPhoneAreaCode() < 1) {
218 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
219 } else if (fax.getPhoneNumber() == null) {
221 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
222 } else if (fax.getPhoneNumber() < 1) {
224 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
228 basicData.setCompanyFaxNumber(fax);
231 // Now try to send to EJB and get an updated version back
234 BusinessBasicData updatedBasicData = this.adminBusinessDataBean.addCompanyBasicData(basicData);
237 this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
238 } catch (final BusinessDataAlreadyAddedException e) {
239 // Does already exist
240 throw new FacesException(e);
243 // Continue to list again
244 return "admin_list_business_contacts"; //NOI18N
248 * Getter for comments
252 public String getCompanyComments () {
253 return this.companyComments;
257 * Setter for comments
259 * @param companyComments Comments
261 public void setCompanyComments (final String companyComments) {
262 this.companyComments = companyComments;
266 * Getter for employee as contact person
268 * @return Employee as contact person
270 public Employee getCompanyContactEmployee () {
271 return this.companyContactEmployee;
275 * Setter for employee as contact person
277 * @param companyContactEmployee Employee as contact person
279 public void setCompanyContactEmployee (final Employee companyContactEmployee) {
280 this.companyContactEmployee = companyContactEmployee;
284 * Getter for company's (main) email address
286 * @return Company's (main) email address
288 public String getCompanyEmailAddress () {
289 return this.companyEmailAddress;
293 * Setter for company's (main) email address
295 * @param companyEmailAddress Company's (main) email address
297 public void setCompanyEmailAddress (final String companyEmailAddress) {
298 this.companyEmailAddress = companyEmailAddress;
302 * Getter for company founder
304 * @return Company founder
306 public Employee getCompanyFounder () {
307 return this.companyFounder;
311 * Setter for company founder
313 * @param companyFounder Company founder
315 public void setCompanyFounder (final Employee companyFounder) {
316 this.companyFounder = companyFounder;
320 * Getter for headquarters data
322 * @return Headquarters data
324 public HeadquartersData getCompanyHeadQuarters () {
325 return this.companyHeadQuarters;
329 * Setter for headquarters data
331 * @param companyHeadQuarters Headquarters data
333 public void setCompanyHeadQuarters (final HeadquartersData companyHeadQuarters) {
334 this.companyHeadQuarters = companyHeadQuarters;
338 * Getter for company name
340 * @return Company name
342 public String getCompanyName () {
343 return this.companyName;
347 * Setter for company name
349 * @param companyName Company name
351 public void setCompanyName (final String companyName) {
352 this.companyName = companyName;
356 * Getter for company tax number
358 * @return Company tax number
360 public String getCompanyTaxNumber () {
361 return this.companyTaxNumber;
365 * Setter for company tax number
367 * @param companyTaxNumber Company tax number
369 public void setCompanyTaxNumber (final String companyTaxNumber) {
370 this.companyTaxNumber = companyTaxNumber;
374 * Getter for owning user instance
376 * @return Owning user instance
378 public User getCompanyUserOwner () {
379 return this.companyUserOwner;
383 * Setter for owning user instance
385 * @param companyUserOwner Owning user instance
387 public void setCompanyUserOwner (final User companyUserOwner) {
388 this.companyUserOwner = companyUserOwner;
392 * Getter for company web site URL
394 * @return Company web site URL
396 public String getCompanyWebsiteUrl () {
397 return this.companyWebsiteUrl;
401 * Getter for company web site URL
403 * @param companyWebsiteUrl Company web site URL
405 public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
406 this.companyWebsiteUrl = companyWebsiteUrl;
410 * Getter for fax number's area code
412 * @return Fax number's area code
414 public Integer getFaxAreaCode () {
415 return this.faxAreaCode;
419 * Setter for fax number's area code
421 * @param faxAreaCode Fax number's area code
423 public void setFaxAreaCode (final Integer faxAreaCode) {
424 this.faxAreaCode = faxAreaCode;
428 * Getter for fax's country instance
430 * @return Fax' country instance
432 public Country getFaxCountry () {
433 return this.faxCountry;
437 * Setter for fax's country instance
439 * @param faxCountry Fax' country instance
441 public void setFaxCountry (final Country faxCountry) {
442 this.faxCountry = faxCountry;
446 * Getter for fax number
450 public Long getFaxNumber () {
451 return this.faxNumber;
455 * Setter for fax number
457 * @param faxNumber Fax number
459 public void setFaxNumber (final Long faxNumber) {
460 this.faxNumber = faxNumber;
464 * Getter for land-line number's area code
466 * @return Land-line number's area code
468 public Integer getLandLineAreaCode () {
469 return this.landLineAreaCode;
473 * Setter for land-line number's area code
475 * @param landLineAreaCode Land-line number's area code
477 public void setLandLineAreaCode (final Integer landLineAreaCode) {
478 this.landLineAreaCode = landLineAreaCode;
482 * Getter for land-line number's country instance
484 * @return Land-line number's country instance
486 public Country getLandLineCountry () {
487 return this.landLineCountry;
491 * Setter for land-line number's country instance
493 * @param landLineCountry Land-line number's country instance
495 public void setLandLineCountry (final Country landLineCountry) {
496 this.landLineCountry = landLineCountry;
500 * Getter for land-line number
502 * @return Land-line number
504 public Long getLandLineNumber () {
505 return this.landLineNumber;
509 * Setter for land-line number
511 * @param landLineNumber Land-line number
513 public void setLandLineNumber (final Long landLineNumber) {
514 this.landLineNumber = landLineNumber;
518 * Post-initialization of this class
521 public void init () {
524 // Get initial context
525 Context context = new InitialContext();
528 this.adminBusinessDataBean = (AdminBusinessDataSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote"); //NOI18N
529 } catch (final NamingException e) {
531 throw new FaceletException(e);