From 1d87b118dc52abf31de88e31b2dc2b264d6ccdaf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 13 Mar 2018 23:05:44 +0100 Subject: [PATCH] Please cherry-pick/rename: - Headquarter is enough for bean name (please rename) - removed some no longer recommended business methods - removed no longer used private methods - made some local variables final which helps the Java compiler in optimization of resulting byte-code - added session EJB for user activity - other improvements (?) - changed copyright to Free Software Foundation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../AddressbookContactSessionBean.java | 119 +--------- ...dressbookAdminBusinessDataSessionBean.java | 12 +- ...dressbookAdminBranchOfficeSessionBean.java | 2 +- ...AddressbookAdminDepartmentSessionBean.java | 18 +- .../AddressbookDepartmentSessionBean.java | 2 +- .../AddressbookAdminEmployeeSessionBean.java | 207 +++++++++++++++++- .../AddressbookEmployeeSessionBean.java | 4 +- ...dressbookAdminHeadquartersSessionBean.java | 48 ++-- .../AddressbookHeadquartersSessionBean.java | 12 +- ...dressbookAdminOpeningTimesSessionBean.java | 2 +- .../AddressbookOpeningTimesSessionBean.java | 2 +- .../AddressbookAdminCountrySingletonBean.java | 2 +- .../user/AddressbookAdminUserSessionBean.java | 4 +- .../user/AddressbookUserSessionBean.java | 71 +----- .../AddressbookUserActivitySessionBean.java | 179 +++++---------- .../AddressbookUserLoginSessionBean.java | 1 + 16 files changed, 333 insertions(+), 352 deletions(-) rename src/java/org/mxchange/jcontactsbusiness/model/{headquarters => headquarter}/AddressbookAdminHeadquartersSessionBean.java (68%) rename src/java/org/mxchange/jcontactsbusiness/model/{headquarters => headquarter}/AddressbookHeadquartersSessionBean.java (74%) diff --git a/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java b/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java index 6c3eccf..cdf4b3c 100644 --- a/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java +++ b/src/java/org/mxchange/jcontacts/model/contact/AddressbookContactSessionBean.java @@ -66,62 +66,6 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i return contacts; } - @Override - @SuppressWarnings ("unchecked") - public List allEmailAddresses () { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList - CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Create query instance - final Query query = this.getEntityManager().createNamedQuery("AllContactEmailAddresses"); //NOI18N - - // Get list - final List emailAddresses = query.getResultList(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N - - // Return it - return emailAddresses; - } - - @Override - public boolean isEmailAddressRegistered (final String emailAddress) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N - - // The email address should be valid - if (null == emailAddress) { - // Is null - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.isEmpty()) { - // Is empty - throw new IllegalArgumentException("emailAddress is empty"); //NOI18N - } - - // Default is not found - boolean isFound = false; - - try { - // Ask other method for contact instance - final Contact contact = this.findContactByEmailAddress(emailAddress); - - // Log debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: Found contact={1} for emailAddress={2}", this.getClass().getSimpleName(), contact, emailAddress)); //NOI18N - - // It is found ... - isFound = true; - } catch (final ContactNotFoundException ex) { - // @TODO Was not found, log exception for spam check? - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N - - // Return status - return isFound; - } - @Override public Contact lookupContact (final Contact contact) { // Log trace message @@ -160,7 +104,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i // Loop through all while (iterator.hasNext()) { // Get contact - Contact next = iterator.next(); + final Contact next = iterator.next(); // Is same contact? if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) { @@ -201,7 +145,7 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i this.setAllContactPhoneEntriesUpdated(contact, isCellphoneUnlinked, isLandlineUnlinked, isFaxUnlinked); // Merge mobile, land-line and fix - Contact detachedContact = this.mergeContactData(contact); + final Contact detachedContact = this.mergeContactData(contact); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N @@ -228,12 +172,12 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i } // Is cell phone/land-line/fax number unlinked? - boolean isCellphoneUnlinked = (contact.getContactMobileNumber() == null); - boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null); - boolean isFaxUnlinked = (contact.getContactFaxNumber() == null); + final boolean isCellphoneUnlinked = (contact.getContactMobileNumber() == null); + final boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null); + final boolean isFaxUnlinked = (contact.getContactFaxNumber() == null); // Call other Method - Contact detachedContact = this.updateContactData(contact, isCellphoneUnlinked, isLandLineUnlinked, isFaxUnlinked); + final Contact detachedContact = this.updateContactData(contact, isCellphoneUnlinked, isLandLineUnlinked, isFaxUnlinked); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N @@ -242,57 +186,6 @@ public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean i return detachedContact; } - /** - * Returns a contact instance which has the given email address. - *

- * @param emailAddress Email address - *

- * @return Contact instance - *

- * @throws ContactNotFoundException If the contact was not found - */ - private Contact findContactByEmailAddress (final String emailAddress) throws ContactNotFoundException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N - - // The parameter must be valid - if (null == emailAddress) { - // Throw NPE - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.isEmpty()) { - // Not valid - throw new IllegalArgumentException("emailAddress is empty"); //NOI18N - } - - // Get query instance - final Query query = this.getEntityManager().createNamedQuery("SearchContactByEmailAddress", UserContact.class); //NOI18N - - // Set parameter and limit - query.setParameter("emailAddress", emailAddress); //NOI18N - query.setMaxResults(1); - - // Init contact instance - final Contact contact; - - // Try to find a result - try { - // Find a single result - contact = (Contact) query.getSingleResult(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new ContactNotFoundException(emailAddress, ex); - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Return found instance - return contact; - } - /** * Returns a contact instance which has the given id number. *

diff --git a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java index 4e2d5e2..6f25bcf 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookAdminBusinessDataSessionBean.java @@ -24,8 +24,9 @@ import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataAlreadyAddedException; -import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jusercore.model.user.User; /** * An administrative stateless session bean for business data @@ -101,6 +102,15 @@ public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookData basicData.setCompanyContactEmployee(managedEmployee); } + // Is a headquarter set? + if (basicData.getCompanyHeadquarterData()instanceof Headquarter) { + // Get managed instance + final Headquarter managedHeadquarter = this.createManaged(basicData.getCompanyHeadquarterData()); + + // Set it back + basicData.setCompanyHeadquarterData(managedHeadquarter); + } + // Set created timestamps for any assigned numbers this.setAllPhoneEntriesCreated(basicData); diff --git a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java index 2a6c8c1..5597caf 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java @@ -23,10 +23,10 @@ import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jusercore.model.user.User; -import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; /** * A stateless session bean for administrative branch office purposes diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java index 9d96fdd..b95556d 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -22,12 +22,12 @@ import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; -import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jusercore.model.user.User; /** * A stateless session bean for administrative department purposes @@ -106,13 +106,13 @@ public class AddressbookAdminDepartmentSessionBean extends BaseAddressbookDataba department.setDepartmentBranchOffice(managedBranchOffice); } - // Is headquarters set? - if (department.getDepartmentHeadquarters() instanceof Headquarter) { - // Get managed headquarters - final Headquarter managedHeadquarters = this.createManaged(department.getDepartmentHeadquarters()); + // Is headquarter set? + if (department.getDepartmentHeadquarter() instanceof Headquarter) { + // Get managed headquarter + final Headquarter managedHeadquarter = this.createManaged(department.getDepartmentHeadquarter()); // Set it back - department.setDepartmentHeadquarters(managedHeadquarters); + department.setDepartmentHeadquarter(managedHeadquarter); } // Is lead employee set? diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java index 24c3f1b..e8dea68 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 diff --git a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java index 4aa191e..0036166 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminEmployeeSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -16,8 +16,20 @@ */ package org.mxchange.jcontactsbusiness.model.employee; +import java.text.MessageFormat; +import java.util.Date; +import javax.ejb.EJB; import javax.ejb.Stateless; import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeAlreadyAddedException; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.model.department.Department; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jusercore.model.user.User; /** * A stateless bean for administrative purposes for company employees. @@ -32,6 +44,12 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookDatabase */ private static final long serialVersionUID = 26_458_796_703_761L; + /** + * EJB for general company employee purposes + */ + @EJB (lookup = "java:global/addressbook-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote") + private EmployeeSessionBeanRemote employeeBean; + /** * Default constructor */ @@ -39,4 +57,191 @@ public class AddressbookAdminEmployeeSessionBean extends BaseAddressbookDatabase super(); } + @Override + public Employable addEmployee (final Employable employee) throws EmployeeAlreadyAddedException { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addEmployee(): employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N + + // Validate parameter + if (null == employee) { + // Throw NPE + throw new NullPointerException("employee is null"); //NOI18N + } else if (employee.getEmployeeId() != null) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is unexpected.", employee.getEmployeeId())); //NOI18N + } else if (employee.getEmployeeCompany() == null) { + // Throw NPE + throw new NullPointerException("employee.employeeCompany is null"); //NOI18N + } else if (employee.getEmployeeCompany().getBasicDataId() == null) { + // Throw it again + throw new NullPointerException("employee.employeeCompany.basicDataId is null"); //NOI18N + } else if (employee.getEmployeeCompany().getBasicDataId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeeCompany.basicDataId={0} is invalid.", employee.getEmployeeCompany().getBasicDataId())); //NOI18N + } else if (employee.getEmployeeBranchOffice() == null && employee.getEmployeeDepartment() == null && employee.getEmployeeHeadquarter() == null) { + // At least one must be set + throw new NullPointerException("employee.employeeBranchOffice, employee.employeeDepartment and employee.employeeHeadquarter is null"); //NOI18N + } else if (employee.getEmployeeBranchOffice() != null && employee.getEmployeeBranchOffice().getBranchId() == null) { + // Throw NPE + throw new NullPointerException("employee.employeeBranchOffice.branchId is null"); //NOI18N + } else if (employee.getEmployeeBranchOffice() != null && employee.getEmployeeBranchOffice().getBranchId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeeBranchOffice.branchId={0} is invalid.", employee.getEmployeeBranchOffice().getBranchId())); //NOI18N + } else if (employee.getEmployeeDepartment() != null && employee.getEmployeeDepartment().getDepartmentId() == null) { + // Throw NPE + throw new NullPointerException("employee.employeeDepartment.departmentId is null"); //NOI18N + } else if (employee.getEmployeeDepartment() != null && employee.getEmployeeDepartment().getDepartmentId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeeDepartment.departmentId={0} is invalid.", employee.getEmployeeDepartment().getDepartmentId())); //NOI18N + } else if (employee.getEmployeeHeadquarter() != null && employee.getEmployeeHeadquarter().getHeadquarterId() == null) { + // Throw NPE + throw new NullPointerException("employee.employeeHeadquarter.headquarterId is null"); //NOI18N + } else if (employee.getEmployeeHeadquarter() != null && employee.getEmployeeHeadquarter().getHeadquarterId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeeHeadquarter.headquarterId={0} is invalid.", employee.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N + } else if ((employee.getEmployeePersonalData() == null) && (employee.getEmployeeNumber() == null)) { + // Both are null + throw new NullPointerException("employee.employeePersonalData and employee.employeeNumber are null"); //NOI18N + } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() == null)) { + // Throw NPE + throw new NullPointerException("employee.employeePersonalData.contactId is null"); //NOI18N + } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeePersonalData.contactId={0} is invalid.", employee.getEmployeePersonalData().getContactId())); //NOI18N + } else if ((employee.getEmployeeNumber() != null) && (employee.getEmployeeNumber().isEmpty())) { + // Throw it again + throw new IllegalArgumentException("employee.employeeNumber is empty"); //NOI18N + } else if ((employee.getEmployeeMobileNumber() != null) && (employee.getEmployeeMobileNumber().getPhoneId() != null)) { + // Throw once more + throw new IllegalArgumentException(MessageFormat.format("employee.employeeMobileNumber.phoneId={0} is unexpected.", employee.getEmployeeMobileNumber().getPhoneId())); //NOI18N + } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() == null)) { + // Throw NPE + throw new NullPointerException("employee.employeePersonalData.contactId is null"); //NOI18N + } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeePersonalData.contactId={0} is unexpected.", employee.getEmployeePersonalData().getContactId())); //NOI18N + } else if ((employee.getEmployeePosition() != null) && (employee.getEmployeePosition().getJobPositionId() == null)) { + // Throw NPE + throw new NullPointerException("employee.employeePosition.jobPositionId is null"); //NOI18N + } else if ((employee.getEmployeePosition() != null) && (employee.getEmployeePosition().getJobPositionId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeePosition.jobPositionId={0} is unexpected.", employee.getEmployeePosition().getJobPositionId())); //NOI18N + } else if ((employee.getEmployeeUserOwner() != null) && (employee.getEmployeeUserOwner().getUserId() == null)) { + // Throw NPE + throw new NullPointerException("employee.employeeUserOwner.userId is null"); //NOI18N + } else if ((employee.getEmployeeUserOwner() != null) && (employee.getEmployeeUserOwner().getUserId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee.employeeUserOwner.userId={0} is unexpected.", employee.getEmployeeUserOwner().getUserId())); //NOI18N + } else if (this.isEmployeeAdded(employee)) { + // Throw exception + throw new EmployeeAlreadyAddedException(); + } + + // Make company (basic data) managed + employee.setEmployeeCompany(this.createManaged(employee.getEmployeeCompany())); + + // Is branch office set? + if (employee.getEmployeeBranchOffice() instanceof BranchOffice) { + // Then make it managed + final BranchOffice branchOffice = this.createManaged(employee.getEmployeeBranchOffice()); + + // Set it back + employee.setEmployeeBranchOffice(branchOffice); + } + + // Is department set? + if (employee.getEmployeeDepartment() instanceof Department) { + // Then make it managed + final Department department = this.createManaged(employee.getEmployeeDepartment()); + + // Set it back + employee.setEmployeeDepartment(department); + } + + // Is headquarter set? + if (employee.getEmployeeHeadquarter() instanceof Headquarter) { + // Then make it managed + final Headquarter headquarter = this.createManaged(employee.getEmployeeHeadquarter()); + + // Set it back + employee.setEmployeeHeadquarter(headquarter); + } + + // Is personal data set? + if (employee.getEmployeePersonalData() instanceof Contact) { + // Then make it managed + final Contact contact = this.createManaged(employee.getEmployeePersonalData()); + + // Set it back + employee.setEmployeePersonalData(contact); + } + + // Is headquarter set? + if (employee.getEmployeePosition() instanceof JobPosition) { + // Then make it managed + final JobPosition jobPosition = this.createManaged(employee.getEmployeePosition()); + + // Set it back + employee.setEmployeePosition(jobPosition); + } + + // Is headquarter set? + if (employee.getEmployeeUserOwner() instanceof User) { + // Then make it managed + final User user = this.createManaged(employee.getEmployeeUserOwner()); + + // Set it back + employee.setEmployeeUserOwner(user); + } + + // Is mobile number set? + if (employee.getEmployeeMobileNumber() instanceof DialableMobileNumber) { + // Yes, then set created there as well + employee.getEmployeeMobileNumber().setPhoneEntryCreated(new Date()); + + // Make mobile provider managed + final MobileProvider mobileProvider = this.createManaged(employee.getEmployeeMobileNumber().getMobileProvider()); + + // Set it back + employee.getEmployeeMobileNumber().setMobileProvider(mobileProvider); + } + + // Set created timestamp + employee.setEmployeeCreated(new Date()); + + // Persist it + this.getEntityManager().persist(employee); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addEmployee(): employee.employeeId={1} - EXIT!", this.getClass().getSimpleName(), employee.getEmployeeId())); //NOI18N + + // Return it + return employee; + } + + /** + * Checks whether employee is already added + *

+ * @param employee Employee to be checked + *

+ * @return Whether employee is already added + */ + private boolean isEmployeeAdded (final Employable employee) { + // Default is not added + boolean isFound = false; + + // Check all entries + for (final Employable otherEmployee : this.employeeBean.allEmployees()) { + // Is same found? + if (Employees.isSameEmployeeFound(employee, otherEmployee)) { + // Found it + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + } diff --git a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java index 503b775..56b25f1 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookEmployeeSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -33,7 +33,7 @@ public class AddressbookEmployeeSessionBean extends BaseAddressbookDatabaseBean /** * Serial number */ - private static final long serialVersionUID = 26_458_796_703_761L; + private static final long serialVersionUID = 26_458_796_703_762L; /** * Default constructor diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/AddressbookAdminHeadquartersSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookAdminHeadquartersSessionBean.java similarity index 68% rename from src/java/org/mxchange/jcontactsbusiness/model/headquarters/AddressbookAdminHeadquartersSessionBean.java rename to src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookAdminHeadquartersSessionBean.java index b2e0d8f..a90afda 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/AddressbookAdminHeadquartersSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookAdminHeadquartersSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -14,14 +14,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.model.headquarters; +package org.mxchange.jcontactsbusiness.model.headquarter; import java.text.MessageFormat; import java.util.Date; import java.util.List; import javax.ejb.EJB; import javax.ejb.Stateless; -import org.mxchange.jcontactsbusiness.exceptions.headquarters.HeadquartersAlreadyAddedException; +import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterAlreadyAddedException; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcountry.model.data.Country; import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; @@ -33,7 +33,7 @@ import org.mxchange.jusercore.model.user.User; * @author Roland Häder */ @Stateless (name = "adminHeadquarter", description = "An administrative statless bean for handling branch office data (all)") -public class AddressbookAdminHeadquartersSessionBean extends BaseAddressbookDatabaseBean implements AdminHeadquartersSessionBeanRemote { +public class AddressbookAdminHeadquarterSessionBean extends BaseAddressbookDatabaseBean implements AdminHeadquarterSessionBeanRemote { /** * Serial number @@ -43,63 +43,63 @@ public class AddressbookAdminHeadquartersSessionBean extends BaseAddressbookData /** * General branch office bean */ - @EJB (lookup = "java:global/addressbook-ejb/headquarters!org.mxchange.jcontactsbusiness.model.headquarters.HeadquarterSessionBeanRemote") - private HeadquartersSessionBeanRemote headquartersBean; + @EJB (lookup = "java:global/addressbook-ejb/headquarter!org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote") + private HeadquarterSessionBeanRemote headquarterBean; /** * Default constructor */ - public AddressbookAdminHeadquartersSessionBean () { + public AddressbookAdminHeadquarterSessionBean () { // Call super constructor super(); } @Override - public Headquarter addHeadquarters (final Headquarter headquarter) throws HeadquartersAlreadyAddedException { + public Headquarter addHeadquarter (final Headquarter headquarter) throws HeadquarterAlreadyAddedException { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarter(): headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N // Validate parameter if (null == headquarter) { // Throw NPE throw new NullPointerException("headquarter is null"); //NOI18N - } else if (headquarter.getHeadquartersId() instanceof Long) { + } else if (headquarter.getHeadquarterId() instanceof Long) { // Should not happen throw new IllegalArgumentException("headquarter.branchId should not be set."); //NOI18N } else if (this.isHeadquarterFound(headquarter)) { // Already added, abort here - throw new HeadquartersAlreadyAddedException(headquarter); + throw new HeadquarterAlreadyAddedException(headquarter); } // Add created timestamp - headquarter.setHeadquartersCreated(new Date()); + headquarter.setHeadquarterCreated(new Date()); // Is user instance set? - if (headquarter.getHeadquartersUserOwner() instanceof User) { + if (headquarter.getHeadquarterUserOwner() instanceof User) { // Get managed instance back - final User managedUser = this.createManaged(headquarter.getHeadquartersUserOwner()); + final User managedUser = this.createManaged(headquarter.getHeadquarterUserOwner()); // Set it back in branch office - headquarter.setHeadquartersUserOwner(managedUser); + headquarter.setHeadquarterUserOwner(managedUser); } // Is user instance set? - if (headquarter.getHeadquartersCountry() instanceof Country) { + if (headquarter.getHeadquarterCountry() instanceof Country) { // Get managed instance back - final Country managedCountry = this.createManaged(headquarter.getHeadquartersCountry()); + final Country managedCountry = this.createManaged(headquarter.getHeadquarterCountry()); // Set it back in branch office - headquarter.setHeadquartersCountry(managedCountry); + headquarter.setHeadquarterCountry(managedCountry); } // Set "created" timestamp on any number assigned this.setAllPhoneEntriesCreated(headquarter); // Get opening times - final List openingTimes = headquarter.getHeadquartersOpeningTimes(); + final List openingTimes = headquarter.getHeadquarterOpeningTimes(); // Debugging: - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addHeadquarters(): headquarter.headquarterOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes)); + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addHeadquarter(): headquarter.headquarterOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes)); // Is opening times set and not empty? if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) { @@ -107,14 +107,14 @@ public class AddressbookAdminHeadquartersSessionBean extends BaseAddressbookData this.setAllOpeningTimesCreated(openingTimes); } else { // Set all to null - headquarter.setHeadquartersOpeningTimes(null); + headquarter.setHeadquarterOpeningTimes(null); } // Persist it this.getEntityManager().persist(headquarter); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter.branchId={1} - EXIT!", this.getClass().getSimpleName(), headquarter.getHeadquartersId())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarter(): headquarter.branchId={1} - EXIT!", this.getClass().getSimpleName(), headquarter.getHeadquarterId())); //NOI18N // Return updated instance return headquarter; @@ -125,13 +125,13 @@ public class AddressbookAdminHeadquartersSessionBean extends BaseAddressbookData * (persisted) list is being loaded and each address is being matched * against the given branch office's address. *

- * @param headquarter Headquarters office being checked + * @param headquarter Headquarter office being checked *

* @return Whether it has been found */ private boolean isHeadquarterFound (final Headquarter headquarter) { // Get whole list - final List headquarters = this.headquartersBean.allHeadquarters(); + final List headquarters = this.headquarterBean.allHeadquarters(); // Default is not found boolean isFound = false; diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/AddressbookHeadquartersSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookHeadquartersSessionBean.java similarity index 74% rename from src/java/org/mxchange/jcontactsbusiness/model/headquarters/AddressbookHeadquartersSessionBean.java rename to src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookHeadquartersSessionBean.java index 967a722..2565557 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/AddressbookHeadquartersSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/AddressbookHeadquartersSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 @@ -14,21 +14,23 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.model.headquarters; +package org.mxchange.jcontactsbusiness.model.headquarter; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import java.text.MessageFormat; import java.util.List; import javax.ejb.Stateless; import javax.persistence.Query; import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; +import org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote; /** - * A stateless session bean for general headquarters purposes + * A stateless session bean for general headquarter purposes *

* @author Roland Häder */ -@Stateless (name = "headquarters", description = "A general statless bean for handling headquarters data (all)") -public class AddressbookHeadquartersSessionBean extends BaseAddressbookDatabaseBean implements HeadquartersSessionBeanRemote { +@Stateless (name = "headquarter", description = "A general statless bean for handling headquarter data (all)") +public class AddressbookHeadquarterSessionBean extends BaseAddressbookDatabaseBean implements HeadquarterSessionBeanRemote { /** * Serial number diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java index 70b22f0..0935f56 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java index 3cae36d..5546004 100644 --- a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java +++ b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Roland Häder + * Copyright (C) 2017, 2018 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 diff --git a/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java b/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java index ed21d59..ab5be18 100644 --- a/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java +++ b/src/java/org/mxchange/jcountry/model/data/AddressbookAdminCountrySingletonBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2016 - 2018 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 diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java index 368d1d2..dc1d482 100644 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java @@ -69,7 +69,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - // user should not be null + // Validate parameter if (null == user) { // Abort here throw new NullPointerException("user is null"); //NOI18N @@ -109,7 +109,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - // user should not be null + // Validate parameters if (null == user) { // Abort here throw new NullPointerException("user is null"); //NOI18N diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java index 6ba30ee..c9d2558 100644 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java @@ -40,7 +40,6 @@ import org.mxchange.jusercore.exceptions.UserStatusLockedException; import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; import org.mxchange.jusercore.model.user.password_history.PasswordHistory; import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory; -import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote; @@ -73,53 +72,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl @Override @SuppressWarnings ("unchecked") - public List allMemberPublicVisibleUsers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - final Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", LoginUser.class); //NOI18N - - // Set parameters - query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N - query.setParameter("members", ProfileMode.MEMBERS); //NOI18N - query.setParameter("public", ProfileMode.PUBLIC); //NOI18N - - // Get result - final List users = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N - - // Return full list - return users; - } - - @Override - @SuppressWarnings ("unchecked") - public List allPublicUsers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - final Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N - - // Set parameters - query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N - query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N - - // Get result - final List users = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N - - // Return full list - return users; - } - - @Override - @SuppressWarnings ("unchecked") + @Deprecated public List allUserNames () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N @@ -201,6 +154,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl } @Override + @Deprecated public User fillUserData (final User user) throws UserNotFoundException { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N @@ -247,6 +201,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl } @Override + @Deprecated public String generateRandomUserName () { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N @@ -271,25 +226,7 @@ public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean impl } @Override - @SuppressWarnings ("unchecked") - public List getEmailAddressList () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - final Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N - - // Get result list - final List emailAddressList = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddressList.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddressList.size())); //NOI18N - - // Return it - return emailAddressList; - } - - @Override + @Deprecated public boolean ifUserExists (final User user) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N diff --git a/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivitySessionBean.java b/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivitySessionBean.java index 2245c34..da8074b 100644 --- a/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivitySessionBean.java +++ b/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivitySessionBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 - 2020 Free Software Foundation + * Copyright (C) 2017 Roland Haeder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,71 +17,83 @@ package org.mxchange.jusercore.model.user.activity; import java.text.MessageFormat; -import java.util.Arrays; import java.util.List; import javax.ejb.EJBException; import javax.ejb.Stateless; import javax.jms.JMSException; import javax.jms.ObjectMessage; import javax.persistence.Query; -import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; import org.mxchange.jusercore.model.user.User; /** - * An EJB for user activity log. This class extends BaseDatabaseBean and not - * project-specific "base class". The simple reason is that this class requires - * no email queue as no emails are ever being sent from this class. + * A stateless, session-scoped EJB for user-activity *

* @author Roland Häder */ -@Stateless (name = "userActivity", description = "A bean handling the user data") -public class AddressbookUserActivitySessionBean extends BaseDatabaseBean implements UserActivityLogSessionBeanRemote { +@Stateless (name = "userActivity", description = "A stateless, session-scored user-activity bean.") +public class AddressbookUserActivitySessionBean extends BaseAddressbookDatabaseBean implements UserActivityLogSessionBeanRemote { /** * Serial number */ - private static final long serialVersionUID = 219_568_677_671_054L; + private static final long serialVersionUID = 1_268_376_401_659L; /** * Default constructor */ public AddressbookUserActivitySessionBean () { - // Call super constructor - super("jms/jjobs-queue-factory", "jms/jjobs-user-activity-log"); //NOI18N + // Invoke super constructor + super("jms/addressbook-queue-factory", "jms/addressbook-user-activity-log"); //NOI18N } @Override public void addUserActivityLog (final LogableUserActivity userActivity) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: userActivity={1} CALLED!", this.getClass().getSimpleName(), userActivity)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: userActivity={1} - CALLED!", this.getClass().getSimpleName(), userActivity)); //NOI18N - // Should be valid + // Validate parameter if (null == userActivity) { // Throw NPE throw new NullPointerException("userActivity is null"); //NOI18N - } else if (userActivity.getActivityId() instanceof Long) { - // Id number should not be set - throw new IllegalArgumentException(MessageFormat.format("userActivity.activityId={0} should be null", userActivity.getActivityId())); //NOI18N - } else if (userActivity.getActivityUser() == null) { - // Throw NPE again - throw new NullPointerException("userActivity.activityUser is null"); //NOI18N + } else if (userActivity.getActivityContactFamilyName() == null) { + // Throw it again + throw new NullPointerException("userActivity.activityContactFamilyName is null"); //NOI18N + } else if (userActivity.getActivityContactFamilyName().isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("userActivity.activityContactFamilyName is empty"); //NOI18N + } else if (userActivity.getActivityContactFirstName() == null) { + // Throw NPE + throw new NullPointerException("userActivity.activityContactFirstName is null"); //NOI18N + } else if (userActivity.getActivityContactFirstName().isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("userActivity.activityContactFirstName is empty"); //NOI18N + } else if (userActivity.getActivityContactPersonalTitle() == null) { + // Throw NPE + throw new NullPointerException("userActivity.activityContactPersonalTitle is null"); //NOI18N + } else if ((userActivity.getActivityMessage() != null) && (userActivity.getActivityMessage().isEmpty())) { + // Throw IAE + throw new IllegalArgumentException("userActivity.activityMessage is empty"); //NOI18N } else if (userActivity.getActivityType() == null) { - // Throw again ... + // Throw NPE throw new NullPointerException("userActivity.activityType is null"); //NOI18N } else if (userActivity.getActivityType().isEmpty()) { - // Empty type - throw new NullPointerException("userActivity.activityType is empty"); //NOI18N - } else if ((userActivity.getActivityMessage() instanceof String) && (userActivity.getActivityMessage().isEmpty())) { - // Set but empty message - throw new NullPointerException("userActivity.activityMessage is empty"); //NOI18N - } else if (userActivity.getActivityTimestamp() == null) { - // Throw NPE again - throw new NullPointerException("userActivity.activityTimestamp is null"); //NOI18N + // Throw IAE + throw new IllegalArgumentException("userActivity.activityType is empty"); //NOI18N + } else if (userActivity.getActivityUserName() == null) { + // Throw NPE + throw new NullPointerException("userActivity.activityUserName is null"); //NOI18N + } else if (userActivity.getActivityUserName().isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("userActivity.activityUserName is empty"); //NOI18N + } else if (userActivity.getActivityId() != null) { + // Throw it again + throw new IllegalArgumentException("userActivity.activityId should never be set."); //NOI18N } try { // Send out email change - ObjectMessage message = this.getSession().createObjectMessage(); + final ObjectMessage message = this.getSession().createObjectMessage(); message.setObject(userActivity); // Send message @@ -90,6 +102,9 @@ public class AddressbookUserActivitySessionBean extends BaseDatabaseBean impleme // Throw again throw new EJBException(ex); } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUserActivityLog: EXIT!", this.getClass().getSimpleName())); //NOI18N } @Override @@ -98,10 +113,10 @@ public class AddressbookUserActivitySessionBean extends BaseDatabaseBean impleme // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUserActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N - // Search for user's activity - Query query = this.getEntityManager().createNamedQuery("AllUserActivityLog", UserActivityLog.class); //NOI18N + // Get named query + final Query query = this.getEntityManager().createNamedQuery("AllUserActivityLog"); //NOI18N - // Get list + // Get list from it List list = query.getResultList(); // Trace message @@ -115,27 +130,27 @@ public class AddressbookUserActivitySessionBean extends BaseDatabaseBean impleme @SuppressWarnings ("unchecked") public List fetchAllUsersActivityLog (final User user) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: CALLED!", this.getClass().getSimpleName())); //NOI18N - // Is user valid? + // Validate parameters if (null == user) { - // Throw NPE + // Abort here throw new NullPointerException("user is null"); //NOI18N } else if (user.getUserId() == null) { - // Throw again + // Id is set throw new NullPointerException("user.userId is null"); //NOI18N } else if (user.getUserId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("user.userId{0} is not valid", user.getUserId())); //NOI18N + // Not valid id number + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N } - // Search for user's activity - Query query = this.getEntityManager().createNamedQuery("FindAllUsersActivity", UserActivityLog.class); //NOI18N + // Get named query + final Query query = this.getEntityManager().createNamedQuery("SearchAllUsersActivity"); //NOI18N // Set parameter query.setParameter("activityUser", user); //NOI18N - // Get list + // Get list from it List list = query.getResultList(); // Trace message @@ -145,86 +160,4 @@ public class AddressbookUserActivitySessionBean extends BaseDatabaseBean impleme return list; } - @Override - @SuppressWarnings ("unchecked") - public List fetchAllUsersActivityLogByMultipleType (final User user, final String[] activityTypes) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: user={1},activityTypes={2} - CALLED!", this.getClass().getSimpleName(), user, Arrays.toString(activityTypes))); //NOI18N - - // Is user valid? - if (null == user) { - // Throw NPE - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Throw again - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("user.userId{0} is not valid", user.getUserId())); //NOI18N - } else if (null == activityTypes) { - // Throw NPE again - throw new NullPointerException("activityTypes is null"); //NOI18N - } else if (activityTypes.length == 0) { - // Should not be empty - throw new IllegalArgumentException("activityTypes is empty"); //NOI18N - } - - // Search for user's activity - Query query = this.getEntityManager().createNamedQuery("FindUsersActivityByMultipleTypes", UserActivityLog.class); //NOI18N - - // Set parameters - query.setParameter("activityUser", user); //NOI18N - query.setParameter("activityTypes", Arrays.asList(activityTypes)); //NOI18N - - // Get list - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @Override - @SuppressWarnings ("unchecked") - public List fetchAllUsersActivityLogByType (final User user, final String activityType) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: user={1},activityType={2} - CALLED!", this.getClass().getSimpleName(), user, activityType)); //NOI18N - - // Is user valid? - if (null == user) { - // Throw NPE - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Throw again - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("user.userId{0} is not valid", user.getUserId())); //NOI18N - } else if (null == activityType) { - // Throw NPE again - throw new NullPointerException("activityType is null"); //NOI18N - } else if (activityType.isEmpty()) { - // Should not be empty - throw new IllegalArgumentException("activityType is empty"); //NOI18N - } - - // Search for user's activity - Query query = this.getEntityManager().createNamedQuery("FindUsersActivityByType", UserActivityLog.class); //NOI18N - - // Set parameters - query.setParameter("activityUser", user); //NOI18N - query.setParameter("activityType", activityType); //NOI18N - - // Get list - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLogByType: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - } diff --git a/src/java/org/mxchange/juserlogincore/model/user/login/AddressbookUserLoginSessionBean.java b/src/java/org/mxchange/juserlogincore/model/user/login/AddressbookUserLoginSessionBean.java index 12fa840..8db7dcd 100644 --- a/src/java/org/mxchange/juserlogincore/model/user/login/AddressbookUserLoginSessionBean.java +++ b/src/java/org/mxchange/juserlogincore/model/user/login/AddressbookUserLoginSessionBean.java @@ -95,6 +95,7 @@ public class AddressbookUserLoginSessionBean extends BaseAddressbookDatabaseBean } // Get user instance from persistance + // @TODO Rewrite this to use JCache instead final User updatedUser = this.userBean.fillUserData(container.getUser()); // Debug message -- 2.39.5