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.jjobs.beans.phone;
19 import java.text.MessageFormat;
20 import java.util.Calendar;
21 import java.util.List;
22 import java.util.Objects;
23 import javax.annotation.PostConstruct;
24 import javax.enterprise.context.RequestScoped;
25 import javax.enterprise.event.Event;
26 import javax.enterprise.event.Observes;
27 import javax.enterprise.inject.Any;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcountry.data.Country;
35 import org.mxchange.jjobs.beans.BaseJobsController;
36 import org.mxchange.jjobs.beans.helper.JobsWebRequestHelperController;
37 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
38 import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
39 import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent;
40 import org.mxchange.jphone.events.fax.removed.AdminFaxNumberRemovedFromListEvent;
41 import org.mxchange.jphone.events.fax.removed.AdminRemoveFaxNumberFromListEvent;
42 import org.mxchange.jphone.events.fax.updated.AdminFaxNumberUpdatedEvent;
43 import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
44 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
45 import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
46 import org.mxchange.jphone.events.landline.deleted.AdminLandLineNumberDeletedEvent;
47 import org.mxchange.jphone.events.landline.removed.AdminLandLineNumberRemovedFromListEvent;
48 import org.mxchange.jphone.events.landline.removed.AdminRemoveLandLineNumberFromListEvent;
49 import org.mxchange.jphone.events.landline.updated.AdminLandLineNumberUpdatedEvent;
50 import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
51 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
52 import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
53 import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent;
54 import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent;
55 import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
56 import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent;
57 import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
58 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
59 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
60 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
61 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
62 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
63 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
64 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
65 import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote;
68 * Administrative controller (bean) for phone numbers
70 * @author Roland Häder<roland@mxchange.org>
72 @Named ("adminPhoneController")
74 public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements JobsAdminPhoneWebRequestController {
79 private static final short THREAD_STACK = 5;
84 private static final long serialVersionUID = 184_598_175_371_269_016L;
87 * Remote EJB for phone number (administrative)
89 private AdminPhoneSessionBeanRemote adminPhoneBean;
95 private JobsWebRequestHelperController beanHelper;
100 private DialableFaxNumber faxNumber;
103 * Event being fired when an administrator has deleted fax number
107 private Event<AdminDeletedFaxNumberEvent> faxNumberDeletedEvent;
110 * Event being fired when an administrator has updated fax number
114 private Event<AdminUpdatedFaxNumberEvent> faxNumberUpdatedEvent;
119 private DialableLandLineNumber landLineNumber;
122 * Event being fired when an administrator has deleted land-line number
126 private Event<AdminDeletedLandLineNumberEvent> landLineNumberDeletedEvent;
129 * Event being fired when an administrator has updated fax number
133 private Event<AdminUpdatedLandLineNumberEvent> landLineNumberUpdatedEvent;
136 * Chosen mobile number
138 private DialableMobileNumber mobileNumber;
141 * Event being fired when an administrator has deleted mobile number
145 private Event<AdminDeletedMobileNumberEvent> mobileNumberDeletedEvent;
148 * Event being fired when an administrator has updated land-line number
152 private Event<AdminUpdatedMobileNumberEvent> mobileNumberUpdatedEvent;
157 private MobileProvider mobileProvider;
160 * Area code (city dial prefix)
162 private Integer phoneAreaCode;
165 * Generic hone controller
168 private JobsPhoneWebApplicationController phoneController;
171 * Country (for dial prefix)
173 private Country phoneCountry;
176 * When the phone entry has been created (persisted)
178 private Calendar phoneEntryCreated;
181 * When the phone entry has been updated
183 private Calendar phoneEntryUpdated;
186 * Phone id (aka primary key)
188 private Long phoneId;
193 private Long phoneNumber;
196 * Event being fired when a list of all unsed fax numbers is being created.
200 private Event<AdminRemoveFaxNumberFromListEvent> removeLinkedFaxNumbersEvent;
203 * Event being fired when a list of all unsed land-line numbers is being
208 private Event<AdminRemoveLandLineNumberFromListEvent> removeLinkedLandLineNumbersEvent;
211 * Event being fired when a list of all unsed mobile numbers is being
216 private Event<AdminRemoveMobileNumberFromListEvent> removeLinkedMobileNumbersEvent;
219 * Default constructor
221 public JobsAdminPhoneWebRequestBean () {
222 // Call super constructor
225 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
226 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
230 * Observes events being fired when a bean helper has successfully created a
231 * fax number instance.
233 * @param event Event being fired
235 public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
236 // The event instance must be valid
239 throw new NullPointerException("event is null"); //NOI18N
240 } else if (event.getFaxNumber() == null) {
242 throw new NullPointerException("event.faxNumber is null"); //NOI18N
243 } else if (event.getFaxNumber().getPhoneId() == null) {
244 // Throw NPE yet again
245 throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
246 } else if (event.getFaxNumber().getPhoneId() < 1) {
247 // Throw NPE yet again
248 throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
251 // Get fax number from event
252 DialableFaxNumber number = event.getFaxNumber();
254 // Copy all data to this bean
255 this.setPhoneId(number.getPhoneId());
256 this.setPhoneCountry(number.getPhoneCountry());
257 this.setPhoneAreaCode(number.getPhoneAreaCode());
258 this.setPhoneNumber(number.getPhoneNumber());
259 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
260 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
264 * Observes events being fired when a bean helper has successfully created a
265 * land-line number instance.
267 * @param event Event being fired
269 public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
270 // The event instance must be valid
273 throw new NullPointerException("event is null"); //NOI18N
274 } else if (event.getLandLineNumber() == null) {
276 throw new NullPointerException("event.landLineNumber is null"); //NOI18N
277 } else if (event.getLandLineNumber().getPhoneId() == null) {
278 // Throw NPE yet again
279 throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
280 } else if (event.getLandLineNumber().getPhoneId() < 1) {
281 // Throw NPE yet again
282 throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
285 // Get fax number from event
286 DialableLandLineNumber number = event.getLandLineNumber();
288 // Copy all data to this bean
289 this.setPhoneId(number.getPhoneId());
290 this.setPhoneCountry(number.getPhoneCountry());
291 this.setPhoneAreaCode(number.getPhoneAreaCode());
292 this.setPhoneNumber(number.getPhoneNumber());
293 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
294 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
298 * Observes events being fired when a bean helper has successfully created a
299 * mobile number instance.
301 * @param event Event being fired
303 public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
304 // The event instance must be valid
307 throw new NullPointerException("event is null"); //NOI18N
308 } else if (event.getMobileNumber() == null) {
310 throw new NullPointerException("event.mobileNumber is null"); //NOI18N
311 } else if (event.getMobileNumber().getPhoneId() == null) {
312 // Throw NPE yet again
313 throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
314 } else if (event.getMobileNumber().getPhoneId() < 1) {
315 // Throw NPE yet again
316 throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
319 // Get fax number from event
320 DialableMobileNumber number = event.getMobileNumber();
322 // Copy all data to this bean
323 this.setPhoneId(number.getPhoneId());
324 this.setMobileProvider(number.getMobileProvider());
325 this.setPhoneNumber(number.getPhoneNumber());
326 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
327 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
331 * Returns a list of all unused ("non-linked") land-line numbers
333 * @return List with all unused land-line numbers
335 public List<DialableFaxNumber> allNonLinkedFaxNumbers () {
336 // Get list of all mobile numbers
337 List<DialableFaxNumber> list = this.phoneController.allFaxNumbers();
339 // Visit all controllers to reduce the list
340 this.removeLinkedFaxNumbersEvent.fire(new AdminFaxNumberRemovedFromListEvent(list));
347 * Returns a list of all unused ("non-linked") land-line numbers
349 * @return List with all unused land-line numbers
351 public List<DialableLandLineNumber> allNonLinkedLandLineNumbers () {
352 // Get list of all mobile numbers
353 List<DialableLandLineNumber> list = this.phoneController.allLandLineNumbers();
355 // Visit all controllers to reduce the list
356 this.removeLinkedLandLineNumbersEvent.fire(new AdminLandLineNumberRemovedFromListEvent(list));
363 * Returns a list of all unused ("non-linked") mobile numbers
365 * @return List with all unused mobile numbers
367 public List<DialableMobileNumber> allNonLinkedMobileNumbers () {
368 // Get list of all mobile numbers
369 List<DialableMobileNumber> list = this.phoneController.allMobileNumbers();
371 // Visit all controllers to reduce the list
372 this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(list));
379 * Deletes given fax entry data
381 * @return Redirect outcome
383 public String deleteFaxData () {
384 // Get fax number from bean helper
385 DialableFaxNumber number = this.createFaxNumber();
388 if (number == null) {
389 // Not set, throw NPE
390 throw new NullPointerException("faxNumber is null"); //NOI18N
391 } else if (number.getPhoneId() == null) {
393 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
394 } else if (number.getPhoneId() < 1) {
396 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
397 } else if (number.getPhoneCountry() == null) {
399 throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
400 } else if (number.getPhoneCountry().getCountryId() == null) {
402 throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
403 } else if (number.getPhoneCountry().getCountryId() < 1) {
405 throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", number.getPhoneCountry().getCountryId())); //NOI18N
406 } else if (number.getPhoneAreaCode() == null) {
408 throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
409 } else if (number.getPhoneAreaCode() < 1) {
411 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", number.getPhoneAreaCode())); //NOI18N
412 } else if (number.getPhoneNumber() == null) {
414 throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
415 } else if (number.getPhoneNumber() < 1) {
417 throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
421 this.adminPhoneBean.deleteFaxData(number);
424 this.faxNumberDeletedEvent.fire(new AdminFaxNumberDeletedEvent(number));
426 // All fine, redirect
427 return "admin_list_fax"; //NOI18N
431 * Deletes given land-line entry data
433 * @return Redirect outcome
435 public String deleteLandLineData () {
436 // Get land-line number from helper
437 DialableLandLineNumber number = this.createLandLineNumber();
440 if (number == null) {
441 // Not set, throw NPE
442 throw new NullPointerException("landLineNumber is null"); //NOI18N
443 } else if (number.getPhoneId() == null) {
445 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
446 } else if (number.getPhoneId() < 1) {
448 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
449 } else if (number.getPhoneCountry() == null) {
451 throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
452 } else if (number.getPhoneCountry().getCountryId() == null) {
454 throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
455 } else if (number.getPhoneCountry().getCountryId() < 1) {
457 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", number.getPhoneCountry().getCountryId())); //NOI18N
458 } else if (number.getPhoneAreaCode() == null) {
460 throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
461 } else if (number.getPhoneAreaCode() < 1) {
463 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", number.getPhoneAreaCode())); //NOI18N
464 } else if (number.getPhoneNumber() == null) {
466 throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
467 } else if (number.getPhoneNumber() < 1) {
469 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
473 this.adminPhoneBean.deleteLandLineData(number);
476 this.landLineNumberDeletedEvent.fire(new AdminLandLineNumberDeletedEvent(number));
478 // All fine, redirect
479 return "admin_list_landline"; //NOI18N
483 * Deletes given mobile entry data
485 * @return Redirect outcome
487 public String deleteMobileData () {
488 // Get mobile number from helper
489 DialableMobileNumber number = this.createMobileNumber();
492 if (number == null) {
493 // Not set, throw NPE
494 throw new NullPointerException("mobileNumber is null"); //NOI18N
495 } else if (number.getPhoneId() == null) {
497 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
498 } else if (number.getPhoneId() < 1) {
500 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
501 } else if (number.getMobileProvider() == null) {
503 throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
504 } else if (number.getMobileProvider().getProviderId() == null) {
506 throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
507 } else if (number.getMobileProvider().getProviderId() < 1) {
509 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
510 } else if (number.getPhoneNumber() == null) {
512 throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
513 } else if (number.getPhoneNumber() < 1) {
515 throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
519 this.adminPhoneBean.deleteMobileData(number);
522 this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(number));
524 // All fine, redirect
525 return "admin_list_mobile"; //NOI18N
529 * Changes fax entry data
531 * @return Redirect outcome
533 public String doChangeFaxNumber () {
534 // Get fax number from bean helper
535 DialableFaxNumber number = this.createFaxNumber();
538 if (number == null) {
539 // Not set, throw NPE
540 throw new NullPointerException("faxNumber is null"); //NOI18N
541 } else if (number.getPhoneId() == null) {
543 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
544 } else if (number.getPhoneId() < 1) {
546 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
547 } else if (number.getPhoneCountry() == null) {
549 throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
550 } else if (number.getPhoneCountry().getCountryId() == null) {
552 throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
553 } else if (number.getPhoneCountry().getCountryId() < 1) {
555 throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", number.getPhoneCountry().getCountryId())); //NOI18N
556 } else if (number.getPhoneAreaCode() == null) {
558 throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
559 } else if (number.getPhoneAreaCode() < 1) {
561 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", number.getPhoneAreaCode())); //NOI18N
562 } else if (number.getPhoneNumber() == null) {
564 throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
565 } else if (number.getPhoneNumber() < 1) {
567 throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
570 // Is the mobile provider and number the same?
571 if ((Objects.equals(this.getPhoneCountry(), number.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), number.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), number.getPhoneNumber()))) {
573 this.showFacesMessage("form_edit_fax:faxNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
575 // No difference in both together, no need to edit
580 number.setPhoneCountry(this.getPhoneCountry());
581 number.setPhoneAreaCode(this.getPhoneAreaCode());
582 number.setPhoneNumber(this.getPhoneNumber());
585 DialableFaxNumber updatedNumber = this.adminPhoneBean.updateFaxData(number);
588 this.faxNumberUpdatedEvent.fire(new AdminFaxNumberUpdatedEvent(updatedNumber));
590 // All fine, redirect
591 return "admin_show_fax"; //NOI18N
595 * Changes land-line entry data
597 * @return Redirect outcome
599 public String doChangeLandLineNumber () {
600 // Get land-line number from helper
601 DialableLandLineNumber number = this.createLandLineNumber();
604 if (number == null) {
605 // Not set, throw NPE
606 throw new NullPointerException("landLineNumber is null"); //NOI18N
607 } else if (number.getPhoneId() == null) {
609 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
610 } else if (number.getPhoneId() < 1) {
612 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
613 } else if (number.getPhoneCountry() == null) {
615 throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
616 } else if (number.getPhoneCountry().getCountryId() == null) {
618 throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
619 } else if (number.getPhoneCountry().getCountryId() < 1) {
621 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", number.getPhoneCountry().getCountryId())); //NOI18N
622 } else if (number.getPhoneAreaCode() == null) {
624 throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
625 } else if (number.getPhoneAreaCode() < 1) {
627 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", number.getPhoneAreaCode())); //NOI18N
628 } else if (number.getPhoneNumber() == null) {
630 throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
631 } else if (number.getPhoneNumber() < 1) {
633 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
636 // Is the mobile provider and number the same?
637 if ((Objects.equals(this.getPhoneCountry(), number.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), number.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), number.getPhoneNumber()))) {
639 this.showFacesMessage("form_edit_landline:landLineNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
641 // No difference in both together, no need to edit
646 number.setPhoneCountry(this.getPhoneCountry());
647 number.setPhoneAreaCode(this.getPhoneAreaCode());
648 number.setPhoneNumber(this.getPhoneNumber());
651 DialableLandLineNumber updatedNumber = this.adminPhoneBean.updateLandLineData(number);
654 this.landLineNumberUpdatedEvent.fire(new AdminLandLineNumberUpdatedEvent(updatedNumber));
656 // All fine, redirect
657 return "admin_show_landline"; //NOI18N
661 * Changes mobile entry data
663 * @return Redirect outcome
665 public String doUpdateMobileNumber () {
666 // Get mobile number from helper
667 DialableMobileNumber number = this.createMobileNumber();
670 if (number == null) {
671 // Not set, throw NPE
672 throw new NullPointerException("mobileNumber is null"); //NOI18N
673 } else if (number.getPhoneId() == null) {
675 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
676 } else if (number.getPhoneId() < 1) {
678 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
679 } else if (number.getMobileProvider() == null) {
681 throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
682 } else if (number.getMobileProvider().getProviderId() == null) {
684 throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
685 } else if (number.getMobileProvider().getProviderId() < 1) {
687 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
688 } else if (number.getPhoneNumber() == null) {
690 throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
691 } else if (number.getPhoneNumber() < 1) {
693 throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
694 } else if (this.getMobileProvider() == null) {
696 this.showFacesMessage("form_edit_mobile:mobileProvider", "ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED"); //NOI18N
698 } else if (this.getMobileProvider().getProviderId() == null) {
699 // Throw NPE again ...
700 throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
701 } else if (this.getMobileProvider().getProviderId() < 0) {
703 throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N
704 } else if (this.getPhoneNumber() == null) {
706 this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_EMPTY_MOBILE_NUMBER"); //NOI18N
710 // Is the mobile provider and number the same?
711 if ((Objects.equals(this.getMobileProvider(), number.getMobileProvider())) && (Objects.equals(this.getPhoneNumber(), number.getPhoneNumber()))) {
713 this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
715 // No difference in both together, no need to edit
720 number.setMobileProvider(this.getMobileProvider());
721 number.setPhoneNumber(this.getPhoneNumber());
724 DialableMobileNumber updatedNumber = this.adminPhoneBean.updateMobileData(number);
727 this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber));
729 // All fine, redirect
730 return "admin_show_mobile"; //NOI18N
734 * Getter for chosen fax number
738 public DialableFaxNumber getFaxNumber () {
739 return this.faxNumber;
743 * Setter for chosen fax number
745 * @param faxNumber fax number
747 public void setFaxNumber (final DialableFaxNumber faxNumber) {
748 this.faxNumber = faxNumber;
752 * Getter for chosen land-line number
754 * @return land-line number
756 public DialableLandLineNumber getLandLineNumber () {
757 return this.landLineNumber;
761 * Setter for chosen land-line number
763 * @param landLineNumber land-line number
765 public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
766 this.landLineNumber = landLineNumber;
770 * Getter for chosen mobile number
772 * @return mobile number
774 public DialableMobileNumber getMobileNumber () {
775 return this.mobileNumber;
779 * Setter for chosen mobile number
781 * @param mobileNumber mobile number
783 public void setMobileNumber (final DialableMobileNumber mobileNumber) {
784 this.mobileNumber = mobileNumber;
788 * Getter for mobile provider
790 * @return Mobile provider
792 public MobileProvider getMobileProvider () {
793 return this.mobileProvider;
797 * Setter for mobile provider
799 * @param mobileProvider Mobile provider
801 public void setMobileProvider (final MobileProvider mobileProvider) {
802 this.mobileProvider = mobileProvider;
806 * Getter for phone area code
808 * @return Phone area code
810 public Integer getPhoneAreaCode () {
811 return this.phoneAreaCode;
815 * Setter for phone area code
817 * @param phoneAreaCode Phone area code
819 public void setPhoneAreaCode (final Integer phoneAreaCode) {
820 this.phoneAreaCode = phoneAreaCode;
824 * Getter for phone country (for dial prefix)
826 * @return Phone country
828 public Country getPhoneCountry () {
829 return this.phoneCountry;
833 * Setter for phone country (for dial prefix)
835 * @param phoneCountry Phone country
837 public void setPhoneCountry (final Country phoneCountry) {
838 this.phoneCountry = phoneCountry;
842 * Getter for phone entry created timestamp
844 * @return Phone entry created timestamp
846 @SuppressWarnings ("ReturnOfDateField")
847 public Calendar getPhoneEntryCreated () {
848 return this.phoneEntryCreated;
852 * Setter for phone entry created timestamp
854 * @param phoneEntryCreated Phone entry created timestamp
856 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
857 public void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
858 this.phoneEntryCreated = phoneEntryCreated;
862 * Getter for phone entry updated timestamp
864 * @return Phone entry updated timestamp
866 @SuppressWarnings ("ReturnOfDateField")
867 public Calendar getPhoneEntryUpdated () {
868 return this.phoneEntryUpdated;
872 * Setter for phone entry updated timestamp
874 * @param phoneEntryUpdated Phone entry updated timestamp
876 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
877 public void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
878 this.phoneEntryUpdated = phoneEntryUpdated;
882 * Getter for phone id
886 public Long getPhoneId () {
891 * Setter for phone id
893 * @param phoneId Phone id
895 public void setPhoneId (final Long phoneId) {
896 this.phoneId = phoneId;
900 * Getter for dial number without prefix
902 * @return Dial number without prefix
904 public Long getPhoneNumber () {
905 return this.phoneNumber;
909 * Setter for dial number without prefix
911 * @param phoneNumber Dial number without prefix
913 public void setPhoneNumber (final Long phoneNumber) {
914 this.phoneNumber = phoneNumber;
918 * Post-construction method
921 public void init () {
924 // Get initial context
925 Context context = new InitialContext();
927 // Try to lookup the beans
928 this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminPhone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N
929 } catch (final NamingException e) {
931 throw new FaceletException(e);
936 * Returns an instance of a DialableFaxNumber from all fields stored in this
939 * @return An instance of a DialableFaxNumber class
941 private DialableFaxNumber createFaxNumber () {
943 DialableFaxNumber number = new FaxNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
945 // Add all other data
946 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
947 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
950 if (this.getPhoneId() instanceof Long) {
952 number.setPhoneId(this.getPhoneId());
960 * Returns an instance of a DialableLandLineNumber from all fields stored in
963 * @return An instance of a DialableLandLineNumber class
965 private DialableLandLineNumber createLandLineNumber () {
967 DialableLandLineNumber number = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
969 // Add all other data
970 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
971 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
974 if (this.getPhoneId() instanceof Long) {
976 number.setPhoneId(this.getPhoneId());
984 * Returns an instance of a DialableMobileNumber from all fields stored in
987 * @return An instance of a DialableMobileNumber class
989 private DialableMobileNumber createMobileNumber () {
991 DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getPhoneNumber());
993 // Add all other data
994 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
995 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
998 if (this.getPhoneId() instanceof Long) {
1000 number.setPhoneId(this.getPhoneId());