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