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