2 * Copyright (C) 2016 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.jjobs.beans.helper;
19 import java.text.MessageFormat;
20 import javax.enterprise.context.RequestScoped;
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import org.mxchange.jcontacts.contact.Contact;
24 import org.mxchange.jjobs.beans.BaseJobsController;
25 import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController;
26 import org.mxchange.jjobs.beans.phone.JobsAdminPhoneWebRequestController;
27 import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController;
28 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
29 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
30 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
31 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
32 import org.mxchange.jusercore.model.user.User;
35 * A general helper for beans
37 * @author Roland Häder<roland@mxchange.org>
41 public class JobsWebRequestHelperBean extends BaseJobsController implements JobsWebRequestHelperController {
44 * Call-stack instance (5 may show BeanELResolver.getValue as caller)
46 private static final short THREAD_STACK = 5;
51 private static final long serialVersionUID = 17_258_793_567_145_701L;
54 * Administrative contact controller
57 private JobsAdminContactWebRequestController adminContactController;
60 * Administrative phone controller
63 private JobsAdminPhoneWebRequestController adminPhoneController;
66 * Administrative user controller
69 private JobsAdminUserWebRequestController adminUserController;
74 private Contact contact;
79 private DialableFaxNumber faxNumber;
84 private DialableLandLineNumber landLineNumber;
89 private DialableMobileNumber mobileNumber;
97 * Regular user controller
100 private JobsUserWebSessionController userController;
103 * Default constructor
105 public JobsWebRequestHelperBean () {
106 // Call super constructor
109 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
110 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
114 public void copyContactToController () {
115 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
116 // System.out.println(MessageFormat.format("{0}.copyContactToController: CALLED, caller: {2}", this.getClass().getSimpleName(), this.contact, caller));
118 // Validate contact instance
119 if (this.getContact() == null) {
121 throw new NullPointerException("this.contact is null"); //NOI18N
122 } else if (this.getContact().getContactId() == null) {
124 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
125 } else if (this.getContact().getContactId() < 1) {
127 throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
130 // Set all phone instances
131 this.setPhoneInstances(this.getContact());
133 // Set all fields: user
134 this.adminContactController.copyContactToController(this.getContact());
138 public void copyFaxNumberToController () {
139 // Validate fax instance
140 if (this.getFaxNumber() == null) {
142 throw new NullPointerException("this.faxNumber is null");
143 } else if (this.getFaxNumber().getPhoneId() == null) {
145 throw new NullPointerException("this.faxNumber.phoneId is null");
146 } else if (this.getFaxNumber().getPhoneId() < 1) {
148 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId()));
149 } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
151 throw new NullPointerException("this.faxNumber.phoneAreaCode is null");
152 } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
154 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode()));
155 } else if (this.getFaxNumber().getPhoneCountry() == null) {
157 throw new NullPointerException("this.faxNumber.phoneCountry is null");
158 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
160 throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null");
161 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
163 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId()));
164 } else if (this.getFaxNumber().getPhoneNumber() == null) {
165 // Throw NPE again ...
166 throw new NullPointerException("this.faxNumber.phoneNumber is null");
167 } else if (this.getFaxNumber().getPhoneNumber() < 1) {
169 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber()));
172 // Copy all (changeable) data fields to admin controller
173 this.adminPhoneController.setPhoneAreaCode(this.getFaxNumber().getPhoneAreaCode());
174 this.adminPhoneController.setPhoneCountry(this.getFaxNumber().getPhoneCountry());
175 this.adminPhoneController.setPhoneNumber(this.getFaxNumber().getPhoneNumber());
179 public void copyLandLineNumberToController () {
180 // Validate land-line instance
181 if (this.getLandLineNumber() == null) {
183 throw new NullPointerException("this.landLineNumber is null");
184 } else if (this.getLandLineNumber().getPhoneId() == null) {
186 throw new NullPointerException("this.landLineNumber.phoneId is null");
187 } else if (this.getLandLineNumber().getPhoneId() < 1) {
189 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId()));
190 } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
192 throw new NullPointerException("this.landLineNumber.phoneAreaCode is null");
193 } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
195 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode()));
196 } else if (this.getLandLineNumber().getPhoneCountry() == null) {
198 throw new NullPointerException("this.landLineNumber.phoneCountry is null");
199 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
201 throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null");
202 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
204 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId()));
205 } else if (this.getLandLineNumber().getPhoneNumber() == null) {
206 // Throw NPE again ...
207 throw new NullPointerException("this.landLineNumber.phoneNumber is null");
208 } else if (this.getLandLineNumber().getPhoneNumber() < 1) {
210 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber()));
213 // Copy all (changeable) data fields to admin controller
214 this.adminPhoneController.setPhoneAreaCode(this.getLandLineNumber().getPhoneAreaCode());
215 this.adminPhoneController.setPhoneCountry(this.getLandLineNumber().getPhoneCountry());
216 this.adminPhoneController.setPhoneNumber(this.getLandLineNumber().getPhoneNumber());
220 public void copyMobileNumberToController () {
221 // Validate mobile instance
222 if (this.getMobileNumber() == null) {
224 throw new NullPointerException("this.mobileNumber is null");
225 } else if (this.getMobileNumber().getPhoneId() == null) {
227 throw new NullPointerException("this.mobileNumber.phoneId is null");
228 } else if (this.getMobileNumber().getPhoneId() < 1) {
230 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneId={0} is not valid", this.getMobileNumber().getPhoneId()));
231 } else if (this.getMobileNumber().getMobileProvider() == null) {
233 throw new NullPointerException("this.mobileNumber.mobileProvider is null");
234 } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
236 throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null");
237 } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
239 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId()));
240 } else if (this.getMobileNumber().getPhoneNumber() == null) {
241 // Throw NPE again ...
242 throw new NullPointerException("this.mobileNumber.phoneNumber is null");
243 } else if (this.getMobileNumber().getPhoneNumber() < 1) {
245 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneNumber={0} is not valid", this.getMobileNumber().getPhoneNumber()));
248 // Copy all (changeable) data fields to admin controller
249 this.adminPhoneController.setMobileProvider(this.getMobileNumber().getMobileProvider());
250 this.adminPhoneController.setPhoneNumber(this.getMobileNumber().getPhoneNumber());
254 public void copyUserToController () {
256 //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N
258 // Validate user instance
259 if (this.getUser() == null) {
261 throw new NullPointerException("this.user is null"); //NOI18N
262 } else if (this.getUser().getUserId() == null) {
264 throw new NullPointerException("this.user.userId is null"); //NOI18N
265 } else if (this.getUser().getUserId() < 1) {
267 throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
271 Contact userContact = this.getUser().getUserContact();
273 // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
274 this.setContact(userContact);
276 // Set all phone instances
277 this.setPhoneInstances(userContact);
279 // Set all fields: user
280 this.userController.setUserName(this.getUser().getUserName());
281 this.adminUserController.setUserName(this.getUser().getUserName());
285 public Contact getContact () {
286 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
287 // System.out.println(MessageFormat.format("{0}: Returning this.contact={1}, caller: {2}", this.getClass().getSimpleName(), this.contact, caller));
292 public void setContact (final Contact contact) {
293 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
294 // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller));
295 this.contact = contact;
299 public String getContactUsageMessageKey (final Contact contact) {
300 // The contact must be valid
301 if (null == contact) {
303 throw new NullPointerException("contact is null"); //NOI18N
304 } else if (contact.getContactId() == null) {
306 throw new NullPointerException("contact.contactId is null"); //NOI18N
307 } else if (contact.getContactId() < 1) {
309 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
312 // Default key is "unused"
313 String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
315 // Check user/recruiter
316 boolean isUserContact = this.userController.isContactFound(contact);
321 messageKey = "CONTACT_IS_USER"; //NOI18N
324 // Return message key
329 public DialableFaxNumber getFaxNumber () {
330 return this.faxNumber;
334 public void setFaxNumber (final DialableFaxNumber faxNumber) {
335 this.faxNumber = faxNumber;
339 public DialableLandLineNumber getLandLineNumber () {
340 return this.landLineNumber;
344 public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
345 this.landLineNumber = landLineNumber;
349 public DialableMobileNumber getMobileNumber () {
350 return this.mobileNumber;
354 public void setMobileNumber (final DialableMobileNumber mobileNumber) {
355 this.mobileNumber = mobileNumber;
359 public User getUser () {
364 public void setUser (final User user) {
369 * Set's all given contact's phone instances: land-line, mobile and
372 * @param contact Contact to set phone instances for
374 private void setPhoneInstances (final Contact contact) {
375 // The contact must be valid
376 if (null == contact) {
378 throw new NullPointerException("contact is null"); //NOI18N
379 } else if (contact.getContactId() == null) {
381 throw new NullPointerException("contact.contactId is null"); //NOI18N
382 } else if (contact.getContactId() < 1) {
384 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
388 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
389 // Yes, then set it in admin controller
390 this.setMobileNumber(contact.getContactMobileNumber());
394 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
395 // Yes, then set it in admin controller
396 this.setLandLineNumber(contact.getContactLandLineNumber());
400 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
401 // Yes, then set it in admin controller
402 this.setFaxNumber(contact.getContactFaxNumber());