From: Roland Häder Date: Wed, 22 Apr 2020 00:02:05 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a7d8eba3ec2a1d733b8c55cfbe41ae5baf548b21;p=jjobs-ejb.git Don't cherry-pick: - JJobs has no need for addressbooks, it can be done without them - renamed backing beans for JJobs - fixed (maybe?) some JNDI names - a lot other fixes, still something is not correct, some interfaces have some missing methods while they should be there Signed-off-by: Roland Häder --- diff --git a/lib/jaddressbook-core.jar b/lib/jaddressbook-core.jar deleted file mode 100644 index 6578dc4..0000000 Binary files a/lib/jaddressbook-core.jar and /dev/null differ diff --git a/lib/jaddressbook-lib.jar b/lib/jaddressbook-lib.jar deleted file mode 100644 index 7347bb6..0000000 Binary files a/lib/jaddressbook-lib.jar and /dev/null differ diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index c1872ee..362be6a 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -812,6 +812,9 @@ exists or setup the property manually. For example like this: + + + @@ -823,6 +826,9 @@ exists or setup the property manually. For example like this: + + + @@ -839,24 +845,21 @@ exists or setup the property manually. For example like this: - - - - - - - - + + + + + @@ -865,77 +868,68 @@ exists or setup the property manually. For example like this: - - - - - - - - + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + @@ -1326,6 +1320,7 @@ exists or setup the property manually. For example like this: + diff --git a/nbproject/project.properties b/nbproject/project.properties index ecc84d1..26c90f7 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -22,8 +22,6 @@ dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= file.reference.cdi-api.jar=lib/cdi-api.jar -file.reference.jaddressbook-core.jar=lib/jaddressbook-core.jar -file.reference.jaddressbook-lib.jar=lib/jaddressbook-lib.jar file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar file.reference.jcontacts-business-lib.jar=lib/jcontacts-business-lib.jar file.reference.jcontacts-core.jar=lib/jcontacts-core.jar @@ -75,8 +73,6 @@ javac.classpath=\ ${file.reference.juser-activity-core.jar}:\ ${file.reference.juser-activity-lib.jar}:\ ${file.reference.jletter-lib.jar}:\ - ${file.reference.jaddressbook-core.jar}:\ - ${file.reference.jaddressbook-lib.jar}:\ ${file.reference.jmailer-ee.jar}:\ ${reference.jjobs-core.jar}:\ ${reference.jjobs-lib.jar}:\ diff --git a/nbproject/project.xml b/nbproject/project.xml index dfb5b8b..5d8475c 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -21,8 +21,6 @@ file.reference.juser-activity-core.jar file.reference.juser-activity-lib.jar file.reference.jletter-lib.jar - file.reference.jaddressbook-core.jar - file.reference.jaddressbook-lib.jar file.reference.jmailer-ee.jar reference.jjobs-core.jar reference.jjobs-lib.jar diff --git a/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java b/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java index e3f6010..35cb77c 100644 --- a/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java +++ b/src/java/org/mxchange/jjobs/enterprise/BaseJobsEnterpriseBean.java @@ -35,7 +35,6 @@ import org.mxchange.jcontactsbusiness.model.department.Department; import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition; -import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcoreee.bean.ejb.BaseEnterpriseBean; import org.mxchange.jcountry.model.data.Country; @@ -370,42 +369,6 @@ public abstract class BaseJobsEnterpriseBean extends BaseEnterpriseBean { return managedHeadquarter; } - /** - * Get back a managed instance from given job position - *

- * @param jobPosition Unmanaged/detached job position instance - *

- * @return Managed job position instance - */ - protected JobPosition createManaged (final JobPosition jobPosition) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: jobPosition={1} - CALLED!", this.getClass().getSimpleName(), jobPosition)); //NOI18N - - // user should not be null - if (null == jobPosition) { - // Abort here - throw new NullPointerException("jobPosition is null"); //NOI18N - } else if (jobPosition.getJobPositionId() == null) { - // Id is set - throw new NullPointerException("jobPosition.jobPositionId is null"); //NOI18N - } else if (jobPosition.getJobPositionId() < 1) { - // Id is set - throw new IllegalArgumentException(MessageFormat.format("jobPosition.jobPositionId={0} is invalid", jobPosition.getJobPositionId())); //NOI18N - } - - // Try to find it (should be there) - final JobPosition managedJobPosition = this.getEntityManager().find(jobPosition.getClass(), jobPosition.getJobPositionId()); - - // Should be there - assert (managedJobPosition instanceof JobPosition) : "managedJobPosition is null"; //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedJobPosition={1} - EXIT!", this.getClass().getSimpleName(), managedJobPosition)); //NOI18N - - // Return it - return managedJobPosition; - } - /** * Get back a managed instance from given mobile provider *

