]> git.mxchange.org Git - addressbook-mailer-ejb.git/blobdiff - src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java
updated jar(s)
[addressbook-mailer-ejb.git] / src / java / org / mxchange / jphone / phonenumbers / phone / AddressbookAdminPhoneSessionBean.java
index 2d1799fdff712e4a0a2f2f410f61f70dbbb7d337..1d63242ca9e3b204d9aa017f34627d4e90237a72 100644 (file)
@@ -21,8 +21,11 @@ import java.util.GregorianCalendar;
 import javax.ejb.Stateless;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.fax.FaxNumbers;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers;
 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers;
 
 /**
  * An EJB for administrative phone purposes
@@ -37,13 +40,21 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
         */
        private static final long serialVersionUID = 18_597_165_817_401_853L;
 
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminPhoneSessionBean () {
+               // Call super constructor
+               super();
+       }
+
        @Override
        public void deleteFaxData (final DialableFaxNumber faxNumber) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
 
                // Is all data set
-               if (null == faxNumber) {
+               if (faxNumber == null) {
                        // Not set, throw NPE
                        throw new NullPointerException("faxNumber is null"); //NOI18N
                } else if (faxNumber.getPhoneId() == null) {
@@ -52,15 +63,21 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
                } else if (faxNumber.getPhoneId() < 1) {
                        // Invalid number
                        throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
-               } else if (faxNumber.getPhoneCountry()== null) {
+               } else if (faxNumber.getPhoneCountry() == null) {
                        // Throw NPE
                        throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
-               } else if (faxNumber.getPhoneCountry().getCountryId()== null) {
-                       // ... throw again
+               } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
                        throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
                } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() < 1) {
                        // Id not valid
-                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid.", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
                } else if (faxNumber.getPhoneNumber() == null) {
                        // Throw NPE again
                        throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
@@ -69,7 +86,7 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
                        throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Merge it to get a managed entity back
+               // Get a managed instance
                DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId());
 
                // Remove it from database
@@ -82,10 +99,10 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
        @Override
        public void deleteLandLineData (final DialableLandLineNumber landLineNumber) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
 
                // Is all data set
-               if (null == landLineNumber) {
+               if (landLineNumber == null) {
                        // Not set, throw NPE
                        throw new NullPointerException("landLineNumber is null"); //NOI18N
                } else if (landLineNumber.getPhoneId() == null) {
@@ -94,15 +111,21 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
                } else if (landLineNumber.getPhoneId() < 1) {
                        // Invalid number
                        throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
-               } else if (landLineNumber.getPhoneCountry()== null) {
+               } else if (landLineNumber.getPhoneCountry() == null) {
                        // Throw NPE
                        throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
-               } else if (landLineNumber.getPhoneCountry().getCountryId()== null) {
-                       // ... throw again
+               } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
                        throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
                } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() < 1) {
                        // Id not valid
-                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid.", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
                } else if (landLineNumber.getPhoneNumber() == null) {
                        // Throw NPE again
                        throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
@@ -111,7 +134,7 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
                        throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Merge it to get a managed entity back
+               // Get a managed instance
                DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId());
 
                // Remove it from database
@@ -153,7 +176,7 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
                        throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Merge it to get a managed entity back
+               // Get a managed instance
                DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId());
 
                // Remove it from database
@@ -164,13 +187,119 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
        }
 
        @Override
-       public DialableFaxNumber updateFaxData (DialableFaxNumber faxNumber) {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber));
+
+               // Is all data set
+               if (faxNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("faxNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+               } else if (faxNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
+               } else if (faxNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (faxNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N
+               } else if (faxNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N
+               } else if (faxNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N
+               } else if (faxNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Get contact from it and find it
+               DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId());
+
+               // Should be found
+               assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
+
+               // Set updated timestamp
+               FaxNumbers.copyAll(faxNumber, managedNumber);
+               managedNumber.setPhoneEntryUpdated(new GregorianCalendar());
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
+
+               // Return it
+               return managedNumber;
        }
 
        @Override
-       public DialableLandLineNumber updateLandLineData (DialableLandLineNumber landLineNumber) {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+       public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber));
+
+               // Is all data set
+               if (landLineNumber == null) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("landLineNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
+               } else if (landLineNumber.getPhoneCountry() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N
+               } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() == null) {
+                       // ... throw again
+                       throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N
+               } else if (landLineNumber.getPhoneAreaCode() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N
+               } else if (landLineNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Get contact from it and find it
+               DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId());
+
+               // Should be found
+               assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
+
+               // Set updated timestamp
+               LandLineNumbers.copyAll(landLineNumber, managedNumber);
+               managedNumber.setPhoneEntryUpdated(new GregorianCalendar());
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
+
+               // Return it
+               return managedNumber;
        }
 
        @Override
@@ -205,26 +334,24 @@ public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBea
                        throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N
                }
 
-               // Set updated timestamp
-               mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
-
                // Get contact from it and find it
-               DialableMobileNumber foundNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId());
+               DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId());
 
                // Should be found
-               assert (foundNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N
+               assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N
 
                // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateMobileData: foundNumber.phoneId={0}", foundNumber.getPhoneId())); //NOI18N
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N
 
-               // Merge contact instance
-               DialableMobileNumber detachedNumber = this.getEntityManager().merge(foundNumber);
+               // Set updated timestamp
+               MobileNumbers.copyAll(mobileNumber, managedNumber);
+               managedNumber.setPhoneEntryUpdated(new GregorianCalendar());
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
 
                // Return it
-               return detachedNumber;
+               return managedNumber;
        }
 
 }