]> git.mxchange.org Git - jjobs-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Wed, 17 Aug 2016 13:21:18 +0000 (15:21 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 17 Aug 2016 19:25:55 +0000 (21:25 +0200)
- implemented business methods unlinkFaxDataFromContact(), unlinkLandLineDataFromContact()

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jcontacts/phone/JobsAdminContactPhoneSessionBean.java

index 745e86062417effbc724f87c9ab10e117e46e831..01abe32ebcf091e753aa31be2a57bdc731f76faf 100644 (file)
@@ -23,7 +23,11 @@ import javax.ejb.Stateless;
 import org.mxchange.jcontacts.contact.Contact;
 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
+import org.mxchange.jphone.exceptions.FaxNumberNotLinkedException;
+import org.mxchange.jphone.exceptions.LandLineNumberNotLinkedException;
 import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
 
 /**
@@ -45,6 +49,90 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsDatabaseBean imple
        @EJB
        private ContactSessionBeanRemote contactBean;
 
+       @Override
+       public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws FaxNumberNotLinkedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N
+
+               // Is the contact set?
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // ... and throw again
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+               } else if (contact.getContactFaxNumber() == null) {
+                       // Not set cell phone instance
+                       throw new FaxNumberNotLinkedException(faxNumber);
+               } else if (contact.getContactFaxNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("contact.contactFaxNumber.phoneId is null"); //NOI18N
+               } else if (contact.getContactFaxNumber().getPhoneId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} is invalid.", contact.getContactFaxNumber().getPhoneId())); //NOI18N
+               } else if (!Objects.equals(faxNumber.getPhoneId(), contact.getContactFaxNumber().getPhoneId())) {
+                       // Not same object
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} and faxNumber.phoneId={1} are not the same.", contact.getContactFaxNumber().getPhoneId(), faxNumber.getPhoneId())); //NOI18N
+               }
+
+               // Remove it from contact
+               contact.setContactFaxNumber(null);
+
+               // Update database
+               Contact updatedContact = this.contactBean.updateContactData(contact);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+
+               // Return it
+               return updatedContact;
+       }
+
+       @Override
+       public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws LandLineNumberNotLinkedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N
+
+               // Is the contact set?
+               if (null == contact) {
+                       // Throw NPE
+                       throw new NullPointerException("contact is null"); //NOI18N
+               } else if (contact.getContactId() == null) {
+                       // ... and throw again
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
+               } else if (contact.getContactId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+               } else if (contact.getContactLandLineNumber() == null) {
+                       // Not set cell phone instance
+                       throw new LandLineNumberNotLinkedException(landLineNumber);
+               } else if (contact.getContactLandLineNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("contact.contactLandLineNumber.phoneId is null"); //NOI18N
+               } else if (contact.getContactLandLineNumber().getPhoneId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} is invalid.", contact.getContactLandLineNumber().getPhoneId())); //NOI18N
+               } else if (!Objects.equals(landLineNumber.getPhoneId(), contact.getContactLandLineNumber().getPhoneId())) {
+                       // Not same object
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} and landLineNumber.phoneId={1} are not the same.", contact.getContactLandLineNumber().getPhoneId(), landLineNumber.getPhoneId())); //NOI18N
+               }
+
+               // Remove it from contact
+               contact.setContactLandLineNumber(null);
+
+               // Update database
+               Contact updatedContact = this.contactBean.updateContactData(contact);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+
+               // Return it
+               return updatedContact;
+       }
+
        @Override
        public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws MobileNumberNotLinkedException {
                // Trace message
@@ -65,13 +153,13 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsDatabaseBean imple
                        throw new MobileNumberNotLinkedException(mobileNumber);
                } else if (contact.getContactMobileNumber().getPhoneId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("contact.contactCellphoneNumber.phoneId is null"); //NOI18N
+                       throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N
                } else if (contact.getContactMobileNumber().getPhoneId() < 1) {
                        // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactCellphoneNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getPhoneId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getPhoneId())); //NOI18N
                } else if (!Objects.equals(mobileNumber.getPhoneId(), contact.getContactMobileNumber().getPhoneId())) {
                        // Not same object
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactCellphoneNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N
                }
 
                // Remove it from contact