]> git.mxchange.org Git - addressbook-war.git/blob
de80c145da716611cd7d17b71aff4bab6af75c19
[addressbook-war.git] /
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.beans.business.basicdata;
18
19 import java.text.MessageFormat;
20 import java.util.LinkedList;
21 import java.util.List;
22 import javax.ejb.EJB;
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.addressbook.beans.BaseAddressbookController;
28 import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
29 import org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote;
30 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
31 import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote;
32 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
33 import org.mxchange.jcountry.data.Country;
34
35 /**
36  * A business contact bean (controller)
37  * <p>
38  * @author Roland Häder<roland@mxchange.org>
39  */
40 @Named ("companyDataController")
41 @SessionScoped
42 public class AddressbookBusinessDataWebSessionBean extends BaseAddressbookController implements AddressbookBusinessDataWebSessionController {
43
44         /**
45          * Serial number
46          */
47         private static final long serialVersionUID = 56_189_028_928_371L;
48
49         /**
50          * EJB for administrative basic business data purposes
51          */
52         @EJB (lookup = "java:global/addressbook-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote", description = "A stateless session bean for administrative purposes.")
53         private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
54
55         /**
56          * A list of all registered companies (globally)
57          */
58         private final List<BusinessBasicData> businessContacts;
59
60         /**
61          * EJB for general basic business data purposes
62          */
63         @EJB (lookup = "java:global/addressbook-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
64         private BusinessDataSessionBeanRemote businessDataBean;
65
66         /**
67          * Comments for this company
68          */
69         private String companyComments;
70
71         /**
72          * Companies (main) email address (example: info@company.example)
73          */
74         private String companyEmailAddress;
75
76         /**
77          * Company name
78          */
79         private String companyName;
80
81         /**
82          * Area code for fax number
83          */
84         private Integer faxAreaCode;
85
86         /**
87          * Country for fax number
88          */
89         private Country faxCountry;
90
91         /**
92          * Dial number for fax number
93          */
94         private Long faxNumber;
95
96         /**
97          * Area code for land-line number
98          */
99         private Integer landLineAreaCode;
100
101         /**
102          * Country for land-line number
103          */
104         private Country landLineCountry;
105
106         /**
107          * Dial number for land-line number
108          */
109         private Long landLineNumber;
110
111         /**
112          * User instance
113          */
114         @Inject
115         private AddressbookUserLoginWebSessionController userLoginController;
116
117         /**
118          * Constructor
119          */
120         public AddressbookBusinessDataWebSessionBean () {
121                 // Call super constructor
122                 super();
123
124                 // Init list
125                 this.businessContacts = new LinkedList<>();
126         }
127
128         /**
129          * Observers events being fired when an administrator has added company
130          * basic data.
131          * <p>
132          * @param event Event being fired
133          */
134         public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
135                 // Is the parameter valid?
136                 if (null == event) {
137                         // Throw NPE
138                         throw new NullPointerException("event is null");
139                 } else if (event.getBasicData() == null) {
140                         // Throw NPE again
141                         throw new NullPointerException("event.basicData is null");
142                 } else if (event.getBasicData().getCompanyDataId() == null) {
143                         // Throw NPE again
144                         throw new NullPointerException("event.basicData.companyDataId is null");
145                 } else if (event.getBasicData().getCompanyDataId() < 1) {
146                         // Throw IAE
147                         throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getCompanyDataId()));
148                 } else if (event.getBasicData().getCompanyName() == null) {
149                         // Throw NPE again
150                         throw new NullPointerException("event.basicData.companyName is null");
151                 } else if (event.getBasicData().getCompanyName().isEmpty()) {
152                         // Throw IAE again
153                         throw new IllegalArgumentException("event.basicData.companyName is empty");
154                 }
155
156                 // Initialize list
157                 this.initializeList();
158
159                 // Add it to list
160                 this.businessContacts.add(event.getBasicData());
161         }
162
163         /**
164          * Returns a list of all business contacts
165          * <p>
166          * @return A list of all business contacts
167          */
168         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
169         public List<BusinessBasicData> allCompanyBasicData () {
170                 // Initialize list
171                 this.initializeList();
172
173                 // Return it
174                 return this.businessContacts;
175         }
176
177         /**
178          * Getter for comments
179          * <p>
180          * @return Comments
181          */
182         public String getCompanyComments () {
183                 return this.companyComments;
184         }
185
186         /**
187          * Setter for comments
188          * <p>
189          * @param companyComments Comments
190          */
191         public void setCompanyComments (final String companyComments) {
192                 this.companyComments = companyComments;
193         }
194
195         /**
196          * Getter for company's (main) email address
197          * <p>
198          * @return Company's (main) email address
199          */
200         public String getCompanyEmailAddress () {
201                 return this.companyEmailAddress;
202         }
203
204         /**
205          * Setter for company's (main) email address
206          * <p>
207          * @param companyEmailAddress Company's (main) email address
208          */
209         public void setCompanyEmailAddress (final String companyEmailAddress) {
210                 this.companyEmailAddress = companyEmailAddress;
211         }
212
213         /**
214          * Getter for company name
215          * <p>
216          * @return Company name
217          */
218         public String getCompanyName () {
219                 return this.companyName;
220         }
221
222         /**
223          * Setter for company name
224          * <p>
225          * @param companyName Company name
226          */
227         public void setCompanyName (final String companyName) {
228                 this.companyName = companyName;
229         }
230
231         /**
232          * Getter for fax number's area code
233          * <p>
234          * @return Fax number's area code
235          */
236         public Integer getFaxAreaCode () {
237                 return this.faxAreaCode;
238         }
239
240         /**
241          * Setter for fax number's area code
242          * <p>
243          * @param faxAreaCode Fax number's area code
244          */
245         public void setFaxAreaCode (final Integer faxAreaCode) {
246                 this.faxAreaCode = faxAreaCode;
247         }
248
249         /**
250          * Getter for fax's country instance
251          * <p>
252          * @return Fax' country instance
253          */
254         public Country getFaxCountry () {
255                 return this.faxCountry;
256         }
257
258         /**
259          * Setter for fax's country instance
260          * <p>
261          * @param faxCountry Fax' country instance
262          */
263         public void setFaxCountry (final Country faxCountry) {
264                 this.faxCountry = faxCountry;
265         }
266
267         /**
268          * Getter for fax number
269          * <p>
270          * @return Fax number
271          */
272         public Long getFaxNumber () {
273                 return this.faxNumber;
274         }
275
276         /**
277          * Setter for fax number
278          * <p>
279          * @param faxNumber Fax number
280          */
281         public void setFaxNumber (final Long faxNumber) {
282                 this.faxNumber = faxNumber;
283         }
284
285         /**
286          * Getter for land-line number's area code
287          * <p>
288          * @return Land-line number's area code
289          */
290         public Integer getLandLineAreaCode () {
291                 return this.landLineAreaCode;
292         }
293
294         /**
295          * Setter for land-line number's area code
296          * <p>
297          * @param landLineAreaCode Land-line number's area code
298          */
299         public void setLandLineAreaCode (final Integer landLineAreaCode) {
300                 this.landLineAreaCode = landLineAreaCode;
301         }
302
303         /**
304          * Getter for land-line number's country instance
305          * <p>
306          * @return Land-line number's country instance
307          */
308         public Country getLandLineCountry () {
309                 return this.landLineCountry;
310         }
311
312         /**
313          * Setter for land-line number's country instance
314          * <p>
315          * @param landLineCountry Land-line number's country instance
316          */
317         public void setLandLineCountry (final Country landLineCountry) {
318                 this.landLineCountry = landLineCountry;
319         }
320
321         /**
322          * Getter for land-line number
323          * <p>
324          * @return Land-line number
325          */
326         public Long getLandLineNumber () {
327                 return this.landLineNumber;
328         }
329
330         /**
331          * Setter for land-line number
332          * <p>
333          * @param landLineNumber Land-line number
334          */
335         public void setLandLineNumber (final Long landLineNumber) {
336                 this.landLineNumber = landLineNumber;
337         }
338
339         /**
340          * Initializer method
341          */
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());
347                 }
348         }
349
350 }