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.Iterator;
21 import java.util.LinkedList;
22 import java.util.List;
23 import javax.annotation.PostConstruct;
25 import javax.enterprise.context.RequestScoped;
26 import javax.enterprise.event.Observes;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
30 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
31 import org.mxchange.jcountry.model.data.Country;
32 import org.mxchange.pizzaapplication.beans.BasePizzaController;
33 import org.mxchange.pizzaapplication.beans.user.login.PizzaUserLoginWebSessionController;
36 * A business contact bean (controller)
38 * @author Roland Häder<roland@mxchange.org>
40 @Named ("companyDataController")
42 public class PizzaBusinessDataWebRequestBean extends BasePizzaController implements PizzaBusinessDataWebRequestController {
47 private static final long serialVersionUID = 56_189_028_928_371L;
50 * EJB for administrative basic business data purposes
52 @EJB (lookup = "java:global/jfinancials-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote", description = "A stateless session bean for administrative purposes.")
53 private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
56 * A list of all registered companies (globally)
59 @Cached (cacheName = "basicDataCache")
60 private transient Cache<Long, BusinessBasicData> basicDataCache;
63 * EJB for general basic business data purposes
65 @EJB (lookup = "java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
66 private BusinessDataSessionBeanRemote businessDataBean;
69 * Comments for this company
71 private String companyComments;
74 * Companies (main) email address (example: info@company.example)
76 private String companyEmailAddress;
81 private String companyName;
84 * Area code for fax number
86 private Integer faxAreaCode;
89 * Country for fax number
91 private Country faxCountry;
94 * Dial number for fax number
96 private Long faxNumber;
99 * Area code for land-line number
101 private Integer landLineAreaCode;
104 * Country for land-line number
106 private Country landLineCountry;
109 * Dial number for land-line number
111 private Long landLineNumber;
117 private PizzaUserLoginWebSessionController userLoginController;
122 public PizzaBusinessDataWebRequestBean () {
123 // Call super constructor
128 * Observers events being fired when an administrator has added company
131 * @param event Event being fired
133 public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
134 // Is the parameter valid?
137 throw new NullPointerException("event is null");
138 } else if (event.getBasicData() == null) {
140 throw new NullPointerException("event.basicData is null");
141 } else if (event.getBasicData().getCompanyDataId() == null) {
143 throw new NullPointerException("event.basicData.companyDataId is null");
144 } else if (event.getBasicData().getCompanyDataId() < 1) {
146 throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getCompanyDataId()));
147 } else if (event.getBasicData().getCompanyName() == null) {
149 throw new NullPointerException("event.basicData.companyName is null");
150 } else if (event.getBasicData().getCompanyName().isEmpty()) {
152 throw new IllegalArgumentException("event.basicData.companyName is empty");
156 this.basicDataCache.put(event.getBasicData().getCompanyDataId(), event.getBasicData());
160 * Returns a list of all business contacts
162 * @return A list of all business contacts
164 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
165 public List<BusinessBasicData> allCompanyBasicData () {
167 List<BusinessBasicData> list = new LinkedList<>();
170 Iterator<Cache.Entry<Long, BusinessBasicData>> iterator = this.basicDataCache.iterator();
173 while (iterator.hasNext()) {
175 final Cache.Entry<Long, BusinessBasicData> next = iterator.next();
178 list.add(next.getValue());
186 * Getter for comments
190 public String getCompanyComments () {
191 return this.companyComments;
195 * Setter for comments
197 * @param companyComments Comments
199 public void setCompanyComments (final String companyComments) {
200 this.companyComments = companyComments;
204 * Getter for company's (main) email address
206 * @return Company's (main) email address
208 public String getCompanyEmailAddress () {
209 return this.companyEmailAddress;
213 * Setter for company's (main) email address
215 * @param companyEmailAddress Company's (main) email address
217 public void setCompanyEmailAddress (final String companyEmailAddress) {
218 this.companyEmailAddress = companyEmailAddress;
222 * Getter for company cacheName
224 * @return Company cacheName
226 public String getCompanyName () {
227 return this.companyName;
231 * Setter for company cacheName
233 * @param companyName Company cacheName
235 public void setCompanyName (final String companyName) {
236 this.companyName = companyName;
240 * Getter for fax number's area code
242 * @return Fax number's area code
244 public Integer getFaxAreaCode () {
245 return this.faxAreaCode;
249 * Setter for fax number's area code
251 * @param faxAreaCode Fax number's area code
253 public void setFaxAreaCode (final Integer faxAreaCode) {
254 this.faxAreaCode = faxAreaCode;
258 * Getter for fax's country instance
260 * @return Fax' country instance
262 public Country getFaxCountry () {
263 return this.faxCountry;
267 * Setter for fax's country instance
269 * @param faxCountry Fax' country instance
271 public void setFaxCountry (final Country faxCountry) {
272 this.faxCountry = faxCountry;
276 * Getter for fax number
280 public Long getFaxNumber () {
281 return this.faxNumber;
285 * Setter for fax number
287 * @param faxNumber Fax number
289 public void setFaxNumber (final Long faxNumber) {
290 this.faxNumber = faxNumber;
294 * Getter for land-line number's area code
296 * @return Land-line number's area code
298 public Integer getLandLineAreaCode () {
299 return this.landLineAreaCode;
303 * Setter for land-line number's area code
305 * @param landLineAreaCode Land-line number's area code
307 public void setLandLineAreaCode (final Integer landLineAreaCode) {
308 this.landLineAreaCode = landLineAreaCode;
312 * Getter for land-line number's country instance
314 * @return Land-line number's country instance
316 public Country getLandLineCountry () {
317 return this.landLineCountry;
321 * Setter for land-line number's country instance
323 * @param landLineCountry Land-line number's country instance
325 public void setLandLineCountry (final Country landLineCountry) {
326 this.landLineCountry = landLineCountry;
330 * Getter for land-line number
332 * @return Land-line number
334 public Long getLandLineNumber () {
335 return this.landLineNumber;
339 * Setter for land-line number
341 * @param landLineNumber Land-line number
343 public void setLandLineNumber (final Long landLineNumber) {
344 this.landLineNumber = landLineNumber;
351 public void initializeList () {
353 if (!this.basicDataCache.iterator().hasNext()) {
355 List<BusinessBasicData> list = this.businessDataBean.allCompanyBasicData();
358 for (final Iterator<BusinessBasicData> iterator = list.iterator(); iterator.hasNext();) {
360 final BusinessBasicData next = iterator.next();
363 this.basicDataCache.put(next.getCompanyDataId(), next);
371 private void clear () {
373 this.setCompanyComments(null);
374 this.setCompanyEmailAddress(null);
375 this.setCompanyName(null);
376 this.setFaxAreaCode(null);
377 this.setFaxCountry(null);
378 this.setFaxNumber(null);
379 this.setLandLineAreaCode(null);
380 this.setLandLineCountry(null);
381 this.setLandLineNumber(null);