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.LinkedList;
21 import java.util.List;
22 import javax.annotation.PostConstruct;
24 import javax.enterprise.context.SessionScoped;
25 import javax.enterprise.event.Observes;
26 import javax.inject.Inject;
27 import javax.inject.Named;
28 import org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote;
29 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
30 import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote;
31 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
32 import org.mxchange.jcountry.data.Country;
33 import org.mxchange.pizzaapplication.beans.BasePizzaController;
34 import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
37 * A business contact bean (controller)
39 * @author Roland Häder<roland@mxchange.org>
41 @Named ("companyDataController")
43 public class PizzaBusinessDataWebSessionBean extends BasePizzaController implements PizzaBusinessDataWebSessionController {
48 private static final long serialVersionUID = 56_189_028_928_371L;
51 * EJB for administrative basic business data purposes
53 @EJB (lookup = "java:global/addressbook-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote", description = "A stateless session bean for administrative purposes.")
54 private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
57 * A list of all registered companies (globally)
59 private final List<BusinessBasicData> businessContacts;
62 * EJB for general basic business data purposes
64 @EJB (lookup = "java:global/addressbook-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
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
126 this.businessContacts = new LinkedList<>();
130 * Observers events being fired when an administrator has added company
133 * @param event Event being fired
135 public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
136 // Is the parameter valid?
139 throw new NullPointerException("event is null");
140 } else if (event.getBasicData() == null) {
142 throw new NullPointerException("event.basicData is null");
143 } else if (event.getBasicData().getCompanyDataId() == null) {
145 throw new NullPointerException("event.basicData.companyDataId is null");
146 } else if (event.getBasicData().getCompanyDataId() < 1) {
148 throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getCompanyDataId()));
149 } else if (event.getBasicData().getCompanyName() == null) {
151 throw new NullPointerException("event.basicData.companyName is null");
152 } else if (event.getBasicData().getCompanyName().isEmpty()) {
154 throw new IllegalArgumentException("event.basicData.companyName is empty");
158 this.businessContacts.add(event.getBasicData());
162 * Returns a list of all business contacts
164 * @return A list of all business contacts
166 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
167 public List<BusinessBasicData> allCompanyBasicData () {
169 return this.businessContacts;
173 * Getter for comments
177 public String getCompanyComments () {
178 return this.companyComments;
182 * Setter for comments
184 * @param companyComments Comments
186 public void setCompanyComments (final String companyComments) {
187 this.companyComments = companyComments;
191 * Getter for company's (main) email address
193 * @return Company's (main) email address
195 public String getCompanyEmailAddress () {
196 return this.companyEmailAddress;
200 * Setter for company's (main) email address
202 * @param companyEmailAddress Company's (main) email address
204 public void setCompanyEmailAddress (final String companyEmailAddress) {
205 this.companyEmailAddress = companyEmailAddress;
209 * Getter for company name
211 * @return Company name
213 public String getCompanyName () {
214 return this.companyName;
218 * Setter for company name
220 * @param companyName Company name
222 public void setCompanyName (final String companyName) {
223 this.companyName = companyName;
227 * Getter for fax number's area code
229 * @return Fax number's area code
231 public Integer getFaxAreaCode () {
232 return this.faxAreaCode;
236 * Setter for fax number's area code
238 * @param faxAreaCode Fax number's area code
240 public void setFaxAreaCode (final Integer faxAreaCode) {
241 this.faxAreaCode = faxAreaCode;
245 * Getter for fax's country instance
247 * @return Fax' country instance
249 public Country getFaxCountry () {
250 return this.faxCountry;
254 * Setter for fax's country instance
256 * @param faxCountry Fax' country instance
258 public void setFaxCountry (final Country faxCountry) {
259 this.faxCountry = faxCountry;
263 * Getter for fax number
267 public Long getFaxNumber () {
268 return this.faxNumber;
272 * Setter for fax number
274 * @param faxNumber Fax number
276 public void setFaxNumber (final Long faxNumber) {
277 this.faxNumber = faxNumber;
281 * Getter for land-line number's area code
283 * @return Land-line number's area code
285 public Integer getLandLineAreaCode () {
286 return this.landLineAreaCode;
290 * Setter for land-line number's area code
292 * @param landLineAreaCode Land-line number's area code
294 public void setLandLineAreaCode (final Integer landLineAreaCode) {
295 this.landLineAreaCode = landLineAreaCode;
299 * Getter for land-line number's country instance
301 * @return Land-line number's country instance
303 public Country getLandLineCountry () {
304 return this.landLineCountry;
308 * Setter for land-line number's country instance
310 * @param landLineCountry Land-line number's country instance
312 public void setLandLineCountry (final Country landLineCountry) {
313 this.landLineCountry = landLineCountry;
317 * Getter for land-line number
319 * @return Land-line number
321 public Long getLandLineNumber () {
322 return this.landLineNumber;
326 * Setter for land-line number
328 * @param landLineNumber Land-line number
330 public void setLandLineNumber (final Long landLineNumber) {
331 this.landLineNumber = landLineNumber;
338 public void initializeList () {
339 // Init user's contact list
340 this.businessContacts.addAll(this.adminBusinessDataBean.allCompanyBasicData());