]> git.mxchange.org Git - addressbook-mailer-ejb.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 18:31:16 +0000 (20:31 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 18:31:40 +0000 (20:31 +0200)
- Implemented business method allUsersNotSharing()
- updated jar(s)

lib/juser-core.jar
src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java

index 94920473f0bd2dcfee1d99e5be9f16c81e3bd70d..c8486cff6d9b8b49ad3e85bc50a515a504837d72 100644 (file)
Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ
index 528f0dd82c591701fe4f1b6437751de01e966bcf..2798d410096843bad27798a14989b90c886b9881 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.addressbook.model.addressbook;
 
 import java.text.MessageFormat;
+import java.util.ArrayList;
 import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.NoResultException;
@@ -56,6 +57,83 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb
                return query.getResultList();
        }
 
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<User> allUsersNotSharing (final User user, final Addressbook addressbook) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: user={0},addressbook={1} - CALLED!", user, addressbook)); //NOI18N
+
+               // Test parameter
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               } else if (null == addressbook) {
+                       // Again NPE
+                       throw new NullPointerException("addressbook is null"); //NOI18N
+               } else if (addressbook.getAddressbookId() == null) {
+                       // Again NPE
+                       throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N
+               } else if (addressbook.getAddressbookId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("addressbook.getAddressbookId={0} is invalid", addressbook.getAddressbookId())); //NOI18N
+               }
+
+               // Get named query for a user list without given user
+               Query allUsersExceptQuery = this.getEntityManager().createNamedQuery("SearchAllUsersExcept", List.class);
+
+               // Set parameter
+               allUsersExceptQuery.setParameter("user", user);
+
+               // Get full list
+               List<User> allUsersExcept = allUsersExceptQuery.getResultList();
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allUsersExcept.size()={0}", allUsersExcept.size()));
+
+               // Now get all users this user is sharing with, first a new query
+               Query allShareesQuery = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class);
+
+               // Set parameter
+               allShareesQuery.setParameter("user", user);
+
+               // Get full list again
+               List<User> allSharees = allShareesQuery.getResultList();
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allSharees.size()={0}", allSharees.size()));
+
+               // Init final user list
+               List<User> userList = new ArrayList<>(0);
+
+               // Walk through all users
+               for (final User u : allUsersExcept) {
+                       // Log message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: u={0}", u));
+
+                       // Is this user not included?
+                       if (!allSharees.contains(u)) {
+                               // Found one to add!
+                               // Log message
+                               this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: u={0} - ADDING!", u));
+
+                               // Add it
+                               userList.add(u);
+                       }
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: userList.size()={0} - EXIT!", userList.size()));
+
+               // Return it
+               return userList;
+       }
+
        @Override
        @SuppressWarnings ("unchecked")
        public Integer countAllUserSharedAddressbooks (final User user) {
@@ -161,7 +239,7 @@ public class AddressbookSessionBean extends BaseDatabaseBean implements Addressb
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<Addressbook> getUsersList (final User loggedInUser) {
+       public List<Addressbook> getUsersAddressbookList (final User loggedInUser) {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N