]> git.mxchange.org Git - jjobs-ejb.git/commitdiff
jjobs-user-ejb has been merged into jjobs-ejb:
authorRoland Haeder <roland@mxchange.org>
Tue, 8 Mar 2016 21:08:10 +0000 (22:08 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 8 Mar 2016 21:08:10 +0000 (22:08 +0100)
- updated project files
- added jcore.jar
- updated jar(s)

12 files changed:
lib/jcontacts-business-core.jar
lib/jcontacts-core.jar
lib/jcore.jar [new file with mode: 0644]
lib/jphone-core.jar
lib/juser-lib.jar [new file with mode: 0644]
nbproject/build-impl.xml
nbproject/genfiles.properties
nbproject/project.properties
nbproject/project.xml
src/java/org/mxchange/jusercore/model/login/UserLoginSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jusercore/model/register/UserRegistrationSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jusercore/model/user/UserSessionBean.java [new file with mode: 0644]

index 38f7bec9b70f927a6c77d80bf420e15e01e2b9eb..fcaadf8ccb43000591b17665bdb1e7b4d4824515 100644 (file)
Binary files a/lib/jcontacts-business-core.jar and b/lib/jcontacts-business-core.jar differ
index a9baa32fa6cfb062f87ed9a9ccba1ebe106e8244..e905316a232cc3f743e47c1d041b3c782fa666f1 100644 (file)
Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ
diff --git a/lib/jcore.jar b/lib/jcore.jar
new file mode 100644 (file)
index 0000000..23ef19d
Binary files /dev/null and b/lib/jcore.jar differ
index 4a792881003d7be6485b4aba1e0a4aa6cf1d4c0e..221f558c88c722e38e98a8f00c55f365f4cf1498 100644 (file)
Binary files a/lib/jphone-core.jar and b/lib/jphone-core.jar differ
diff --git a/lib/juser-lib.jar b/lib/juser-lib.jar
new file mode 100644 (file)
index 0000000..e9610b7
Binary files /dev/null and b/lib/juser-lib.jar differ
index f4f3ed36c3c401856c0d7e152df2ead36336c453..e765d00b292d895372e5beb408794a408addf93f 100644 (file)
@@ -826,6 +826,7 @@ exists or setup the property manually. For example like this:
     </target>
     <target depends="compile,-library-inclusion-in-archive-weblogic,-library-inclusion-in-archive-by-user" name="library-inclusion-in-archive"/>
     <target if="is.jars.in.ejbjar" name="-library-inclusion-in-archive-by-user">
+        <copyfiles files="${file.reference.jcore.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jcoreee.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jcore-logger-lib.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jcontacts-core.jar}" todir="${build.classes.dir}"/>
@@ -833,10 +834,12 @@ exists or setup the property manually. For example like this:
         <copyfiles files="${file.reference.jcountry-core.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jphone-core.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.juser-core.jar}" todir="${build.classes.dir}"/>
+        <copyfiles files="${file.reference.juser-lib.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jletter-lib.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${reference.jjobs-lib.jar}" todir="${build.classes.dir}"/>
     </target>
     <target if="is.server.weblogic" name="-library-inclusion-in-archive-weblogic">
+        <basename file="${file.reference.jcore.jar}" property="manifest.file.reference.jcore.jar"/>
         <basename file="${file.reference.jcoreee.jar}" property="manifest.file.reference.jcoreee.jar"/>
         <basename file="${file.reference.jcore-logger-lib.jar}" property="manifest.file.reference.jcore-logger-lib.jar"/>
         <basename file="${file.reference.jcontacts-core.jar}" property="manifest.file.reference.jcontacts-core.jar"/>
@@ -844,22 +847,26 @@ exists or setup the property manually. For example like this:
         <basename file="${file.reference.jcountry-core.jar}" property="manifest.file.reference.jcountry-core.jar"/>
         <basename file="${file.reference.jphone-core.jar}" property="manifest.file.reference.jphone-core.jar"/>
         <basename file="${file.reference.juser-core.jar}" property="manifest.file.reference.juser-core.jar"/>
+        <basename file="${file.reference.juser-lib.jar}" property="manifest.file.reference.juser-lib.jar"/>
         <basename file="${file.reference.jletter-lib.jar}" property="manifest.file.reference.jletter-lib.jar"/>
         <basename file="${reference.jjobs-lib.jar}" property="manifest.reference.jjobs-lib.jar"/>
         <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update">
-            <attribute name="Extension-List" value="jar-1 jar-2 jar-3 jar-4 jar-5 jar-6 jar-7 jar-8 jar-9 "/>
-            <attribute name="jar-1-Extension-Name" value="${manifest.file.reference.jcoreee.jar}"/>
-            <attribute name="jar-2-Extension-Name" value="${manifest.file.reference.jcore-logger-lib.jar}"/>
-            <attribute name="jar-3-Extension-Name" value="${manifest.file.reference.jcontacts-core.jar}"/>
-            <attribute name="jar-4-Extension-Name" value="${manifest.file.reference.jcontacts-business-core.jar}"/>
-            <attribute name="jar-5-Extension-Name" value="${manifest.file.reference.jcountry-core.jar}"/>
-            <attribute name="jar-6-Extension-Name" value="${manifest.file.reference.jphone-core.jar}"/>
-            <attribute name="jar-7-Extension-Name" value="${manifest.file.reference.juser-core.jar}"/>
-            <attribute name="jar-8-Extension-Name" value="${manifest.file.reference.jletter-lib.jar}"/>
-            <attribute name="jar-9-Extension-Name" value="${manifest.reference.jjobs-lib.jar}"/>
+            <attribute name="Extension-List" value="jar-1 jar-2 jar-3 jar-4 jar-5 jar-6 jar-7 jar-8 jar-9 jar-10 jar-11 "/>
+            <attribute name="jar-1-Extension-Name" value="${manifest.file.reference.jcore.jar}"/>
+            <attribute name="jar-2-Extension-Name" value="${manifest.file.reference.jcoreee.jar}"/>
+            <attribute name="jar-3-Extension-Name" value="${manifest.file.reference.jcore-logger-lib.jar}"/>
+            <attribute name="jar-4-Extension-Name" value="${manifest.file.reference.jcontacts-core.jar}"/>
+            <attribute name="jar-5-Extension-Name" value="${manifest.file.reference.jcontacts-business-core.jar}"/>
+            <attribute name="jar-6-Extension-Name" value="${manifest.file.reference.jcountry-core.jar}"/>
+            <attribute name="jar-7-Extension-Name" value="${manifest.file.reference.jphone-core.jar}"/>
+            <attribute name="jar-8-Extension-Name" value="${manifest.file.reference.juser-core.jar}"/>
+            <attribute name="jar-9-Extension-Name" value="${manifest.file.reference.juser-lib.jar}"/>
+            <attribute name="jar-10-Extension-Name" value="${manifest.file.reference.jletter-lib.jar}"/>
+            <attribute name="jar-11-Extension-Name" value="${manifest.reference.jjobs-lib.jar}"/>
         </manifest>
     </target>
     <target depends="compile" name="library-inclusion-in-manifest">
+        <copyfiles files="${file.reference.jcore.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jcoreee.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jcore-logger-lib.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jcontacts-core.jar}" todir="${dist.ear.dir}/lib"/>
@@ -867,6 +874,7 @@ exists or setup the property manually. For example like this:
         <copyfiles files="${file.reference.jcountry-core.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jphone-core.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.juser-core.jar}" todir="${dist.ear.dir}/lib"/>
+        <copyfiles files="${file.reference.juser-lib.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jletter-lib.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${reference.jjobs-lib.jar}" todir="${dist.ear.dir}/lib"/>
         <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update"/>
index c5ec1464ffdf9e37040f71df4fde1542bbd5501a..06c57adce83d3854ba6d40541ead3da4ba77f395 100644 (file)
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=9a28cef7
+build.xml.data.CRC32=1100511e
 build.xml.script.CRC32=9c0f08a9
 build.xml.stylesheet.CRC32=5910fda3@1.55.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=9a28cef7
-nbproject/build-impl.xml.script.CRC32=92d9d94c
+nbproject/build-impl.xml.data.CRC32=1100511e
+nbproject/build-impl.xml.script.CRC32=866bcec0
 nbproject/build-impl.xml.stylesheet.CRC32=6096d939@1.55.1
index c02dd660d04f4552aa17963adf3fdbe88171b414..e3a440e50c91ec30325b794b1a480b8204453e75 100644 (file)
@@ -24,11 +24,13 @@ excludes=
 file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar
 file.reference.jcontacts-core.jar=lib/jcontacts-core.jar
 file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar
+file.reference.jcore.jar=lib/jcore.jar
 file.reference.jcoreee.jar=lib/jcoreee.jar
 file.reference.jcountry-core.jar=lib/jcountry-core.jar
 file.reference.jletter-lib.jar=lib/jletter-lib.jar
 file.reference.jphone-core.jar=lib/jphone-core.jar
 file.reference.juser-core.jar=lib/juser-core.jar
+file.reference.juser-lib.jar=lib/juser-lib.jar
 includes=**
 j2ee.compile.on.save=true
 j2ee.deploy.on.save=true
@@ -44,6 +46,7 @@ jar.compress=false
 jar.name=jjobs-ejb.jar
 jars.in.ejbjar=false
 javac.classpath=\
+    ${file.reference.jcore.jar}:\
     ${file.reference.jcoreee.jar}:\
     ${file.reference.jcore-logger-lib.jar}:\
     ${file.reference.jcontacts-core.jar}:\
@@ -51,6 +54,7 @@ javac.classpath=\
     ${file.reference.jcountry-core.jar}:\
     ${file.reference.jphone-core.jar}:\
     ${file.reference.juser-core.jar}:\
+    ${file.reference.juser-lib.jar}:\
     ${file.reference.jletter-lib.jar}:\
     ${reference.jjobs-lib.jar}
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
@@ -93,11 +97,13 @@ source.encoding=UTF-8
 source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/
 source.reference.jcontacts-core.jar=../jcontacts-core/src/
 source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/
+source.reference.jcore.jar=../jcore/src/
 source.reference.jcoreee.jar=../jcoreee/src/
 source.reference.jcountry-core.jar=../jcountry-core/src/
 source.reference.jletter-lib.jar=../jletter-lib/src/
 source.reference.jphone-core.jar=../jphone-core/src/
 source.reference.juser-core.jar=../juser-core/src/
+source.reference.juser-lib.jar=../juser-lib/src/
 source.root=src
 src.dir=${source.root}/java
 test.src.dir=test
index 30d1c2d67f07a6c12ce0996e6582399ebefef7d2..8b607f6a53e18139ed59b17591ce00e896c4380c 100644 (file)
@@ -5,6 +5,7 @@
         <data xmlns="http://www.netbeans.org/ns/j2ee-ejbjarproject/3">
             <name>jjobs-ejb</name>
             <minimum-ant-version>1.6.5</minimum-ant-version>
+            <included-library dirs="200">file.reference.jcore.jar</included-library>
             <included-library dirs="200">file.reference.jcoreee.jar</included-library>
             <included-library dirs="200">file.reference.jcore-logger-lib.jar</included-library>
             <included-library dirs="200">file.reference.jcontacts-core.jar</included-library>
@@ -12,6 +13,7 @@
             <included-library dirs="200">file.reference.jcountry-core.jar</included-library>
             <included-library dirs="200">file.reference.jphone-core.jar</included-library>
             <included-library dirs="200">file.reference.juser-core.jar</included-library>
+            <included-library dirs="200">file.reference.juser-lib.jar</included-library>
             <included-library dirs="200">file.reference.jletter-lib.jar</included-library>
             <included-library dirs="200">reference.jjobs-lib.jar</included-library>
             <source-roots>
diff --git a/src/java/org/mxchange/jusercore/model/login/UserLoginSessionBean.java b/src/java/org/mxchange/jusercore/model/login/UserLoginSessionBean.java
new file mode 100644 (file)
index 0000000..feb7e33
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.login;
+
+import java.text.MessageFormat;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jusercore.container.login.LoginContainer;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
+import org.mxchange.jusercore.exceptions.UserStatusLockedException;
+import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
+import org.mxchange.jusercore.model.register.UserRegistrationSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jusercore.model.user.UserUtils;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+
+/**
+ * A session bean for user logins
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "login", mappedName = "ejb/stateless-jjobs-login", description = "A bean handling the user login")
+public class UserLoginSessionBean extends BaseDatabaseBean implements UserLoginSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 21_785_978_127_581_965L;
+
+       /**
+        * Registration bean
+        */
+       @EJB
+       private UserRegistrationSessionBeanRemote registerBean;
+
+       /**
+        * User bean
+        */
+       @EJB
+       private UserSessionBeanRemote userBean;
+
+       @Override
+       public User validateUserAccountStatus (final LoginContainer container) throws UserNotFoundException, UserStatusLockedException, UserStatusUnconfirmedException, UserPasswordMismatchException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("loginUser: container={0} - CALLED!", container)); //NOI18N
+
+               // Check some beans
+               assert(this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
+               assert(this.registerBean instanceof UserRegistrationSessionBeanRemote) : "this.registerBean is not set"; //NOI18N
+
+               // user should not be null
+               if (null == container) {
+                       // Abort here
+                       throw new NullPointerException("container is null"); //NOI18N
+               } else if (container.getUser() == null) {
+                       // NPE again
+                       throw new NullPointerException("container.user is null"); //NOI18N
+               } else if (container.getUserPassword() == null) {
+                       // And yet again NPE
+                       throw new NullPointerException("container.userPassword is null"); //NOI18N
+               } else if (container.getUserPassword().isEmpty()) {
+                       // Empty password is not allowed, hardcoded.
+                       throw new IllegalArgumentException("container.userPassword is empty"); //NOI18N
+               }
+
+               // Is the account there?
+               if (!this.registerBean.isUserNameRegistered(container.getUser())) {
+                       // Not registered
+                       throw new UserNotFoundException(container.getUser());
+               }
+
+               // Get user instance from persistance
+               User updatedUser = this.userBean.fillUserData(container.getUser());
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("loginUser: updatedUser={0}", updatedUser)); //NOI18N
+
+               // Is the user account unconfirmed?
+               if (updatedUser.getUserAccountStatus().equals(UserAccountStatus.UNCONFIRMED)) {
+                       // Is unconfirmed
+                       throw new UserStatusUnconfirmedException(container.getUser());
+               } else if (updatedUser.getUserAccountStatus().equals(UserAccountStatus.LOCKED)) {
+                       // Is locked
+                       throw new UserStatusLockedException(container.getUser());
+               } else if (!this.isPasswordMatching(container, updatedUser)) {
+                       // Not matcing passwords
+                       throw new UserPasswordMismatchException(container.getUser());
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("loginUser: updatedUser={0} - EXIT!", updatedUser)); //NOI18N
+
+               // Return it
+               return updatedUser;
+       }
+
+       /**
+        * Checks if password matches of both instances. Both user instances must
+        * not match, the first one is the one from the calling bean/controller, the
+        * second is the from database.
+        * <p>
+        * @param container Container instance holding the user instance and
+        * unencrypted password
+        * @param updatedUser User instance found for given user name
+        * <p>
+        * @return Whether the password matches
+        */
+       private boolean isPasswordMatching (final LoginContainer container, final User updatedUser) {
+               // First math both instances
+               if (null == container) {
+                       // Throw NPE
+                       throw new NullPointerException("container is null"); //NOI18N
+               } else if (null == updatedUser) {
+                       // Throw NPE
+                       throw new NullPointerException("updatedUser is null"); //NOI18N
+               } else if (container.getUser().equals(updatedUser)) {
+                       // Both same instance!
+                       throw new IllegalArgumentException(MessageFormat.format("container.user matches updatedUser: {0}", container.getUser())); //NOI18N
+               }
+
+               // Is it the same same password?
+               return UserUtils.ifPasswordMatches(container, updatedUser);
+       }
+}
diff --git a/src/java/org/mxchange/jusercore/model/register/UserRegistrationSessionBean.java b/src/java/org/mxchange/jusercore/model/register/UserRegistrationSessionBean.java
new file mode 100644 (file)
index 0000000..4a14da3
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.register;
+
+import java.text.MessageFormat;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
+import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+
+/**
+ * A session bean for user registration
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "register", mappedName = "ejb/stateless-jjobs-register", description = "A bean handling the user registration")
+public class UserRegistrationSessionBean extends BaseDatabaseBean implements UserRegistrationSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 12_348_958_986_818_627L;
+
+       /**
+        * User bean
+        */
+       @EJB
+       private UserSessionBeanRemote userBean;
+
+       @Override
+       public boolean isEmailAddressRegistered (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressRegistered: user={0} - CALLED!", user)); //NOI18N
+
+               // Check bean
+               assert(this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
+
+               // Call other bean
+               return this.userBean.isEmailAddressReqistered(user);
+       }
+
+       @Override
+       public boolean isUserNameRegistered (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserNameRegistered: user={0} - CALLED!", user)); //NOI18N
+
+               // Check bean
+               assert(this.userBean instanceof UserSessionBeanRemote) : "this.userBean is not set"; //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
+
+               // Call other bean
+               return this.userBean.isUserNameReqistered(user);
+       }
+
+       @Override
+       public User registerUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: user={0} - CALLED!", user)); //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
+
+               // Check if user is registered
+               if (this.isUserNameRegistered(user)) {
+                       // Abort here
+                       throw new UserNameAlreadyRegisteredException(user);
+               } else if (this.isEmailAddressRegistered(user)) {
+                       // Abort here
+                       throw new EmailAddressAlreadyRegisteredException(user);
+               }
+
+               // Persist it
+               this.getEntityManager().persist(user);
+
+               // Flush to get id back
+               this.getEntityManager().flush();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("registerUser: user={0},user.id={1} - EXIT!", user, user.getUserId())); //NOI18N
+
+               // Return it
+               return user;
+       }
+}
diff --git a/src/java/org/mxchange/jusercore/model/user/UserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/UserSessionBean.java
new file mode 100644 (file)
index 0000000..2502c7c
--- /dev/null
@@ -0,0 +1,436 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.user;
+
+import java.text.MessageFormat;
+import java.util.GregorianCalendar;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.PersistenceException;
+import javax.persistence.Query;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
+import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+
+/**
+ * A user bean
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "user", mappedName = "ejb/stateless-jjobs-user", description = "A bean handling the user data")
+public class UserSessionBean extends BaseDatabaseBean implements UserSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 542_145_347_916L;
+
+       /**
+        * Default constructor
+        */
+       public UserSessionBean () {
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<User> allMemberPublicVisibleUsers () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("allMemberPublicVisibleUsers: CALLED!"); //NOI18N
+
+               // Get named query
+               Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", List.class); //NOI18N
+
+               // Set parameters
+               query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
+               query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
+               query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
+
+               // Get result
+               List<User> users = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allMemberPublicVisibleUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
+
+               // Return full list
+               return users;
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<User> allPublicUsers () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace("allPublicUsers: CALLED!"); //NOI18N
+
+               // Get named query
+               Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", List.class); //NOI18N
+
+               // Set parameters
+               query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
+               query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
+
+               // Get result
+               List<User> users = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allPublicUsers: users.size()={0} - EXIT!", users.size())); //NOI18N
+
+               // Return full list
+               return users;
+       }
+
+       @Override
+       public User fillUserData (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillUserData: user={0} - CALLED!", user)); //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
+
+               // Try to locate it
+               Query query = this.getEntityManager().createNamedQuery("SearchUserName", LoginUser.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("param", user.getUserName()); //NOI18N
+
+               // Initialize variable
+               User foundUser = null;
+
+               // Try it
+               try {
+                       // Try to get single result
+                       foundUser = (User) query.getSingleResult();
+               } catch (final NoResultException ex) {
+                       // Log it
+                       this.getLoggerBeanLocal().logException(ex);
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("fillUserData: foundUser={0} - EXIT!", foundUser)); //NOI18N
+
+               // Return prepared instance
+               return foundUser;
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<String> getEmailAddressList () {
+               // Get query
+               Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
+
+               // Get result list
+               List<String> emailAddressList = query.getResultList();
+
+               // Return it
+               return emailAddressList;
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<String> getUserNameList () {
+               // Get query
+               Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N
+
+               // Get result list
+               List<String> userNameList = query.getResultList();
+
+               // Return it
+               return userNameList;
+       }
+
+       @Override
+       public boolean ifUserIdExists (final Long userId) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserIdExists: userId={0} - CALLED!", userId)); //NOI18N
+
+               // userId should not be null
+               if (null == userId) {
+                       // Abort here
+                       throw new NullPointerException("userId is null"); //NOI18N
+               } else if (userId < 1) {
+                       // Invalid number
+                       throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", userId)); //NOI18N
+               }
+
+               // Generate query
+               Query query = this.getEntityManager().createNamedQuery("SearchUserId", LoginUser.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("id", userId); //NOI18N
+
+               // Try this
+               try {
+                       User dummy = (User) query.getSingleResult();
+
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserIdExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
+               } catch (final NoResultException ex) {
+                       // Log it
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserIdExists: getSingleResult() returned no result: {0}", ex)); //NOI18N
+
+                       // User name does not exist
+                       return false;
+               } catch (final PersistenceException ex) {
+                       // Something bad happened
+                       this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one user id {0} found.", userId, ex)); //NOI18N
+
+                       // Throw again
+                       throw ex;
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserIdExists: Found user id {0} - EXIT!", userId)); //NOI18N
+
+               // Found it
+               return true;
+       }
+
+       @Override
+       public boolean isEmailAddressReqistered (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressReqistered: user={0} - CALLED!", user)); //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
+
+               // Generate query
+               Query query = this.getEntityManager().createNamedQuery("SearchEmailAddress", LoginUser.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("param", user.getUserContact().getContactEmailAddress()); //NOI18N
+
+               // Search for it
+               try {
+                       User dummy = (User) query.getSingleResult();
+
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isEmailAddressReqistered: dummy.id={0} found.", dummy.getUserId())); //NOI18N
+               } catch (final NoResultException ex) {
+                       // Log it
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isEmailAddressReqistered: getSingleResult() returned no result: {0}", ex)); //NOI18N
+
+                       // Email address does not exist
+                       return false;
+               } catch (final PersistenceException ex) {
+                       // Something bad happened
+                       this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
+
+                       // Throw again
+                       throw ex;
+               }
+
+               // Found it
+               return true;
+       }
+
+       @Override
+       public boolean isUserNameReqistered (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserNameReqistered: user={0} - CALLED!", user)); //NOI18N
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       throw new NullPointerException("user is null"); //NOI18N
+               }
+
+               // Generate query
+               Query query = this.getEntityManager().createNamedQuery("SearchUserName", LoginUser.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("param", user.getUserName()); //NOI18N
+
+               // Try this
+               try {
+                       User dummy = (User) query.getSingleResult();
+
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserNameReqistered: dummy.id={0} found.", dummy.getUserId())); //NOI18N
+               } catch (final NoResultException ex) {
+                       // Log it
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserNameReqistered: getSingleResult() returned no result: {0}", ex)); //NOI18N
+
+                       // User name does not exist
+                       return false;
+               } catch (final PersistenceException ex) {
+                       // Something bad happened
+                       this.getLoggerBeanLocal().logWarning(MessageFormat.format("More than one email address {0} found.", user.getUserContact().getContactEmailAddress()), ex); //NOI18N
+
+                       // Throw again
+                       throw ex;
+               }
+
+               // Found it
+               return true;
+       }
+
+       @Override
+       public void updateUserPersonalData (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateUserPersonalData: user={0} - CALLED!", user));
+
+               // user should not be null
+               if (null == user) {
+                       // Abort here
+                       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) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N
+               } else if (user.getUserAccountStatus() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userAccountStatus is null"); //NOI18N
+               } else if (!this.ifUserIdExists(user.getUserId())) {
+                       // User does not exist
+                       throw new PersistenceException(MessageFormat.format("User with id {0} does not exist.", user.getUserId())); //NOI18N
+               }
+
+               // Find the instance
+               User foundUser = this.getEntityManager().find(user.getClass(), user.getUserId());
+
+               // Should be found!
+               assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
+
+               // Merge user
+               User detachedUser = this.getEntityManager().merge(foundUser);
+
+               // Should be found!
+               assert (detachedUser instanceof User) : MessageFormat.format("User with id {0} not merged, but should be.", user.getUserId()); //NOI18N
+
+               // Copy all data
+               detachedUser.copyAll(user);
+
+               // Set as updated
+               detachedUser.setUserUpdated(new GregorianCalendar());
+               detachedUser.getUserContact().setContactUpdated(new GregorianCalendar());
+
+               // Get contact from it and find it
+               Contact foundContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId());
+
+               // Should be found
+               assert (foundContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId()));
+
+               // Merge contact instance
+               Contact detachedContact = this.getEntityManager().merge(foundContact);
+
+               // Copy all
+               detachedContact.copyAll(user.getUserContact());
+
+               // Set it back in user
+               user.setUserContact(detachedContact);
+
+               // Should be found!
+               assert (detachedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N
+
+               // Get cellphone instance
+               DialableCellphoneNumber cellphone = detachedContact.getContactCellphoneNumber();
+
+               // Is there a  cellphone instance set?
+               if (cellphone instanceof DialableCellphoneNumber) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId()));
+
+                       // Then find it, too
+                       DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
+
+                       // Should be there
+                       assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId());
+
+                       // Then merge it, too
+                       DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone);
+
+                       // Should be there
+                       assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId());
+
+                       // Copy all
+                       detachedCellphone.copyAll(user.getUserContact().getContactCellphoneNumber());
+
+                       // Set it back
+                       detachedContact.setContactCellphoneNumber(detachedCellphone);
+               }
+
+               // Get cellphone instance
+               DialableFaxNumber fax = detachedContact.getContactFaxNumber();
+
+               // Is there a  fax instance set?
+               if (fax instanceof DialableFaxNumber) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: fax.phoneId={0} is being updated ...", fax.getPhoneId()));
+
+                       // Then find it, too
+                       DialableFaxNumber foundFax = this.getEntityManager().find(fax.getClass(), fax.getPhoneId());
+
+                       // Should be there
+                       assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId());
+
+                       // Then merge it, too
+                       DialableFaxNumber detachedFax = this.getEntityManager().merge(foundFax);
+
+                       // Should be there
+                       assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId());
+
+                       // Copy all
+                       detachedFax.copyAll(user.getUserContact().getContactFaxNumber());
+
+                       // Set it back
+                       detachedContact.setContactFaxNumber(detachedFax);
+               }
+
+               // Get cellphone instance
+               DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
+
+               // Is there a  fax instance set?
+               if (landLine instanceof DialableLandLineNumber) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLine.phoneId={0} is being updated ...", landLine.getPhoneId()));
+
+                       // Then find it, too
+                       DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLine.getClass(), landLine.getPhoneId());
+
+                       // Should be there
+                       assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId());
+
+                       // Then merge it, too
+                       DialableLandLineNumber detachedLandLine = this.getEntityManager().merge(foundLandLine);
+
+                       // Should be there
+                       assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId());
+
+                       // Copy all
+                       detachedLandLine.copyAll(user.getUserContact().getContactLandLineNumber());
+
+                       // Set it back
+                       detachedContact.setContactLandLineNumber(detachedLandLine);
+               }
+       }
+
+}