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