From 7919e07513885a0021d921aa475c7d36c62e8228 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 3 May 2016 15:13:35 +0200 Subject: [PATCH] Continued a bit: - implemented linkUser() - use interface for class name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../model/user/PizzaUserSessionBean.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java index ccbaef6..f86f5a2 100644 --- a/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java @@ -488,16 +488,35 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS @Override public User linkUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException { - // userId should not be null + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("linkUser: user={0} - CALLED!", user)); //NOI18N + + // user should not be null + // @TODO Add check for email address if (null == user) { // Abort here throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() instanceof Long) { + // Id is set + throw new IllegalArgumentException("user.userId is not null"); //NOI18N } else if (user.getUserContact() == null) { // Throw NPE again throw new NullPointerException("user.userContact is null"); //NOI18N + } else if (user.getUserContact().getContactId() == null) { + // Throw NPE again + throw new NullPointerException("user.userContact.contactId is null"); //NOI18N } else if (user.getUserContact().getContactId() < 1) { - // Not valid id + // Not valid id number throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N + } else if (user.getUserAccountStatus() == null) { + // Throw NPE again + throw new NullPointerException("user.userAccountStatus is null"); //NOI18N + } else if (this.ifUserNameExists(user.getUserName())) { + // Name already found + throw new UserNameAlreadyRegisteredException(user.getUserName()); + } else if (this.ifUserExists(user)) { + // User does not exist + throw new IllegalStateException("User does already exist."); //NOI18N } // Check if user is registered @@ -530,7 +549,7 @@ public class PizzaUserSessionBean extends BasePizzaDatabaseBean implements UserS // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("linkUser: user.userId={0} - EXIT!", user.getUserId())); //NOI18N - // Return updated instance + // Return updated instanc return user; } -- 2.39.5