From: Roland Haeder Date: Thu, 15 Oct 2015 18:31:16 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=57c4a8922da1ceb5dce81a95cd62209d12bdccf0;p=addressbook-mailer-ejb.git Continued: - Implemented business method allUsersNotSharing() - updated jar(s) --- diff --git a/lib/juser-core.jar b/lib/juser-core.jar index 9492047..c8486cf 100644 Binary files a/lib/juser-core.jar and b/lib/juser-core.jar differ diff --git a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java index 528f0dd..2798d41 100644 --- a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java +++ b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java @@ -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 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 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 allSharees = allShareesQuery.getResultList(); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allSharees.size()={0}", allSharees.size())); + + // Init final user list + List 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 getUsersList (final User loggedInUser) { + public List getUsersAddressbookList (final User loggedInUser) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N