+++ /dev/null
-/*
- * 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.addressbook.model.addressbook;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
-import org.mxchange.jjobs.exceptions.AddressbookNameAlreadyUsedException;
-import org.mxchange.jjobs.exceptions.AddressbookNotFoundException;
-import org.mxchange.jjobs.model.addressbook.Addressbook;
-import org.mxchange.jjobs.model.addressbook.AddressbookSessionBeanRemote;
-import org.mxchange.jjobs.model.addressbook.UserAddressbook;
-import org.mxchange.jjobs.model.addressbook.entry.AddressbookEntry;
-import org.mxchange.jjobs.model.addressbook.shared.ShareableAddressbook;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A stateless bean handling addressbooks
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Stateless (name = "jjobs-adr", mappedName = "ejb/stateless-jjobs-adr", description = "A stateless bean for handling JJobs addressbooks")
-public class AddressbookSessionBean extends BaseDatabaseBean implements AddressbookSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 129_857_871_287_691L;
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<AddressbookEntry> allEntries (final Addressbook addressbook) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("allEntries: addressbook={0} - CALLED!", addressbook)); //NOI18N
-
- // Validate parameter
- if (null == addressbook) {
- // Throw NPE
- throw new NullPointerException("addressbook is null");
- } else if (addressbook.getAddressbookId() == null) {
- // Throw NPE again
- throw new NullPointerException("addressbook.addressbookId is null");
- } else if (addressbook.getAddressbookId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId()));
- } else if (addressbook.getAddressbookUser() == null) {
- // Throw again NPE
- throw new NullPointerException("addressbook.addressbookUser is null");
- } else if (addressbook.getAddressbookUser().getUserId() == null) {
- // Throw again NPE
- throw new NullPointerException("addressbook.addressbookUser.userId is null");
- } else if (addressbook.getAddressbookUser().getUserId() < 1) {
- // Invalid id number again
- throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid", addressbook.getAddressbookUser().getUserId()));
- }
-
- // Generate query
- Query query = this.getEntityManager().createNamedQuery("SearchUsersAddressbookEntries", List.class); //NOI18N
-
- // Set parameters
- query.setParameter("addressbook", addressbook); //NOI18N
- query.setParameter("owner", addressbook.getAddressbookUser()); //NOI18N
-
- // Return it
- return query.getResultList();
- }
-
- @Override
- public Addressbook createAddressbook (final Addressbook addressbook) throws AddressbookNameAlreadyUsedException {
- // Is it not null?
- if (null == addressbook) {
- // Abort here
- throw new NullPointerException("addressbook is null"); //NOI18N
- } else if (addressbook.getAddressbookUser() == null) {
- // User instance is null
- throw new NullPointerException("addressbook.user should not be null."); //NOI18N
- } else if (addressbook.getAddressbookName() == null) {
- // Address book name not set
- throw new NullPointerException("addressbook.addressbookName should not be null"); //NOI18N
- } else if (addressbook.getAddressbookName().isEmpty()) {
- // Address book name not set
- throw new IllegalArgumentException("addressbook.addressbookName should not be empty"); //NOI18N
- } else if (this.isAddressbookNameUsed(addressbook)) {
- // The assigned user already used that name
- throw new AddressbookNameAlreadyUsedException(addressbook);
- }
-
- // Persist it now
- this.getEntityManager().persist(addressbook);
-
- // Flush it to get all data
- this.getEntityManager().flush();
-
- // Return it updated
- return addressbook;
- }
-
- @Override
- public Addressbook getAddressbookById (final Long addressbookId) throws AddressbookNotFoundException {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAddressbookById: addressbookId={0} - CALLED!", addressbookId)); //NOI18N
-
- // addressbookId should not be null or below 1
- if (null == addressbookId) {
- // Throw NPE
- throw new NullPointerException("addressbookId is null"); //NOI18N
- } else if (addressbookId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N
- } else if (!this.isAddressbookIdUsed(addressbookId)) {
- // No address book found
- throw new AddressbookNotFoundException(addressbookId);
- }
-
- // Get named query instance
- Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N
-
- // Set parameter
- query.setParameter("id", addressbookId); //NOI18N
-
- // Return it
- return (Addressbook) query.getSingleResult();
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<Addressbook> getUsersAddressbookList (final User loggedInUser) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N
-
- // Is the user instance null?
- if (null == loggedInUser) {
- // Abort here
- throw new NullPointerException("loggedInUser is null"); //NOI18N
- }
-
- // Get query instance
- Query query = this.getEntityManager().createNamedQuery("AllUsersAddressbooks", List.class); //NOI18N
-
- // Set parameter
- query.setParameter("param", loggedInUser); //NOI18N
-
- // Get full list from JPA
- List<Addressbook> addressbooks = query.getResultList();
-
- // Return it
- return addressbooks;
- }
-
- @Override
- public boolean isAddressbookIdUsed (final Long addressbookId) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} - CALLED!", addressbookId)); //NOI18N
-
- // Is it null or zero?
- if (null == addressbookId) {
- // Throw NPE
- throw new NullPointerException("addressbookId is null"); //NOI18N
- } else if (addressbookId < 1) {
- // Not valid id number
- throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N
- }
-
- // Get query instance
- Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N
-
- // Set parameter
- query.setParameter("id", addressbookId); //NOI18N
-
- // Default is not valid
- boolean isValid = false;
-
- // Try it again, yes no other way
- try {
- // Get single result
- Addressbook addressbook = (Addressbook) query.getSingleResult();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbook={0} - FOUND!", addressbook)); //NOI18N
-
- // Found one!
- isValid = true;
- } catch (final NoResultException ex) {
- // Debug log only, maybe out-dated link followed
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} is not valid: {1}", addressbookId, ex)); //NOI18N
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: isValid={0} - EXIT!", isValid)); //NOI18N
-
- // Return result
- return isValid;
- }
-
- @Override
- public boolean isAddressbookNameUsed (final Addressbook addressbook) {
- // Is it not null?
- if (null == addressbook) {
- // Abort here
- throw new NullPointerException("addressbook is null"); //NOI18N
- } else if (addressbook.getAddressbookUser() == null) {
- // User instance is null
- throw new NullPointerException("addressbook.addressbookUser is null."); //NOI18N
- } else if (addressbook.getAddressbookUser().getUserId() == null) {
- // User instance is null
- throw new NullPointerException("addressbook.addressbookUser.userId is null."); //NOI18N
- } else if (addressbook.getAddressbookUser().getUserId() < 1) {
- // User instance is null
- throw new NullPointerException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid.", addressbook.getAddressbookUser().getUserId())); //NOI18N
- } else if (addressbook.getAddressbookName() == null) {
- // Address book name not set
- throw new NullPointerException("addressbook.addressbookName should not be null"); //NOI18N
- } else if (addressbook.getAddressbookName().isEmpty()) {
- // Address book name not set
- throw new IllegalArgumentException("addressbook.addressbookName should not be empty"); //NOI18N
- }
-
- // Get query instance
- Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class); //NOI18N
-
- // Set parameter
- query.setParameter("user", addressbook.getAddressbookUser()); //NOI18N
- query.setParameter("name", addressbook.getAddressbookName()); //NOI18N
-
- // Default is not found
- boolean isUsed = false;
-
- // Try it
- try {
- // Get a single result
- Addressbook dummy = (Addressbook) query.getSingleResult();
-
- // Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy)); //NOI18N
-
- // Found one
- isUsed = true;
- } catch (final NoResultException ex) {
- // No result found, so log it away
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: getSingleResult() did not return a result: {0}", ex)); //NOI18N
- }
-
- // Return result
- return isUsed;
- }
-}
--- /dev/null
+/*
+ * 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.addressbook.model.addressbook;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jjobs.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.jjobs.exceptions.AddressbookNotFoundException;
+import org.mxchange.jjobs.model.addressbook.Addressbook;
+import org.mxchange.jjobs.model.addressbook.AddressbookSessionBeanRemote;
+import org.mxchange.jjobs.model.addressbook.UserAddressbook;
+import org.mxchange.jjobs.model.addressbook.entry.AddressbookEntry;
+import org.mxchange.jjobs.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A stateless bean handling addressbooks
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "jjobs-adr", mappedName = "ejb/stateless-jjobs-adr", description = "A stateless bean for handling JJobs addressbooks")
+public class JobsAddressbookSessionBean extends BaseDatabaseBean implements AddressbookSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 129_857_871_287_691L;
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<AddressbookEntry> allEntries (final Addressbook addressbook) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("allEntries: addressbook={0} - CALLED!", addressbook)); //NOI18N
+
+ // Validate parameter
+ if (null == addressbook) {
+ // Throw NPE
+ throw new NullPointerException("addressbook is null");
+ } else if (addressbook.getAddressbookId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("addressbook.addressbookId is null");
+ } else if (addressbook.getAddressbookId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId()));
+ } else if (addressbook.getAddressbookUser() == null) {
+ // Throw again NPE
+ throw new NullPointerException("addressbook.addressbookUser is null");
+ } else if (addressbook.getAddressbookUser().getUserId() == null) {
+ // Throw again NPE
+ throw new NullPointerException("addressbook.addressbookUser.userId is null");
+ } else if (addressbook.getAddressbookUser().getUserId() < 1) {
+ // Invalid id number again
+ throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid", addressbook.getAddressbookUser().getUserId()));
+ }
+
+ // Generate query
+ Query query = this.getEntityManager().createNamedQuery("SearchUsersAddressbookEntries", List.class); //NOI18N
+
+ // Set parameters
+ query.setParameter("addressbook", addressbook); //NOI18N
+ query.setParameter("owner", addressbook.getAddressbookUser()); //NOI18N
+
+ // Return it
+ return query.getResultList();
+ }
+
+ @Override
+ public Addressbook createAddressbook (final Addressbook addressbook) throws AddressbookNameAlreadyUsedException {
+ // Is it not null?
+ if (null == addressbook) {
+ // Abort here
+ throw new NullPointerException("addressbook is null"); //NOI18N
+ } else if (addressbook.getAddressbookUser() == null) {
+ // User instance is null
+ throw new NullPointerException("addressbook.user should not be null."); //NOI18N
+ } else if (addressbook.getAddressbookName() == null) {
+ // Address book name not set
+ throw new NullPointerException("addressbook.addressbookName should not be null"); //NOI18N
+ } else if (addressbook.getAddressbookName().isEmpty()) {
+ // Address book name not set
+ throw new IllegalArgumentException("addressbook.addressbookName should not be empty"); //NOI18N
+ } else if (this.isAddressbookNameUsed(addressbook)) {
+ // The assigned user already used that name
+ throw new AddressbookNameAlreadyUsedException(addressbook);
+ }
+
+ // Persist it now
+ this.getEntityManager().persist(addressbook);
+
+ // Flush it to get all data
+ this.getEntityManager().flush();
+
+ // Return it updated
+ return addressbook;
+ }
+
+ @Override
+ public Addressbook getAddressbookById (final Long addressbookId) throws AddressbookNotFoundException {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAddressbookById: addressbookId={0} - CALLED!", addressbookId)); //NOI18N
+
+ // addressbookId should not be null or below 1
+ if (null == addressbookId) {
+ // Throw NPE
+ throw new NullPointerException("addressbookId is null"); //NOI18N
+ } else if (addressbookId < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N
+ } else if (!this.isAddressbookIdUsed(addressbookId)) {
+ // No address book found
+ throw new AddressbookNotFoundException(addressbookId);
+ }
+
+ // Get named query instance
+ Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("id", addressbookId); //NOI18N
+
+ // Return it
+ return (Addressbook) query.getSingleResult();
+ }
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<Addressbook> getUsersAddressbookList (final User loggedInUser) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N
+
+ // Is the user instance null?
+ if (null == loggedInUser) {
+ // Abort here
+ throw new NullPointerException("loggedInUser is null"); //NOI18N
+ }
+
+ // Get query instance
+ Query query = this.getEntityManager().createNamedQuery("AllUsersAddressbooks", List.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("param", loggedInUser); //NOI18N
+
+ // Get full list from JPA
+ List<Addressbook> addressbooks = query.getResultList();
+
+ // Return it
+ return addressbooks;
+ }
+
+ @Override
+ public boolean isAddressbookIdUsed (final Long addressbookId) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} - CALLED!", addressbookId)); //NOI18N
+
+ // Is it null or zero?
+ if (null == addressbookId) {
+ // Throw NPE
+ throw new NullPointerException("addressbookId is null"); //NOI18N
+ } else if (addressbookId < 1) {
+ // Not valid id number
+ throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N
+ }
+
+ // Get query instance
+ Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("id", addressbookId); //NOI18N
+
+ // Default is not valid
+ boolean isValid = false;
+
+ // Try it again, yes no other way
+ try {
+ // Get single result
+ Addressbook addressbook = (Addressbook) query.getSingleResult();
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbook={0} - FOUND!", addressbook)); //NOI18N
+
+ // Found one!
+ isValid = true;
+ } catch (final NoResultException ex) {
+ // Debug log only, maybe out-dated link followed
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} is not valid: {1}", addressbookId, ex)); //NOI18N
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: isValid={0} - EXIT!", isValid)); //NOI18N
+
+ // Return result
+ return isValid;
+ }
+
+ @Override
+ public boolean isAddressbookNameUsed (final Addressbook addressbook) {
+ // Is it not null?
+ if (null == addressbook) {
+ // Abort here
+ throw new NullPointerException("addressbook is null"); //NOI18N
+ } else if (addressbook.getAddressbookUser() == null) {
+ // User instance is null
+ throw new NullPointerException("addressbook.addressbookUser is null."); //NOI18N
+ } else if (addressbook.getAddressbookUser().getUserId() == null) {
+ // User instance is null
+ throw new NullPointerException("addressbook.addressbookUser.userId is null."); //NOI18N
+ } else if (addressbook.getAddressbookUser().getUserId() < 1) {
+ // User instance is null
+ throw new NullPointerException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid.", addressbook.getAddressbookUser().getUserId())); //NOI18N
+ } else if (addressbook.getAddressbookName() == null) {
+ // Address book name not set
+ throw new NullPointerException("addressbook.addressbookName should not be null"); //NOI18N
+ } else if (addressbook.getAddressbookName().isEmpty()) {
+ // Address book name not set
+ throw new IllegalArgumentException("addressbook.addressbookName should not be empty"); //NOI18N
+ }
+
+ // Get query instance
+ Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("user", addressbook.getAddressbookUser()); //NOI18N
+ query.setParameter("name", addressbook.getAddressbookName()); //NOI18N
+
+ // Default is not found
+ boolean isUsed = false;
+
+ // Try it
+ try {
+ // Get a single result
+ Addressbook dummy = (Addressbook) query.getSingleResult();
+
+ // Log it
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy)); //NOI18N
+
+ // Found one
+ isUsed = true;
+ } catch (final NoResultException ex) {
+ // No result found, so log it away
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: getSingleResult() did not return a result: {0}", ex)); //NOI18N
+ }
+
+ // Return result
+ return isUsed;
+ }
+}
+++ /dev/null
-/*
- * 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.jphone.phonenumbers.smsprovider;
-
-import java.util.List;
-import javax.ejb.Singleton;
-import javax.ejb.Startup;
-import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
-
-/**
- * A singleton bean for country informations
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Startup
-@Singleton (name = "smsprovider", mappedName = "ejb/jjobs-singleton-smsprovider", description = "A singleton session bean for SMS provider informations")
-public class AddressbookSmsProviderSingletonBean extends BaseDatabaseBean implements AddressbookSmsProviderSingletonBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 15_846_983_298_691_207L;
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<SmsProvider> allSmsProvider () {
- // Init query
- Query query = this.getEntityManager().createNamedQuery("AllSmsProvider", List.class); //NOI18N
-
- // Return it
- return query.getResultList();
- }
-
-}
--- /dev/null
+/*
+ * 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.jphone.phonenumbers.smsprovider;
+
+import java.util.List;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.persistence.Query;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+
+/**
+ * A singleton bean for country informations
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Startup
+@Singleton (name = "smsprovider", mappedName = "ejb/jjobs-singleton-smsprovider", description = "A singleton session bean for SMS provider informations")
+public class JobsSmsProviderSingletonBean extends BaseDatabaseBean implements AddressbookSmsProviderSingletonBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 15_846_983_298_691_207L;
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<SmsProvider> allSmsProvider () {
+ // Init query
+ Query query = this.getEntityManager().createNamedQuery("AllSmsProvider", List.class); //NOI18N
+
+ // Return it
+ return query.getResultList();
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2016 quix0r
- *
- * 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.email_address;
-
-import java.text.MessageFormat;
-import java.util.List;
-import javax.ejb.EJB;
-import javax.ejb.EJBException;
-import javax.ejb.Stateless;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-
-/**
- * A session bean for changing email addresses
- * <p>
- * @author Roland Haeder<roland@mxchange.org>
- */
-@Stateless (name = "email-change", mappedName = "ejb/stateless-jjobs-email-change", description = "A bean handling email changes")
-public class EmailChangeSessionBean extends BaseDatabaseBean implements EmailChangeSessionBeanRemote {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 182_698_165_971_548L;
-
- /**
- * User bean
- */
- @EJB
- private UserSessionBeanRemote userBean;
-
- /**
- * Default constructor
- */
- public EmailChangeSessionBean () {
- }
-
- @Override
- @SuppressWarnings ("unchecked")
- public List<String> allQueuedAddressesAsList () {
- // Trace message
- this.getLoggerBeanLocal().logTrace("allQueuedAddressesAsList: CALLED!"); //NOI18N
-
- // Get named query
- Query query = this.getEntityManager().createNamedQuery("AllEmailAddressChanges", List.class);
-
- // Get all entries
- List<String> emailAddresses = query.getResultList();
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("allQueuedAddressesAsList: emailAddresses.size()={0} - EXIT!", emailAddresses.size())); //NOI18N
-
- // Return it
- return emailAddresses;
- }
-
- @Override
- public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailAddress) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("enqueueEmailAddressForChange: emailAddress={0} - CALLED!", emailAddress)); //NOI18N
-
- // user should not be null
- if (null == emailAddress) {
- // Abort here
- throw new NullPointerException("emailAddress is null"); //NOI18N
- } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
- // User does not exist
- throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
- } else if (this.isEmailAddressEnqueued(emailAddress.getEmailAddress())) {
- // Email address is already enqueued
- throw new EJBException(MessageFormat.format("Email address {0} is already enqueued.", emailAddress.getEmailAddress()));
- }
-
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public boolean isEmailAddressEnqueued (final String emailAddress) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressEnqueued: emailAddress={0} - CALLED!", emailAddress)); //NOI18N
-
- // Create query instance
- Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByEmail"); //NOI18N
-
- // Add email address as parameter
- query.setParameter("email", emailAddress); //NOI18N
-
- // Initialize variable
- boolean isFound = false;
-
- // Try it
- try {
- // Try to get single result
- ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult();
-
- // Found it
- isFound = true;
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logException(ex);
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressEnqueued: isFound={0} - EXIT!", isFound)); //NOI18N
-
- // Return it
- return isFound;
- }
-
- @Override
- public void updateEmailAddress (final ChangeableEmailAddress emailAddress) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateEmailAddress: emailAddress={0} - CALLED!", emailAddress)); //NOI18N
-
- // user should not be null
- if (null == emailAddress) {
- // Abort here
- throw new NullPointerException("emailAddress is null"); //NOI18N
- } else if (emailAddress.getEmailChangeId() == null) {
- // Throw NPE again
- throw new NullPointerException("emailAddress.emailChangeId is null"); //NOI18N
- } else if (emailAddress.getEmailChangeId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("emailAddress.emailChangeId={0} is not valid.", emailAddress.getEmailChangeId())); //NOI18N
- } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
- // User does not exist
- throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
- } else if (!this.isEmailAddressEnqueued(emailAddress.getEmailAddress())) {
- // Email address is not enqueued
- throw new EJBException(MessageFormat.format("Email address {0} is not enqueued.", emailAddress.getEmailAddress()));
- }
-
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 quix0r
+ *
+ * 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.email_address;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+
+/**
+ * A session bean for changing email addresses
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Stateless (name = "email-change", mappedName = "ejb/stateless-jjobs-email-change", description = "A bean handling email changes")
+public class JobsEmailChangeSessionBean extends BaseDatabaseBean implements EmailChangeSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 182_698_165_971_548L;
+
+ /**
+ * User bean
+ */
+ @EJB
+ private UserSessionBeanRemote userBean;
+
+ /**
+ * Default constructor
+ */
+ public JobsEmailChangeSessionBean () {
+ }
+
+ @Override
+ @SuppressWarnings ("unchecked")
+ public List<String> allQueuedAddressesAsList () {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("allQueuedAddressesAsList: CALLED!"); //NOI18N
+
+ // Get named query
+ Query query = this.getEntityManager().createNamedQuery("AllEmailAddressChanges", List.class);
+
+ // Get all entries
+ List<String> emailAddresses = query.getResultList();
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("allQueuedAddressesAsList: emailAddresses.size()={0} - EXIT!", emailAddresses.size())); //NOI18N
+
+ // Return it
+ return emailAddresses;
+ }
+
+ @Override
+ public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailAddress) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("enqueueEmailAddressForChange: emailAddress={0} - CALLED!", emailAddress)); //NOI18N
+
+ // user should not be null
+ if (null == emailAddress) {
+ // Abort here
+ throw new NullPointerException("emailAddress is null"); //NOI18N
+ } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
+ // User does not exist
+ throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
+ } else if (this.isEmailAddressEnqueued(emailAddress.getEmailAddress())) {
+ // Email address is already enqueued
+ throw new EJBException(MessageFormat.format("Email address {0} is already enqueued.", emailAddress.getEmailAddress()));
+ }
+
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public boolean isEmailAddressEnqueued (final String emailAddress) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressEnqueued: emailAddress={0} - CALLED!", emailAddress)); //NOI18N
+
+ // Create query instance
+ Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByEmail"); //NOI18N
+
+ // Add email address as parameter
+ query.setParameter("email", emailAddress); //NOI18N
+
+ // Initialize variable
+ boolean isFound = false;
+
+ // Try it
+ try {
+ // Try to get single result
+ ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult();
+
+ // Found it
+ isFound = true;
+ } catch (final NoResultException ex) {
+ // Log it
+ this.getLoggerBeanLocal().logException(ex);
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("isEmailAddressEnqueued: isFound={0} - EXIT!", isFound)); //NOI18N
+
+ // Return it
+ return isFound;
+ }
+
+ @Override
+ public void updateEmailAddress (final ChangeableEmailAddress emailAddress) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("updateEmailAddress: emailAddress={0} - CALLED!", emailAddress)); //NOI18N
+
+ // user should not be null
+ if (null == emailAddress) {
+ // Abort here
+ throw new NullPointerException("emailAddress is null"); //NOI18N
+ } else if (emailAddress.getEmailChangeId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("emailAddress.emailChangeId is null"); //NOI18N
+ } else if (emailAddress.getEmailChangeId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("emailAddress.emailChangeId={0} is not valid.", emailAddress.getEmailChangeId())); //NOI18N
+ } else if (!this.userBean.ifUserExists(emailAddress.getEmailChangeUser())) {
+ // User does not exist
+ throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailAddress.getEmailChangeId())); //NOI18N
+ } else if (!this.isEmailAddressEnqueued(emailAddress.getEmailAddress())) {
+ // Email address is not enqueued
+ throw new EJBException(MessageFormat.format("Email address {0} is not enqueued.", emailAddress.getEmailAddress()));
+ }
+
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+}
--- /dev/null
+/*
+ * 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 JobsUserLoginSessionBean 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);
+ }
+}
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * 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 JobsUserRegistrationSessionBean 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;
+ }
+}
+++ /dev/null
-/*
- * 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;
- }
-}
--- /dev/null
+/*
+ * 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.EJBException;
+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 JobsUserSessionBean extends BaseDatabaseBean implements UserSessionBeanRemote {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_916L;
+
+ /**
+ * Default constructor
+ */
+ public JobsUserSessionBean () {
+ }
+
+ @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 ifUserExists (final User user) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: user={0} - CALLED!", user)); //NOI18N
+
+ // userId should not be null
+ if (null == user) {
+ // Abort here
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (user.getUserId() == null) {
+ // Abort here
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (user.getUserId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
+ }
+
+ // Generate query
+ Query query = this.getEntityManager().createNamedQuery("SearchUserId", LoginUser.class); //NOI18N
+
+ // Set parameter
+ query.setParameter("id", user.getUserId()); //NOI18N
+
+ // Try this
+ try {
+ User dummy = (User) query.getSingleResult();
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
+ } catch (final NoResultException ex) {
+ // Log it
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: 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 {0} found.", user, ex)); //NOI18N
+
+ // Throw again
+ throw ex;
+ }
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: Found user {0} - EXIT!", user)); //NOI18N
+
+ // Found it
+ return true;
+ }
+
+ @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.ifUserExists(user)) {
+ // User does not exist
+ throw new EJBException(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);
+ }
+ }
+
+}
+++ /dev/null
-/*
- * 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.EJBException;
-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 ifUserExists (final User user) {
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: user={0} - CALLED!", user)); //NOI18N
-
- // userId should not be null
- if (null == user) {
- // Abort here
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // Abort here
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
- }
-
- // Generate query
- Query query = this.getEntityManager().createNamedQuery("SearchUserId", LoginUser.class); //NOI18N
-
- // Set parameter
- query.setParameter("id", user.getUserId()); //NOI18N
-
- // Try this
- try {
- User dummy = (User) query.getSingleResult();
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: dummy.id={0} found.", dummy.getUserId())); //NOI18N
- } catch (final NoResultException ex) {
- // Log it
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("ifUserExists: 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 {0} found.", user, ex)); //NOI18N
-
- // Throw again
- throw ex;
- }
-
- // Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("ifUserExists: Found user {0} - EXIT!", user)); //NOI18N
-
- // Found it
- return true;
- }
-
- @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.ifUserExists(user)) {
- // User does not exist
- throw new EJBException(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);
- }
- }
-
-}