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 java.text.MessageFormat;
20 import java.util.List;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.SessionScoped;
23 import javax.enterprise.event.Observes;
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.BusinessDataSessionBeanRemote;
33 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
34 import org.mxchange.jcountry.data.Country;
35 import org.mxchange.pizzaapplication.beans.BasePizzaController;
36 import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
39 * A business contact bean (controller)
41 * @author Roland Häder<roland@mxchange.org>
43 @Named ("companyDataController")
45 public class PizzaBusinessDataWebSessionBean extends BasePizzaController implements PizzaBusinessDataWebSessionController {
50 private static final long serialVersionUID = 56_189_028_928_371L;
55 private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
58 * A list of all registered companies (globally)
60 private List<BusinessBasicData> businessContacts;
65 private BusinessDataSessionBeanRemote businessDataBean;
68 * Comments for this company
70 private String companyComments;
73 * Companies (main) email address (example: info@company.example)
75 private String companyEmailAddress;
80 private String companyName;
83 * Area code for fax number
85 private Integer faxAreaCode;
88 * Country for fax number
90 private Country faxCountry;
93 * Dial number for fax number
95 private Long faxNumber;
98 * Area code for land-line number
100 private Integer landLineAreaCode;
103 * Country for land-line number
105 private Country landLineCountry;
108 * Dial number for land-line number
110 private Long landLineNumber;
116 private PizzaUserLoginWebSessionController userLoginController;
121 public PizzaBusinessDataWebSessionBean () {
122 // Call super constructor
127 * Observers events being fired when an administrator has added company
130 * @param event Event being fired
132 public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
133 // Is the parameter valid?
136 throw new NullPointerException("event is null");
137 } else if (event.getBasicData() == null) {
139 throw new NullPointerException("event.basicData is null");
140 } else if (event.getBasicData().getCompanyDataId() == null) {
142 throw new NullPointerException("event.basicData.companyDataId is null");
143 } else if (event.getBasicData().getCompanyDataId() < 1) {
145 throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getCompanyDataId()));
146 } else if (event.getBasicData().getCompanyName() == null) {
148 throw new NullPointerException("event.basicData.companyName is null");
149 } else if (event.getBasicData().getCompanyName().isEmpty()) {
151 throw new IllegalArgumentException("event.basicData.companyName is empty");
155 this.businessContacts.add(event.getBasicData());
159 * Returns a list of all business contacts
161 * @return A list of all business contacts
163 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
164 public List<BusinessBasicData> allCompanyBasicData () {
165 return this.businessContacts;
169 * Getter for comments
173 public String getCompanyComments () {
174 return this.companyComments;
178 * Setter for comments
180 * @param companyComments Comments
182 public void setCompanyComments (final String companyComments) {
183 this.companyComments = companyComments;
187 * Getter for company's (main) email address
189 * @return Company's (main) email address
191 public String getCompanyEmailAddress () {
192 return this.companyEmailAddress;
196 * Setter for company's (main) email address
198 * @param companyEmailAddress Company's (main) email address
200 public void setCompanyEmailAddress (final String companyEmailAddress) {
201 this.companyEmailAddress = companyEmailAddress;
205 * Getter for company name
207 * @return Company name
209 public String getCompanyName () {
210 return this.companyName;
214 * Setter for company name
216 * @param companyName Company name
218 public void setCompanyName (final String companyName) {
219 this.companyName = companyName;
223 * Getter for fax number's area code
225 * @return Fax number's area code
227 public Integer getFaxAreaCode () {
228 return this.faxAreaCode;
232 * Setter for fax number's area code
234 * @param faxAreaCode Fax number's area code
236 public void setFaxAreaCode (final Integer faxAreaCode) {
237 this.faxAreaCode = faxAreaCode;
241 * Getter for fax's country instance
243 * @return Fax' country instance
245 public Country getFaxCountry () {
246 return this.faxCountry;
250 * Setter for fax's country instance
252 * @param faxCountry Fax' country instance
254 public void setFaxCountry (final Country faxCountry) {
255 this.faxCountry = faxCountry;
259 * Getter for fax number
263 public Long getFaxNumber () {
264 return this.faxNumber;
268 * Setter for fax number
270 * @param faxNumber Fax number
272 public void setFaxNumber (final Long faxNumber) {
273 this.faxNumber = faxNumber;
277 * Getter for land-line number's area code
279 * @return Land-line number's area code
281 public Integer getLandLineAreaCode () {
282 return this.landLineAreaCode;
286 * Setter for land-line number's area code
288 * @param landLineAreaCode Land-line number's area code
290 public void setLandLineAreaCode (final Integer landLineAreaCode) {
291 this.landLineAreaCode = landLineAreaCode;
295 * Getter for land-line number's country instance
297 * @return Land-line number's country instance
299 public Country getLandLineCountry () {
300 return this.landLineCountry;
304 * Setter for land-line number's country instance
306 * @param landLineCountry Land-line number's country instance
308 public void setLandLineCountry (final Country landLineCountry) {
309 this.landLineCountry = landLineCountry;
313 * Getter for land-line number
315 * @return Land-line number
317 public Long getLandLineNumber () {
318 return this.landLineNumber;
322 * Setter for land-line number
324 * @param landLineNumber Land-line number
326 public void setLandLineNumber (final Long landLineNumber) {
327 this.landLineNumber = landLineNumber;
331 * Post-initialization of this class
334 public void init () {
337 // Get initial context
338 Context context = new InitialContext();
341 this.businessDataBean = (BusinessDataSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote"); //NOI18N
344 this.adminBusinessDataBean = (AdminBusinessDataSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote"); //NOI18N
345 } catch (final NamingException e) {
347 throw new FaceletException(e);
350 // Init user's contact list
351 this.businessContacts = this.adminBusinessDataBean.allCompanyBasicData();