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 fish.payara.cdi.jsr107.impl.NamedCache;
20 import java.text.MessageFormat;
21 import java.util.Iterator;
22 import java.util.LinkedList;
23 import java.util.List;
24 import javax.annotation.PostConstruct;
25 import javax.cache.Cache;
27 import javax.enterprise.context.RequestScoped;
28 import javax.enterprise.event.Observes;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
32 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
33 import org.mxchange.jcountry.model.data.Country;
34 import org.mxchange.pizzaapplication.beans.BasePizzaController;
35 import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
38 * A business contact bean (controller)
40 * @author Roland Häder<roland@mxchange.org>
42 @Named ("companyDataController")
44 public class PizzaBusinessDataWebRequestBean extends BasePizzaController implements PizzaBusinessDataWebRequestController {
49 private static final long serialVersionUID = 56_189_028_928_371L;
52 * EJB for administrative basic business data purposes
54 @EJB (lookup = "java:global/jfinancials-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote", description = "A stateless session bean for administrative purposes.")
55 private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
58 * A list of all registered companies (globally)
61 @NamedCache (cacheName = "basicDataCache", managementEnabled = true)
62 private transient Cache<Long, BusinessBasicData> basicDataCache;
65 * EJB for general basic business data purposes
67 @EJB (lookup = "java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
68 private BusinessDataSessionBeanRemote businessDataBean;
71 * Comments for this company
73 private String companyComments;
76 * Companies (main) email address (example: info@company.example)
78 private String companyEmailAddress;
83 private String companyName;
86 * Area code for fax number
88 private Integer faxAreaCode;
91 * Country for fax number
93 private Country faxCountry;
96 * Dial number for fax number
98 private Long faxNumber;
101 * Area code for land-line number
103 private Integer landLineAreaCode;
106 * Country for land-line number
108 private Country landLineCountry;
111 * Dial number for land-line number
113 private Long landLineNumber;
119 private PizzaUserLoginWebSessionController userLoginController;
124 public PizzaBusinessDataWebRequestBean () {
125 // Call super constructor
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.basicDataCache.put(event.getBasicData().getCompanyDataId(), 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 List<BusinessBasicData> list = new LinkedList<>();
172 Iterator<Cache.Entry<Long, BusinessBasicData>> iterator = this.basicDataCache.iterator();
175 while (iterator.hasNext()) {
177 final Cache.Entry<Long, BusinessBasicData> next = iterator.next();
180 list.add(next.getValue());
188 * Getter for comments
192 public String getCompanyComments () {
193 return this.companyComments;
197 * Setter for comments
199 * @param companyComments Comments
201 public void setCompanyComments (final String companyComments) {
202 this.companyComments = companyComments;
206 * Getter for company's (main) email address
208 * @return Company's (main) email address
210 public String getCompanyEmailAddress () {
211 return this.companyEmailAddress;
215 * Setter for company's (main) email address
217 * @param companyEmailAddress Company's (main) email address
219 public void setCompanyEmailAddress (final String companyEmailAddress) {
220 this.companyEmailAddress = companyEmailAddress;
224 * Getter for company cacheName
226 * @return Company cacheName
228 public String getCompanyName () {
229 return this.companyName;
233 * Setter for company cacheName
235 * @param companyName Company cacheName
237 public void setCompanyName (final String companyName) {
238 this.companyName = companyName;
242 * Getter for fax number's area code
244 * @return Fax number's area code
246 public Integer getFaxAreaCode () {
247 return this.faxAreaCode;
251 * Setter for fax number's area code
253 * @param faxAreaCode Fax number's area code
255 public void setFaxAreaCode (final Integer faxAreaCode) {
256 this.faxAreaCode = faxAreaCode;
260 * Getter for fax's country instance
262 * @return Fax' country instance
264 public Country getFaxCountry () {
265 return this.faxCountry;
269 * Setter for fax's country instance
271 * @param faxCountry Fax' country instance
273 public void setFaxCountry (final Country faxCountry) {
274 this.faxCountry = faxCountry;
278 * Getter for fax number
282 public Long getFaxNumber () {
283 return this.faxNumber;
287 * Setter for fax number
289 * @param faxNumber Fax number
291 public void setFaxNumber (final Long faxNumber) {
292 this.faxNumber = faxNumber;
296 * Getter for land-line number's area code
298 * @return Land-line number's area code
300 public Integer getLandLineAreaCode () {
301 return this.landLineAreaCode;
305 * Setter for land-line number's area code
307 * @param landLineAreaCode Land-line number's area code
309 public void setLandLineAreaCode (final Integer landLineAreaCode) {
310 this.landLineAreaCode = landLineAreaCode;
314 * Getter for land-line number's country instance
316 * @return Land-line number's country instance
318 public Country getLandLineCountry () {
319 return this.landLineCountry;
323 * Setter for land-line number's country instance
325 * @param landLineCountry Land-line number's country instance
327 public void setLandLineCountry (final Country landLineCountry) {
328 this.landLineCountry = landLineCountry;
332 * Getter for land-line number
334 * @return Land-line number
336 public Long getLandLineNumber () {
337 return this.landLineNumber;
341 * Setter for land-line number
343 * @param landLineNumber Land-line number
345 public void setLandLineNumber (final Long landLineNumber) {
346 this.landLineNumber = landLineNumber;
353 public void initializeList () {
355 if (!this.basicDataCache.iterator().hasNext()) {
357 List<BusinessBasicData> list = this.businessDataBean.allCompanyBasicData();
360 for (final Iterator<BusinessBasicData> iterator = list.iterator(); iterator.hasNext();) {
362 final BusinessBasicData next = iterator.next();
365 this.basicDataCache.put(next.getCompanyDataId(), next);
373 private void clear () {
375 this.setCompanyComments(null);
376 this.setCompanyEmailAddress(null);
377 this.setCompanyName(null);
378 this.setFaxAreaCode(null);
379 this.setFaxCountry(null);
380 this.setFaxNumber(null);
381 this.setLandLineAreaCode(null);
382 this.setLandLineCountry(null);
383 this.setLandLineNumber(null);