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