]> git.mxchange.org Git - pizzaservice-mailer-ejb.git/commitdiff
Implemented new business method findUserById() + ignored strings for i18n
authorRoland Haeder <roland@mxchange.org>
Fri, 15 Apr 2016 12:42:39 +0000 (14:42 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 15 Apr 2016 12:43:51 +0000 (14:43 +0200)
src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java

index 173e749682fd997257c30afa6342c477c143347d..b46e6d3582299ab68364f002ffc77dd086dda610 100644 (file)
@@ -32,6 +32,7 @@ import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
 import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
@@ -223,6 +224,36 @@ public class AddressbookUserSessionBean extends BaseDatabaseBean implements User
                return foundUser;
        }
 
+       @Override
+       public User findUserById (final Long userId) throws UserNotFoundException {
+               // Is the parameter valid?
+               if (null == userId) {
+                       // Throw NPE
+                       throw new NullPointerException("userId is null"); //NOI18N
+               } else if (userId < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
+               } else if (!this.ifUserIdExists(userId)) {
+                       // Does not exist
+                       throw new UserNotFoundException(userId);
+               }
+
+               // Create query instance
+               Query query = this.getEntityManager().createNamedQuery("SearchUserId", LoginUser.class); //NOI18N
+
+               // Set user id
+               query.setParameter("id", userId); //NOI18N
+
+               // Fetch the result, it should be there by now
+               User user = (User) query.getSingleResult();
+
+               // Should be there
+               assert(user instanceof User) : "user is null"; //NOI18N
+
+               // Return found user
+               return user;
+       }
+
        @Override
        @SuppressWarnings ("unchecked")
        public List<String> getEmailAddressList () {
@@ -431,7 +462,7 @@ public class AddressbookUserSessionBean extends BaseDatabaseBean implements User
        @Override
        public void updateUserPersonalData (final User user) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPersonalData: user={0} - CALLED!", user));
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPersonalData: user={0} - CALLED!", user)); //NOI18N
 
                // user should not be null
                if (null == user) {
@@ -477,7 +508,7 @@ public class AddressbookUserSessionBean extends BaseDatabaseBean implements User
                assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
 
                // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId()));
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
 
                // Merge contact instance
                Contact detachedContact = this.getEntityManager().merge(foundContact);
@@ -497,19 +528,19 @@ public class AddressbookUserSessionBean extends BaseDatabaseBean implements User
                // Is there a  cellphone instance set?
                if (cellphone instanceof DialableCellphoneNumber) {
                        // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId()));
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N
 
                        // Then find it, too
                        DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
 
                        // Should be there
-                       assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId());
+                       assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId()); //NOI18N
 
                        // Then merge it, too
                        DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone);
 
                        // Should be there
-                       assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId());
+                       assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId()); //NOI18N
 
                        // Copy all
                        detachedCellphone.copyAll(user.getUserContact().getContactCellphoneNumber());
@@ -524,19 +555,19 @@ public class AddressbookUserSessionBean extends BaseDatabaseBean implements User
                // Is there a  fax instance set?
                if (fax instanceof DialableFaxNumber) {
                        // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId()));
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId())); //NOI18N
 
                        // Then find it, too
                        DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
 
                        // Should be there
-                       assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId());
+                       assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N
 
                        // Then merge it, too
                        DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
 
                        // Should be there
-                       assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId());
+                       assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
 
                        // Copy all
                        detachedFax.copyAll(user.getUserContact().getContactFaxNumber());
@@ -551,19 +582,19 @@ public class AddressbookUserSessionBean extends BaseDatabaseBean implements User
                // Is there a  fax instance set?
                if (landLine instanceof DialableLandLineNumber) {
                        // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId()));
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId())); //NOI18N
 
                        // Then find it, too
                        DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
 
                        // Should be there
-                       assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId());
+                       assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N
 
                        // Then merge it, too
                        DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
 
                        // Should be there
-                       assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId());
+                       assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
 
                        // Copy all
                        detachedLandLine.copyAll(user.getUserContact().getContactLandLineNumber());