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.LinkedList;
22 import java.util.List;
23 import java.util.Objects;
24 import javax.annotation.PostConstruct;
25 import javax.cache.Cache;
27 import javax.enterprise.context.RequestScoped;
28 import javax.enterprise.event.Observes;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
32 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
33 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
34 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
35 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
36 import org.mxchange.jcontacts.model.contact.Contact;
37 import org.mxchange.jjobs.beans.BaseJobsBean;
38 import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
39 import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
40 import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
41 import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
42 import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
43 import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
44 import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
45 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
48 import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
49 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
52 * Regular controller (bean) for phone numbers
54 * @author Roland Häder<roland@mxchange.org>
56 @Named ("phoneController")
58 public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWebRequestController {
63 private static final long serialVersionUID = 491_058_674_675_690_105L;
69 @NamedCache (cacheName = "faxNumberCache")
70 private Cache<Long, DialableFaxNumber> faxNumberCache;
73 * All land-line numbers
76 @NamedCache (cacheName = "landLineNumberCache")
77 private Cache<Long, DialableLandLineNumber> landLineNumberCache;
83 @NamedCache (cacheName = "mobileNumberCache")
84 private Cache<Long, DialableMobileNumber> mobileNumberCache;
87 * General EJB for phone numbers
89 @EJB (lookup = "java:global/jjobs-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote")
90 private PhoneSessionBeanRemote phoneBean;
95 public JobsPhoneWebRequestBean () {
96 // Call super constructor
101 * Observes events being fired when an administrator has added a new
104 * @param event Event being fired
106 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
107 // The event must be valid
110 throw new NullPointerException("event is null"); //NOI18N
111 } else if (event.getAddedContact() == null) {
113 throw new NullPointerException("event.addedContact is null"); //NOI18N
114 } else if (event.getAddedContact().getContactId() == null) {
116 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
117 } else if (event.getAddedContact().getContactId() < 1) {
119 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
122 // Update contact's mobile, land-line and fax number
123 this.updateContactPhoneNumbers(event.getAddedContact());
130 * Event observer for newly added users by administrator
132 * @param event Event being fired
134 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
135 // Event and contained entity instance should not be null
138 throw new NullPointerException("event is null"); //NOI18N
139 } else if (event.getAddedUser() == null) {
141 throw new NullPointerException("event.addedUser is null"); //NOI18N
142 } else if (event.getAddedUser().getUserId() == null) {
144 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
145 } else if (event.getAddedUser().getUserId() < 1) {
147 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
150 // Update contact's mobile, land-line and fax number
151 this.updateContactPhoneNumbers(event.getAddedUser().getUserContact());
158 * Observes events being fired when an administrator has deleted a fax
161 * @param event Event being fired
163 public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent event) {
164 // Event and contained entity instance should not be null
167 throw new NullPointerException("event is null"); //NOI18N
168 } else if (event.getDeletedFaxNumber() == null) {
170 throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N
171 } else if (event.getDeletedFaxNumber().getPhoneId() == null) {
173 throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N
174 } else if (event.getDeletedFaxNumber().getPhoneId() < 1) {
176 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N
179 // Update contact's mobile, land-line and fax number
180 this.allFaxNumbers().remove(event.getDeletedFaxNumber());
187 * Observes events being fired when an administrator has deleted a land-line
190 * @param event Event being fired
192 public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent event) {
193 // Event and contained entity instance should not be null
196 throw new NullPointerException("event is null"); //NOI18N
197 } else if (event.getDeletedLandLineNumber() == null) {
199 throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N
200 } else if (event.getDeletedLandLineNumber().getPhoneId() == null) {
202 throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N
203 } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) {
205 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N
208 // Update contact's mobile, land-line and fax number
209 this.allLandLineNumbers().remove(event.getDeletedLandLineNumber());
216 * Observes events being fired when an administrator has deleted a mobile
219 * @param event Event being fired
221 public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent event) {
222 // Event and contained entity instance should not be null
225 throw new NullPointerException("event is null"); //NOI18N
226 } else if (event.getDeletedMobileNumber() == null) {
228 throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N
229 } else if (event.getDeletedMobileNumber().getPhoneId() == null) {
231 throw new NullPointerException("event.deletedMobileNumber.phoneId is null"); //NOI18N
232 } else if (event.getDeletedMobileNumber().getPhoneId() < 1) {
234 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getPhoneId())); //NOI18N
237 // Update contact's mobile, land-line and fax number
238 this.allMobileNumbers().remove(event.getDeletedMobileNumber());
245 * Observes events being fired when an administrator has a linked a fax
248 * @param event Event being fired
250 public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) {
251 // Is the event fine?
254 throw new NullPointerException("event is null"); //NOI18N
255 } else if (event.getContact() == null) {
257 throw new NullPointerException("event.contact is null"); //NOI18N
258 } else if (event.getContact().getContactId() == null) {
260 throw new NullPointerException("event.contact.contactId is null"); //NOI18N
261 } else if (event.getContact().getContactId() < 1) {
263 throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
264 } else if (event.getContact().getContactFaxNumber() == null) {
266 throw new NullPointerException("event.contact.contactFaxNumber is null"); //NOI18N
267 } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
269 throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); //NOI18N
270 } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
272 throw new NullPointerException("event.contact.contactFaxNumber.phoneId=" + event.getContact().getContactFaxNumber().getPhoneId() + " is invalid"); //NOI18N
273 } else if (event.getLinkedFaxNumber() == null) {
275 throw new NullPointerException("event.linkedFaxNumer is null"); //NOI18N
278 // Is the id number in linked number not set?
279 if (event.getLinkedFaxNumber().getPhoneId() == null) {
280 // Then it is a new number, so add it from contact as there the id number has been set
281 this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber());
286 * Observes events being fired when an administrator has a linked a
289 * @param event Event being fired
291 public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) {
292 // Is the event fine?
295 throw new NullPointerException("event is null"); //NOI18N
296 } else if (event.getContact() == null) {
298 throw new NullPointerException("event.contact is null"); //NOI18N
299 } else if (event.getContact().getContactId() == null) {
301 throw new NullPointerException("event.contact.contactId is null"); //NOI18N
302 } else if (event.getContact().getContactId() < 1) {
304 throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
305 } else if (event.getContact().getContactLandLineNumber() == null) {
307 throw new NullPointerException("event.contact.contactLandLineNumber is null"); //NOI18N
308 } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
310 throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); //NOI18N
311 } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
313 throw new NullPointerException("event.contact.contactLandLineNumber.phoneId=" + event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid"); //NOI18N
314 } else if (event.getLinkedLandLineNumber() == null) {
316 throw new NullPointerException("event.linkedLandLineNumer is null"); //NOI18N
319 // Is the id number in linked number not set?
320 if (event.getLinkedLandLineNumber().getPhoneId() == null) {
321 // Then it is a new number, so add it from contact as there the id number has been set
322 this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber());
327 * Observes events being fired when an administrator has a linked a mobile
330 * @param event Event being fired
332 public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) {
333 // Is the event fine?
336 throw new NullPointerException("event is null"); //NOI18N
337 } else if (event.getContact() == null) {
339 throw new NullPointerException("event.contact is null"); //NOI18N
340 } else if (event.getContact().getContactId() == null) {
342 throw new NullPointerException("event.contact.contactId is null"); //NOI18N
343 } else if (event.getContact().getContactId() < 1) {
345 throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
346 } else if (event.getContact().getContactMobileNumber() == null) {
348 throw new NullPointerException("event.contact.contactMobileNumber is null"); //NOI18N
349 } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) {
351 throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null"); //NOI18N
352 } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) {
354 throw new NullPointerException("event.contact.contactMobileNumber.phoneId=" + event.getContact().getContactMobileNumber().getPhoneId() + " is invalid"); //NOI18N
355 } else if (event.getLinkedMobileNumber() == null) {
357 throw new NullPointerException("event.linkedMobileNumer is null"); //NOI18N
360 // Is the id number in linked number not set?
361 if (event.getLinkedMobileNumber().getPhoneId() == null) {
362 // Then it is a new number, so add it from contact as there the id number has been set
363 this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber());
368 * Observes events being fired when an administrator has updated contact
371 * @param event Event being fired
373 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
374 // Event and contained entity instance should not be null
377 throw new NullPointerException("event is null"); //NOI18N
378 } else if (event.getUpdatedContact() == null) {
380 throw new NullPointerException("event.updatedContact is null"); //NOI18N
381 } else if (event.getUpdatedContact().getContactId() == null) {
383 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
384 } else if (event.getUpdatedContact().getContactId() < 1) {
386 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
389 // Update contact's mobile, land-line and fax number
390 this.updateContactPhoneNumbers(event.getUpdatedContact());
397 * Observes events being fired when an administrator has updated a fax
400 * @param event Event being fired
402 public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent event) {
403 // Event and contained entity instance should not be null
406 throw new NullPointerException("event is null"); //NOI18N
407 } else if (event.getUpdatedFaxNumber() == null) {
409 throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N
410 } else if (event.getUpdatedFaxNumber().getPhoneId() == null) {
412 throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N
413 } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) {
415 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N
419 this.uniqueAddFaxNumber(event.getUpdatedFaxNumber());
426 * Observes events being fired when an administrator has updated a land-line
429 * @param event Event being fired
431 public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent event) {
432 // Event and contained entity instance should not be null
435 throw new NullPointerException("event is null"); //NOI18N
436 } else if (event.getUpdatedLandLineNumber() == null) {
438 throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N
439 } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) {
441 throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N
442 } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) {
444 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N
448 this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber());
455 * Observes events being fired when an administrator has updated a mobile
458 * @param event Event being fired
460 public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent event) {
461 // Event and contained entity instance should not be null
464 throw new NullPointerException("event is null"); //NOI18N
465 } else if (event.getUpdatedMobileNumber() == null) {
467 throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N
468 } else if (event.getUpdatedMobileNumber().getPhoneId() == null) {
470 throw new NullPointerException("event.updatedMobileNumber.phoneId is null"); //NOI18N
471 } else if (event.getUpdatedMobileNumber().getPhoneId() < 1) {
473 throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getPhoneId())); //NOI18N
477 this.uniqueAddMobileNumber(event.getUpdatedMobileNumber());
484 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
485 public List<DialableFaxNumber> allFaxNumbers () {
487 final List<DialableFaxNumber> list = new LinkedList<>();
490 for (final Cache.Entry<Long, DialableFaxNumber> currentEntry : this.faxNumberCache) {
492 list.add(currentEntry.getValue());
500 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
501 public List<DialableLandLineNumber> allLandLineNumbers () {
503 final List<DialableLandLineNumber> list = new LinkedList<>();
506 for (final Cache.Entry<Long, DialableLandLineNumber> currentEntry : this.landLineNumberCache) {
508 list.add(currentEntry.getValue());
516 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
517 public List<DialableMobileNumber> allMobileNumbers () {
519 final List<DialableMobileNumber> list = new LinkedList<>();
522 for (final Cache.Entry<Long, DialableMobileNumber> currentEntry : this.mobileNumberCache) {
524 list.add(currentEntry.getValue());
532 public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException {
534 if (null == faxNumberId) {
536 throw new NullPointerException("faxNumberId is null"); //NOI18N
537 } else if (faxNumberId < 1) {
539 throw new IllegalArgumentException("faxNumberId=" + faxNumberId + " is invalid."); //NOI18N
540 } else if (!this.faxNumberCache.containsKey(faxNumberId)) {
542 throw new PhoneEntityNotFoundException(faxNumberId);
546 final DialableFaxNumber faxNumber = this.faxNumberCache.get(faxNumberId);
553 public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException {
555 if (null == landLineNumberId) {
557 throw new NullPointerException("landLineNumberId is null"); //NOI18N
558 } else if (landLineNumberId < 1) {
560 throw new IllegalArgumentException("landLineNumberId=" + landLineNumberId + " is invalid."); //NOI18N
561 } else if (!this.landLineNumberCache.containsKey(landLineNumberId)) {
563 throw new PhoneEntityNotFoundException(landLineNumberId);
567 final DialableLandLineNumber landLineNumber = this.landLineNumberCache.get(landLineNumberId);
570 return landLineNumber;
574 public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException {
576 if (null == mobileNumberId) {
578 throw new NullPointerException("mobileNumberId is null"); //NOI18N
579 } else if (mobileNumberId < 1) {
581 throw new IllegalArgumentException("mobileNumberId=" + mobileNumberId + " is invalid."); //NOI18N
582 } else if (!this.mobileNumberCache.containsKey(mobileNumberId)) {
584 throw new PhoneEntityNotFoundException(mobileNumberId);
588 final DialableMobileNumber mobileNumber = this.mobileNumberCache.get(mobileNumberId);
595 * Post-construction method
598 public void init () {
600 if (!this.faxNumberCache.iterator().hasNext()) {
602 for (final DialableFaxNumber faxNumber : this.phoneBean.allFaxNumbers()) {
604 this.faxNumberCache.put(faxNumber.getPhoneId(), faxNumber);
609 if (!this.landLineNumberCache.iterator().hasNext()) {
611 for (final DialableLandLineNumber lineNumber : this.phoneBean.allLandLineNumbers()) {
613 this.landLineNumberCache.put(lineNumber.getPhoneId(), lineNumber);
618 if (!this.mobileNumberCache.iterator().hasNext()) {
620 for (final DialableMobileNumber mobileNumber : this.phoneBean.allMobileNumbers()) {
622 this.mobileNumberCache.put(mobileNumber.getPhoneId(), mobileNumber);
630 private void clear () {
635 * Uniquely add given fax number to this bean's list. First remove the old
636 * instance (by id number), then re-add it again.
638 * @param faxNumber number to add
640 private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
641 // Make sure the parameter is valid
642 if (null == faxNumber) {
644 throw new NullPointerException("faxNumber is null"); //NOI18N
645 } else if (faxNumber.getPhoneId() == null) {
647 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
648 } else if (faxNumber.getPhoneId() < 1) {
650 throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); //NOI18N
654 if (!this.allFaxNumbers().remove(faxNumber)) {
655 // Did not work, try by id number
656 for (final DialableFaxNumber fax : this.allFaxNumbers()) {
657 // Is id number the same?
658 if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) {
660 this.allFaxNumbers().remove(fax);
667 this.allFaxNumbers().add(faxNumber);
671 * Uniquely add given land-line number to this bean's list. First remove the
672 * old instance (by id number), then re-add it again.
674 * @param landLineNumber Land-line number to add
676 private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
677 // Make sure the parameter is valid
678 if (null == landLineNumber) {
680 throw new NullPointerException("landLineNumber is null"); //NOI18N
681 } else if (landLineNumber.getPhoneId() == null) {
683 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
684 } else if (landLineNumber.getPhoneId() < 1) {
686 throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); //NOI18N
690 if (!this.allLandLineNumbers().remove(landLineNumber)) {
691 // Did not work, try by id number
692 for (final DialableLandLineNumber landLine : this.allLandLineNumbers()) {
693 // Is id number the same?
694 if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) {
696 this.allLandLineNumbers().remove(landLine);
703 this.allLandLineNumbers().add(landLineNumber);
707 * Uniquely add given mobile number to this bean's list. First remove the
708 * old instance (by id number), then re-add it again.
710 * @param mobileNumber Mobile number to add
712 private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) {
713 // Make sure the parameter is valid
714 if (null == mobileNumber) {
716 throw new NullPointerException("mobileNumber is null"); //NOI18N
717 } else if (mobileNumber.getPhoneId() == null) {
719 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
720 } else if (mobileNumber.getPhoneId() < 1) {
722 throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId())); //NOI18N
725 // First remove it by object
726 if (!this.allMobileNumbers().remove(mobileNumber)) {
727 // Did not work, try by id number
728 for (final DialableMobileNumber cell : this.allMobileNumbers()) {
729 // Is id number the same?
730 if (Objects.equals(cell.getPhoneId(), mobileNumber.getPhoneId())) {
732 this.allMobileNumbers().remove(cell);
739 this.allMobileNumbers().add(mobileNumber);
743 * Updates given contact's mobile, land-line and fax number
745 * @param contact Contact instance
747 private void updateContactPhoneNumbers (final Contact contact) {
748 // Parameter must be valid
749 if (null == contact) {
751 throw new NullPointerException("contact is null"); //NOI18N
752 } else if (contact.getContactId() == null) {
754 throw new NullPointerException("contact.contactId is null"); //NOI18N
755 } else if (contact.getContactId() < 1) {
756 // Id number is not valid
760 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
762 this.uniqueAddMobileNumber(contact.getContactMobileNumber());
766 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
768 this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
772 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
774 this.uniqueAddFaxNumber(contact.getContactFaxNumber());