]> git.mxchange.org Git - jfinancials-mailer-ejb.git/blob - src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java
Continued a bit:
[jfinancials-mailer-ejb.git] / src / java / org / mxchange / jcontacts / phone / AddressbookAdminContactPhoneSessionBean.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontacts.phone;
18
19 import java.text.MessageFormat;
20 import java.util.GregorianCalendar;
21 import java.util.Objects;
22 import javax.ejb.EJB;
23 import javax.ejb.Stateless;
24 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
25 import org.mxchange.jcontacts.contact.Contact;
26 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
27 import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
28 import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
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
33 /**
34  * A session EJB for administrative contact's phone number purposes
35  * <p>
36  * @author Roland Häder<roland@mxchange.org>
37  */
38 @Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data")
39 public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
40
41         /**
42          * Serial number
43          */
44         private static final long serialVersionUID = 189_217_561_460_237_108L;
45
46         /**
47          * Contact EJB
48          */
49         @EJB
50         private ContactSessionBeanRemote contactBean;
51
52         @Override
53         public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException {
54                 // Trace message
55                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
56
57                 // Is the contact set?
58                 if (null == contact) {
59                         // Throw NPE
60                         throw new NullPointerException("contact is null"); //NOI18N
61                 } else if (contact.getContactId() == null) {
62                         // ... and throw again
63                         throw new NullPointerException("contact.contactId is null"); //NOI18N
64                 } else if (contact.getContactId() < 1) {
65                         // Invalid id number
66                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
67                 } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
68                         // Not set cell phone instance
69                         throw new PhoneNumberAlreadyLinkedException(faxNumber);
70                 } else if (null == faxNumber) {
71                         // Throw NPE
72                         throw new NullPointerException("faxNumber is null"); //NOI18N
73                 } else if (faxNumber.getPhoneId() == null) {
74                         // Throw it again
75                         throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
76                 } else if (faxNumber.getPhoneId() < 1) {
77                         // Invalid id
78                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
79                 } else if (faxNumber.getPhoneCountry() == null) {
80                         // ... and again
81                         throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
82                 } else if (faxNumber.getPhoneAreaCode() == null) {
83                         // Throw it again
84                         throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
85                 } else if (faxNumber.getPhoneAreaCode() < 1) {
86                         // Invalid id
87                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N
88                 } else if (faxNumber.getPhoneNumber() == null) {
89                         // Throw it again
90                         throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
91                 } else if (faxNumber.getPhoneNumber() < 1) {
92                         // Invalid id
93                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N
94                 }
95
96                 // Set fax number in contact
97                 contact.setContactFaxNumber(faxNumber);
98
99                 // Update database
100                 Contact updatedContact = this.contactBean.updateContactData(contact);
101
102                 // Trace message
103                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
104
105                 // Return it
106                 return updatedContact;
107         }
108
109         @Override
110         public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException {
111                 // Trace message
112                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
113
114                 // Is the contact set?
115                 if (null == contact) {
116                         // Throw NPE
117                         throw new NullPointerException("contact is null"); //NOI18N
118                 } else if (contact.getContactId() == null) {
119                         // ... and throw again
120                         throw new NullPointerException("contact.contactId is null"); //NOI18N
121                 } else if (contact.getContactId() < 1) {
122                         // Invalid id number
123                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
124                 } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
125                         // Not set cell phone instance
126                         throw new PhoneNumberAlreadyLinkedException(landLineNumber);
127                 } else if (null == landLineNumber) {
128                         // Throw NPE
129                         throw new NullPointerException("landLineNumber is null"); //NOI18N
130                 } else if (landLineNumber.getPhoneId() == null) {
131                         // Throw it again
132                         throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
133                 } else if (landLineNumber.getPhoneId() < 1) {
134                         // Invalid id
135                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
136                 } else if (landLineNumber.getPhoneCountry() == null) {
137                         // ... and again
138                         throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
139                 } else if (landLineNumber.getPhoneAreaCode() == null) {
140                         // Throw it again
141                         throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
142                 } else if (landLineNumber.getPhoneAreaCode() < 1) {
143                         // Invalid id
144                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N
145                 } else if (landLineNumber.getPhoneNumber() == null) {
146                         // Throw it again
147                         throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
148                 } else if (landLineNumber.getPhoneNumber() < 1) {
149                         // Invalid id
150                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N
151                 }
152
153                 // Set land-line number in contact
154                 contact.setContactLandLineNumber(landLineNumber);
155
156                 // Update database
157                 Contact updatedContact = this.contactBean.updateContactData(contact);
158
159                 // Trace message
160                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
161
162                 // Return it
163                 return updatedContact;
164         }
165
166         @Override
167         public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException {
168                 // Trace message
169                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
170
171                 // Is the contact set?
172                 if (null == contact) {
173                         // Throw NPE
174                         throw new NullPointerException("contact is null"); //NOI18N
175                 } else if (contact.getContactId() == null) {
176                         // ... and throw again
177                         throw new NullPointerException("contact.contactId is null"); //NOI18N
178                 } else if (contact.getContactId() < 1) {
179                         // Invalid id number
180                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
181                 } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
182                         // Not set cell phone instance
183                         throw new PhoneNumberAlreadyLinkedException(mobileNumber);
184                 } else if (null == mobileNumber) {
185                         // Throw NPE
186                         throw new NullPointerException("mobileNumber is null"); //NOI18N
187                 } else if (mobileNumber.getPhoneId() == null) {
188                         // Throw it again
189                         throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
190                 } else if (mobileNumber.getPhoneId() < 1) {
191                         // Invalid id
192                         throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
193                 } else if (mobileNumber.getMobileProvider() == null) {
194                         // Throw NPE again
195                         throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
196                 } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
197                         // Throw NPE again
198                         throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
199                 } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
200                         // Throw NPE again
201                         throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
202                 }
203
204                 // Set mobile number in contact
205                 contact.setContactMobileNumber(mobileNumber);
206
207                 // Update database
208                 Contact updatedContact = this.contactBean.updateContactData(contact);
209
210                 // Trace message
211                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
212
213                 // Return it
214                 return updatedContact;
215         }
216
217         @Override
218         public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException {
219                 // Trace message
220                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
221
222                 // Is the contact set?
223                 if (null == contact) {
224                         // Throw NPE
225                         throw new NullPointerException("contact is null"); //NOI18N
226                 } else if (contact.getContactId() == null) {
227                         // ... and throw again
228                         throw new NullPointerException("contact.contactId is null"); //NOI18N
229                 } else if (contact.getContactId() < 1) {
230                         // Invalid id number
231                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
232                 } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
233                         // Not set cell phone instance
234                         throw new PhoneNumberAlreadyLinkedException(faxNumber);
235                 } else if (null == faxNumber) {
236                         // Throw NPE
237                         throw new NullPointerException("faxNumber is null"); //NOI18N
238                 } else if (faxNumber.getPhoneId() instanceof Long) {
239                         // Throw it again
240                         throw new IllegalStateException(MessageFormat.format("faxNumber.phoneId={0} is not null", faxNumber.getPhoneId())); //NOI18N
241                 } else if (faxNumber.getPhoneCountry() == null) {
242                         // ... and again
243                         throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
244                 } else if (faxNumber.getPhoneAreaCode() == null) {
245                         // Throw it again
246                         throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
247                 } else if (faxNumber.getPhoneAreaCode() < 1) {
248                         // Invalid id
249                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N
250                 } else if (faxNumber.getPhoneNumber() == null) {
251                         // Throw it again
252                         throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
253                 } else if (faxNumber.getPhoneNumber() < 1) {
254                         // Invalid id
255                         throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N
256                 }
257
258                 // Set created instance
259                 faxNumber.setPhoneEntryCreated(new GregorianCalendar());
260
261                 // Set fax number in contact
262                 contact.setContactFaxNumber(faxNumber);
263
264                 // Update database
265                 Contact updatedContact = this.contactBean.updateContactData(contact);
266
267                 // Trace message
268                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
269
270                 // Return it
271                 return updatedContact;
272         }
273
274         @Override
275         public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException {
276                 // Trace message
277                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
278
279                 // Is the contact set?
280                 if (null == contact) {
281                         // Throw NPE
282                         throw new NullPointerException("contact is null"); //NOI18N
283                 } else if (contact.getContactId() == null) {
284                         // ... and throw again
285                         throw new NullPointerException("contact.contactId is null"); //NOI18N
286                 } else if (contact.getContactId() < 1) {
287                         // Invalid id number
288                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
289                 } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
290                         // Not set cell phone instance
291                         throw new PhoneNumberAlreadyLinkedException(landLineNumber);
292                 } else if (null == landLineNumber) {
293                         // Throw NPE
294                         throw new NullPointerException("landLineNumber is null"); //NOI18N
295                 } else if (landLineNumber.getPhoneId() instanceof Long) {
296                         // Throw it again
297                         throw new IllegalStateException(MessageFormat.format("landLineNumber.phoneId={0} is not null", landLineNumber.getPhoneId())); //NOI18N
298                 } else if (landLineNumber.getPhoneCountry() == null) {
299                         // ... and again
300                         throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
301                 } else if (landLineNumber.getPhoneAreaCode() == null) {
302                         // Throw it again
303                         throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
304                 } else if (landLineNumber.getPhoneAreaCode() < 1) {
305                         // Invalid id
306                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N
307                 } else if (landLineNumber.getPhoneNumber() == null) {
308                         // Throw it again
309                         throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
310                 } else if (landLineNumber.getPhoneNumber() < 1) {
311                         // Invalid id
312                         throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N
313                 }
314
315                 // Set created instance
316                 landLineNumber.setPhoneEntryCreated(new GregorianCalendar());
317
318                 // Set landLine number in contact
319                 contact.setContactLandLineNumber(landLineNumber);
320
321                 // Update database
322                 Contact updatedContact = this.contactBean.updateContactData(contact);
323
324                 // Trace message
325                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
326
327                 // Return it
328                 return updatedContact;
329         }
330
331         @Override
332         public Contact linkNewMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException {
333                 // Trace message
334                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
335
336                 // Is the contact set?
337                 if (null == contact) {
338                         // Throw NPE
339                         throw new NullPointerException("contact is null"); //NOI18N
340                 } else if (contact.getContactId() == null) {
341                         // ... and throw again
342                         throw new NullPointerException("contact.contactId is null"); //NOI18N
343                 } else if (contact.getContactId() < 1) {
344                         // Invalid id number
345                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
346                 } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
347                         // Not set cell phone instance
348                         throw new PhoneNumberAlreadyLinkedException(mobileNumber);
349                 } else if (null == mobileNumber) {
350                         // Throw NPE
351                         throw new NullPointerException("mobileNumber is null"); //NOI18N
352                 } else if (mobileNumber.getPhoneId() instanceof Long) {
353                         // Throw it again
354                         throw new IllegalStateException(MessageFormat.format("mobileNumber.phoneId={0} is not null", mobileNumber.getPhoneId())); //NOI18N
355                 } else if (mobileNumber.getMobileProvider() == null) {
356                         // Throw NPE again
357                         throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
358                 } else if (mobileNumber.getMobileProvider().getProviderId() == null) {
359                         // Throw NPE again
360                         throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
361                 } else if (mobileNumber.getMobileProvider().getProviderId() < 1) {
362                         // Throw NPE again
363                         throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N
364                 }
365
366                 // Set created instance
367                 mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
368
369                 // Set mobile number in contact
370                 contact.setContactMobileNumber(mobileNumber);
371
372                 // Update database
373                 Contact updatedContact = this.contactBean.updateContactData(contact);
374
375                 // Trace message
376                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
377
378                 // Return it
379                 return updatedContact;
380         }
381
382         @Override
383         public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException {
384                 // Trace message
385                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
386
387                 // Is the contact set?
388                 if (null == contact) {
389                         // Throw NPE
390                         throw new NullPointerException("contact is null"); //NOI18N
391                 } else if (contact.getContactId() == null) {
392                         // ... and throw again
393                         throw new NullPointerException("contact.contactId is null"); //NOI18N
394                 } else if (contact.getContactId() < 1) {
395                         // Invalid id number
396                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
397                 } else if (contact.getContactFaxNumber() == null) {
398                         // Not set cell phone instance
399                         throw new PhoneNumberNotLinkedException(faxNumber);
400                 } else if (contact.getContactFaxNumber().getPhoneId() == null) {
401                         // Throw NPE again
402                         throw new NullPointerException("contact.contactFaxNumber.phoneId is null"); //NOI18N
403                 } else if (contact.getContactFaxNumber().getPhoneId() < 1) {
404                         // Invalid id number
405                         throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} is invalid.", contact.getContactFaxNumber().getPhoneId())); //NOI18N
406                 } else if (!Objects.equals(faxNumber.getPhoneId(), contact.getContactFaxNumber().getPhoneId())) {
407                         // Not same object
408                         throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} and faxNumber.phoneId={1} are not the same.", contact.getContactFaxNumber().getPhoneId(), faxNumber.getPhoneId())); //NOI18N
409                 }
410
411                 // Remove it from contact
412                 contact.setContactFaxNumber(null);
413
414                 // Update database
415                 Contact updatedContact = this.contactBean.updateContactData(contact);
416
417                 // Trace message
418                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
419
420                 // Return it
421                 return updatedContact;
422         }
423
424         @Override
425         public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException {
426                 // Trace message
427                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
428
429                 // Is the contact set?
430                 if (null == contact) {
431                         // Throw NPE
432                         throw new NullPointerException("contact is null"); //NOI18N
433                 } else if (contact.getContactId() == null) {
434                         // ... and throw again
435                         throw new NullPointerException("contact.contactId is null"); //NOI18N
436                 } else if (contact.getContactId() < 1) {
437                         // Invalid id number
438                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
439                 } else if (contact.getContactLandLineNumber() == null) {
440                         // Not set cell phone instance
441                         throw new PhoneNumberNotLinkedException(landLineNumber);
442                 } else if (contact.getContactLandLineNumber().getPhoneId() == null) {
443                         // Throw NPE again
444                         throw new NullPointerException("contact.contactLandLineNumber.phoneId is null"); //NOI18N
445                 } else if (contact.getContactLandLineNumber().getPhoneId() < 1) {
446                         // Invalid id number
447                         throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} is invalid.", contact.getContactLandLineNumber().getPhoneId())); //NOI18N
448                 } else if (!Objects.equals(landLineNumber.getPhoneId(), contact.getContactLandLineNumber().getPhoneId())) {
449                         // Not same object
450                         throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} and landLineNumber.phoneId={1} are not the same.", contact.getContactLandLineNumber().getPhoneId(), landLineNumber.getPhoneId())); //NOI18N
451                 }
452
453                 // Remove it from contact
454                 contact.setContactLandLineNumber(null);
455
456                 // Update database
457                 Contact updatedContact = this.contactBean.updateContactData(contact);
458
459                 // Trace message
460                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
461
462                 // Return it
463                 return updatedContact;
464         }
465
466         @Override
467         public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberNotLinkedException {
468                 // Trace message
469                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N
470
471                 // Is the contact set?
472                 if (null == contact) {
473                         // Throw NPE
474                         throw new NullPointerException("contact is null"); //NOI18N
475                 } else if (contact.getContactId() == null) {
476                         // ... and throw again
477                         throw new NullPointerException("contact.contactId is null"); //NOI18N
478                 } else if (contact.getContactId() < 1) {
479                         // Invalid id number
480                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
481                 } else if (contact.getContactMobileNumber() == null) {
482                         // Not set cell phone instance
483                         throw new PhoneNumberNotLinkedException(mobileNumber);
484                 } else if (contact.getContactMobileNumber().getPhoneId() == null) {
485                         // Throw NPE again
486                         throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N
487                 } else if (contact.getContactMobileNumber().getPhoneId() < 1) {
488                         // Invalid id number
489                         throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getPhoneId())); //NOI18N
490                 } else if (!Objects.equals(mobileNumber.getPhoneId(), contact.getContactMobileNumber().getPhoneId())) {
491                         // Not same object
492                         throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N
493                 }
494
495                 // Remove it from contact
496                 contact.setContactMobileNumber(null);
497
498                 // Update database
499                 Contact updatedContact = this.contactBean.updateContactData(contact);
500
501                 // Trace message
502                 this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
503
504                 // Return it
505                 return updatedContact;
506         }
507
508 }