From 469821a6a37bf285d6d1231765f9a2c84fe07732 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 27 Apr 2017 14:30:22 +0200 Subject: [PATCH] ported project to new libraries jaddressbook-share-core/lib MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- nbproject/build-impl.xml | 20 ++- nbproject/genfiles.properties | 4 +- nbproject/project.properties | 6 + nbproject/project.xml | 2 + .../addressbook/AddressbookSessionBean.java | 150 +---------------- .../share}/SharedAddressbooksSessionBean.java | 154 +++++++++++++++++- 6 files changed, 176 insertions(+), 160 deletions(-) rename src/java/org/mxchange/addressbook/model/{shared => addressbook/share}/SharedAddressbooksSessionBean.java (56%) diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 376c8cc..631e677 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -857,6 +857,8 @@ exists or setup the property manually. For example like this: + + @@ -877,13 +879,15 @@ exists or setup the property manually. For example like this: + + - + @@ -897,11 +901,13 @@ exists or setup the property manually. For example like this: - - - - - + + + + + + + @@ -918,6 +924,8 @@ exists or setup the property manually. For example like this: + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index db5f447..9cafdc3 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -3,6 +3,6 @@ build.xml.script.CRC32=7d41e0fd build.xml.stylesheet.CRC32=5910fda3@1.51.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=85adc17b -nbproject/build-impl.xml.script.CRC32=2401f53a +nbproject/build-impl.xml.data.CRC32=8d819964 +nbproject/build-impl.xml.script.CRC32=a108c83f nbproject/build-impl.xml.stylesheet.CRC32=6096d939@1.55.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index f874234..45072a3 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -25,6 +25,8 @@ file.reference.addressbook-mailer.jar=lib/addressbook-mailer.jar file.reference.cdi-api.jar=lib/cdi-api.jar file.reference.jaddressbook-core.jar=lib/jaddressbook-core.jar file.reference.jaddressbook-lib.jar=lib/jaddressbook-lib.jar +file.reference.jaddressbook-share-core.jar=lib/jaddressbook-share-core.jar +file.reference.jaddressbook-share-lib.jar=lib/jaddressbook-share-lib.jar file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar file.reference.jcontacts-core.jar=lib/jcontacts-core.jar file.reference.jcontacts-lib.jar=lib/jcontacts-lib.jar @@ -65,6 +67,8 @@ javac.classpath=\ ${file.reference.juser-lib.jar}:\ ${file.reference.jaddressbook-core.jar}:\ ${file.reference.jaddressbook-lib.jar}:\ + ${file.reference.jaddressbook-share-core.jar}:\ + ${file.reference.jaddressbook-share-lib.jar}:\ ${file.reference.jmailer-ee.jar}:\ ${reference.addressbook-core.jar}:\ ${reference.addressbook-lib.jar}:\ @@ -116,6 +120,8 @@ source.encoding=UTF-8 source.reference.addressbook-mailer.jar=../addressbook-mailer/src/ source.reference.jaddressbook-core.jar=../jaddressbook-core/src/ source.reference.jaddressbook-lib.jar=../jaddressbook-lib/src/ +source.reference.jaddressbook-share-core.jar=../jaddressbook-share-core/src +source.reference.jaddressbook-share-lib.jar=../jaddressbook-share-lib/src source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/ source.reference.jcontacts-core.jar=../jcontacts-core/src/ source.reference.jcontacts-lib.jar=../jcontacts-lib/src/ diff --git a/nbproject/project.xml b/nbproject/project.xml index 8818717..33d7dcf 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -18,6 +18,8 @@ file.reference.juser-lib.jar file.reference.jaddressbook-core.jar file.reference.jaddressbook-lib.jar + file.reference.jaddressbook-share-core.jar + file.reference.jaddressbook-share-lib.jar file.reference.jmailer-ee.jar reference.addressbook-core.jar reference.addressbook-lib.jar diff --git a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java index f1c6b98..c4c6ebc 100644 --- a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java +++ b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java @@ -17,19 +17,16 @@ package org.mxchange.addressbook.model.addressbook; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.GregorianCalendar; -import java.util.LinkedList; import java.util.List; import javax.ejb.Stateless; import javax.persistence.NoResultException; import javax.persistence.Query; -import org.mxchange.jaddressbookcore.exceptions.AddressbookNameAlreadyUsedException; -import org.mxchange.jaddressbookcore.exceptions.AddressbookNotFoundException; -import org.mxchange.jaddressbookcore.model.addressbook.Addressbook; -import org.mxchange.jaddressbookcore.model.addressbook.UserAddressbook; -import org.mxchange.jaddressbookcore.model.addressbook.entry.AddressbookEntry; -import org.mxchange.jaddressbookcore.model.addressbook.shared.ShareableAddressbook; +import org.mxchange.jaddressbook.exceptions.AddressbookNameAlreadyUsedException; +import org.mxchange.jaddressbook.exceptions.AddressbookNotFoundException; +import org.mxchange.jaddressbook.model.addressbook.Addressbook; +import org.mxchange.jaddressbook.model.addressbook.UserAddressbook; +import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry; import org.mxchange.jcoreee.database.BaseDatabaseBean; import org.mxchange.jusercore.model.user.User; @@ -84,143 +81,6 @@ 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); //NOI18N - - // Set parameter - allUsersExceptQuery.setParameter("user", user); //NOI18N - - // Get full list - List allUsersExcept = allUsersExceptQuery.getResultList(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allUsersExcept.size()={0}", allUsersExcept.size())); //NOI18N - - // Now get all shares this user has created - Query allSharesQuery = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N - - // Set parameter - allSharesQuery.setParameter("user", user); //NOI18N - - // Get full list again - List allShares = allSharesQuery.getResultList(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allShares.size()={0}", allShares.size())); //NOI18N - - // List for users aharing with given - List sharingUsers = new ArrayList<>(allShares.size()); - - // Check all entries - for (final ShareableAddressbook share : allShares) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: share.shareUserSharee={0}", share.getShareUserSharee())); //NOI18N - - // Add it - sharingUsers.add(share.getShareUserSharee()); - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: sharingUsers.size()={0}", sharingUsers.size())); //NOI18N - - // Init final user list - List userList = new LinkedList<>(); - - // Walk through all users - for (final User foundUser : allUsersExcept) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0}", foundUser)); //NOI18N - - // Does the list contain it ? - if (!sharingUsers.contains(foundUser)) { - // Found one to add - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0} - ADDING!", foundUser)); //NOI18N - - // Add it - userList.add(foundUser); - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: userList.size()={0} - EXIT!", userList.size())); //NOI18N - - // Return it - return userList; - } - - @Override - @SuppressWarnings ("unchecked") - public Integer countAllUserSharedAddressbooks (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N - - // user should be valid - 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 - } - - // Get named query - Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N - - // Set parameter - query.setParameter("user", user); //NOI18N - - // Default is zero - Integer count = 0; - - // Try it - try { - // Get whole list - List dummy = query.getResultList(); - - // Set size - count = dummy.size(); - } catch (final NoResultException ex) { - // Need to catch this, so log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("countAllUserSharedAddressbooks: getResultList() failed: {0}", ex)); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: count={0} - EXIT!", count)); //NOI18N - - // Return count - return count; - } - @Override public Addressbook createAddressbook (final Addressbook addressbook) throws AddressbookNameAlreadyUsedException { // Is it not null? diff --git a/src/java/org/mxchange/addressbook/model/shared/SharedAddressbooksSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/share/SharedAddressbooksSessionBean.java similarity index 56% rename from src/java/org/mxchange/addressbook/model/shared/SharedAddressbooksSessionBean.java rename to src/java/org/mxchange/addressbook/model/addressbook/share/SharedAddressbooksSessionBean.java index 8ff75bc..901ca67 100644 --- a/src/java/org/mxchange/addressbook/model/shared/SharedAddressbooksSessionBean.java +++ b/src/java/org/mxchange/addressbook/model/addressbook/share/SharedAddressbooksSessionBean.java @@ -14,18 +14,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.addressbook.model.shared; +package org.mxchange.addressbook.model.addressbook.share; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import javax.ejb.Stateless; import javax.persistence.NoResultException; import javax.persistence.Query; -import org.mxchange.jaddressbookcore.exceptions.UserAlreadySharingAddressbookException; -import org.mxchange.jaddressbookcore.model.addressbook.Addressbook; -import org.mxchange.jaddressbookcore.model.addressbook.shared.AddressbookShare; -import org.mxchange.jaddressbookcore.model.addressbook.shared.ShareableAddressbook; +import org.mxchange.addressbook.model.shared.AddressbookShareSessionBeanRemote; +import org.mxchange.jaddressbook.model.addressbook.Addressbook; +import org.mxchange.jaddressbookshare.exceptions.UserAlreadySharingAddressbookException; +import org.mxchange.jaddressbookshare.model.addressbook.shared.AddressbookShare; +import org.mxchange.jaddressbookshare.model.addressbook.shared.ShareableAddressbook; import org.mxchange.jcoreee.database.BaseDatabaseBean; import org.mxchange.jusercore.model.user.User; @@ -35,7 +38,7 @@ import org.mxchange.jusercore.model.user.User; * @author Roland Häder */ @Stateless (name = "share", description = "A stateless bean for handling shared addressbooks") -public class SharedAddressbooksSessionBean extends BaseDatabaseBean implements SharedAddressbooksSessionBeanRemote { +public class SharedAddressbooksSessionBean extends BaseDatabaseBean implements AddressbookShareSessionBeanRemote { /** * Serial number @@ -76,6 +79,143 @@ public class SharedAddressbooksSessionBean extends BaseDatabaseBean implements S return list; } + @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); //NOI18N + + // Set parameter + allUsersExceptQuery.setParameter("user", user); //NOI18N + + // Get full list + List allUsersExcept = allUsersExceptQuery.getResultList(); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allUsersExcept.size()={0}", allUsersExcept.size())); //NOI18N + + // Now get all shares this user has created + Query allSharesQuery = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N + + // Set parameter + allSharesQuery.setParameter("user", user); //NOI18N + + // Get full list again + List allShares = allSharesQuery.getResultList(); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allShares.size()={0}", allShares.size())); //NOI18N + + // List for users aharing with given + List sharingUsers = new ArrayList<>(allShares.size()); + + // Check all entries + for (final ShareableAddressbook share : allShares) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: share.shareUserSharee={0}", share.getShareUserSharee())); //NOI18N + + // Add it + sharingUsers.add(share.getShareUserSharee()); + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: sharingUsers.size()={0}", sharingUsers.size())); //NOI18N + + // Init final user list + List userList = new LinkedList<>(); + + // Walk through all users + for (final User foundUser : allUsersExcept) { + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0}", foundUser)); //NOI18N + + // Does the list contain it ? + if (!sharingUsers.contains(foundUser)) { + // Found one to add + this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0} - ADDING!", foundUser)); //NOI18N + + // Add it + userList.add(foundUser); + } + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: userList.size()={0} - EXIT!", userList.size())); //NOI18N + + // Return it + return userList; + } + + @Override + @SuppressWarnings ("unchecked") + public Integer countAllUserSharedAddressbooks (final User user) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N + + // user should be valid + 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 + } + + // Get named query + Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N + + // Set parameter + query.setParameter("user", user); //NOI18N + + // Default is zero + Integer count = 0; + + // Try it + try { + // Get whole list + List dummy = query.getResultList(); + + // Set size + count = dummy.size(); + } catch (final NoResultException ex) { + // Need to catch this, so log it + this.getLoggerBeanLocal().logDebug(MessageFormat.format("countAllUserSharedAddressbooks: getResultList() failed: {0}", ex)); //NOI18N + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: count={0} - EXIT!", count)); //NOI18N + + // Return count + return count; + } + @Override public Boolean isUserSharingAddressbooks (final User user) { // Trace message @@ -165,7 +305,7 @@ public class SharedAddressbooksSessionBean extends BaseDatabaseBean implements S * with the sharee. *

* @param addressbook Address book to be shared with - * @param sharee User sharee instance + * @param sharee User sharee instance *

* @return Wether the address book is already shared with the sharee */ -- 2.39.5