*/
private static final long serialVersionUID = 136_984_697_285_694_710L;
- /**
- * Shared address books
- */
- private List<ShareableAddressbook> shares;
-
- /**
- * Default constructor
- */
- public SharedAddressbooksSessionBean () {
- // Init shares list
- this.shares = null;
- }
-
@Override
@SuppressWarnings ("unchecked")
- public Boolean isUserSharingAddressbooks (final User user) {
+ public List<ShareableAddressbook> allSharedAddressbooks (final User user) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: user={0} - CALLED!", user)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("allSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N
// Is user null?
if (null == user) {
}
// Get named query
- Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", AddressbookShare.class); //NOI18N
+ Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks"); //NOI18N
// Set parameter
query.setParameter("user", user); //NOI18N
- // Default is not sharing
- Boolean isSharing = Boolean.FALSE;
-
- // Try it as an exception may be thrown
- try {
- // Get results
- this.shares = query.getResultList();
+ // Return full list
+ return query.getResultList();
+ }
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserSharingAddressbooks: shares.size()={0}", this.shares.size())); //NOI18N
+ @Override
+ public Boolean isUserSharingAddressbooks (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: user={0} - CALLED!", user)); //NOI18N
- // Is it not empty?
- isSharing = (!this.shares.isEmpty());
- } catch (final NoResultException ex) {
- // Not sharing anything
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserSharingAddressbooks: User {0} is not sharing address books: {1}", user, ex)); //NOI18N
+ // Is user null?
+ if (null == user) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Null userId is not allowed
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Not allowed value
+ throw new IllegalArgumentException(MessageFormat.format("user.UserId={0} is an invalid value", user.getUserId())); //NOI18N
}
+ // Get results
+ List<ShareableAddressbook> list = this.allSharedAddressbooks(user);
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserSharingAddressbooks: list.size()={0}", list.size())); //NOI18N
+
+ // Is it not empty?
+ Boolean isSharing = (!list.isEmpty());
+
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: iSharing={0} - EXIT!", isSharing)); //NOI18N
ShareableAddressbook share = new AddressbookShare(addressbook, sharee);
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("startSharing: share={0}", share));
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("startSharing: share={0}", share)); //NOI18N
// Persist it
this.getEntityManager().persist(share);