]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Thu, 11 Aug 2016 08:02:39 +0000 (10:02 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 16 Aug 2016 17:50:33 +0000 (19:50 +0200)
- maybe implemented unlinkCellphoneDataFromContact() as this may not work by just unsetting (null) the instance

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

index 3df4fbd92549007f2d2ed8d2dae9c60561b15171..91234772b955b6f962581f32e66301f0b60d6462 100644 (file)
  */
 package org.mxchange.jcontacts.phone;
 
+import java.text.MessageFormat;
+import java.util.Objects;
+import javax.ejb.EJB;
 import javax.ejb.Stateless;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
+import org.mxchange.jphone.exceptions.CellphoneNotLinkedException;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
 
 /**
@@ -24,7 +31,7 @@ import org.mxchange.pizzaaplication.database.BasePizzaDatabaseBean;
  * <p>
  * @author Roland Haeder<rhaeder@cho-time.de>
  */
-@Stateless (name = "admincontactphone", description = "An administrative bean handling contact's phone data")
+@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data")
 public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean implements AdminContactsPhoneSessionBeanRemote {
 
        /**
@@ -32,4 +39,52 @@ public class PizzaAdminContactPhoneSessionBean extends BasePizzaDatabaseBean imp
         */
        private static final long serialVersionUID = 189_217_561_460_237_108L;
 
+       /**
+        * Contact EJB
+        */
+       @EJB
+       private ContactSessionBeanRemote contactBean;
+
+       @Override
+       public Contact unlinkCellphoneDataFromContact (final Contact contact, final DialableCellphoneNumber cellphoneNumber) throws CellphoneNotLinkedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkCellphoneDataFromContact: contact={1},cellphoneNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, cellphoneNumber)); //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.getContactCellphoneNumber() == null) {
+                       // Not set cell phone instance
+                       throw new CellphoneNotLinkedException(cellphoneNumber);
+               } else if (contact.getContactCellphoneNumber().getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("contact.contactCellphoneNumber.phoneId is null"); //NOI18N
+               } else if (contact.getContactCellphoneNumber().getPhoneId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactCellphoneNumber.phoneId={0} is invalid.", contact.getContactCellphoneNumber().getPhoneId())); //NOI18N
+               } else if (!Objects.equals(cellphoneNumber.getPhoneId(), contact.getContactCellphoneNumber().getPhoneId())) {
+                       // Not same object
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactCellphoneNumber.phoneId={0} and cellphoneNumber.phoneId={1} are not the same.", contact.getContactCellphoneNumber().getPhoneId(), cellphoneNumber.getPhoneId())); //NOI18N
+               }
+
+               // Remove it from contact
+               contact.setContactCellphoneNumber(null);
+
+               // Update database
+               Contact updatedContact = this.contactBean.updateContactData(contact);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkCellphoneDataFromContact: updatedContact={1} - EXIT!", this.getClass().getSimpleName(), updatedContact)); //NOI18N
+
+               // Return it
+               return updatedContact;
+       }
+
 }