2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.addressbook.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.addressbook.beans.BaseAddressbookBean;
32 import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
33 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
34 import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
35 import org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote;
36 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
37 import org.mxchange.jcountry.model.data.Country;
40 * A business contact bean (controller)
42 * @author Roland Häder<roland@mxchange.org>
44 @Named ("basicDataController")
46 public class AddressbookBusinessDataWebRequestBean extends BaseAddressbookBean implements AddressbookBusinessDataWebRequestController {
51 private static final long serialVersionUID = 56_189_028_928_371L;
54 * EJB for administrative basic business data purposes
56 @EJB (lookup = "java:global/addressbook-ejb/adminBasicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote", description = "A stateless session bean for administrative purposes.")
57 private AdminBasicCompanyDataSessionBeanRemote adminBasicCompanyDataBean;
60 * A list of all registered companies (globally)
63 @NamedCache (cacheName = "basicDataCache")
64 private Cache<Long, BusinessBasicData> basicDataCache;
67 * EJB for general basic business data purposes
69 @EJB (lookup = "java:global/addressbook-ejb/basicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
70 private BasicCompanyDataSessionBeanRemote businessDataBean;
73 * Comments for this company
75 private String companyComments;
78 * Companies (main) email address (example: info@company.example)
80 private String companyEmailAddress;
85 private String companyName;
88 * Area code for fax number
90 private Integer faxAreaCode;
93 * Country for fax number
95 private Country faxCountry;
98 * Dial number for fax number
100 private Long faxNumber;
103 * Area code for land-line number
105 private Integer landLineAreaCode;
108 * Country for land-line number
110 private Country landLineCountry;
113 * Dial number for land-line number
115 private Long landLineNumber;
121 private AddressbookUserLoginWebSessionController userLoginController;
126 public AddressbookBusinessDataWebRequestBean () {
127 // Call super constructor
132 * Observers events being fired when an administrator has added company
135 * @param event Event being fired
137 public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
138 // Is the parameter valid?
141 throw new NullPointerException("event is null");
142 } else if (event.getBasicData() == null) {
144 throw new NullPointerException("event.basicData is null");
145 } else if (event.getBasicData().getBasicDataId() == null) {
147 throw new NullPointerException("event.basicData.basicDataId is null");
148 } else if (event.getBasicData().getBasicDataId() < 1) {
150 throw new IllegalArgumentException(MessageFormat.format("event.basicData.basicDataId={0} is invalid", event.getBasicData().getBasicDataId()));
151 } else if (event.getBasicData().getCompanyName() == null) {
153 throw new NullPointerException("event.basicData.companyName is null");
154 } else if (event.getBasicData().getCompanyName().isEmpty()) {
156 throw new IllegalArgumentException("event.basicData.companyName is empty");
160 this.basicDataCache.put(event.getBasicData().getBasicDataId(), event.getBasicData());
164 * Returns a list of all business contacts
166 * @return A list of all business contacts
168 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
169 public List<BusinessBasicData> allCompanyBasicData () {
171 final List<BusinessBasicData> list = new LinkedList<>();
174 final Iterator<Cache.Entry<Long, BusinessBasicData>> iterator = this.basicDataCache.iterator();
177 while (iterator.hasNext()) {
179 final Cache.Entry<Long, BusinessBasicData> next = iterator.next();
182 list.add(next.getValue());
190 * Getter for comments
194 public String getCompanyComments () {
195 return this.companyComments;
199 * Setter for comments
201 * @param companyComments Comments
203 public void setCompanyComments (final String companyComments) {
204 this.companyComments = companyComments;
208 * Getter for company's (main) email address
210 * @return Company's (main) email address
212 public String getCompanyEmailAddress () {
213 return this.companyEmailAddress;
217 * Setter for company's (main) email address
219 * @param companyEmailAddress Company's (main) email address
221 public void setCompanyEmailAddress (final String companyEmailAddress) {
222 this.companyEmailAddress = companyEmailAddress;
226 * Getter for company cacheName
228 * @return Company cacheName
230 public String getCompanyName () {
231 return this.companyName;
235 * Setter for company cacheName
237 * @param companyName Company cacheName
239 public void setCompanyName (final String companyName) {
240 this.companyName = companyName;
244 * Getter for fax number's area code
246 * @return Fax number's area code
248 public Integer getFaxAreaCode () {
249 return this.faxAreaCode;
253 * Setter for fax number's area code
255 * @param faxAreaCode Fax number's area code
257 public void setFaxAreaCode (final Integer faxAreaCode) {
258 this.faxAreaCode = faxAreaCode;
262 * Getter for fax's country instance
264 * @return Fax' country instance
266 public Country getFaxCountry () {
267 return this.faxCountry;
271 * Setter for fax's country instance
273 * @param faxCountry Fax' country instance
275 public void setFaxCountry (final Country faxCountry) {
276 this.faxCountry = faxCountry;
280 * Getter for fax number
284 public Long getFaxNumber () {
285 return this.faxNumber;
289 * Setter for fax number
291 * @param faxNumber Fax number
293 public void setFaxNumber (final Long faxNumber) {
294 this.faxNumber = faxNumber;
298 * Getter for land-line number's area code
300 * @return Land-line number's area code
302 public Integer getLandLineAreaCode () {
303 return this.landLineAreaCode;
307 * Setter for land-line number's area code
309 * @param landLineAreaCode Land-line number's area code
311 public void setLandLineAreaCode (final Integer landLineAreaCode) {
312 this.landLineAreaCode = landLineAreaCode;
316 * Getter for land-line number's country instance
318 * @return Land-line number's country instance
320 public Country getLandLineCountry () {
321 return this.landLineCountry;
325 * Setter for land-line number's country instance
327 * @param landLineCountry Land-line number's country instance
329 public void setLandLineCountry (final Country landLineCountry) {
330 this.landLineCountry = landLineCountry;
334 * Getter for land-line number
336 * @return Land-line number
338 public Long getLandLineNumber () {
339 return this.landLineNumber;
343 * Setter for land-line number
345 * @param landLineNumber Land-line number
347 public void setLandLineNumber (final Long landLineNumber) {
348 this.landLineNumber = landLineNumber;
355 public void initializeList () {
357 if (!this.basicDataCache.iterator().hasNext()) {
359 final List<BusinessBasicData> list = this.businessDataBean.allCompanyBasicData();
362 for (final Iterator<BusinessBasicData> iterator = list.iterator(); iterator.hasNext();) {
364 final BusinessBasicData next = iterator.next();
367 this.basicDataCache.put(next.getBasicDataId(), next);
375 private void clear () {
377 this.setCompanyComments(null);
378 this.setCompanyEmailAddress(null);
379 this.setCompanyName(null);
380 this.setFaxAreaCode(null);
381 this.setFaxCountry(null);
382 this.setFaxNumber(null);
383 this.setLandLineAreaCode(null);
384 this.setLandLineCountry(null);
385 this.setLandLineNumber(null);