2 * Copyright (C) 2016 - 2020 Free Software Foundation
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 fish.payara.cdi.jsr107.impl.NamedCache;
20 import java.text.MessageFormat;
21 import java.util.Iterator;
22 import java.util.LinkedList;
23 import java.util.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.cache.Cache;
28 import javax.enterprise.context.RequestScoped;
29 import javax.enterprise.event.Observes;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
33 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
34 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
35 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
36 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
37 import org.mxchange.jcontacts.model.contact.Contact;
38 import org.mxchange.jjobs.beans.BaseJobsBean;
39 import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
40 import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
41 import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
42 import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
43 import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
44 import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
45 import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
46 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
47 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
49 import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
50 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
53 * Regular controller (bean) for phone numbers
55 * @author Roland Häder<roland@mxchange.org>
57 @Named ("phoneController")
59 public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWebRequestController {
64 private static final long serialVersionUID = 491_058_674_675_690_105L;
70 @NamedCache (cacheName = "faxNumberCache")
71 private Cache<Long, DialableFaxNumber> faxNumberCache;
74 * All land-line numbers
77 @NamedCache (cacheName = "landLineNumberCache")
78 private Cache<Long, DialableLandLineNumber> landLineNumberCache;
84 @NamedCache (cacheName = "mobileNumberCache")
85 private Cache<Long, DialableMobileNumber> mobileNumberCache;
88 * General EJB for phone numbers
90 @EJB (lookup = "java:global/jjobs-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote")
91 private PhoneSessionBeanRemote phoneBean;
96 public JobsPhoneWebRequestBean () {
97 // Call super constructor
102 * Observes events being fired when an administrator has added a new
105 * @param event Event being fired
107 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
108 // The event must be valid
111 throw new NullPointerException("event is null"); //NOI18N
112 } else if (event.getAddedContact() == null) {
114 throw new NullPointerException("event.addedContact is null"); //NOI18N
115 } else if (event.getAddedContact().getContactId() == null) {
117 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
118 } else if (event.getAddedContact().getContactId() < 1) {
120 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
123 // Update contact's mobile, land-line and fax number
124 this.updateContactPhoneNumbers(event.getAddedContact());
131 * Event observer for newly added users by administrator
133 * @param event Event being fired
135 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
136 // event should not be null
139 throw new NullPointerException("event is null"); //NOI18N
140 } else if (event.getAddedUser() == null) {
142 throw new NullPointerException("event.addedUser is null"); //NOI18N
143 } else if (event.getAddedUser().getUserId() == null) {
145 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
146 } else if (event.getAddedUser().getUserId() < 1) {
148 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
151 // Update contact's mobile, land-line and fax number
152 this.updateContactPhoneNumbers(event.getAddedUser().getUserContact());
159 * Observes events being fired when an administrator has deleted a fax
162 * @param event Event being fired
164 public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent event) {
165 // event should not be null
168 throw new NullPointerException("event is null"); //NOI18N
169 } else if (event.getDeletedFaxNumber() == null) {
171 throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N
172 } else if (event.getDeletedFaxNumber().getPhoneId() == null) {
174 throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N
175 } else if (event.getDeletedFaxNumber().getPhoneId() < 1) {
177 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N
180 // Update contact's mobile, land-line and fax number
181 this.allFaxNumbers().remove(event.getDeletedFaxNumber());
188 * Observes events being fired when an administrator has deleted a land-line
191 * @param event Event being fired
193 public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent event) {
194 // event should not be null
197 throw new NullPointerException("event is null"); //NOI18N
198 } else if (event.getDeletedLandLineNumber() == null) {
200 throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N
201 } else if (event.getDeletedLandLineNumber().getPhoneId() == null) {
203 throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N
204 } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) {
206 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N
209 // Update contact's mobile, land-line and fax number
210 this.allLandLineNumbers().remove(event.getDeletedLandLineNumber());
217 * Observes events being fired when an administrator has deleted a mobile
220 * @param event Event being fired
222 public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent event) {
223 // event should not be null
226 throw new NullPointerException("event is null"); //NOI18N
227 } else if (event.getDeletedMobileNumber() == null) {
229 throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N
230 } else if (event.getDeletedMobileNumber().getPhoneId() == null) {
232 throw new NullPointerException("event.deletedMobileNumber.phoneId is null"); //NOI18N
233 } else if (event.getDeletedMobileNumber().getPhoneId() < 1) {
235 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getPhoneId())); //NOI18N
238 // Update contact's mobile, land-line and fax number
239 this.allMobileNumbers().remove(event.getDeletedMobileNumber());
246 * Observes events being fired when an administrator has a linked a fax
249 * @param event Event being fired
251 public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) {
252 // Is the event fine?
255 throw new NullPointerException("event is null"); //NOI18N
256 } else if (event.getContact() == null) {
258 throw new NullPointerException("event.contact is null"); //NOI18N
259 } else if (event.getContact().getContactId() == null) {
261 throw new NullPointerException("event.contact.contactId is null"); //NOI18N
262 } else if (event.getContact().getContactId() < 1) {
264 throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
265 } else if (event.getContact().getContactFaxNumber() == null) {
267 throw new NullPointerException("event.contact.contactFaxNumber is null"); //NOI18N
268 } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
270 throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); //NOI18N
271 } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
273 throw new NullPointerException("event.contact.contactFaxNumber.phoneId=" + event.getContact().getContactFaxNumber().getPhoneId() + " is invalid"); //NOI18N
274 } else if (event.getLinkedFaxNumber() == null) {
276 throw new NullPointerException("event.linkedFaxNumer is null"); //NOI18N
279 // Is the id number in linked number not set?
280 if (event.getLinkedFaxNumber().getPhoneId() == null) {
281 // Then it is a new number, so add it from contact as there the id number has been set
282 this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber());
287 * Observes events being fired when an administrator has a linked a
290 * @param event Event being fired
292 public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) {
293 // Is the event fine?
296 throw new NullPointerException("event is null"); //NOI18N
297 } else if (event.getContact() == null) {
299 throw new NullPointerException("event.contact is null"); //NOI18N
300 } else if (event.getContact().getContactId() == null) {
302 throw new NullPointerException("event.contact.contactId is null"); //NOI18N
303 } else if (event.getContact().getContactId() < 1) {
305 throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
306 } else if (event.getContact().getContactLandLineNumber() == null) {
308 throw new NullPointerException("event.contact.contactLandLineNumber is null"); //NOI18N
309 } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
311 throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); //NOI18N
312 } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
314 throw new NullPointerException("event.contact.contactLandLineNumber.phoneId=" + event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid"); //NOI18N
315 } else if (event.getLinkedLandLineNumber() == null) {
317 throw new NullPointerException("event.linkedLandLineNumer is null"); //NOI18N
320 // Is the id number in linked number not set?
321 if (event.getLinkedLandLineNumber().getPhoneId() == null) {
322 // Then it is a new number, so add it from contact as there the id number has been set
323 this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber());
328 * Observes events being fired when an administrator has a linked a mobile
331 * @param event Event being fired
333 public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) {
334 // Is the event fine?
337 throw new NullPointerException("event is null"); //NOI18N
338 } else if (event.getContact() == null) {
340 throw new NullPointerException("event.contact is null"); //NOI18N
341 } else if (event.getContact().getContactId() == null) {
343 throw new NullPointerException("event.contact.contactId is null"); //NOI18N
344 } else if (event.getContact().getContactId() < 1) {
346 throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
347 } else if (event.getContact().getContactMobileNumber() == null) {
349 throw new NullPointerException("event.contact.contactMobileNumber is null"); //NOI18N
350 } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) {
352 throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null"); //NOI18N
353 } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) {
355 throw new NullPointerException("event.contact.contactMobileNumber.phoneId=" + event.getContact().getContactMobileNumber().getPhoneId() + " is invalid"); //NOI18N
356 } else if (event.getLinkedMobileNumber() == null) {
358 throw new NullPointerException("event.linkedMobileNumer is null"); //NOI18N
361 // Is the id number in linked number not set?
362 if (event.getLinkedMobileNumber().getPhoneId() == null) {
363 // Then it is a new number, so add it from contact as there the id number has been set
364 this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber());
369 * Observes events being fired when an administrator has updated contact
372 * @param event Event being fired
374 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
375 // event should not be null
378 throw new NullPointerException("event is null"); //NOI18N
379 } else if (event.getUpdatedContact() == null) {
381 throw new NullPointerException("event.updatedContact is null"); //NOI18N
382 } else if (event.getUpdatedContact().getContactId() == null) {
384 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
385 } else if (event.getUpdatedContact().getContactId() < 1) {
387 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
390 // Update contact's mobile, land-line and fax number
391 this.updateContactPhoneNumbers(event.getUpdatedContact());
398 * Observes events being fired when an administrator has updated a fax
401 * @param event Event being fired
403 public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent event) {
404 // event should not be null
407 throw new NullPointerException("event is null"); //NOI18N
408 } else if (event.getUpdatedFaxNumber() == null) {
410 throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N
411 } else if (event.getUpdatedFaxNumber().getPhoneId() == null) {
413 throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N
414 } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) {
416 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N
420 this.uniqueAddFaxNumber(event.getUpdatedFaxNumber());
427 * Observes events being fired when an administrator has updated a land-line
430 * @param event Event being fired
432 public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent event) {
433 // event should not be null
436 throw new NullPointerException("event is null"); //NOI18N
437 } else if (event.getUpdatedLandLineNumber() == null) {
439 throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N
440 } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) {
442 throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N
443 } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) {
445 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N
449 this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber());
456 * Observes events being fired when an administrator has updated a mobile
459 * @param event Event being fired
461 public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent event) {
462 // event should not be null
465 throw new NullPointerException("event is null"); //NOI18N
466 } else if (event.getUpdatedMobileNumber() == null) {
468 throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N
469 } else if (event.getUpdatedMobileNumber().getPhoneId() == null) {
471 throw new NullPointerException("event.updatedMobileNumber.phoneId is null"); //NOI18N
472 } else if (event.getUpdatedMobileNumber().getPhoneId() < 1) {
474 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getPhoneId())); //NOI18N
478 this.uniqueAddMobileNumber(event.getUpdatedMobileNumber());
485 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
486 public List<DialableFaxNumber> allFaxNumbers () {
488 final List<DialableFaxNumber> list = new LinkedList<>();
491 final Iterator<Cache.Entry<Long, DialableFaxNumber>> iterator = this.faxNumberCache.iterator();
494 while (iterator.hasNext()) {
496 final Cache.Entry<Long, DialableFaxNumber> next = iterator.next();
499 list.add(next.getValue());
507 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
508 public List<DialableLandLineNumber> allLandLineNumbers () {
510 final List<DialableLandLineNumber> list = new LinkedList<>();
513 final Iterator<Cache.Entry<Long, DialableLandLineNumber>> iterator = this.landLineNumberCache.iterator();
516 while (iterator.hasNext()) {
518 final Cache.Entry<Long, DialableLandLineNumber> next = iterator.next();
521 list.add(next.getValue());
529 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
530 public List<DialableMobileNumber> allMobileNumbers () {
532 final List<DialableMobileNumber> list = new LinkedList<>();
535 final Iterator<Cache.Entry<Long, DialableMobileNumber>> iterator = this.mobileNumberCache.iterator();
538 while (iterator.hasNext()) {
540 final Cache.Entry<Long, DialableMobileNumber> next = iterator.next();
543 list.add(next.getValue());
551 public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException {
553 if (null == faxNumberId) {
555 throw new NullPointerException("faxNumberId is null"); //NOI18N
556 } else if (faxNumberId < 1) {
558 throw new IllegalArgumentException("faxNumberId=" + faxNumberId + " is invalid."); //NOI18N
559 } else if (!this.faxNumberCache.containsKey(faxNumberId)) {
561 throw new PhoneEntityNotFoundException(faxNumberId);
565 final DialableFaxNumber faxNumber = this.faxNumberCache.get(faxNumberId);
572 public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException {
574 if (null == landLineNumberId) {
576 throw new NullPointerException("landLineNumberId is null"); //NOI18N
577 } else if (landLineNumberId < 1) {
579 throw new IllegalArgumentException("landLineNumberId=" + landLineNumberId + " is invalid."); //NOI18N
580 } else if (!this.landLineNumberCache.containsKey(landLineNumberId)) {
582 throw new PhoneEntityNotFoundException(landLineNumberId);
586 final DialableLandLineNumber landLineNumber = this.landLineNumberCache.get(landLineNumberId);
589 return landLineNumber;
593 public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException {
595 if (null == mobileNumberId) {
597 throw new NullPointerException("mobileNumberId is null"); //NOI18N
598 } else if (mobileNumberId < 1) {
600 throw new IllegalArgumentException("mobileNumberId=" + mobileNumberId + " is invalid."); //NOI18N
601 } else if (!this.mobileNumberCache.containsKey(mobileNumberId)) {
603 throw new PhoneEntityNotFoundException(mobileNumberId);
607 final DialableMobileNumber mobileNumber = this.mobileNumberCache.get(mobileNumberId);
614 * Post-construction method
617 public void init () {
619 if (!this.faxNumberCache.iterator().hasNext()) {
621 final List<DialableFaxNumber> faxNumbers = this.phoneBean.allFaxNumbers();
624 for (final DialableFaxNumber faxNumber : faxNumbers) {
626 this.faxNumberCache.put(faxNumber.getPhoneId(), faxNumber);
631 if (!this.landLineNumberCache.iterator().hasNext()) {
633 final List<DialableLandLineNumber> lineNumbers = this.phoneBean.allLandLineNumbers();
636 for (final DialableLandLineNumber lineNumber : lineNumbers) {
638 this.landLineNumberCache.put(lineNumber.getPhoneId(), lineNumber);
643 if (!this.mobileNumberCache.iterator().hasNext()) {
645 final List<DialableMobileNumber> mobileNumbers = this.phoneBean.allMobileNumbers();
648 for (final DialableMobileNumber mobileNumber : mobileNumbers) {
650 this.mobileNumberCache.put(mobileNumber.getPhoneId(), mobileNumber);
658 private void clear () {
663 * Uniquely add given fax number to this bean's list. First remove the old
664 * instance (by id number), then re-add it again.
666 * @param faxNumber number to add
668 private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
669 // Make sure the parameter is valid
670 if (null == faxNumber) {
672 throw new NullPointerException("faxNumber is null"); //NOI18N
673 } else if (faxNumber.getPhoneId() == null) {
675 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
676 } else if (faxNumber.getPhoneId() < 1) {
678 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); //NOI18N
682 if (!this.allFaxNumbers().remove(faxNumber)) {
683 // Did not work, try by id number
684 for (final DialableFaxNumber fax : this.allFaxNumbers()) {
685 // Is id number the same?
686 if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) {
688 this.allFaxNumbers().remove(fax);
695 this.allFaxNumbers().add(faxNumber);
699 * Uniquely add given land-line number to this bean's list. First remove the
700 * old instance (by id number), then re-add it again.
702 * @param landLineNumber Land-line number to add
704 private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
705 // Make sure the parameter is valid
706 if (null == landLineNumber) {
708 throw new NullPointerException("landLineNumber is null"); //NOI18N
709 } else if (landLineNumber.getPhoneId() == null) {
711 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
712 } else if (landLineNumber.getPhoneId() < 1) {
714 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); //NOI18N
718 if (!this.allLandLineNumbers().remove(landLineNumber)) {
719 // Did not work, try by id number
720 for (final DialableLandLineNumber landLine : this.allLandLineNumbers()) {
721 // Is id number the same?
722 if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) {
724 this.allLandLineNumbers().remove(landLine);
731 this.allLandLineNumbers().add(landLineNumber);
735 * Uniquely add given mobile number to this bean's list. First remove the
736 * old instance (by id number), then re-add it again.
738 * @param mobileNumber Mobile number to add
740 private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) {
741 // Make sure the parameter is valid
742 if (null == mobileNumber) {
744 throw new NullPointerException("mobileNumber is null"); //NOI18N
745 } else if (mobileNumber.getPhoneId() == null) {
747 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
748 } else if (mobileNumber.getPhoneId() < 1) {
750 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId())); //NOI18N
753 // First remove it by object
754 if (!this.allMobileNumbers().remove(mobileNumber)) {
755 // Did not work, try by id number
756 for (final DialableMobileNumber cell : this.allMobileNumbers()) {
757 // Is id number the same?
758 if (Objects.equals(cell.getPhoneId(), mobileNumber.getPhoneId())) {
760 this.allMobileNumbers().remove(cell);
767 this.allMobileNumbers().add(mobileNumber);
771 * Updates given contact's mobile, land-line and fax number
773 * @param contact Contact instance
775 private void updateContactPhoneNumbers (final Contact contact) {
776 // Parameter must be valid
777 if (null == contact) {
779 throw new NullPointerException("contact is null"); //NOI18N
780 } else if (contact.getContactId() == null) {
782 throw new NullPointerException("contact.contactId is null"); //NOI18N
783 } else if (contact.getContactId() < 1) {
784 // Id number is not valid
788 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
790 this.uniqueAddMobileNumber(contact.getContactMobileNumber());
794 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
796 this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
800 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
802 this.uniqueAddFaxNumber(contact.getContactFaxNumber());