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