diff --git a/src/java/org/mxchange/jjobs/model/addressbook/JobsAddressbookSessionBean.java b/src/java/org/mxchange/jjobs/model/addressbook/JobsAddressbookSessionBean.java deleted file mode 100644 index 36e3626..0000000 --- a/src/java/org/mxchange/jjobs/model/addressbook/JobsAddressbookSessionBean.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.model.addressbook; - -import java.text.MessageFormat; -import java.util.Date; -import java.util.List; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote; -import org.mxchange.jaddressbook.exceptions.AddressbookNameAlreadyUsedException; -import org.mxchange.jaddressbook.exceptions.AddressbookNotFoundException; -import org.mxchange.jaddressbook.model.addressbook.Addressbook; -import org.mxchange.jaddressbook.model.addressbook.UserAddressbook; -import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry; -import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean; -import org.mxchange.jusercore.model.user.User; - -/** - * A stateless bean handling address books - *

- * @author Roland Häder - */ -@Stateless (name = "addressbook", description = "A stateless bean for handling JJobs addressbooks") -public class JobsAddressbookSessionBean extends BaseJobsEnterpriseBean implements AddressbookSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 129_857_871_287_691L; - - /** - * Default constructor - */ - public JobsAddressbookSessionBean () { - // Call super constructor - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List 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"); //NOI18N - } else if (addressbook.getAddressbookId() == null) { - // Throw NPE again - throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N - } else if (addressbook.getAddressbookId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); //NOI18N - } else if (addressbook.getAddressbookUser() == null) { - // Throw again NPE - throw new NullPointerException("addressbook.addressbookUser is null"); //NOI18N - } else if (addressbook.getAddressbookUser().getUserId() == null) { - // Throw again NPE - throw new NullPointerException("addressbook.addressbookUser.userId is null"); //NOI18N - } else if (addressbook.getAddressbookUser().getUserId() < 1) { - // Invalid id number again - throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid", addressbook.getAddressbookUser().getUserId())); //NOI18N - } - - // 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); - } - - // Add timestamp of creation - addressbook.setAddressbookCreated(new Date()); - - // 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 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 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; - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java index 40ae85c..9ff0e68 100644 --- a/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/JobsUserSessionBean.java @@ -287,10 +287,10 @@ public class JobsUserSessionBean extends BaseJobsEnterpriseBean implements UserS final 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.", detachedUser.getUserId()); //NOI18N + assert (foundUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N // Copy all data - Users.copyUserData(detachedUser, foundUser); + Users.copyUserData(user, foundUser); // Merge user final User managedUser = this.getEntityManager().merge(foundUser); diff --git a/src/java/org/mxchange/juserlogincore/model/user/login/JobsUserLoginSessionBean.java b/src/java/org/mxchange/juserlogincore/model/user/login/JobsUserLoginSessionBean.java deleted file mode 100644 index a7f2e75..0000000 --- a/src/java/org/mxchange/juserlogincore/model/user/login/JobsUserLoginSessionBean.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.juserlogincore.model.user.login; - -import java.text.MessageFormat; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.jjobs.enterprise.BaseJobsEnterpriseBean; -import org.mxchange.jusercore.exceptions.UserNotFoundException; -import org.mxchange.jusercore.exceptions.UserStatusLockedException; -import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.UserSessionBeanRemote; -import org.mxchange.jusercore.model.user.status.UserAccountStatus; -import org.mxchange.juserlogincore.container.login.LoginContainer; -import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException; -import org.mxchange.juserlogincore.login.UserLoginUtils; - -/** - * A session EJB for user logins - *

- * @author Roland Häder - */ -@Stateless (name = "userLogin", description = "A bean handling the user login for Jobs project") -public class JobsUserLoginSessionBean extends BaseJobsEnterpriseBean implements UserLoginSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 21_785_978_127_581_965L; - - /** - * User EJB - */ - @EJB (lookup = "java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") - private UserSessionBeanRemote userBean; - - /** - * Default constructor - */ - public JobsUserLoginSessionBean () { - // Call super constructor - super(); - } - - @Override - public User validateUserAccountStatus (final LoginContainer container) throws UserNotFoundException, UserStatusLockedException, UserStatusUnconfirmedException, UserPasswordMismatchException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.loginUser: container={1} - CALLED!", this.getClass().getSimpleName(), container)); //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.userBean.isUserNameRegistered(container.getUser())) { - // Not registered - throw new UserNotFoundException(container.getUser()); - } - - // Get user instance from persistance - // @TODO Rewrite this to use JCache instead - final 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("{0}.loginUser: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), 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. - *

- * @param container Container instance holding the user instance and - * clear-text password - * @param updatedUser Updated user instance found for given user name - *

- * @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 UserLoginUtils.ifPasswordMatches(container, updatedUser); - } - -}