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