]> git.mxchange.org Git - jjobs-ejb.git/commitdiff
Rewrite continued: (please cherry-pick)
authorRoland Häder <roland@mxchange.org>
Wed, 10 Aug 2016 11:05:22 +0000 (13:05 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 16 Aug 2016 19:20:39 +0000 (21:20 +0200)
- moved business methods to proper EJB as they are not contact-related but "phone-generic" enough. Maybe still mail notifications can be added to them.

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

index 3ac7dd829361710d620ea436278922475ca55c4c..71873d4243f45ee2f6d5ecb26663866612e8e9b2 100644 (file)
  */
 package org.mxchange.jcontacts.phone;
 
-import java.text.MessageFormat;
-import java.util.GregorianCalendar;
 import javax.ejb.Stateless;
 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 
 /**
  * A session EJB for administrative contact's phone number purposes
@@ -35,97 +32,4 @@ public class JobsAdminContactPhoneSessionBean extends BaseJobsDatabaseBean imple
         */
        private static final long serialVersionUID = 189_217_561_460_237_108L;
 
-       @Override
-       public void deleteCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
-
-               // Is all data set
-               if (null == cellPhoneNumber) {
-                       // Not set, throw NPE
-                       throw new NullPointerException("cellphoneNumber is null"); //NOI18N
-               } else if (cellPhoneNumber.getPhoneId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N
-               } else if (cellPhoneNumber.getPhoneId() < 1) {
-                       // Invalid number
-                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
-               } else if (cellPhoneNumber.getCellphoneProvider() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N
-               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
-                       // ... throw again
-                       throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
-               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
-                       // Id not valid
-                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
-               } else if (cellPhoneNumber.getPhoneNumber() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N
-               } else if (cellPhoneNumber.getPhoneNumber() < 1) {
-                       // Throw NPE again
-                       throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
-               }
-
-               // Remove it from database
-               this.getEntityManager().remove(cellPhoneNumber);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteCellphoneData: EXIT!", this.getClass().getSimpleName()));
-       }
-
-       @Override
-       public DialableCellphoneNumber updateCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
-
-               // Is all data set
-               if (null == cellPhoneNumber) {
-                       // Not set, throw NPE
-                       throw new NullPointerException("cellphoneNumber is null"); //NOI18N
-               } else if (cellPhoneNumber.getPhoneId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N
-               } else if (cellPhoneNumber.getPhoneId() < 1) {
-                       // Invalid number
-                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
-               } else if (cellPhoneNumber.getCellphoneProvider() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N
-               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
-                       // ... throw again
-                       throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
-               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
-                       // Id not valid
-                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
-               } else if (cellPhoneNumber.getPhoneNumber() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N
-               } else if (cellPhoneNumber.getPhoneNumber() < 1) {
-                       // Throw NPE again
-                       throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
-               }
-
-               // Set updated timestamp
-               cellPhoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
-
-               // Get contact from it and find it
-               DialableCellphoneNumber foundNumber = this.getEntityManager().find(cellPhoneNumber.getClass(), cellPhoneNumber.getPhoneId());
-
-               // Should be found
-               assert (foundNumber instanceof DialableCellphoneNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", cellPhoneNumber.getPhoneId()); //NOI18N
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateCellphoneData: foundNumber.phoneId={0}", foundNumber.getPhoneId())); //NOI18N
-
-               // Merge contact instance
-               DialableCellphoneNumber detachedNumber = this.getEntityManager().merge(foundNumber);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
-
-               // Return it
-               return detachedNumber;
-       }
-
 }
index 187d1d446b7903504d99f983b6afdae63b26d640..57f58c54dc9d8e01df207175c5665f8f9fc37d8d 100644 (file)
  */
 package org.mxchange.jphone.phonenumbers.phone;
 
+import java.text.MessageFormat;
+import java.util.GregorianCalendar;
 import javax.ejb.Stateless;
 import org.mxchange.jjobs.database.BaseJobsDatabaseBean;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 
 /**
  * An EJB for administrative phone purposes
@@ -32,4 +35,97 @@ public class JobsAdminPhoneSessionBean extends BaseJobsDatabaseBean implements A
         */
        private static final long serialVersionUID = 18_597_165_817_401_853L;
 
+       @Override
+       public void deleteCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
+
+               // Is all data set
+               if (null == cellPhoneNumber) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("cellphoneNumber is null"); //NOI18N
+               } else if (cellPhoneNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N
+               } else if (cellPhoneNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
+               } else if (cellPhoneNumber.getCellphoneProvider() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N
+               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
+               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
+               } else if (cellPhoneNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N
+               } else if (cellPhoneNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Remove it from database
+               this.getEntityManager().remove(cellPhoneNumber);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteCellphoneData: EXIT!", this.getClass().getSimpleName()));
+       }
+
+       @Override
+       public DialableCellphoneNumber updateCellphoneData (final DialableCellphoneNumber cellPhoneNumber) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: cellPhoneNumber={1} - CALLED!", this.getClass().getSimpleName(), cellPhoneNumber));
+
+               // Is all data set
+               if (null == cellPhoneNumber) {
+                       // Not set, throw NPE
+                       throw new NullPointerException("cellphoneNumber is null"); //NOI18N
+               } else if (cellPhoneNumber.getPhoneId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("cellphoneNumber.phoneId is null"); //NOI18N
+               } else if (cellPhoneNumber.getPhoneId() < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.phoneId={0} is not valid", cellPhoneNumber.getPhoneId())); //NOI18N
+               } else if (cellPhoneNumber.getCellphoneProvider() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("cellphoneNumber.cellphoneProvider is null"); //NOI18N
+               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() == null) {
+                       // ... throw again
+                       throw new NullPointerException("cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N
+               } else if (cellPhoneNumber.getCellphoneProvider().getProviderId() < 1) {
+                       // Id not valid
+                       throw new IllegalArgumentException(MessageFormat.format("cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", cellPhoneNumber.getCellphoneProvider().getProviderId())); //NOI18N
+               } else if (cellPhoneNumber.getPhoneNumber() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("cellphoneNumber.phoneNumber is null"); //NOI18N
+               } else if (cellPhoneNumber.getPhoneNumber() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("cellphoneNumber.phoneNumber={0} is not valid.", cellPhoneNumber.getPhoneNumber())); //NOI18N
+               }
+
+               // Set updated timestamp
+               cellPhoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
+
+               // Get contact from it and find it
+               DialableCellphoneNumber foundNumber = this.getEntityManager().find(cellPhoneNumber.getClass(), cellPhoneNumber.getPhoneId());
+
+               // Should be found
+               assert (foundNumber instanceof DialableCellphoneNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", cellPhoneNumber.getPhoneId()); //NOI18N
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateCellphoneData: foundNumber.phoneId={0}", foundNumber.getPhoneId())); //NOI18N
+
+               // Merge contact instance
+               DialableCellphoneNumber detachedNumber = this.getEntityManager().merge(foundNumber);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateCellphoneData: detachedNumber={1} - EXIT!", this.getClass().getSimpleName(), detachedNumber)); //NOI18N
+
+               // Return it
+               return detachedNumber;
+       }
+
 }