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.jfinancials.beans.business.basicdata;
19 import java.text.MessageFormat;
20 import java.util.LinkedList;
21 import java.util.List;
23 import javax.enterprise.context.SessionScoped;
24 import javax.enterprise.event.Observes;
25 import javax.inject.Inject;
26 import javax.inject.Named;
27 import org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote;
28 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
29 import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote;
30 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
31 import org.mxchange.jcountry.data.Country;
32 import org.mxchange.jfinancials.beans.BaseFinancialsController;
33 import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController;
36 * A business contact bean (controller)
38 * @author Roland Häder<roland@mxchange.org>
40 @Named ("companyDataController")
42 public class FinancialsBusinessDataWebSessionBean extends BaseFinancialsController implements FinancialsBusinessDataWebSessionController {
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)
58 private final List<BusinessBasicData> businessContacts;
61 * EJB for general basic business data purposes
63 @EJB (lookup = "java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
64 private BusinessDataSessionBeanRemote businessDataBean;
67 * Comments for this company
69 private String companyComments;
72 * Companies (main) email address (example: info@company.example)
74 private String companyEmailAddress;
79 private String companyName;
82 * Area code for fax number
84 private Integer faxAreaCode;
87 * Country for fax number
89 private Country faxCountry;
92 * Dial number for fax number
94 private Long faxNumber;
97 * Area code for land-line number
99 private Integer landLineAreaCode;
102 * Country for land-line number
104 private Country landLineCountry;
107 * Dial number for land-line number
109 private Long landLineNumber;
115 private FinancialsUserLoginWebSessionController userLoginController;
120 public FinancialsBusinessDataWebSessionBean () {
121 // Call super constructor
125 this.businessContacts = new LinkedList<>();
129 * Observers events being fired when an administrator has added company
132 * @param event Event being fired
134 public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
135 // Is the parameter valid?
138 throw new NullPointerException("event is null");
139 } else if (event.getBasicData() == null) {
141 throw new NullPointerException("event.basicData is null");
142 } else if (event.getBasicData().getCompanyDataId() == null) {
144 throw new NullPointerException("event.basicData.companyDataId is null");
145 } else if (event.getBasicData().getCompanyDataId() < 1) {
147 throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getCompanyDataId()));
148 } else if (event.getBasicData().getCompanyName() == null) {
150 throw new NullPointerException("event.basicData.companyName is null");
151 } else if (event.getBasicData().getCompanyName().isEmpty()) {
153 throw new IllegalArgumentException("event.basicData.companyName is empty");
157 this.initializeList();
160 this.businessContacts.add(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 this.initializeList();
174 return this.businessContacts;
178 * Getter for comments
182 public String getCompanyComments () {
183 return this.companyComments;
187 * Setter for comments
189 * @param companyComments Comments
191 public void setCompanyComments (final String companyComments) {
192 this.companyComments = companyComments;
196 * Getter for company's (main) email address
198 * @return Company's (main) email address
200 public String getCompanyEmailAddress () {
201 return this.companyEmailAddress;
205 * Setter for company's (main) email address
207 * @param companyEmailAddress Company's (main) email address
209 public void setCompanyEmailAddress (final String companyEmailAddress) {
210 this.companyEmailAddress = companyEmailAddress;
214 * Getter for company name
216 * @return Company name
218 public String getCompanyName () {
219 return this.companyName;
223 * Setter for company name
225 * @param companyName Company name
227 public void setCompanyName (final String companyName) {
228 this.companyName = companyName;
232 * Getter for fax number's area code
234 * @return Fax number's area code
236 public Integer getFaxAreaCode () {
237 return this.faxAreaCode;
241 * Setter for fax number's area code
243 * @param faxAreaCode Fax number's area code
245 public void setFaxAreaCode (final Integer faxAreaCode) {
246 this.faxAreaCode = faxAreaCode;
250 * Getter for fax's country instance
252 * @return Fax' country instance
254 public Country getFaxCountry () {
255 return this.faxCountry;
259 * Setter for fax's country instance
261 * @param faxCountry Fax' country instance
263 public void setFaxCountry (final Country faxCountry) {
264 this.faxCountry = faxCountry;
268 * Getter for fax number
272 public Long getFaxNumber () {
273 return this.faxNumber;
277 * Setter for fax number
279 * @param faxNumber Fax number
281 public void setFaxNumber (final Long faxNumber) {
282 this.faxNumber = faxNumber;
286 * Getter for land-line number's area code
288 * @return Land-line number's area code
290 public Integer getLandLineAreaCode () {
291 return this.landLineAreaCode;
295 * Setter for land-line number's area code
297 * @param landLineAreaCode Land-line number's area code
299 public void setLandLineAreaCode (final Integer landLineAreaCode) {
300 this.landLineAreaCode = landLineAreaCode;
304 * Getter for land-line number's country instance
306 * @return Land-line number's country instance
308 public Country getLandLineCountry () {
309 return this.landLineCountry;
313 * Setter for land-line number's country instance
315 * @param landLineCountry Land-line number's country instance
317 public void setLandLineCountry (final Country landLineCountry) {
318 this.landLineCountry = landLineCountry;
322 * Getter for land-line number
324 * @return Land-line number
326 public Long getLandLineNumber () {
327 return this.landLineNumber;
331 * Setter for land-line number
333 * @param landLineNumber Land-line number
335 public void setLandLineNumber (final Long landLineNumber) {
336 this.landLineNumber = landLineNumber;
342 private void initializeList () {
343 // Is the list empty?
344 if (this.businessContacts.isEmpty()) {
345 // Init user's contact list
346 this.businessContacts.addAll(this.adminBusinessDataBean.allCompanyBasicData());