]> 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.List;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.SessionScoped;
23 import javax.enterprise.event.Observes;
24 import javax.faces.view.facelets.FaceletException;
25 import javax.inject.Inject;
26 import javax.inject.Named;
27 import javax.naming.Context;
28 import javax.naming.InitialContext;
29 import javax.naming.NamingException;
30 import org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote;
31 import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
32 import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote;
33 import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
34 import org.mxchange.jcountry.data.Country;
35 import org.mxchange.jjobs.beans.BaseJobsController;
36 import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController;
37
38 /**
39  * A business contact bean (controller)
40  * <p>
41  * @author Roland Häder<roland@mxchange.org>
42  */
43 @Named ("companyDataController")
44 @SessionScoped
45 public class JobsBusinessDataWebSessionBean extends BaseJobsController implements JobsBusinessDataWebSessionController {
46
47         /**
48          * Serial number
49          */
50         private static final long serialVersionUID = 56_189_028_928_371L;
51
52         /**
53          * Remote contact bean
54          */
55         private AdminBusinessDataSessionBeanRemote adminBusinessDataBean;
56
57         /**
58          * A list of all registered companies (globally)
59          */
60         private List<BusinessBasicData> businessContacts;
61
62         /**
63          * Remote contact bean
64          */
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
126         /**
127          * Observers events being fired when an administrator has added company
128          * basic data.
129          * <p>
130          * @param event Event being fired
131          */
132         public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
133                 // Is the parameter valid?
134                 if (null == event) {
135                         // Throw NPE
136                         throw new NullPointerException("event is null");
137                 } else if (event.getBasicData() == null) {
138                         // Throw NPE again
139                         throw new NullPointerException("event.basicData is null");
140                 } else if (event.getBasicData().getCompanyDataId() == null) {
141                         // Throw NPE again
142                         throw new NullPointerException("event.basicData.companyDataId is null");
143                 } else if (event.getBasicData().getCompanyDataId() < 1) {
144                         // Throw IAE
145                         throw new IllegalArgumentException(MessageFormat.format("event.basicData.companyDataId={0} is invalid", event.getBasicData().getCompanyDataId()));
146                 } else if (event.getBasicData().getCompanyName() == null) {
147                         // Throw NPE again
148                         throw new NullPointerException("event.basicData.companyName is null");
149                 } else if (event.getBasicData().getCompanyName().isEmpty()) {
150                         // Throw IAE again
151                         throw new IllegalArgumentException("event.basicData.companyName is empty");
152                 }
153
154                 // Add it to list
155                 this.businessContacts.add(event.getBasicData());
156         }
157
158         /**
159          * Returns a list of all business contacts
160          * <p>
161          * @return A list of all business contacts
162          */
163         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
164         public List<BusinessBasicData> allCompanyBasicData () {
165                 return this.businessContacts;
166         }
167
168         /**
169          * Getter for comments
170          * <p>
171          * @return Comments
172          */
173         public String getCompanyComments () {
174                 return this.companyComments;
175         }
176
177         /**
178          * Setter for comments
179          * <p>
180          * @param companyComments Comments
181          */
182         public void setCompanyComments (final String companyComments) {
183                 this.companyComments = companyComments;
184         }
185
186         /**
187          * Getter for company's (main) email address
188          * <p>
189          * @return Company's (main) email address
190          */
191         public String getCompanyEmailAddress () {
192                 return this.companyEmailAddress;
193         }
194
195         /**
196          * Setter for company's (main) email address
197          * <p>
198          * @param companyEmailAddress Company's (main) email address
199          */
200         public void setCompanyEmailAddress (final String companyEmailAddress) {
201                 this.companyEmailAddress = companyEmailAddress;
202         }
203
204         /**
205          * Getter for company name
206          * <p>
207          * @return Company name
208          */
209         public String getCompanyName () {
210                 return this.companyName;
211         }
212
213         /**
214          * Setter for company name
215          * <p>
216          * @param companyName Company name
217          */
218         public void setCompanyName (final String companyName) {
219                 this.companyName = companyName;
220         }
221
222         /**
223          * Getter for fax number's area code
224          * <p>
225          * @return Fax number's area code
226          */
227         public Integer getFaxAreaCode () {
228                 return this.faxAreaCode;
229         }
230
231         /**
232          * Setter for fax number's area code
233          * <p>
234          * @param faxAreaCode Fax number's area code
235          */
236         public void setFaxAreaCode (final Integer faxAreaCode) {
237                 this.faxAreaCode = faxAreaCode;
238         }
239
240         /**
241          * Getter for fax's country instance
242          * <p>
243          * @return Fax' country instance
244          */
245         public Country getFaxCountry () {
246                 return this.faxCountry;
247         }
248
249         /**
250          * Setter for fax's country instance
251          * <p>
252          * @param faxCountry Fax' country instance
253          */
254         public void setFaxCountry (final Country faxCountry) {
255                 this.faxCountry = faxCountry;
256         }
257
258         /**
259          * Getter for fax number
260          * <p>
261          * @return Fax number
262          */
263         public Long getFaxNumber () {
264                 return this.faxNumber;
265         }
266
267         /**
268          * Setter for fax number
269          * <p>
270          * @param faxNumber Fax number
271          */
272         public void setFaxNumber (final Long faxNumber) {
273                 this.faxNumber = faxNumber;
274         }
275
276         /**
277          * Getter for land-line number's area code
278          * <p>
279          * @return Land-line number's area code
280          */
281         public Integer getLandLineAreaCode () {
282                 return this.landLineAreaCode;
283         }
284
285         /**
286          * Setter for land-line number's area code
287          * <p>
288          * @param landLineAreaCode Land-line number's area code
289          */
290         public void setLandLineAreaCode (final Integer landLineAreaCode) {
291                 this.landLineAreaCode = landLineAreaCode;
292         }
293
294         /**
295          * Getter for land-line number's country instance
296          * <p>
297          * @return Land-line number's country instance
298          */
299         public Country getLandLineCountry () {
300                 return this.landLineCountry;
301         }
302
303         /**
304          * Setter for land-line number's country instance
305          * <p>
306          * @param landLineCountry Land-line number's country instance
307          */
308         public void setLandLineCountry (final Country landLineCountry) {
309                 this.landLineCountry = landLineCountry;
310         }
311
312         /**
313          * Getter for land-line number
314          * <p>
315          * @return Land-line number
316          */
317         public Long getLandLineNumber () {
318                 return this.landLineNumber;
319         }
320
321         /**
322          * Setter for land-line number
323          * <p>
324          * @param landLineNumber Land-line number
325          */
326         public void setLandLineNumber (final Long landLineNumber) {
327                 this.landLineNumber = landLineNumber;
328         }
329
330         /**
331          * Post-initialization of this class
332          */
333         @PostConstruct
334         public void init () {
335                 // Try it
336                 try {
337                         // Get initial context
338                         Context context = new InitialContext();
339
340                         // Try to lookup
341                         this.businessDataBean = (BusinessDataSessionBeanRemote) context.lookup("java:global/jjobs-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote"); //NOI18N
342
343                         // Try to lookup
344                         this.adminBusinessDataBean = (AdminBusinessDataSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminBusinessData!org.mxchange.jcontactsbusiness.basicdata.AdminBusinessDataSessionBeanRemote"); //NOI18N
345                 } catch (final NamingException e) {
346                         // Throw again
347                         throw new FaceletException(e);
348                 }
349
350                 // Init user's contact list
351                 this.businessContacts = this.adminBusinessDataBean.allCompanyBasicData();
352         }
353
354 }