From: Roland Häder Date: Sat, 8 Jul 2017 17:16:55 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=93d5c099d3230a3568bb47585403cce6dd2a388d;p=jfinancials-mailer-ejb.git Please cherry-pick: - new project 'jfinancials-mailer-ejb' initialized from jfinancials-ejb - this includes one message-driven bean and a singleton bean - the message-driven bean accepts "wrapper" objects per JMS from outside EJB - the singleton bean is then the "backend" which loads templates and delivers the mail - this split from general EJB project has the benefit of easier distributing (cluster) load - a lot libs were no longer needed - added velocity engine (from jfinancials-mailer) as library Signed-off-by: Roland Häder --- diff --git a/build.xml b/build.xml index cb14d30..296d372 100644 --- a/build.xml +++ b/build.xml @@ -7,8 +7,8 @@ - - Builds, tests, and runs the project addressbook-ejb. + + Builds, tests, and runs the project jfinancials-mailer-ejb. - + @@ -433,7 +433,7 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - + @@ -585,7 +585,7 @@ or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties f - + @@ -806,13 +806,7 @@ exists or setup the property manually. For example like this: COMPILATION SECTION --> - - - - - - - + @@ -820,13 +814,7 @@ exists or setup the property manually. For example like this: - - - - - - - + @@ -846,95 +834,35 @@ exists or setup the property manually. For example like this: - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - + + @@ -1318,9 +1246,7 @@ exists or setup the property manually. For example like this: CLEANUP SECTION --> - - - + diff --git a/nbproject/project.properties b/nbproject/project.properties index 09f240a..8c68fb6 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -21,25 +21,11 @@ dist.jar=${dist.dir}/${jar.name} dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= -file.reference.addressbook-mailer.jar=lib/addressbook-mailer.jar +file.reference.jfinancials-mailer.jar=lib/jfinancials-mailer.jar 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.jaddressbook-share-core.jar=lib/jaddressbook-share-core.jar -file.reference.jaddressbook-share-lib.jar=lib/jaddressbook-share-lib.jar -file.reference.jcontacts-core.jar=lib/jcontacts-core.jar -file.reference.jcontacts-lib.jar=lib/jcontacts-lib.jar file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar file.reference.jcoreee.jar=lib/jcoreee.jar -file.reference.jcountry-core.jar=lib/jcountry-core.jar -file.reference.jcountry-lib.jar=lib/jcountry-lib.jar file.reference.jmailer-ee.jar=lib/jmailer-ee.jar -file.reference.jphone-core.jar=lib/jphone-core.jar -file.reference.jphone-lib.jar=lib/jphone-lib.jar -file.reference.juser-activity-core.jar=lib/juser-activity-core.jar -file.reference.juser-activity-lib.jar=lib/juser-activity-lib.jar -file.reference.juser-core.jar=lib/juser-core.jar -file.reference.juser-lib.jar=lib/juser-lib.jar includes=** j2ee.compile.on.save=true j2ee.deploy.on.save=true @@ -52,30 +38,15 @@ j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.ja j2ee.platform.wsit.classpath= j2ee.server.type=gfv3ee6 jar.compress=false -jar.name=addressbook-ejb.jar +jar.name=jfinancials-mailer-ejb.jar jars.in.ejbjar=false javac.classpath=\ ${file.reference.jcoreee.jar}:\ ${file.reference.jcore-logger-lib.jar}:\ - ${file.reference.jcountry-core.jar}:\ - ${file.reference.jcountry-lib.jar}:\ - ${file.reference.jphone-core.jar}:\ - ${file.reference.jphone-lib.jar}:\ - ${file.reference.jcontacts-core.jar}:\ - ${file.reference.jcontacts-lib.jar}:\ - ${file.reference.juser-core.jar}:\ - ${file.reference.juser-lib.jar}:\ - ${file.reference.juser-activity-core.jar}:\ - ${file.reference.juser-activity-lib.jar}:\ ${file.reference.jmailer-ee.jar}:\ - ${file.reference.jaddressbook-core.jar}:\ - ${file.reference.jaddressbook-lib.jar}:\ - ${file.reference.jaddressbook-share-core.jar}:\ - ${file.reference.jaddressbook-share-lib.jar}:\ - ${reference.addressbook-core.jar}:\ - ${reference.addressbook-lib.jar}:\ - ${reference.addressbook-mailer.jar}:\ - ${file.reference.cdi-api.jar} + ${file.reference.cdi-api.jar}:\ + ${libs.velocity.classpath}:\ + ${reference.jfinancials-mailer-lib.jar} javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.debug=true javac.deprecation=true @@ -98,19 +69,15 @@ javadoc.private=true javadoc.splitindex=true javadoc.use=true javadoc.version=true -javadoc.windowtitle=addressbook EJBs +javadoc.windowtitle=jfinancials EJBs meta.inf=${source.root}/conf meta.inf.excludes=sun-cmp-mappings.xml platform.active=default_platform -project.addressbook-core=../../NetBeansProjects/addressbook-core -project.addressbook-lib=../addressbook-lib -project.addressbook-mailer=../addressbook-mailer +project.jfinancials-mailer-lib=../../NetBeansProjects/jfinancials-mailer-lib project.juser-core=../juser-core project.license=agpl30 project.serviceLocator.class=de.chotime.landingpage.mailer.model.delivery.LandingMailer -reference.addressbook-core.jar=${project.addressbook-core}/dist/addressbook-core.jar -reference.addressbook-lib.jar=${project.addressbook-lib}/dist/addressbook-lib.jar -reference.addressbook-mailer.jar=${project.addressbook-mailer}/dist/addressbook-mailer.jar +reference.jfinancials-mailer-lib.jar=${project.jfinancials-mailer-lib}/dist/jfinancials-mailer-lib.jar resource.dir=setup run.test.classpath=\ ${javac.test.classpath}:\ @@ -119,24 +86,10 @@ run.test.classpath=\ # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): runmain.jvmargs= source.encoding=UTF-8 -source.reference.addressbook-mailer.jar=../addressbook-mailer/src/ -source.reference.jaddressbook-core.jar=../jaddressbook-core/src -source.reference.jaddressbook-lib.jar=../jaddressbook-lib/src -source.reference.jaddressbook-share-core.jar=../jaddressbook-share-core/src -source.reference.jaddressbook-share-lib.jar=../jaddressbook-share-lib/src -source.reference.jcontacts-core.jar=../jcontacts-core/src/ -source.reference.jcontacts-lib.jar=../jcontacts-lib/src/ +source.reference.jfinancials-mailer.jar=../jfinancials-mailer/src/ source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/ source.reference.jcoreee.jar=../jcoreee/src/ -source.reference.jcountry-core.jar=../jcountry-core/src/ -source.reference.jcountry-lib.jar=../jcountry-lib/src/ source.reference.jmailer-ee.jar=../jmailer-ee/src/ -source.reference.jphone-core.jar=../jphone-core/src/ -source.reference.jphone-lib.jar=../jphone-lib/src/ -source.reference.juser-activity-core.jar=../juser-activity-core/src/ -source.reference.juser-activity-lib.jar=../juser-activity-lib/src/ -source.reference.juser-core.jar=../juser-core/src/ -source.reference.juser-lib.jar=../juser-lib/src/ source.root=src src.dir=${source.root}/java test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml index 4dcbc09..e3684ff 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -3,29 +3,14 @@ org.netbeans.modules.j2ee.ejbjarproject - addressbook-ejb + jfinancials-mailer-ejb 1.6.5 file.reference.jcoreee.jar file.reference.jcore-logger-lib.jar - file.reference.jcountry-core.jar - file.reference.jcountry-lib.jar - file.reference.jphone-core.jar - file.reference.jphone-lib.jar - file.reference.jcontacts-core.jar - file.reference.jcontacts-lib.jar - file.reference.juser-core.jar - file.reference.juser-lib.jar - file.reference.juser-activity-core.jar - file.reference.juser-activity-lib.jar file.reference.jmailer-ee.jar - file.reference.jaddressbook-core.jar - file.reference.jaddressbook-lib.jar - file.reference.jaddressbook-share-core.jar - file.reference.jaddressbook-share-lib.jar - reference.addressbook-core.jar - reference.addressbook-lib.jar - reference.addressbook-mailer.jar file.reference.cdi-api.jar + libs.velocity.classpath + reference.jfinancials-mailer-lib.jar @@ -38,23 +23,7 @@ - addressbook-core - jar - - jar - clean - jar - - - addressbook-lib - jar - - jar - clean - jar - - - addressbook-mailer + jfinancials-mailer-lib jar jar diff --git a/src/conf/persistence.xml b/src/conf/persistence.xml deleted file mode 100644 index b5a4906..0000000 --- a/src/conf/persistence.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - jdbc/addressbook - org.mxchange.jaddressbook.model.addressbook.UserAddressbook - org.mxchange.jaddressbook.model.addressbook.entry.UserAddressbookEntry - org.mxchange.jaddressbookshare.model.addressbook.shared.AddressbookShare - org.mxchange.jcontacts.contact.UserContact - org.mxchange.jcountry.data.CountryData - org.mxchange.jphone.phonenumbers.fax.FaxNumber - org.mxchange.jphone.phonenumbers.landline.LandLineNumber - org.mxchange.jphone.phonenumbers.mobile.MobileNumber - org.mxchange.jphone.phonenumbers.mobileprovider.CellphoneProvider - org.mxchange.jusercore.model.email_address.EmailAddressChange - org.mxchange.jusercore.model.user.LoginUser - org.mxchange.jusercore.model.user.activity.UserActivityLog - org.mxchange.jusercore.model.user.password_history.UserPasswordHistory - false - - - - - diff --git a/src/java/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java b/src/java/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java deleted file mode 100644 index b74a841..0000000 --- a/src/java/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java +++ /dev/null @@ -1,734 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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 . - */ -package org.mxchange.addressbook.database; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.Objects; -import java.util.Properties; -import javax.ejb.EJBException; -import javax.jms.JMSException; -import javax.jms.ObjectMessage; -import javax.mail.Address; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.ContactUtils; -import org.mxchange.jcoreee.database.BaseDatabaseBean; -import org.mxchange.jmailee.model.delivery.wrapper.EmailDeliveryWrapper; -import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.fax.FaxNumbers; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers; -import org.mxchange.jphone.utils.PhoneUtils; -import org.mxchange.jusercore.model.user.LoginUser; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.UserUtils; - -/** - * A helper class for beans that access the database. - *

- * @author Roland Häder - */ -public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { - - /** - * Serial number - */ - private static final long serialVersionUID = 12_895_410_275_811_963L; - - /** - * Protected constructor - */ - protected BaseAddressbookDatabaseBean () { - // Call super constructor - super(); - } - - /** - * Constructor with queue factory JNDI and queue JNDI names - *

- * @param factoryJndi JNDI name for queue factory - * @param queueJndi JNDI name for email queue - */ - protected BaseAddressbookDatabaseBean (final String factoryJndi, final String queueJndi) { - // Call super constructor - super(factoryJndi, queueJndi); - } - - /** - * Updates all contact's phone entry's created timestamps - *

- * @param contact Contact instance to update - */ - protected void setAllContactPhoneEntriesCreated (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } - - // Get all phone instances - DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber(); - DialableFaxNumber faxNumber = contact.getContactFaxNumber(); - DialableMobileNumber mobileNumber = contact.getContactMobileNumber(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: landLineNumber={1},faxNumber={2},mobileNumber={3}", this.getClass().getSimpleName(), landLineNumber, faxNumber, mobileNumber)); //NOI18N - - // Is a phone number instance set? - if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() == null)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - landLineNumber.setPhoneEntryCreated(new GregorianCalendar()); - } - - // Is a fax number instance set? - if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() == null)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - faxNumber.setPhoneEntryCreated(new GregorianCalendar()); - } - - // Is a mobile number instance set? - if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - mobileNumber.setPhoneEntryCreated(new GregorianCalendar()); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - /** - * Returns a managed instance from given mobile number - *

- * @param mobileNumber Mobile instance - * @param fetchedNumber Found mobile number in database - *

- * @return Managed instance - */ - protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N - - // Should be valid - if (null == mobileNumber) { - // Throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (null == fetchedNumber) { - // Throw NPE again - throw new NullPointerException("fetchedNumber is null"); //NOI18N - } else if (fetchedNumber.getPhoneId() == null) { - // ..and again - throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N - - // Default is null - DialableMobileNumber managedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) { - // Merge this entry - managedNumber = this.getEntityManager().merge(fetchedNumber); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - /** - * Returns a managed instance from given land-line number - *

- * @param landLineNumber Land-line instance - * @param fetchedNumber Found land-line number in database - *

- * @return Managed instance - */ - protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: landLineNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), landLineNumber, fetchedNumber)); //NOI18N - - // Should be valid - if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (null == fetchedNumber) { - // Throw NPE again - throw new NullPointerException("fetchedNumber is null"); //NOI18N - } else if (fetchedNumber.getPhoneId() == null) { - // ..and again - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N - - // Default is null - DialableLandLineNumber managedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) { - // Merge this entry - managedNumber = this.getEntityManager().merge(fetchedNumber); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - /** - * Returns a managed instance from given fax number - *

- * @param faxNumber Fax instance - * @param fetchedNumber Found fax number in database - *

- * @return Managed instance - */ - protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: faxNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), faxNumber, fetchedNumber)); //NOI18N - - // Should be valid - if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (null == fetchedNumber) { - // Throw NPE again - throw new NullPointerException("fetchedNumber is null"); //NOI18N - } else if (fetchedNumber.getPhoneId() == null) { - // ..and again - throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N - - // Default is null - DialableFaxNumber managedNumber = null; - - // Is there a difference? - if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) { - // Merge this entry - managedNumber = this.getEntityManager().merge(fetchedNumber); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - /** - * Get back a managed instance from given user - *

- * @param user Unmanaged/detached user instance - *

- * @return Managed user instance - */ - protected User getManagedUser (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Id is set - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Id is set - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N - } else if (user.getUserContact() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactId() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactId is null"); //NOI18N - } else if (user.getUserContact().getContactId() < 1) { - // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N# - } - - // Try to find it (should be there) - User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId()); - - // Should be there - assert (managedUser instanceof User) : "managedUser is null"; //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N - - // Return it - return managedUser; - } - - /** - * Merges given (detached) contact's data - *

- * @param detachedContact Contact instance to merge - *

- * @return Detached contact instance - */ - protected Contact mergeContactData (final Contact detachedContact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N - - // The contact instance must be valid - if (null == detachedContact) { - // Throw NPE again - throw new NullPointerException("detachedContact is null"); //NOI18N - } else if (detachedContact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N - } else if (detachedContact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N - } - - // Get contact from it and find it - Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId()); - - // Should be found - assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: managedContact.contactId={1}", this.getClass().getSimpleName(), managedContact.getContactId())); //NOI18N - - // Is a fax number set? - if (detachedContact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Make fax numbers managed - managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber())); - } - - // Is a land-line number set? - if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Make land-line numbers managed - managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber())); - } - - // Is a mobile number set? - if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Make mobile numbers managed - managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber())); - } - - // Set updated timestamp - managedContact.setContactUpdated(new GregorianCalendar()); - - // Copy all - ContactUtils.copyAll(detachedContact, managedContact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return detached contact - return managedContact; - } - - /** - * Merges given (detached) contact's cellphone, land-line and fax numbers - *

- * @param detachedContact Detached contact instance - */ - protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactsMobileLandLineFaxNumbers: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N - - // The contact instance must be valid - if (null == detachedContact) { - // Throw NPE again - throw new NullPointerException("detachedContact is null"); //NOI18N - } else if (detachedContact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N - } else if (detachedContact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N - } - - // Get all instances - DialableMobileNumber cellphone = detachedContact.getContactMobileNumber(); - DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber(); - DialableFaxNumber fax = detachedContact.getContactFaxNumber(); - - // Is there a cellphone instance set? - if (cellphone instanceof DialableMobileNumber) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: cellphone.phoneId={0} is being updated ...", cellphone.getPhoneId())); //NOI18N - - // Then find it, too - DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId()); - - // Should be there - assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N - - // Then merge it, too - DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile); - - // Should be there - assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N - - // Copy all - MobileNumbers.copyAll(detachedContact.getContactMobileNumber(), managedMobile); - - // Set it back - detachedContact.setContactMobileNumber(managedMobile); - } - - // 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())); //NOI18N - - // 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()); //NOI18N - - // Then merge it, too - DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax); - - // Should be there - assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N - - // Copy all - FaxNumbers.copyAll(detachedContact.getContactFaxNumber(), managedFax); - - // Set it back - detachedContact.setContactFaxNumber(managedFax); - } - - // 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())); //NOI18N - - // 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()); //NOI18N - - // Then merge it, too - DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine); - - // Should be there - assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N - - // Copy all - LandLineNumbers.copyAll(detachedContact.getContactLandLineNumber(), managedLandLine); - - // Set it back - detachedContact.setContactLandLineNumber(managedLandLine); - } - - // Trace message - this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //NOI18N - } - - /** - * Sends an email with given subject line, template name to given recipient - * and user data - *

- * @param subjectLine Subject line - * @param templateName Template name - * @param user User instance - * @param baseUrl Base URL - * @param randomPassword A randomly-generated password or NULL if user had - * to enter it. - */ - protected void sendEmail (final String subjectLine, final String templateName, final User user, final String baseUrl, final String randomPassword) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},user={2},baseUrl={3} - CALLED!", subjectLine, templateName, user, baseUrl)); //NOI18N - - // All should be set - if (null == subjectLine) { - // Throw NPE - throw new NullPointerException("subjectLine is null"); //NOI18N - } else if (subjectLine.isEmpty()) { - // No subject line - throw new IllegalArgumentException("subjectLine is empty"); //NOI18N - } else if (null == templateName) { - // Throw NPE - throw new NullPointerException("templateName is null"); //NOI18N - } else if (templateName.isEmpty()) { - // No template name - throw new IllegalArgumentException("templateName is empty"); //NOI18N - } else if (null == user) { - // Throw NPE - 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 number - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid.", user.getUserId())); //NOI18N - } else if (user.getUserName() == null) { - // Throw NPE again - throw new NullPointerException("user.userName is null"); //NOI18N - } else if (user.getUserName().isEmpty()) { - // Empty string - throw new IllegalArgumentException("user.userName is empty"); //NOI18N - } else if (user.getUserAccountStatus() == null) { - // Throw NPE - throw new NullPointerException("user.userAccountStatus is null"); //NOI18N - } else if (user.getUserContact() == null) { - // Throw it again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactId() == null) { - // .. and again - throw new NullPointerException("user.userContact.contactId is null"); //NOI18N - } else if (user.getUserContact().getContactId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N - } else if (user.getUserContact().getContactPersonalTitle() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactPersonalTitle is null"); //NOI18N - } else if (user.getUserLocale() == null) { - // Throw NPE again - throw new NullPointerException("user.userLocale is null"); //NOI18N - } else if (this.getSession() == null) { - // Throw NPE - throw new NullPointerException("this.session is not set. Have you forgotten to call super(String, String) and called only super() ?"); //NOI18N - } - - // Set all values - Properties variables = UserUtils.getAllUserFields(user); - - // Set base URL and random password - variables.put("baseUrl", baseUrl); //NOI18N - variables.put("randomPassword", ""); //NOI18N - - // Is the random password set? - if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) { - variables.put("randomPassword", randomPassword); //NOI18N - } - - // Init addresss - Address recipientAddress; - - try { - // Create email address and set - recipientAddress = new InternetAddress(user.getUserContact().getContactEmailAddress()); - } catch (final AddressException ex) { - // Throw again - throw new EJBException(ex); - } - - // Prepare mail wrapper - // @TODO Language from message bundle - WrapableEmailDelivery emailWrapper = new EmailDeliveryWrapper(recipientAddress, subjectLine, templateName, variables, user.getUserLocale()); - - try { - // Send out email change - ObjectMessage message = this.getSession().createObjectMessage(); - message.setObject(emailWrapper); - - // Send message - this.sendMessage(message); - } catch (final JMSException ex) { - // Throw again - throw new EJBException(ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace("sendEmail: EXIT!"); //NOI18N - } - - /** - * Updates all contact's phone instances from other contact, both contacts - * should be the same. - *

- * @param contact Contact to set instances - * @param other Other contact to get instances from - */ - protected void setAllContactPhoneEntries (final Contact contact, final Contact other) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: contact={1},other={2} - CALLED!", this.getClass().getSimpleName(), contact, other)); //NOI18N - - // Both must be the same and not null - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (null == other) { - // Throw NPE - throw new NullPointerException("other is null"); //NOI18N - } else if (!Objects.equals(contact, other)) { - // Not same instances - throw new IllegalArgumentException(MessageFormat.format("contact={0} and other={1} are not equal!", contact, other)); //NOI18N - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N - - // Is other cellphone not set? - if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N - - // Is the fax number set? - if (other.getContactMobileNumber() instanceof DialableMobileNumber) { - // Copy cellphone number - contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber())); - } else { - // Null it - contact.setContactMobileNumber(null); - } - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N - - // Is other cellphone not set? - if ((other.getContactLandLineNumber() == null) || (PhoneUtils.isSameLandLineNumber(contact.getContactLandLineNumber(), other.getContactLandLineNumber()))) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying land-line entry ...", this.getClass().getSimpleName())); //NOI18N - - // Is the land-line number set? - if (other.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Copy land-line number - contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber())); - } else { - // Null it - contact.setContactLandLineNumber(null); - } - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactFaxNumber={1}", this.getClass().getSimpleName(), other.getContactFaxNumber())); //NOI18N - - // Is other cellphone not set? - if ((other.getContactFaxNumber() == null) || (PhoneUtils.isSameFaxNumber(contact.getContactFaxNumber(), other.getContactFaxNumber()))) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying fax entry ...", this.getClass().getSimpleName())); //NOI18N - - // Is the fax number set? - if (other.getContactFaxNumber() instanceof DialableFaxNumber) { - // Copy fax number - contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber())); - } else { - // Null it - contact.setContactFaxNumber(null); - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - /** - * Updates all contact's phone entry's updated timestamps - *

- * @param contact Contact instance to update - * @param isMobileUnlinked Whether a mobile entry has been unlinked in - * contact instance - * @param isLandlineUnlinked Whether a land-line entry has been unlinked in - * contact instance - * @param isFaxUnlinked Whether a fax entry has been unlinked in - * contact instance - */ - protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } - - // Get all phone instances - DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber(); - DialableFaxNumber faxNumber = contact.getContactFaxNumber(); - DialableMobileNumber mobileNumber = contact.getContactMobileNumber(); - - // Flags and instances must be constistent - if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) { - // Bad state - throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but mobileNumber is set."); //NOI18N - } else if (isLandlineUnlinked && landLineNumber instanceof DialableLandLineNumber) { - // Bad state - throw new IllegalStateException("isLandlineUnlinked is TRUE, but landLineNumber is set."); //NOI18N - } else if (isFaxUnlinked && faxNumber instanceof DialableFaxNumber) { - // Bad state - throw new IllegalStateException("isFaxUnlinked is TRUE, but faxNumber is set."); //NOI18N - } - - // Is a phone number instance set? - if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - landLineNumber.setPhoneEntryUpdated(new GregorianCalendar()); - } - - // Is a fax number instance set? - if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneId() instanceof Long) && (faxNumber.getPhoneId() > 0)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - faxNumber.setPhoneEntryUpdated(new GregorianCalendar()); - } - - // Is a mobile number instance set? - if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N - - // Set updated timestamp - mobileNumber.setPhoneEntryUpdated(new GregorianCalendar()); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - -} diff --git a/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java b/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java deleted file mode 100644 index 044b302..0000000 --- a/src/java/org/mxchange/addressbook/mailer/model/delivery/AddressbookEmailDeliveryMessageBean.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.addressbook.mailer.model.delivery; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Properties; -import java.util.ResourceBundle; -import javax.annotation.PostConstruct; -import javax.ejb.ActivationConfigProperty; -import javax.ejb.MessageDriven; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.ObjectMessage; -import javax.mail.MessagingException; -import javax.naming.NamingException; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; - -/** - * A message-driven bean for sending out emails - *

- * @author Roland Häder - */ -@MessageDriven ( - name = "addressbookEmailDelivery", - description = "A message bean for email delivery", - activationConfig = { - @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/addressbook-email-queue"), - @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") - }) -public class AddressbookEmailDeliveryMessageBean extends BaseAddressbookDatabaseBean implements MessageListener { - - /** - * Serial number - */ - private static final long serialVersionUID = 75_638_176_619_024L; - - /** - * Configuration file - */ - private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N - - /** - * Mailer instance - */ - private final DeliverableAddressbookEmail mailer; - - /** - * Default constructor - *

- * @throws javax.naming.NamingException If a JNDI name could not be found - */ - public AddressbookEmailDeliveryMessageBean () throws NamingException { - // Call super constructor - super(); - - // Init mailer instance - this.mailer = new AddressbookMailer(); - } - - /** - * Post-construction - */ - @PostConstruct - public void init () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Try to load bundle - ResourceBundle bundle = ResourceBundle.getBundle(this.configFile); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: bundle={1}", this.getClass().getSimpleName(), bundle)); //NOI18N - - // The bunble should be valid - if (null == bundle) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N - } - - // Init Properties - Properties properties = new Properties(); - - // Is the bundle not empty? - if (!bundle.keySet().isEmpty()) { - // Loop through all - for (final String key : bundle.keySet()) { - // Log debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: key={1}", this.getClass().getSimpleName(), key)); //NOI18N - - // Get string from bundle and set it in properties - properties.put(key, bundle.getString(key)); - } - } - - // Handle it over to the mailer - this.mailer.init(properties); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - @Override - public void onMessage (final Message message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N - - // The parameter should be valid - if (null == message) { - // Throw NPE - throw new NullPointerException("message is null"); //NOI18N - } else if (!(message instanceof ObjectMessage)) { - // Not implementing right interface - throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N - } - - // Securely cast it - ObjectMessage objectMessage = (ObjectMessage) message; - - // Init variable - Serializable serializable; - - try { - // Get object from message - serializable = objectMessage.getObject(); - } catch (final JMSException ex) { - // Log it and don't continue any further - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N - - // Okay, is it the right interface? - if (null == serializable) { - // Throw NPE - throw new NullPointerException("serializable is null"); //NOI18N - } else if (!(serializable instanceof WrapableEmailDelivery)) { - // Not correct object send - throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N - } - - // Securely cast it - WrapableEmailDelivery wrapper = (WrapableEmailDelivery) serializable; - - // Is all required set? - if (wrapper.getLocale() == null) { - // Throw NPE - throw new NullPointerException("wrapper.locale is null"); //NOI18N - } else if (wrapper.getRecipientAddress()== null) { - // Throw again ... - throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N - } else if (wrapper.getSubjectLine() == null) { - // ... and again - throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N - } else if (wrapper.getSubjectLine().isEmpty()) { - // Is empty - throw new IllegalArgumentException("wrapper.subjectLine is empty"); //NOI18N - } else if (wrapper.getTemplateName() == null) { - // Throw NPE again - throw new NullPointerException("wrapper.templateName is null"); //NOI18N - } else if (wrapper.getTemplateName().isEmpty()) { - // Is empty - throw new IllegalArgumentException("wrapper.templateName is empty"); //NOI18N - } - - try { - // Send email out - this.mailer.sendDeliverableMail(wrapper); - } catch (final MessagingException ex) { - // Opps, something went wrong - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage - EXIT!", this.getClass().getSimpleName())); //NOI18N - } - -} diff --git a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java deleted file mode 100644 index 95e5045..0000000 --- a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.addressbook.model.addressbook; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.List; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -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.jusercore.model.user.User; - -/** - * A stateless bean handling address books - *

- * @author Roland Häder - */ -@Stateless (name = "addressbook", description = "A stateless bean for handling Addressbook addressbooks") -public class AddressbookSessionBean extends BaseAddressbookDatabaseBean implements AddressbookSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 129_857_871_287_691L; - - @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"); - } 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); - } - - // Add timestamp of creation - addressbook.setAddressbookCreated(new GregorianCalendar()); - - // 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/addressbook/model/addressbook/share/SharedAddressbooksSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/share/SharedAddressbooksSessionBean.java deleted file mode 100644 index 9a90c99..0000000 --- a/src/java/org/mxchange/addressbook/model/addressbook/share/SharedAddressbooksSessionBean.java +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.addressbook.model.addressbook.share; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.addressbook.model.shared.AddressbookShareSessionBeanRemote; -import org.mxchange.jaddressbook.model.addressbook.Addressbook; -import org.mxchange.jaddressbookshare.exceptions.UserAlreadySharingAddressbookException; -import org.mxchange.jaddressbookshare.model.addressbook.shared.AddressbookShare; -import org.mxchange.jaddressbookshare.model.addressbook.shared.ShareableAddressbook; -import org.mxchange.jusercore.model.user.User; - -/** - * A stateless bean for handling address book sharing - *

- * @author Roland Häder - */ -@Stateless (name = "share", description = "A stateless bean for handling shared addressbooks") -public class SharedAddressbooksSessionBean extends BaseAddressbookDatabaseBean implements AddressbookShareSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 136_984_697_285_694_710L; - - @Override - @SuppressWarnings ("unchecked") - public List allSharedAddressbooks (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("allSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N - - // Is user null? - if (null == user) { - // Throw NPE - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Null userId is not allowed - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Not allowed value - throw new IllegalArgumentException(MessageFormat.format("user.UserId={0} is an invalid value", user.getUserId())); //NOI18N - } - - // Get named query - Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N - - // Set parameter - query.setParameter("user", user); //NOI18N - - // Return full list - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("allSharedAddressbooks: list.size()={0} - EXIT!", list.size())); - - // Return list - return list; - } - - @Override - @SuppressWarnings ("unchecked") - public List allUsersNotSharing (final User user, final Addressbook addressbook) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: user={0},addressbook={1} - CALLED!", user, addressbook)); //NOI18N - - // Test parameter - if (null == user) { - // Throw NPE - 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) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N - } else if (null == addressbook) { - // Again NPE - throw new NullPointerException("addressbook is null"); //NOI18N - } else if (addressbook.getAddressbookId() == null) { - // Again NPE - throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N - } else if (addressbook.getAddressbookId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("addressbook.getAddressbookId={0} is invalid", addressbook.getAddressbookId())); //NOI18N - } - - // Get named query for a user list without given user - Query allUsersExceptQuery = this.getEntityManager().createNamedQuery("SearchAllUsersExcept", List.class); //NOI18N - - // Set parameter - allUsersExceptQuery.setParameter("user", user); //NOI18N - - // Get full list - List allUsersExcept = allUsersExceptQuery.getResultList(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allUsersExcept.size()={0}", allUsersExcept.size())); //NOI18N - - // Now get all shares this user has created - Query allSharesQuery = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N - - // Set parameter - allSharesQuery.setParameter("user", user); //NOI18N - - // Get full list again - List allShares = allSharesQuery.getResultList(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allShares.size()={0}", allShares.size())); //NOI18N - - // List for users aharing with given - List sharingUsers = new ArrayList<>(allShares.size()); - - // Check all entries - for (final ShareableAddressbook share : allShares) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: share.shareUserSharee={0}", share.getShareUserSharee())); //NOI18N - - // Add it - sharingUsers.add(share.getShareUserSharee()); - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: sharingUsers.size()={0}", sharingUsers.size())); //NOI18N - - // Init final user list - List userList = new LinkedList<>(); - - // Walk through all users - for (final User foundUser : allUsersExcept) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0}", foundUser)); //NOI18N - - // Does the list contain it ? - if (!sharingUsers.contains(foundUser)) { - // Found one to add - this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0} - ADDING!", foundUser)); //NOI18N - - // Add it - userList.add(foundUser); - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: userList.size()={0} - EXIT!", userList.size())); //NOI18N - - // Return it - return userList; - } - - @Override - @SuppressWarnings ("unchecked") - public Integer countAllUserSharedAddressbooks (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N - - // user should be valid - if (null == user) { - // Throw NPE - 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) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N - } - - // Get named query - Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N - - // Set parameter - query.setParameter("user", user); //NOI18N - - // Default is zero - Integer count = 0; - - // Try it - try { - // Get whole list - List dummy = query.getResultList(); - - // Set size - count = dummy.size(); - } catch (final NoResultException ex) { - // Need to catch this, so log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("countAllUserSharedAddressbooks: getResultList() failed: {0}", ex)); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: count={0} - EXIT!", count)); //NOI18N - - // Return count - return count; - } - - @Override - public Boolean isUserSharingAddressbooks (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: user={0} - CALLED!", user)); //NOI18N - - // Is user null? - if (null == user) { - // Throw NPE - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Null userId is not allowed - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Not allowed value - throw new IllegalArgumentException(MessageFormat.format("user.UserId={0} is an invalid value", user.getUserId())); //NOI18N - } - - // Get results - List list = this.allSharedAddressbooks(user); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserSharingAddressbooks: list.size()={0}", list.size())); //NOI18N - - // Is it not empty? - Boolean isSharing = (!list.isEmpty()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: iSharing={0} - EXIT!", isSharing)); //NOI18N - - // Return it - return isSharing; - } - - @Override - public ShareableAddressbook startSharing (final User sharee, final Addressbook addressbook) throws UserAlreadySharingAddressbookException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("startSharing: sharee={0},addressbook={1} - CALLED!", sharee, addressbook)); //NOI18N - - // Check all conditions - if (null == sharee) { - // Throw NPE - throw new NullPointerException("sharee is null"); //NOI18N - } else if (sharee.getUserId() == null) { - // Throw NPE again - throw new NullPointerException("sharee.userId is null"); //NOI18N - } else if (sharee.getUserId() < 1) { - // Invalid id number - throw new IllegalStateException(MessageFormat.format("sharee.userId={0} is invalid", sharee.getUserId())); //NOI18N - } else if (null == addressbook) { - // Throw NPE again - 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 (Objects.equals(addressbook.getAddressbookUser(), sharee)) { - // Sharing with yourself! - throw new IllegalStateException("User tries to share with himself."); //NOI18N - } - - // Is the entry already there? - if (this.isUserAlreadySharingAddressbook(addressbook, sharee)) { - // Abort here - throw new UserAlreadySharingAddressbookException(addressbook, sharee); - } - - // All fine so far, then create the instance - ShareableAddressbook share = new AddressbookShare(addressbook, sharee); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("startSharing: share={0}", share)); //NOI18N - - // Persist it - this.getEntityManager().persist(share); - - // Flush to get id number - this.getEntityManager().flush(); - - // Return updated instance - return share; - } - - /** - * Checks whether the owner of the given address book is already sharing it - * with the sharee. - *

- * @param addressbook Address book to be shared with - * @param sharee User sharee instance - *

- * @return Wether the address book is already shared with the sharee - */ - private boolean isUserAlreadySharingAddressbook (final Addressbook addressbook, final User sharee) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserAlreadySharingAddressbook: addressbook={0},sharee={1} - CALLED!", addressbook, sharee)); //NOI18N - - // Get named query - Query query = this.getEntityManager().createNamedQuery("SearchShareeAddressbookShare", AddressbookShare.class); //NOI18N - - // Set parameter - query.setParameter("addressbook", addressbook); //NOI18N - query.setParameter("sharee", sharee); //NOI18N - - // Default is not found - boolean isFound = false; - - // Try it - try { - // Get single instance - ShareableAddressbook share = (ShareableAddressbook) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserAlreadySharingAddressbook: share={0} - FOUND!", share)); //NOI18N - - // Set found - isFound = true; - } catch (final NoResultException ex) { - // Not found, log exception - this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserAlreadySharingAddressbook: Notfound. Exception: {0}", ex)); //NOI18N - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserAlreadySharingAddressbook: isFound={0} - EXIT!", isFound)); //NOI18N - - // Return it - return isFound; - } -} diff --git a/src/java/org/mxchange/jcontacts/contact/AddressbookAdminContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/AddressbookAdminContactSessionBean.java deleted file mode 100644 index baff654..0000000 --- a/src/java/org/mxchange/jcontacts/contact/AddressbookAdminContactSessionBean.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jcontacts.contact; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; - -/** - * An administrative contact EJB - *

- * @author Roland Häder - */ -@Stateless (name = "adminContact", description = "An administrative contact EJB") -public class AddressbookAdminContactSessionBean extends BaseAddressbookDatabaseBean implements AdminContactSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Default constructor - */ - public AddressbookAdminContactSessionBean () { - // Call super constructor - super(); - } - - @Override - public Contact addContact (final Contact contact) throws ContactAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Is the instance set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} - is not null", contact.getContactId())); //NOI18N - } - - // Set created timestamp - contact.setContactCreated(new GregorianCalendar()); - - // Set all created timestamps, if instance is there - this.setAllContactPhoneEntriesCreated(contact); - - // Persist it - this.getEntityManager().persist(contact); - - // Flush it to get contactId set - this.getEntityManager().flush(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addContact: contact.contactId={1} after persisting - EXIT!", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N - - // Return it - return contact; - } - - @Override - public void deleteContactData (final Contact contact) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Is the instance set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Should not be null - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N - } - - // Merge it to get a managed entity back - Contact managedContact = this.getEntityManager().getReference(contact.getClass(), contact.getContactId()); - - // Remove it from database - this.getEntityManager().remove(managedContact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteContactData: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - -} diff --git a/src/java/org/mxchange/jcontacts/contact/AddressbookContactSessionBean.java b/src/java/org/mxchange/jcontacts/contact/AddressbookContactSessionBean.java deleted file mode 100644 index 2610872..0000000 --- a/src/java/org/mxchange/jcontacts/contact/AddressbookContactSessionBean.java +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jcontacts.contact; - -import java.text.MessageFormat; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.exceptions.ContactNotFoundException; - -/** - * A contact EJB - *

- * @author Roland Häder - */ -@Stateless (name = "contact", description = "A bean handling contact data") -public class AddressbookContactSessionBean extends BaseAddressbookDatabaseBean implements ContactSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Default constructor - */ - public AddressbookContactSessionBean () { - // Call super constructor - super(); - } - - @Override - public 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 - Query query = this.getEntityManager().createNamedQuery("SearchContactByEmailAddress", UserContact.class); //NOI18N - - // Set parameter - query.setParameter("emailAddress", emailAddress); //NOI18N - - // Init contact instance - 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; - } - - @Override - public Contact findContactById (final Long contactId) throws ContactNotFoundException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contactId={1} - CALLED!", this.getClass().getSimpleName(), contactId)); //NOI18N - - // The parameter must be valid - if (null == contactId) { - // Throw NPE - throw new NullPointerException("contactId is null"); //NOI18N - } else if (contactId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("contactId={0} is not valid", contactId)); //NOI18N - } - - // Get query instance - Query query = this.getEntityManager().createNamedQuery("SearchContactById", UserContact.class); //NOI18N - - // Set parameter - query.setParameter("contactId", contactId); //NOI18N - - // Init contact instance - 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}.findContactById: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N - } catch (final NoResultException ex) { - // No result found - throw new ContactNotFoundException(contactId, ex); - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactById: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Return found instance - return contact; - } - - @Override - @SuppressWarnings ("unchecked") - public List getAllContacts () { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts - CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Create query instance - Query query = this.getEntityManager().createNamedQuery("AllContacts"); //NOI18N - - // Get list - List contacts = query.getResultList(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getAllContacts: contacts.size()={1} - EXIT!", this.getClass().getSimpleName(), contacts.size())); //NOI18N - - // Return it - return contacts; - } - - @Override - @SuppressWarnings ("unchecked") - public List getEmailAddressList () { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList - CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Create query instance - Query query = this.getEntityManager().createNamedQuery("AllContactEmailAddresses"); //NOI18N - - // Get list - 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 - 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 - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // Parameter should be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() > 0) { - try { - // Id set, ask other method - return this.findContactById(contact.getContactId()); - } catch (final ContactNotFoundException ex) { - // Not found, should not happen - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is set, but not found.", contact.getContactId()), ex); //NOI18N - } - } - - // Default is not found - Contact foundContact = null; - - // Get whole list - List contacts = this.getAllContacts(); - - // Is the list empty? - if (contacts.isEmpty()) { - // Then abort here - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: No contacts registered, returning NULL ...", this.getClass().getSimpleName())); //NOI18N - return null; - } - - // Get iterator - Iterator iterator = contacts.iterator(); - - // Loop through all - while (iterator.hasNext()) { - // Get contact - Contact next = iterator.next(); - - // Is same contact? - if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isContactFound: Found same contact: contactId={1}", this.getClass().getSimpleName(), next.getContactId())); //NOI18N - - // Found it - foundContact = next; - break; - } - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isContactFound: foundContact={1} - EXIT!", this.getClass().getSimpleName(), foundContact)); //NOI18N - - // Return found contact - return foundContact; - } - - @Override - public Contact updateContactData (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1},isMobileUnlinked={2},isLandlineUnlinked={3},isFaxUnlinked={4} - CALLED!", this.getClass().getSimpleName(), contact, isMobileUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } - - // Merge cellphone, land-line and fix - Contact managedContact = this.mergeContactData(contact); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact updateContactData (final Contact contact) { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N - - // The contact instance must be valid - if (null == contact) { - // Throw NPE again - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } - - // Is cell phone/land-line/fax number unlinked? - boolean isMobileUnlinked = (contact.getContactMobileNumber() == null); - boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null); - boolean isFaxUnlinked = (contact.getContactFaxNumber() == null); - - // Call other Method - Contact managedContact = this.updateContactData(contact, isMobileUnlinked, isLandLineUnlinked, isFaxUnlinked); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - -} diff --git a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java b/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java deleted file mode 100644 index 8ef28c2..0000000 --- a/src/java/org/mxchange/jcontacts/phone/AddressbookAdminContactPhoneSessionBean.java +++ /dev/null @@ -1,544 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jcontacts.phone; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.Objects; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; -import org.mxchange.jcontacts.contact.UserContact; -import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException; -import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; - -/** - * A session EJB for administrative contact's phone number purposes - *

- * @author Roland Häder - */ -@Stateless (name = "adminContactPhone", description = "An administrative bean handling contact's phone data") -public class AddressbookAdminContactPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminContactsPhoneSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 189_217_561_460_237_108L; - - /** - * Contact EJB - */ - @EJB - private ContactSessionBeanRemote contactBean; - - /** - * Default constructor - */ - public AddressbookAdminContactPhoneSessionBean () { - // Call super constructor - super(); - } - - @Override - public Contact linkExistingFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(faxNumber); - } else if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N - } else if (faxNumber.getPhoneId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N - } - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Merge phone number - DialableFaxNumber managedNumber = this.getEntityManager().merge(faxNumber); - - // Set fax number in contact - managedContact.setContactFaxNumber(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingFaxNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact linkExistingLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(landLineNumber); - } else if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } else if (landLineNumber.getPhoneId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Merge phone number - DialableLandLineNumber managedNumber = this.getEntityManager().merge(landLineNumber); - - // Set fax number in contact - managedContact.setContactLandLineNumber(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingLandLineNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact linkExistingMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(mobileNumber); - } else if (null == mobileNumber) { - // Throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() == null) { - // Throw it again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getPhoneId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Throw NPE again - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Merge phone number - DialableMobileNumber managedNumber = this.getEntityManager().merge(mobileNumber); - - // Set fax number in contact - managedContact.setContactMobileNumber(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkExistingMobileNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact linkNewFaxNumberWithContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(faxNumber); - } else if (null == faxNumber) { - // Throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() instanceof Long) { - // Throw it again - throw new IllegalStateException(MessageFormat.format("faxNumber.phoneId={0} is not null", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid", faxNumber.getPhoneNumber())); //NOI18N - } - - // Set created instance - faxNumber.setPhoneEntryCreated(new GregorianCalendar()); - - // Persist it - this.getEntityManager().persist(faxNumber); - - // Flush it - this.getEntityManager().flush(); - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Set fax number in contact - managedContact.setContactFaxNumber(faxNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewFaxNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact linkNewLandLineNumberWithContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(landLineNumber); - } else if (null == landLineNumber) { - // Throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() instanceof Long) { - // Throw it again - throw new IllegalStateException(MessageFormat.format("landLineNumber.phoneId={0} is not null", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // ... and again - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw it again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Set created instance - landLineNumber.setPhoneEntryCreated(new GregorianCalendar()); - - // Persist it - this.getEntityManager().persist(landLineNumber); - - // Flush it - this.getEntityManager().flush(); - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Set land-line number in contact - managedContact.setContactLandLineNumber(landLineNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewLandLineNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact linkNewMobileNumberWithContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberAlreadyLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Not set cell phone instance - throw new PhoneNumberAlreadyLinkedException(mobileNumber); - } else if (null == mobileNumber) { - // Throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() instanceof Long) { - // Throw it again - throw new IllegalStateException(MessageFormat.format("mobileNumber.phoneId={0} is not null", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Throw NPE again - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } - - // Set created instance - mobileNumber.setPhoneEntryCreated(new GregorianCalendar()); - - // Persist it - this.getEntityManager().persist(mobileNumber); - - // Flush it - this.getEntityManager().flush(); - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Set land-line number in contact - managedContact.setContactMobileNumber(mobileNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkNewMobileNumberWithContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact unlinkFaxDataFromContact (final Contact contact, final DialableFaxNumber faxNumber) throws PhoneNumberNotLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: contact={1},faxNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, faxNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactFaxNumber() == null) { - // Not set cell phone instance - throw new PhoneNumberNotLinkedException(faxNumber); - } else if (contact.getContactFaxNumber().getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactFaxNumber.phoneId is null"); //NOI18N - } else if (contact.getContactFaxNumber().getPhoneId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} is invalid.", contact.getContactFaxNumber().getPhoneId())); //NOI18N - } else if (!Objects.equals(faxNumber.getPhoneId(), contact.getContactFaxNumber().getPhoneId())) { - // Not same object - throw new IllegalArgumentException(MessageFormat.format("contact.contactFaxNumber.phoneId={0} and faxNumber.phoneId={1} are not the same.", contact.getContactFaxNumber().getPhoneId(), faxNumber.getPhoneId())); //NOI18N - } - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Remove it from contact - managedContact.setContactFaxNumber(null); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkFaxDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact unlinkLandLineDataFromContact (final Contact contact, final DialableLandLineNumber landLineNumber) throws PhoneNumberNotLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: contact={1},landLineNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, landLineNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactLandLineNumber() == null) { - // Not set cell phone instance - throw new PhoneNumberNotLinkedException(landLineNumber); - } else if (contact.getContactLandLineNumber().getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactLandLineNumber.phoneId is null"); //NOI18N - } else if (contact.getContactLandLineNumber().getPhoneId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} is invalid.", contact.getContactLandLineNumber().getPhoneId())); //NOI18N - } else if (!Objects.equals(landLineNumber.getPhoneId(), contact.getContactLandLineNumber().getPhoneId())) { - // Not same object - throw new IllegalArgumentException(MessageFormat.format("contact.contactLandLineNumber.phoneId={0} and landLineNumber.phoneId={1} are not the same.", contact.getContactLandLineNumber().getPhoneId(), landLineNumber.getPhoneId())); //NOI18N - } - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Remove it from contact - managedContact.setContactLandLineNumber(null); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkLandLineDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - - @Override - public Contact unlinkMobileDataFromContact (final Contact contact, final DialableMobileNumber mobileNumber) throws PhoneNumberNotLinkedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: contact={1},mobileNumber={2} - CALLED!", this.getClass().getSimpleName(), contact, mobileNumber)); //NOI18N - - // Is the contact set? - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // ... and throw again - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N - } else if (contact.getContactMobileNumber() == null) { - // Not set cell phone instance - throw new PhoneNumberNotLinkedException(mobileNumber); - } else if (contact.getContactMobileNumber().getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("contact.contactMobileNumber.phoneId is null"); //NOI18N - } else if (contact.getContactMobileNumber().getPhoneId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} is invalid.", contact.getContactMobileNumber().getPhoneId())); //NOI18N - } else if (!Objects.equals(mobileNumber.getPhoneId(), contact.getContactMobileNumber().getPhoneId())) { - // Not same object - throw new IllegalArgumentException(MessageFormat.format("contact.contactMobileNumber.phoneId={0} and mobileNumber.phoneId={1} are not the same.", contact.getContactMobileNumber().getPhoneId(), mobileNumber.getPhoneId())); //NOI18N - } - - // Find contact - Contact managedContact = this.getEntityManager().find(UserContact.class, contact.getContactId()); - - // Remove it from contact - managedContact.setContactMobileNumber(null); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.unlinkMobileDataFromContact: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N - - // Return it - return managedContact; - } - -} diff --git a/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java b/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java deleted file mode 100644 index 8d1f5a4..0000000 --- a/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jcountry.data; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.List; -import javax.ejb.Singleton; -import javax.ejb.Startup; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException; - -/** - * A singleton EJB for country informations - *

- * @author Roland Häder - */ -@Startup -@Singleton (name = "country", description = "A singleton session-scoped bean for country informations") -public class AddressbookCountrySingletonBean extends BaseAddressbookDatabaseBean implements CountrySingletonBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_846_983_298_691_207L; - - /** - * Default constructor - */ - public AddressbookCountrySingletonBean () { - // Call super constructor - super(); - } - - @Override - public Country addCountry (final Country country) throws CountryAlreadyAddedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N - - // Is it already there? - if (null == country) { - // Throw NPE - throw new NullPointerException("country is null"); //NOI18N - } else if (country.getCountryCode().isEmpty()) { - // Code is not set - throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N - } else if (country.getCountryI18nKey().isEmpty()) { - // I18n key is not set - throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N - } else if (country.getCountryId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N - } else if (this.isCountryAdded(country)) { - // Yes, then abort here - throw new CountryAlreadyAddedException(country); - } - - // Add timestamp - country.setCountryEntryCreated(new GregorianCalendar()); - - // It is not added, so persist it - this.getEntityManager().persist(country); - - // Flush it to get id number back, maybe it is directly needed? - this.getEntityManager().flush(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addCountry: country={1} - EXIT!", this.getClass().getSimpleName(), country)); //NOI18N - - // Return updated instance - return country; - } - - @Override - @SuppressWarnings ("unchecked") - public List allCountries () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Init query - Query query = this.getEntityManager().createNamedQuery("AllCountries", CountryData.class); //NOI18N - - // Get list - List countries = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCountries: countries.size()={1} - EXIT!", this.getClass().getSimpleName(), countries.size())); //NOI18N - - // Return it - return countries; - } - - /** - * Checks whether given country is already added by i18n key or country - * code, what comes first. - *

- * @param country Country instance to check - *

- * @return Whether the country was found - */ - private boolean isCountryAdded (final Country country) { - if (null == country) { - // Throw NPE - throw new NullPointerException("country is null"); //NOI18N - } else if (country.getCountryCode().isEmpty()) { - // Code is not set - throw new IllegalArgumentException("country.countryCode is empty"); //NOI18N - } else if (country.getCountryI18nKey().isEmpty()) { - // I18n key is not set - throw new IllegalArgumentException("country.countryI18nKey is empty"); //NOI18N - } else if (country.getCountryId() != null) { - // Should be null - throw new IllegalArgumentException(MessageFormat.format("country.countryId is not null ({0})", country.getCountryId())); //NOI18N - } - - // Default is not found - boolean isAdded = false; - - // Get query instance - Query query = this.getEntityManager().createNamedQuery("SearchCountryByCodeI18nKey", CountryData.class); //NOI18N - - // Assign all parameters - query.setParameter("code", country.getCountryCode()); //NOI18N - query.setParameter("key", country.getCountryI18nKey()); //NOI18N - - // Try to get a single result - try { - // Get single result - Country foundCountry = (Country) query.getSingleResult(); - - // Found it? - isAdded = (foundCountry instanceof Country); - } catch (final NoResultException ex) { - // Not found, don't log this - } - - // Return result - return isAdded; - } - -} diff --git a/src/java/org/mxchange/jfinancials/model/mailer/FinancialsEmailDeliveryMessageBean.java b/src/java/org/mxchange/jfinancials/model/mailer/FinancialsEmailDeliveryMessageBean.java new file mode 100644 index 0000000..3bc3c04 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/model/mailer/FinancialsEmailDeliveryMessageBean.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * 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.jfinancials.model.mailer; + +import java.io.Serializable; +import java.text.MessageFormat; +import javax.ejb.ActivationConfigProperty; +import javax.ejb.EJB; +import javax.ejb.MessageDriven; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.ObjectMessage; +import javax.mail.MessagingException; +import javax.naming.NamingException; +import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; + +/** + * A message-driven bean for sending out mails + *

+ * @author Roland Häder + */ +@MessageDriven ( + name = "jfinancialsEmailDelivery", + description = "A message bean for email delivery", + activationConfig = { + @ActivationConfigProperty (propertyName = "destinationLookup", propertyValue = "jms/jfinancials-email-queue"), + @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue") + }) +public class FinancialsEmailDeliveryMessageBean extends BaseDatabaseBean implements MessageListener { + + /** + * Serial number + */ + private static final long serialVersionUID = 75_638_176_619_024L; + + /** + * Mailer instance + */ + @EJB + private DeliverableFinancialsEmailLocal mailerBean; + + /** + * Default constructor + *

+ * @throws javax.naming.NamingException If a JNDI name could not be found + */ + public FinancialsEmailDeliveryMessageBean () throws NamingException { + // Call super constructor + super(); + } + + @Override + public void onMessage (final Message message) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N + + // The parameter should be valid + if (null == message) { + // Throw NPE + throw new NullPointerException("message is null"); //NOI18N + } else if (!(message instanceof ObjectMessage)) { + // Not implementing right interface + throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N + } + + // Securely cast it + ObjectMessage objectMessage = (ObjectMessage) message; + + // Init variable + Serializable serializable; + + try { + // Get object from message + serializable = objectMessage.getObject(); + } catch (final JMSException ex) { + // Log it and don't continue any further + this.getLoggerBeanLocal().logException(ex); + return; + } + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N + + // Okay, is it the right interface? + if (null == serializable) { + // Throw NPE + throw new NullPointerException("serializable is null"); //NOI18N + } else if (!(serializable instanceof WrapableEmailDelivery)) { + // Not correct object send + throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement WrapableEmailDelivery", serializable)); //NOI18N + } + + // Securely cast it + WrapableEmailDelivery wrapper = (WrapableEmailDelivery) serializable; + + // Is all required set? + if (wrapper.getLocale() == null) { + // Throw NPE + throw new NullPointerException("wrapper.locale is null"); //NOI18N + } else if (wrapper.getRecipientAddress() == null) { + // Throw again ... + throw new NullPointerException("wrapper.recipientAddress is null"); //NOI18N + } else if (wrapper.getSubjectLine() == null) { + // ... and again + throw new NullPointerException("wrapper.subjectLine is null"); //NOI18N + } else if (wrapper.getSubjectLine().isEmpty()) { + // Is empty + throw new IllegalArgumentException("wrapper.subjectLine is empty"); //NOI18N + } else if (wrapper.getTemplateName() == null) { + // Throw NPE again + throw new NullPointerException("wrapper.templateName is null"); //NOI18N + } else if (wrapper.getTemplateName().isEmpty()) { + // Is empty + throw new IllegalArgumentException("wrapper.templateName is empty"); //NOI18N + } + + try { + // Send email out + this.mailerBean.sendDeliverableMail(wrapper); + } catch (final MessagingException ex) { + // Opps, something went wrong + this.getLoggerBeanLocal().logException(ex); + return; + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage - EXIT!", this.getClass().getSimpleName())); //NOI18N + } + +} diff --git a/src/java/org/mxchange/jfinancials/model/mailer/FinancialsMailerSingletonBean.java b/src/java/org/mxchange/jfinancials/model/mailer/FinancialsMailerSingletonBean.java new file mode 100644 index 0000000..efdb2a0 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/model/mailer/FinancialsMailerSingletonBean.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * 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 . + */ +package org.mxchange.jfinancials.model.mailer; + +import java.text.MessageFormat; +import java.util.Map; +import java.util.Properties; +import java.util.ResourceBundle; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import javax.ejb.Singleton; +import javax.mail.MessagingException; +import javax.mail.Session; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.mxchange.jmailee.model.delivery.BaseMailerBean; +import org.mxchange.jmailee.model.delivery.wrapper.WrapableEmailDelivery; + +/** + * A singleton mailer EJB + *

+ * @author Roland Häder + */ +@Singleton +public class FinancialsMailerSingletonBean extends BaseMailerBean implements DeliverableFinancialsEmailLocal { + + /** + * Serial number + */ + private static final long serialVersionUID = 17_857_816_596_030_918L; + + /** + * Configuration file + */ + private final String configFile = "org.mxchange.jmailer.config"; //NOI18N//NOI18N + + /** + * Email session + */ + @Resource (name = "jfinancialsSmtpSession", description = "A Java Mail session") + private Session mailSession; + + /** + * Default constructor + *

+ */ + public FinancialsMailerSingletonBean () { + } + + /** + * Post-construction + */ + @PostConstruct + public void init () { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: CALLED!", this.getClass().getSimpleName())); //NOI18N + + // Try to load bundle + ResourceBundle bundle = ResourceBundle.getBundle(this.configFile); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: bundle={1}", this.getClass().getSimpleName(), bundle)); //NOI18N + + // The bunble should be valid + if (null == bundle) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("bundle is null, maybe file {0} does not exist?", this.configFile)); //NOI18N + } + + // Init Properties + Properties properties = new Properties(); + + // Is the bundle not empty? + if (!bundle.keySet().isEmpty()) { + // Loop through all + for (final String key : bundle.keySet()) { + // Log debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.init: key={1}", this.getClass().getSimpleName(), key)); //NOI18N + + // Get string from bundle and set it in properties + properties.put(key, bundle.getString(key)); + } + } + + // Handle it over to the mailer + this.setProperties(properties); + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.init: EXIT!", this.getClass().getSimpleName())); //NOI18N + } + + @Override + public void sendDeliverableMail (final WrapableEmailDelivery emailWrapper) throws MessagingException { + // Log trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendDeliverableMail: emailWrapper={0} - CALLED!", emailWrapper)); //NOI18N + + // The parameter must be valid + if (null == emailWrapper) { + // Throw NPE + throw new NullPointerException("emailWrapper is null"); //NOI18N + } else if (emailWrapper.getRecipientAddress() == null) { + // Throw NPE again + throw new NullPointerException("emailWrapper.recipientAddress is null"); //NOI18N + } else if (emailWrapper.getSubjectLine() == null) { + // ... and again + throw new NullPointerException("emailWrapper.subjectLine is null"); //NOI18N + } else if (emailWrapper.getSubjectLine().isEmpty()) { + // Is empty + throw new IllegalArgumentException("emailWrapper.subjectLine is empty"); //NOI18N + } else if (emailWrapper.getTemplateName() == null) { + // ... and again + throw new NullPointerException("emailWrapper.templateName is null"); //NOI18N + } else if (emailWrapper.getTemplateName().isEmpty()) { + // Is empty + throw new IllegalArgumentException("emailWrapper.templateName is empty"); //NOI18N + } else if (emailWrapper.getLocale() == null) { + // Throw NPE again + throw new NullPointerException("emailWrapper.locale is null"); //NOI18N + } else if (!emailWrapper.getTemplateVariables().containsKey("baseUrl")) { //NOI18N + // Not set + throw new IllegalArgumentException("emailWrapper.templateVariables.baseUrl is not set"); //NOI18N + } + + // All required data is set, load template + Template template = this.getTemplateEngine().getTemplate(String.format("templates/%s/%s.vm", emailWrapper.getLocale().getLanguage().toLowerCase(), emailWrapper.getTemplateName())); //NOI18N + + // Init context + VelocityContext context = new VelocityContext(); + + // Are some variables set? + if ((emailWrapper.getTemplateVariables() != null) && (!emailWrapper.getTemplateVariables().isEmpty())) { + // Add all variables + for (Map.Entry entry : emailWrapper.getTemplateVariables().entrySet()) { + // Get key/value + String key = (String) entry.getKey(); + String value = (String) entry.getValue(); + + // Both should not be empty + if (null == key) { + // Throw NPE + throw new NullPointerException("key is null"); //NOI18N + } else if (null == value) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("value for key={0} is null", key)); //NOI18N + } + + // Set it + context.put(key, value); + } + } + + // Send the email + this.deliverMailWithTemplate(template, context, emailWrapper, this.mailSession); + + // Trace message + this.getLoggerBeanLocal().logTrace("sendDeliverableMail: EXIT!"); //NOI18N + } + +} diff --git a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java deleted file mode 100644 index 923ad7f..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jphone.phonenumbers.mobileprovider; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException; - -/** - * An administrative singleton EJB for mobile provider informations - *

- * @author Roland Häder - */ -@Stateless (name = "adminMobileProvider", description = "A singleton session-scoped bean for mobile provider informations, admin-edition") -public class AddressbookAdminMobileProviderSessionBean extends BaseAddressbookDatabaseBean implements AdminMobileProviderSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_846_983_298_691_207L; - - /** - * Default constructor - */ - public AddressbookAdminMobileProviderSessionBean () { - // Call super constructor - super(); - } - - @Override - public MobileProvider addMobileProvider (final MobileProvider mobileProvider) throws MobileProviderAlreadyAddedException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider={1} - CALLED!", this.getClass().getSimpleName(), mobileProvider)); //NOI18N - - // Is the instance valid? - if (null == mobileProvider) { - // Throw NPE - throw new NullPointerException("mobileProvider is null"); //NOI18N - } else if (mobileProvider.getProviderDialPrefix() == null) { - // Throw NPE again - throw new NullPointerException("mobileProvider.providerDialPrefix is null"); //NOI18N - } else if (mobileProvider.getProviderDialPrefix() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerDialPrefix={0} is not valid.", mobileProvider.getProviderDialPrefix())); //NOI18N - } else if (mobileProvider.getProviderCountry() == null) { - // Throw again a NPE - throw new NullPointerException("mobileProvider.providerCountry is null"); //NOI18N - } else if (mobileProvider.getProviderMailPattern() == null) { - // ... and again ... - throw new NullPointerException("mobileProvider.providerMailPattern is null"); //NOI18N - } else if (mobileProvider.getProviderMailPattern().isEmpty()) { - // Empty pattern set (not allowed) - throw new IllegalArgumentException("mobileProvider.providerMailPattern is empty."); //NOI18N - } else if (!mobileProvider.getProviderMailPattern().contains("%s")) { //NOI18N - // No place-holder found - throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerMailPattern={0} does not contain '%s' which is need to be replaced with the full mobile number.", mobileProvider.getProviderMailPattern())); //NOI18N - } else if (mobileProvider.getProviderName() == null) { - // Throw NPE again - throw new NullPointerException("mobileProvider.providerName is null"); //NOI18N - } else if (mobileProvider.getProviderName().isEmpty()) { - // Empty name is not allowed - throw new IllegalArgumentException("mobileProvider.providerName is empty"); //NOI18N - } - - // Set creation timestamp - mobileProvider.setProviderEntryCreated(new GregorianCalendar()); - - // Persist it - this.getEntityManager().persist(mobileProvider); - - // ... and flush it to get id back - this.getEntityManager().flush(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addMobileProvider: mobileProvider.providerId={1} - EXIT!", this.getClass().getSimpleName(), mobileProvider.getProviderId())); //NOI18N - - // Return updated - return mobileProvider; - } - -} diff --git a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java b/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java deleted file mode 100644 index 3de7139..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jphone.phonenumbers.mobileprovider; - -import java.text.MessageFormat; -import java.util.List; -import javax.ejb.Singleton; -import javax.ejb.Startup; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; - -/** - * A singleton EJB for mobile provider informations - *

- * @author Roland Häder - */ -@Startup -@Singleton (name = "mobileprovider", description = "A singleton session-scoped bean for SMS provider informations") -public class AddressbookMobileProviderSingletonBean extends BaseAddressbookDatabaseBean implements MobileProviderSingletonBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 15_846_983_298_691_207L; - - /** - * Default constructor - */ - public AddressbookMobileProviderSingletonBean () { - // Call super constructor - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List allMobileProvider () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Init query - Query query = this.getEntityManager().createNamedQuery("AllMobileProvider", CellphoneProvider.class); //NOI18N - - // Get list from it - List mobileProviders = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileProvider: mobileProviders.size()={1} - EXIT!", this.getClass().getSimpleName(), mobileProviders.size())); //NOI18N - - // Return it - return mobileProviders; - } - -} diff --git a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java deleted file mode 100644 index 1d63242..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jphone.phonenumbers.phone; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.fax.FaxNumbers; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers; - -/** - * An EJB for administrative phone purposes - *

- * @author Roland Häder - */ -@Stateless (name = "adminPhone", description = "An administrative bean handling phone data") -public class AddressbookAdminPhoneSessionBean extends BaseAddressbookDatabaseBean implements AdminPhoneSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 18_597_165_817_401_853L; - - /** - * Default constructor - */ - public AddressbookAdminPhoneSessionBean () { - // Call super constructor - super(); - } - - @Override - public void deleteFaxData (final DialableFaxNumber faxNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); - - // Is all data set - if (faxNumber == null) { - // Not set, throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N - } else if (faxNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N - } - - // Get a managed instance - DialableFaxNumber managedNumber = this.getEntityManager().getReference(faxNumber.getClass(), faxNumber.getPhoneId()); - - // Remove it from database - this.getEntityManager().remove(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); - } - - @Override - public void deleteLandLineData (final DialableLandLineNumber landLineNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); - - // Is all data set - if (landLineNumber == null) { - // Not set, throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } else if (landLineNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Get a managed instance - DialableLandLineNumber managedNumber = this.getEntityManager().getReference(landLineNumber.getClass(), landLineNumber.getPhoneId()); - - // Remove it from database - this.getEntityManager().remove(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); - } - - @Override - public void deleteMobileData (final DialableMobileNumber mobileNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); - - // Is all data set - if (null == mobileNumber) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } else if (mobileNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N - } - - // Get a managed instance - DialableMobileNumber managedNumber = this.getEntityManager().getReference(mobileNumber.getClass(), mobileNumber.getPhoneId()); - - // Remove it from database - this.getEntityManager().remove(managedNumber); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteMobileData: EXIT!", this.getClass().getSimpleName())); - } - - @Override - public DialableFaxNumber updateFaxData (final DialableFaxNumber faxNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); - - // Is all data set - if (faxNumber == null) { - // Not set, throw NPE - throw new NullPointerException("faxNumber is null"); //NOI18N - } else if (faxNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N - } else if (faxNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N - } else if (faxNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N - } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (faxNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N - } - - // Get contact from it and find it - DialableFaxNumber managedNumber = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId()); - - // Should be found - assert (managedNumber instanceof DialableFaxNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", faxNumber.getPhoneId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateFaxData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N - - // Set updated timestamp - FaxNumbers.copyAll(faxNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateFaxData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - @Override - public DialableLandLineNumber updateLandLineData (final DialableLandLineNumber landLineNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); - - // Is all data set - if (landLineNumber == null) { - // Not set, throw NPE - throw new NullPointerException("landLineNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N - } else if (landLineNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N - } else if (landLineNumber.getPhoneCountry() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { - // Throw NPE - throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N - } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() == null) { - // ... throw again - throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N - } - - // Get contact from it and find it - DialableLandLineNumber managedNumber = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId()); - - // Should be found - assert (managedNumber instanceof DialableLandLineNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", landLineNumber.getPhoneId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateLandLineData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N - - // Set updated timestamp - LandLineNumbers.copyAll(landLineNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateLandLineData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - - @Override - public DialableMobileNumber updateMobileData (final DialableMobileNumber mobileNumber) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: mobileNumber={1} - CALLED!", this.getClass().getSimpleName(), mobileNumber)); - - // Is all data set - if (null == mobileNumber) { - // Not set, throw NPE - throw new NullPointerException("mobileNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneId() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N - } else if (mobileNumber.getPhoneId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N - } else if (mobileNumber.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("mobileNumber.cellphoneProvider is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("mobileNumber.cellphoneProvider.providerId is null"); //NOI18N - } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumber.cellphoneProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N - } else if (mobileNumber.getPhoneNumber() == null) { - // Throw NPE again - throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneNumber() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N - } - - // Get contact from it and find it - DialableMobileNumber managedNumber = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId()); - - // Should be found - assert (managedNumber instanceof DialableMobileNumber) : MessageFormat.format("Cell phone number with id {0} not found, but should be.", mobileNumber.getPhoneId()); //NOI18N - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateMobileData: managedNumber.phoneId={1}", this.getClass().getSimpleName(), managedNumber.getPhoneId())); //NOI18N - - // Set updated timestamp - MobileNumbers.copyAll(mobileNumber, managedNumber); - managedNumber.setPhoneEntryUpdated(new GregorianCalendar()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateMobileData: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N - - // Return it - return managedNumber; - } - -} diff --git a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java b/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java deleted file mode 100644 index 63084f5..0000000 --- a/src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jphone.phonenumbers.phone; - -import java.text.MessageFormat; -import java.util.List; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.fax.FaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; - -/** - * A general phone EJB - *

- * @author Roland Häder - */ -@Stateless (name = "phone", description = "A bean handling phone data") -public class AddressbookPhoneSessionBean extends BaseAddressbookDatabaseBean implements PhoneSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 134_945_698_127_601L; - - /** - * Default constructor - */ - public AddressbookPhoneSessionBean () { - // Call super constructor - super(); - } - - @SuppressWarnings ("unchecked") - @Override - public List allFaxNumbers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - Query query = this.getEntityManager().createNamedQuery("AllFaxNumbers", FaxNumber.class); //NOI18N - - // Get list from it - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allFaxNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @SuppressWarnings ("unchecked") - @Override - public List allLandLineNumbers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - Query query = this.getEntityManager().createNamedQuery("AllLandLineNumbers", LandLineNumber.class); //NOI18N - - // Get list from it - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allLandLineNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @SuppressWarnings ("unchecked") - @Override - public List allMobileNumbers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - Query query = this.getEntityManager().createNamedQuery("AllMobileNumbers", MobileNumber.class); //NOI18N - - // Get list from it - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMobileNumbers: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @Override - public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), faxNumberId)); //NOI18N - - // The id number should be valid - if (null == faxNumberId) { - // Throw NPE - throw new NullPointerException("faxNumberId is null"); //NOI18N - } else if (faxNumberId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("faxNumberId={0} is not valid.", faxNumberId)); //NOI18N - } - - // Now find it - Query query = this.getEntityManager().createNamedQuery("SearchFaxNumberId", FaxNumber.class); //NOI18N - - // Set parameter - query.setParameter("faxNumberId", faxNumberId); //NOI18N - - // Init instance - DialableFaxNumber faxNumber = null; - - // Try to get a result - try { - // Get a single result - faxNumber = (DialableFaxNumber) query.getSingleResult(); - } catch (NoResultException ex) { - // The entry was not found, so throw it again - throw new PhoneEntityNotFoundException(faxNumberId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findFaxNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N - - // Return found instance - return faxNumber; - } - - @Override - public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), landLineNumberId)); //NOI18N - - // The id number should be valid - if (null == landLineNumberId) { - // Throw NPE - throw new NullPointerException("landLineNumberId is null"); //NOI18N - } else if (landLineNumberId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is not valid.", landLineNumberId)); //NOI18N - } - - // Now find it - Query query = this.getEntityManager().createNamedQuery("SearchLandLineNumberId", LandLineNumber.class); //NOI18N - - // Set parameter - query.setParameter("landLineNumberId", landLineNumberId); //NOI18N - - // Init instance - DialableLandLineNumber landLineNumber = null; - - // Try to get a result - try { - // Get a single result - landLineNumber = (DialableLandLineNumber) query.getSingleResult(); - } catch (NoResultException ex) { - // The entry was not found, so throw it again - throw new PhoneEntityNotFoundException(landLineNumberId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findLandLineNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N - - // Return found instance - return landLineNumber; - } - - @Override - public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: mobileNumberId={1} - CALLED!", this.getClass().getSimpleName(), mobileNumberId)); //NOI18N - - // The id number should be valid - if (null == mobileNumberId) { - // Throw NPE - throw new NullPointerException("mobileNumberId is null"); //NOI18N - } else if (mobileNumberId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is not valid.", mobileNumberId)); //NOI18N - } - - // Now find it - Query query = this.getEntityManager().createNamedQuery("SearchMobileNumberId", MobileNumber.class); //NOI18N - - // Set parameter - query.setParameter("mobileNumberId", mobileNumberId); //NOI18N - - // Init instance - DialableMobileNumber cellphone = null; - - // Try to get a result - try { - // Get a single result - cellphone = (DialableMobileNumber) query.getSingleResult(); - } catch (NoResultException ex) { - // The entry was not found, so throw it again - throw new PhoneEntityNotFoundException(mobileNumberId, ex); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findMobileNumberById: cellphone={1} - EXIT!", this.getClass().getSimpleName(), cellphone)); //NOI18N - - // Return found instance - return cellphone; - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java deleted file mode 100644 index 1dc8927..0000000 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; -import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; -import org.mxchange.jusercore.exceptions.UserNotFoundException; -import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; -import org.mxchange.jusercore.exceptions.UserStatusLockedException; -import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; -import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote; -import org.mxchange.jusercore.model.user.status.UserAccountStatus; - -/** - * An administrative user EJB - *

- * @author Roland Häder - */ -@Stateless (name = "adminUser", description = "A bean handling the user data") -public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean implements AdminUserSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Registration EJB - */ - @EJB - private UserRegistrationSessionBeanRemote registerBean; - - /** - * Regular user bean - */ - @EJB - private UserSessionBeanRemote userBean; - - /** - * Default constructor - */ - public AddressbookAdminUserSessionBean () { - // Call super constructor - super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N - } - - @Override - public User addUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() instanceof Long) { - // Not allowed here - throw new IllegalStateException(MessageFormat.format("user.userId must be null, is: {0}", user.getUserId())); //NOI18N - } - - // Check if user is registered - if (this.registerBean.isUserNameRegistered(user)) { - // Abort here - throw new UserNameAlreadyRegisteredException(user); - } else if (this.registerBean.isEmailAddressRegistered(user)) { - // Abort here - throw new EmailAddressAlreadyRegisteredException(user); - } - - // Set created timestamp - user.setUserCreated(new GregorianCalendar()); - user.getUserContact().setContactCreated(new GregorianCalendar()); - - // Update cellphone, land-line and fax instance - this.setAllContactPhoneEntriesCreated(user.getUserContact()); - - // Persist it - this.getEntityManager().persist(user); - - // Flush to get id back - this.getEntityManager().flush(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1},user.userId={2} - EXIT!", this.getClass().getSimpleName(), user, user.getUserId())); //NOI18N - - // Return it - return user; - } - - @Override - public void deleteUser (final User user, final String userDeleteReason) throws UserNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Id is set - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N - } else if (user.getUserContact() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactId() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactId is null"); //NOI18N - } else if (user.getUserContact().getContactId() < 1) { - // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N - } else if (user.getUserAccountStatus() == null) { - // Throw NPE again - throw new NullPointerException("user.userAccountStatus is null"); //NOI18N - } else if (!this.userBean.ifUserExists(user)) { - // Name already found - throw new UserNotFoundException(user); - } - - // Get a managed instance - User managedUser = this.getManagedUser(user); - - // Should be found! - assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N - - // Delete it - this.getEntityManager().remove(managedUser); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - @Override - public User linkUser (final User user) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkUser: user={0} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() instanceof Long) { - // Id is set - throw new IllegalArgumentException("user.userId is not null"); //NOI18N - } else if (user.getUserContact() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactId() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactId is null"); //NOI18N - } else if (user.getUserContact().getContactId() < 1) { - // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N - } else if (user.getUserAccountStatus() == null) { - // Throw NPE again - throw new NullPointerException("user.userAccountStatus is null"); //NOI18N - } else if (this.userBean.ifUserNameExists(user.getUserName())) { - // Name already found - throw new UserNameAlreadyRegisteredException(user.getUserName()); - } - - // Try to find the contact - Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId()); - - // Should be found! - assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", user.getUserContact().getContactId()); //NOI18N - - // Set detached object in rexcruiter instance - user.setUserContact(managedContact); - - // Set timestamp - user.setUserCreated(new GregorianCalendar()); - - // Perist it - this.getEntityManager().persist(user); - - // Flush it to get updated instance back - this.getEntityManager().flush(); - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.linkUser: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N - - // Return updated instanc - return user; - } - - @Override - public User lockUserAccount (final User user, final String userLockReason, final String baseUrl) throws UserStatusLockedException, UserStatusUnconfirmedException, UserNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: user={1},userLockReason={2},baseUrl={3} - CALLED!", this.getClass().getSimpleName(), user, userLockReason, baseUrl)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Id is set - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Id is set - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N - } else if (user.getUserContact() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactId() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactId is null"); //NOI18N - } else if (user.getUserContact().getContactId() < 1) { - // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N - } else if (user.getUserAccountStatus() == null) { - // Throw NPE again - throw new NullPointerException("user.userAccountStatus is null"); //NOI18N - } else if (!this.userBean.ifUserExists(user)) { - // Name already found - throw new UserNotFoundException(user); - } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) { - // Account is locked - throw new UserStatusLockedException(user); - } else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) { - // Account is unconfirmed - throw new UserStatusUnconfirmedException(user); - } else if (null == userLockReason) { - // Throw NPE again - throw new NullPointerException("userLockReason is null"); //NOI18N - } else if (userLockReason.isEmpty()) { - // Is empty - throw new IllegalArgumentException("userLockReason is empty"); //NOI18N - } - - // Remove contact instance as this is not updated - user.setUserContact(null); - - // Set as locked, set timestamp and lock reason - user.setUserAccountStatus(UserAccountStatus.LOCKED); - user.setUserLastLocked(new GregorianCalendar()); - user.setUserLastLockedReason(userLockReason); - - // Update user - User managedUser = this.userBean.updateUserData(user); - - // @TODO Create user lock history entry - - // Send out email - // @TODO externalize subject line - this.sendEmail("User account locked", "user_account_locked", managedUser, baseUrl, null); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N - - // Return detached (and updated) user - return managedUser; - } - - @Override - public User unlockUserAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusUnconfirmedException, UserNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserId() == null) { - // Id is set - throw new NullPointerException("user.userId is null"); //NOI18N - } else if (user.getUserId() < 1) { - // Id is set - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N - } else if (user.getUserContact() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactId() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactId is null"); //NOI18N - } else if (user.getUserContact().getContactId() < 1) { - // Not valid id number - throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is not valid", user.getUserContact().getContactId())); //NOI18N - } else if (user.getUserAccountStatus() == null) { - // Throw NPE again - throw new NullPointerException("user.userAccountStatus is null"); //NOI18N - } else if (!this.userBean.ifUserExists(user)) { - // Name already found - throw new UserNotFoundException(user); - } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) { - // Account is confirmed - throw new UserStatusConfirmedException(user); - } else if (user.getUserAccountStatus() == UserAccountStatus.UNCONFIRMED) { - // Account is unconfirmed - throw new UserStatusUnconfirmedException(user); - } - - // Remove contact instance as this is not updated - user.setUserContact(null); - - // Unlock account - user.setUserAccountStatus(UserAccountStatus.CONFIRMED); - - // Update user - User managedUser = this.userBean.updateUserData(user); - - // @TODO Create user lock history entry - - // Send out email - // @TODO externalize subject line - this.sendEmail("User account unlocked", "user_account_unlocked", managedUser, baseUrl, null); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.lockUserAccount: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N - - // Return changed account - return managedUser; - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java b/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java deleted file mode 100644 index 9cdc6a7..0000000 --- a/src/java/org/mxchange/jusercore/model/user/AddressbookUserSessionBean.java +++ /dev/null @@ -1,800 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -import java.util.List; -import javax.ejb.EJB; -import javax.ejb.EJBException; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.PersistenceException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.ContactUtils; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.fax.FaxNumbers; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.landline.LandLineNumbers; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.phonenumbers.mobile.MobileNumbers; -import org.mxchange.jusercore.exceptions.UserNotFoundException; -import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; -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.register.UserRegistrationSessionBeanRemote; -import org.mxchange.jusercore.model.user.status.UserAccountStatus; - -/** - * A user EJB - *

- * @author Roland Häder - */ -@Stateless (name = "user", description = "A bean handling the user data") -public class AddressbookUserSessionBean extends BaseAddressbookDatabaseBean implements UserSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * Registration EJB - */ - @EJB - private UserRegistrationSessionBeanRemote registerBean; - - /** - * Default constructor - */ - public AddressbookUserSessionBean () { - // Call super constructor - super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N - } - - @Override - @SuppressWarnings ("unchecked") - public List allMemberPublicVisibleUsers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - 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 - 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 - 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 - 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") - public List allUsers () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - Query query = this.getEntityManager().createNamedQuery("AllUsers", LoginUser.class); //NOI18N - - // Get result - List users = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N - - // Return full list - return users; - } - - @Override - public User confirmAccount (final User user, final String baseUrl) throws UserStatusConfirmedException, UserStatusLockedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N - - // Parameter must be valid - 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 - } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) { - // Account is already confirmed - throw new UserStatusConfirmedException(user); - } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) { - // Account is already confirmed - throw new UserStatusLockedException(user); - } else if (user.getUserConfirmKey() == null) { - // Throw NPE - throw new NullPointerException("user.userConfirmKey is null"); //NOI18N - } else if (null == baseUrl) { - // Throw it again - throw new NullPointerException("baseUrl is null"); //NOI18N - } else if (baseUrl.isEmpty()) { - // Invalid parameter - throw new IllegalArgumentException("baseUrl is empty"); //NOI18N - } - - // Update user status and remove confirmation key - user.setUserAccountStatus(UserAccountStatus.CONFIRMED); - user.setUserConfirmKey(null); - user.setUserUpdated(new GregorianCalendar()); - - // Update user account - User updatedUser = this.updateUserData(user); - - // Send out email - this.sendEmail("User account confirmed", "user_account_confirmed", updatedUser, baseUrl, null); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.confirmAccount: updatedUser={1} - EXIT!", this.getClass().getSimpleName(), updatedUser)); //NOI18N - - // Return updated instance - return updatedUser; - } - - @Override - public User fillUserData (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), 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("SearchUserByName", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("userName", 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("{0}.fillUserData: foundUser={1} - EXIT!", this.getClass().getSimpleName(), foundUser)); //NOI18N - - // Return prepared instance - return foundUser; - } - - @Override - public User findUserById (final Long userId) throws UserNotFoundException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: userId={1} - CALLED!", this.getClass().getSimpleName(), userId)); //NOI18N - - // Is the parameter valid? - if (null == userId) { - // Throw NPE - throw new NullPointerException("userId is null"); //NOI18N - } else if (userId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N - } else if (!this.ifUserIdExists(userId)) { - // Does not exist - throw new UserNotFoundException(userId); - } - - // Create query instance - Query query = this.getEntityManager().createNamedQuery("SearchUserById", LoginUser.class); //NOI18N - - // Set user id - query.setParameter("id", userId); //NOI18N - - // Fetch the result, it should be there by now - User user = (User) query.getSingleResult(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findUserById: user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N - - // Return found user - return user; - } - - @Override - public String generateRandomUserName () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get full list - List userList = this.getUserNameList(); - - // Init variable - String userName = null; - - // Loop until a user name is found - while ((userName == null) || (userList.contains(userName))) { - // Generate random name - userName = UserUtils.generateRandomUserName(); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName: userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N - - // Found one, so return it - return userName; - } - - @Override - @SuppressWarnings ("unchecked") - public List getEmailAddressList () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N - - // Get result list - 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 - @SuppressWarnings ("unchecked") - public List getUserNameList () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get query - Query query = this.getEntityManager().createNamedQuery("AllUserNames", String.class); //NOI18N - - // Get result list - List userNameList = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: userNameList.size()={1} - EXIT!", this.getClass().getSimpleName(), userNameList.size())); //NOI18N - - // Return it - return userNameList; - } - - @Override - public boolean ifUserExists (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: user={1} - CALLED!", this.getClass().getSimpleName(), 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("SearchUserById", 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("{0}.ifUserExists: Found user {1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N - - // Found it - return true; - } - - @Override - public boolean ifUserIdExists (final Long userId) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserIdExists: userId={1} - CALLED!", this.getClass().getSimpleName(), 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("SearchUserById", 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("{0}.ifUserIdExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserIdExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), 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("{0}.ifUserIdExists: Found userId={1} - EXIT!", this.getClass().getSimpleName(), userId)); //NOI18N - - // Found it - return true; - } - - @Override - public boolean ifUserNameExists (final String userName) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: userName={1} - CALLED!", this.getClass().getSimpleName(), userName)); //NOI18N - - // userId should not be null - if (null == userName) { - // Abort here - throw new NullPointerException("userName is null"); //NOI18N - } else if (userName.isEmpty()) { - // Abort here - throw new NullPointerException("userName is empty"); //NOI18N - } - - // Generate query - Query query = this.getEntityManager().createNamedQuery("SearchUserByName", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("userName", userName); //NOI18N - - // Try this - try { - User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.ifUserNameExists: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), ex)); //NOI18N - - // User name does not exist - return false; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserNameExists: Found userName={1} - EXIT!", this.getClass().getSimpleName(), userName)); //NOI18N - - // Found it - return true; - } - - @Override - public boolean isEmailAddressRegistered (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), 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("SearchUserByEmailAddress", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("emailAddress", user.getUserContact().getContactEmailAddress()); //NOI18N - - // Search for it - try { - User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), 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; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Found it - return true; - } - - @Override - public boolean isUserNameRegistered (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), 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("SearchUserByName", LoginUser.class); //NOI18N - - // Set parameter - query.setParameter("userName", user.getUserName()); //NOI18N - - // Try this - try { - User dummy = (User) query.getSingleResult(); - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: dummy.userId={1} found.", this.getClass().getSimpleName(), dummy.getUserId())); //NOI18N - } catch (final NoResultException ex) { - // Log it - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isUserNameRegistered: getSingleResult() returned no result: {1}", this.getClass().getSimpleName(), 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; - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: Returning true ... - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Found it - return true; - } - - @Override - public User updateUserData (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // 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 - } - - // Remove contact instance as this is not updated - user.setUserContact(null); - - // Find the instance - User managedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); - - // Should be found! - assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N - - // Copy all data - UserUtils.copyAll(user, managedUser); - - // Set as updated - managedUser.setUserUpdated(new GregorianCalendar()); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserData: managedUser={1} - CALLED!", this.getClass().getSimpleName(), managedUser)); //NOI18N - - // Return updated instance - return managedUser; - } - - @Override - public PasswordHistory updateUserPassword (final User user, final String baseUrl) throws UserNotFoundException, UserStatusUnconfirmedException, UserStatusLockedException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: user={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), user, baseUrl)); //NOI18N - - // 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 - throw new NullPointerException("user.userAccountStatus is null"); //NOI18N - } else if (user.getUserContact() == null) { - // Throw it again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactId() == null) { - // .. and again - throw new NullPointerException("user.userContact.contactId is null"); //NOI18N - } else if (user.getUserContact().getContactId() < 1) { - // Invalid id - throw new IllegalArgumentException(MessageFormat.format("user.userContact.contactId={0} is invalid", user.getUserContact().getContactId())); //NOI18N - } else if (user.getUserContact().getContactPersonalTitle() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactPersonalTitle 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 - } else if (null == baseUrl) { - // Throw it again - throw new NullPointerException("baseUrl is null"); //NOI18N - } else if (baseUrl.isEmpty()) { - // Invalid parameter - throw new IllegalArgumentException("baseUrl is empty"); //NOI18N - } - - // Call other method - User updatedUser = this.updateUserData(user); - - // Create history entry - PasswordHistory entry = new UserPasswordHistory(user.getUserEncryptedPassword(), updatedUser); - - // Set created timestamp - entry.setUserPasswordHistoryCreated(new GregorianCalendar()); - - // Persist it - this.getEntityManager().persist(entry); - - // Flush it to get id number back - this.getEntityManager().flush(); - - // Send email to user - this.sendEmail("User password change", "user_password_change", user, baseUrl, null); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPassword: entry.userPasswordHistoryId={1} - EXIT!", this.getClass().getSimpleName(), entry.getUserPasswordHistoryId())); //NOI18N - - // Return it - return entry; - } - - @Override - public User updateUserPersonalData (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // 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 managedUser = this.getEntityManager().find(user.getClass(), user.getUserId()); - - // Should be found! - assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N - - // Copy all data - UserUtils.copyAll(user, managedUser); - - // Set as updated - managedUser.setUserUpdated(new GregorianCalendar()); - managedUser.getUserContact().setContactUpdated(new GregorianCalendar()); - - // Get contact from it and find it - Contact managedContact = this.getEntityManager().find(user.getUserContact().getClass(), user.getUserContact().getContactId()); - - // Should be found - assert (managedContact 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: managedContact.contactId={0}", managedContact.getContactId())); //NOI18N - - // Copy all - ContactUtils.copyAll(user.getUserContact(), managedContact); - - // Set it back in user - user.setUserContact(managedContact); - - // Should be found! - assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not merged, but should be.", user.getUserContact().getContactId()); //NOI18N - - // Get mobile instance - DialableMobileNumber mobileNumber = managedContact.getContactMobileNumber(); - - // Is there a mobile instance set? - if (mobileNumber instanceof DialableMobileNumber) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: mobile.phoneId={0} is being updated ...", mobileNumber.getPhoneId())); //NOI18N - - // Then find it, too - DialableMobileNumber foundMobile = this.getEntityManager().find(mobileNumber.getClass(), mobileNumber.getPhoneId()); - - // Should be there - assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N - - // Then merge it, too - DialableMobileNumber managedMobile = this.getEntityManager().merge(foundMobile); - - // Should be there - assert (managedMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", managedMobile.getPhoneId()); //NOI18N - - // Copy all - MobileNumbers.copyAll(managedUser.getUserContact().getContactMobileNumber(), managedMobile); - - // Set it back - managedContact.setContactMobileNumber(this.getManaged(mobileNumber, mobileNumber)); - } - - // Get mobile instance - DialableFaxNumber faxNumber = managedContact.getContactFaxNumber(); - - // Is there a fax instance set? - if (faxNumber instanceof DialableFaxNumber) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: faxNumber.phoneId={0} is being updated ...", faxNumber.getPhoneId())); //NOI18N - - // Then find it, too - DialableFaxNumber foundFax = this.getEntityManager().find(faxNumber.getClass(), faxNumber.getPhoneId()); - - // Should be there - assert (foundFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", foundFax.getPhoneId()); //NOI18N - - // Then merge it, too - DialableFaxNumber managedFax = this.getEntityManager().merge(foundFax); - - // Should be there - assert (managedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", managedFax.getPhoneId()); //NOI18N - - // Copy all - FaxNumbers.copyAll(managedUser.getUserContact().getContactFaxNumber(), managedFax); - - // Set it back - managedContact.setContactFaxNumber(managedFax); - } - - // Get mobile instance - DialableLandLineNumber landLineNumber = managedContact.getContactLandLineNumber(); - - // Is there a fax instance set? - if (landLineNumber instanceof DialableLandLineNumber) { - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("updateUserPersonalData: landLineNumber.phoneId={0} is being updated ...", landLineNumber.getPhoneId())); //NOI18N - - // Then find it, too - DialableLandLineNumber foundLandLine = this.getEntityManager().find(landLineNumber.getClass(), landLineNumber.getPhoneId()); - - // Should be there - assert (foundLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", foundLandLine.getPhoneId()); //NOI18N - - // Then merge it, too - DialableLandLineNumber managedLandLine = this.getEntityManager().merge(foundLandLine); - - // Should be there - assert (managedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", managedLandLine.getPhoneId()); //NOI18N - - // Copy all - LandLineNumbers.copyAll(managedUser.getUserContact().getContactLandLineNumber(), managedLandLine); - - // Set it back - managedContact.setContactLandLineNumber(managedLandLine); - } - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateUserPersonalData: entry.managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N - - // Return updated user instance - return managedUser; - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivityLogMessageBean.java b/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivityLogMessageBean.java deleted file mode 100644 index 4d8b70e..0000000 --- a/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivityLogMessageBean.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user.activity; - -import java.io.Serializable; -import java.text.MessageFormat; -import javax.ejb.ActivationConfigProperty; -import javax.ejb.MessageDriven; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.ObjectMessage; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jusercore.model.user.User; - -/** - * A message-driven bean for adding user activity log - *

- * @author Roland Häder - */ -@MessageDriven ( - name = "userActivityLog", - description = "A message-driven bean for adding user activity log", - activationConfig = { - @ActivationConfigProperty ( - propertyName = "destinationLookup", - propertyValue = "jms/addressbook-user-activity-log" - ), - @ActivationConfigProperty ( - propertyName = "destinationType", - propertyValue = "javax.jms.Queue" - ) - } -) -public class AddressbookUserActivityLogMessageBean extends BaseAddressbookDatabaseBean implements MessageListener { - - /** - * Serial number - */ - private static final long serialVersionUID = 14_920_686_785_732_054L; - - /** - * Default constructor - */ - public AddressbookUserActivityLogMessageBean () { - // Call super constructor - super(); - } - - @Override - public void onMessage (final Message message) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: message={1} - CALLED!", this.getClass().getSimpleName(), message)); //NOI18N - - // The parameter should be valid - if (null == message) { - // Throw NPE - throw new NullPointerException("message is null"); //NOI18N - } else if (!(message instanceof ObjectMessage)) { - // Not implementing right interface - throw new IllegalArgumentException(MessageFormat.format("message={0} does not implemented ObjectMessage", message)); //NOI18N - } - - // Securely cast it - ObjectMessage objectMessage = (ObjectMessage) message; - - // Init variable - Serializable serializable; - - try { - // Get object from message - serializable = objectMessage.getObject(); - } catch (final JMSException ex) { - // Log it and don't continue any further - this.getLoggerBeanLocal().logException(ex); - return; - } - - // Debug message - this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.onMessage: serializable={1}", this.getClass().getSimpleName(), serializable)); //NOI18N - - // Okay, is it the right interface? - if (null == serializable) { - // Throw NPE - throw new NullPointerException("serializable is null"); //NOI18N - } else if (!(serializable instanceof LogableUserActivity)) { - // Not correct object send - throw new IllegalArgumentException(MessageFormat.format("serializable={0} does not implement LogableUserActivity", serializable)); //NOI18N - } - - // Securely cast it - LogableUserActivity userActivity = (LogableUserActivity) serializable; - - // Should be valid - 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.getActivityUser().getUserId() == null) { - // Throw NPE again - throw new NullPointerException("userActivity.activityUser.userId is null"); //NOI18N - } else if (userActivity.getActivityUser().getUserId() < 1) { - // Throw NPE again - throw new IllegalArgumentException(MessageFormat.format("userActivity.activityUser.userId={0} is not valid", userActivity.getActivityUser().getUserId())); //NOI18N - } else if (userActivity.getActivityType() == null) { - // Throw again ... - throw new NullPointerException("userActivity.activityType is null"); //NOI18N - } else if (userActivity.getActivityType().isEmpty()) { - // Empty type - throw new IllegalArgumentException("userActivity.activityType is empty"); //NOI18N - } else if ((userActivity.getActivityMessage() instanceof String) && (userActivity.getActivityMessage().isEmpty())) { - // Set but empty message - throw new IllegalArgumentException("userActivity.activityMessage is empty"); //NOI18N - } else if (userActivity.getActivityTimestamp() == null) { - // Throw NPE again - throw new NullPointerException("userActivity.activityTimestamp is null"); //NOI18N - } - - // Make user instance managed - User managedUser = this.getManagedUser(userActivity.getActivityUser()); - - // Set it back - userActivity.setActivityUser(managedUser); - - // All fine, persist it - this.getEntityManager().persist(userActivity); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.onMessage: EXIT!", this.getClass().getSimpleName())); //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 deleted file mode 100644 index f883689..0000000 --- a/src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivitySessionBean.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.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.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. - *

- * @author Roland Häder - */ -@Stateless (name = "userActivity", description = "A bean handling the user data") -public class AddressbookUserActivitySessionBean extends BaseAddressbookDatabaseBean implements UserActivityLogSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 219_568_677_671_054L; - - /** - * Default constructor - */ - public AddressbookUserActivitySessionBean () { - // Call super constructor - super("jms/jjobs-queue-factory", "jms/jjobs-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 - - // Should be valid - 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.getActivityType() == null) { - // Throw again ... - 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 - } - - try { - // Send out email change - ObjectMessage message = this.getSession().createObjectMessage(); - message.setObject(userActivity); - - // Send message - this.sendMessage(message); - } catch (final JMSException ex) { - // Throw again - throw new EJBException(ex); - } - } - - @Override - @SuppressWarnings ("unchecked") - public List fetchAllUserActivityLog () { - // 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 list - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUserActivityLog: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - return list; - } - - @Override - @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 - - // 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 - } - - // Search for user's activity - Query query = this.getEntityManager().createNamedQuery("FindAllUsersActivity", UserActivityLog.class); //NOI18N - - // Set parameter - query.setParameter("activityUser", user); //NOI18N - - // Get list - List list = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fetchAllUsersActivityLog: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N - - // Return it - 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/jusercore/model/user/email_address/AddressbookUserEmailChangeSessionBean.java b/src/java/org/mxchange/jusercore/model/user/email_address/AddressbookUserEmailChangeSessionBean.java deleted file mode 100644 index c035310..0000000 --- a/src/java/org/mxchange/jusercore/model/user/email_address/AddressbookUserEmailChangeSessionBean.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user.email_address; - -import java.text.MessageFormat; -import java.util.GregorianCalendar; -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.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; -import org.mxchange.jusercore.model.email_address.EmailAddressChange; -import org.mxchange.jusercore.model.user.UserSessionBeanRemote; -import org.mxchange.jusercore.model.user.UserUtils; - -/** - * A session-scoped bean for changing email addresses - *

- * @author Roland Häder - */ -@Stateless (name = "userEmailChange", description = "A bean handling user email changes") -public class AddressbookUserEmailChangeSessionBean extends BaseAddressbookDatabaseBean implements UserEmailChangeSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 182_698_165_971_548L; - - /** - * User bean - */ - @EJB - private UserSessionBeanRemote userBean; - - /** - * Default constructor - */ - public AddressbookUserEmailChangeSessionBean () { - // Call super constructor - super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N - } - - @Override - @SuppressWarnings ("unchecked") - public List allQueuedAddresses () { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: CALLED!", this.getClass().getSimpleName())); //NOI18N - - // Get named query - Query query = this.getEntityManager().createNamedQuery("AllEmailAddressChanges", String.class); //NOI18N - - // Get all entries - List emailAddresses = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allQueuedAddresses: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N - - // Return it - return emailAddresses; - } - - @Override - public void enqueueEmailAddressForChange (final ChangeableEmailAddress emailChange, final String baseUrl) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange: emailChange={1},baseUrl={2} - CALLED!", this.getClass().getSimpleName(), emailChange, baseUrl)); //NOI18N - - // Email address change should be valid - if (null == emailChange) { - // Abort here - throw new NullPointerException("emailChange is null"); //NOI18N - } else if (emailChange.getEmailChangeUser() == null) { - // Throw NPE again - throw new NullPointerException("emailChange.emailChangeUser is null"); //NOI18N - } else if (emailChange.getEmailChangeUser().getUserId() == null) { - // Throw NPE again - throw new NullPointerException("emailChange.emailChangeUser.userId is null"); //NOI18N - } else if (emailChange.getEmailChangeUser().getUserId() < 1) { - // Not valid id - throw new IllegalArgumentException(MessageFormat.format("emailChange.emailChangeUser.userId={0} is invalid.", emailChange.getEmailChangeUser().getUserId())); //NOI18N - } else if (!this.userBean.ifUserExists(emailChange.getEmailChangeUser())) { - // User does not exist - throw new EJBException(MessageFormat.format("Email change with id {0} does not exist.", emailChange.getEmailChangeId())); //NOI18N - } else if (emailChange.getEmailAddress().trim().isEmpty()) { - // Email address is empty - throw new IllegalArgumentException("emailChange.emaiLAddress is empty."); //NOI18N - } else if (this.isEmailAddressEnqueued(emailChange.getEmailAddress())) { - // Email address is already enqueued - throw new EJBException(MessageFormat.format("Email address {0} is already enqueued.", emailChange.getEmailAddress())); //NOI18N - } - - // The email change is not (yet) there, add secure hash and "created" timestamp - emailChange.setEmailChangeCreated(new GregorianCalendar()); - this.generateSecureHash(emailChange); - - // Persist it - //@TODO Fix email delivery then allow this: this.getEntityManager().persist(emailChange); - - // Send email - this.sendEmail("User email change", "user_email_change", emailChange.getEmailChangeUser(), baseUrl, null); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.enqueueEmailAddressForChange - EXIT!", this.getClass().getSimpleName())); //NOI18N - } - - @Override - public boolean isEmailAddressEnqueued (final String emailAddress) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressEnqueued: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), 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("{0}.isEmailAddressEnqueued: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N - - // Return it - return isFound; - } - - @Override - public void updateEmailAddress (final ChangeableEmailAddress emailAddress) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N - - // Email address change should be valid - 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 (emailAddress.getEmailAddress().trim().isEmpty()) { - // Email address is empty - throw new IllegalArgumentException("emailAddress.emaiLAddress is empty."); //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())); //NOI18N - } - - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - /** - * Generates a secure, unique hash for given email address change. This - * requires to check if the hash is really not there. - *

- * @param emailAddress Email address change - */ - private void generateSecureHash (final ChangeableEmailAddress emailAddress) { - // Email address change should be valid - if (null == emailAddress) { - // Abort here - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.getEmailAddress().trim().isEmpty()) { - // Email address is empty - throw new IllegalArgumentException("emailAddress.emaiLAddress is empty."); //NOI18N - } - - // Initialize loop with null - String hash = null; - - // Default is not used - boolean isUsed = true; - - // Search for free hash - while (isUsed) { - // Generate hash, there is already in UserUtils a nice method that can be used for this purpose. - hash = UserUtils.encryptPassword(String.format("%s:%s", emailAddress.getEmailAddress(), emailAddress.toString())); //NOI18N - - // The hash *may* be unique, better test it - Query query = this.getEntityManager().createNamedQuery("SearchEmailChangeByHash", EmailAddressChange.class); //NOI18N - - // Set hash as parameter - query.setParameter("hash", hash); //NOI18N - - // Try to get single result - try { - // Get single result - ChangeableEmailAddress dummy = (ChangeableEmailAddress) query.getSingleResult(); - } catch (final NoResultException ex) { - // Not found - isUsed = false; - } - } - - // hash should not be null and set - assert (hash != null) : "hash is null"; //NOI18N - assert (!hash.isEmpty()) : "hash is empty"; //NOI18N - - // Set it in email change - emailAddress.setEmailChangeHash(hash); - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/login/FinancialsUserLoginSessionBean.java b/src/java/org/mxchange/jusercore/model/user/login/FinancialsUserLoginSessionBean.java deleted file mode 100644 index 699565c..0000000 --- a/src/java/org/mxchange/jusercore/model/user/login/FinancialsUserLoginSessionBean.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user.login; - -import java.text.MessageFormat; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -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.login.user.UserLoginSessionBeanRemote; -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.register.UserRegistrationSessionBeanRemote; -import org.mxchange.jusercore.model.user.status.UserAccountStatus; - -/** - * A session EJB for user logins - *

- * @author Roland Häder - */ -@Stateless (name = "userLogin", description = "A bean handling the user login for Financials project") -public class FinancialsUserLoginSessionBean extends BaseAddressbookDatabaseBean implements UserLoginSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 21_785_978_127_581_965L; - - /** - * Registration EJB - */ - @EJB - private UserRegistrationSessionBeanRemote registerBean; - - /** - * User EJB - */ - @EJB - private UserSessionBeanRemote userBean; - - /** - * Default constructor - */ - public FinancialsUserLoginSessionBean () { - // 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 - - // 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("{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 UserUtils.ifPasswordMatches(container, updatedUser); - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/password_history/AddressbookUserPasswordHistorySessionBean.java b/src/java/org/mxchange/jusercore/model/user/password_history/AddressbookUserPasswordHistorySessionBean.java deleted file mode 100644 index dfb2503..0000000 --- a/src/java/org/mxchange/jusercore/model/user/password_history/AddressbookUserPasswordHistorySessionBean.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user.password_history; - -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.jusercore.model.user.User; - -/** - * A user password history EJB - *

- * @author Roland Häder - */ -@Stateless (name = "userPasswordHistory", description = "A stateless EJB for user's password history. This bean does return the full user's password history and not limited. The application then needs to limit it to it's purpose.") -public class AddressbookUserPasswordHistorySessionBean extends BaseAddressbookDatabaseBean implements UserPasswordHistorySessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 395_767_546_195_014L; - - /** - * Default constructor - */ - public AddressbookUserPasswordHistorySessionBean () { - // Call super constructor - super(); - } - - @Override - @SuppressWarnings ("unchecked") - public List getUserPasswordHistory (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): user={1} - EXIT!", this.getClass().getSimpleName(), user)); //NOI18N - - // 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) { - // Illegal id number - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not allowed.", user.getUserId())); //NOI18N - } - - // Get named query - Query query = this.getEntityManager().createNamedQuery("AllUsersHistoryEntries", UserPasswordHistory.class); //NOI18N - - // Set parameter - query.setParameter("user", user); //NOI18N - - // Get full history - List history = query.getResultList(); - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserPasswordHistory(): history.size()={1} - EXIT !", this.getClass().getSimpleName(), history.size())); //NOI18N - - // Return it - return history; - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/register/AddressbookUserRegistrationSessionBean.java b/src/java/org/mxchange/jusercore/model/user/register/AddressbookUserRegistrationSessionBean.java deleted file mode 100644 index 385111d..0000000 --- a/src/java/org/mxchange/jusercore/model/user/register/AddressbookUserRegistrationSessionBean.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user.register; - -import java.text.MessageFormat; -import java.util.Objects; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import javax.persistence.NoResultException; -import javax.persistence.Query; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; -import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; -import org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote; -import org.mxchange.jusercore.model.user.LoginUser; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.UserSessionBeanRemote; -import org.mxchange.jusercore.model.user.UserUtils; - -/** - * A session-scoped bean for user registration - *

- * @author Roland Häder - */ -@Stateless (name = "userRegistration", description = "A bean handling the user registration") -public class AddressbookUserRegistrationSessionBean extends BaseAddressbookDatabaseBean implements UserRegistrationSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 12_348_958_986_818_627L; - - /** - * Administrative user bean - */ - @EJB - private AdminUserSessionBeanRemote adminUserBean; - - /** - * Regular user EJB - */ - @EJB - private UserSessionBeanRemote userBean; - - /** - * Default constructor - */ - public AddressbookUserRegistrationSessionBean () { - // Call super constructor - super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N - } - - @Override - public String generateConfirmationKey (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } - - // Create named instance - Query query = this.getEntityManager().createNamedQuery("SearchUserByConfirmKey", LoginUser.class); //NOI18N - - // Init confirmation key - String confirmationKey = null; - - // Find a free one - while (confirmationKey == null) { - // Create new one - String key = UserUtils.generatedConfirmationKey(user); - - // Set key as parameter - query.setParameter("confirmKey", key); //NOI18N - - // Try it - try { - // Get contact instance - Contact contact = (Contact) query.getSingleResult(); - - // Warning message - this.getLoggerBeanLocal().logWarning(MessageFormat.format("{0}.generateConfirmationKey: key {1} already found: contact.contactId={2}", this.getClass().getSimpleName(), key, contact.getContactId())); //NOI18N - } catch (final NoResultException ex) { - // Not found, normal case - confirmationKey = key; - break; - } - } - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateConfirmationKey: confirmationKey={1} - EXIT!", this.getClass().getSimpleName(), confirmationKey)); //NOI18N - - // Return it - return confirmationKey; - } - - @Override - public boolean isEmailAddressRegistered (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), 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.isEmailAddressRegistered(user); - } - - @Override - public boolean isUserNameRegistered (final User user) { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isUserNameRegistered: user={1} - CALLED!", this.getClass().getSimpleName(), 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.isUserNameRegistered(user); - } - - @Override - public User registerUser (final User user, final String baseUrl, final String randomPassword) throws UserNameAlreadyRegisteredException, EmailAddressAlreadyRegisteredException { - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: user={1},baseUrl={2},randomPassword[]={3} - CALLED!", this.getClass().getSimpleName(), user, baseUrl, Objects.toString(randomPassword))); //NOI18N - - // user should not be null - if (null == user) { - // Abort here - throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserContact() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact is null"); //NOI18N - } else if (user.getUserContact().getContactEmailAddress() == null) { - // Throw NPE again - throw new NullPointerException("user.userContact.contactEmailAddress is null"); //NOI18N - } else if (user.getUserContact().getContactEmailAddress().isEmpty()) { - // Is empty - throw new IllegalArgumentException("user.userContact.contactEmailAddress is empty"); //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); - } - - // Call other EJB - User addedUser = this.adminUserBean.addUser(user); - - // Default template is with no random password - String templateName = "user_registration"; //NOI18N - - // Is password set? - if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) { - // Switch to other template - templateName = "user_registration_random"; //NOI18N - } - - // Send email - // @TODO: Internationlize the subject line somehow - this.sendEmail("Registration", templateName, addedUser, baseUrl, randomPassword); //NOI18N - - // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.registerUser: addedUser={1},addedUser.userId={2} - EXIT!", this.getClass().getSimpleName(), addedUser, addedUser.getUserId())); //NOI18N - - // Return it - return addedUser; - } - -} diff --git a/src/java/org/mxchange/jusercore/model/user/resendlink/AddressbookResendLinkSessionBean.java b/src/java/org/mxchange/jusercore/model/user/resendlink/AddressbookResendLinkSessionBean.java deleted file mode 100644 index 70ed720..0000000 --- a/src/java/org/mxchange/jusercore/model/user/resendlink/AddressbookResendLinkSessionBean.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * 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.jusercore.model.user.resendlink; - -import java.text.MessageFormat; -import java.util.Locale; -import javax.ejb.EJB; -import javax.ejb.Stateless; -import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean; -import org.mxchange.jusercore.exceptions.UserNotFoundException; -import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; -import org.mxchange.jusercore.exceptions.UserStatusLockedException; -import org.mxchange.jusercore.model.user.LoginUser; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.UserSessionBeanRemote; -import org.mxchange.jusercore.model.user.register.UserRegistrationSessionBeanRemote; -import org.mxchange.jusercore.model.user.status.UserAccountStatus; - -/** - * A session-based EJB for resending confirmation links - *

- * @author Roland Häder - */ -@Stateless (name = "userResendConfirmationLink", description = "A bean resending confirmation links") -public class AddressbookResendLinkSessionBean extends BaseAddressbookDatabaseBean implements ResendLinkSessionBeanRemote { - - /** - * Serial number - */ - private static final long serialVersionUID = 71_546_726_857_195_360L; - - /** - * Registration bean - */ - @EJB - private UserRegistrationSessionBeanRemote registerBean; - - /** - * Regular user bean - */ - @EJB - private UserSessionBeanRemote userBean; - - /** - * Default constructor - */ - public AddressbookResendLinkSessionBean () { - // Call super constructor - super("jms/addressbook-queue-factory", "jms/addressbook-email-queue"); //NOI18N - } - - @Override - public void resendConfirmationLink (final User user, final Locale locale, final String baseUrl) throws UserNotFoundException, UserStatusConfirmedException, UserStatusLockedException { - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: user={1},locale={2},baseUrl={3} - CALLED!", this.getClass().getSimpleName(), user, locale, baseUrl)); //NOI18N - - // The user instance should be valid - if (null == user) { - // Throw NPE - 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) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N - } else if (!this.userBean.ifUserExists(user)) { - // User not found - throw new UserNotFoundException(user); - } else if (user.getUserConfirmKey() == null) { - // Throw NPE again - throw new NullPointerException("this.userConfirmKey is null"); //NOI18N - } else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) { - // User account status is not UNCONFIRMED - throw new UserStatusConfirmedException(user); - } else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) { - // User account status is not UNCONFIRMED - throw new UserStatusLockedException(user); - } else if (null == locale) { - // Locale should be set - throw new NullPointerException("locale is null"); //NOI18N - } - - // Get new registration key - String confirmationKey = this.registerBean.generateConfirmationKey(user); - - // Get managed instance - User managedUser = this.getEntityManager().find(LoginUser.class, user.getUserId()); - - // Set it in user - managedUser.setUserConfirmKey(confirmationKey); - - // Send email - // @TODO: Internationlize the subject line somehow - this.sendEmail("Resend user confirmation link", "user_resend_confirmation_link", user, baseUrl, null); //NOI18N - - // Log trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.resendConfirmationLink: EXIT!", this.getClass().getSimpleName())); //NOI18N - } - -} diff --git a/src/java/templates/de/account_confirmed.vm b/src/java/templates/de/account_confirmed.vm new file mode 100644 index 0000000..f56ac6c --- /dev/null +++ b/src/java/templates/de/account_confirmed.vm @@ -0,0 +1,10 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie hatten soeben ($userUpdated) Ihren Account bestätigt. Vielen Dank. + +Sie können sich mit Ihrem Benutzernamen $userName und Ihrem vergebenen Passwort im Mitgliedsbereich einloggen. + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/de/account_confirmed_1.vm b/src/java/templates/de/account_confirmed_1.vm new file mode 100644 index 0000000..f56ac6c --- /dev/null +++ b/src/java/templates/de/account_confirmed_1.vm @@ -0,0 +1,10 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie hatten soeben ($userUpdated) Ihren Account bestätigt. Vielen Dank. + +Sie können sich mit Ihrem Benutzernamen $userName und Ihrem vergebenen Passwort im Mitgliedsbereich einloggen. + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/de/registration.vm b/src/java/templates/de/registration.vm new file mode 100644 index 0000000..c0e5baa --- /dev/null +++ b/src/java/templates/de/registration.vm @@ -0,0 +1,53 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie hatten sich eben ($userCreated) bei uns angemeldet. Sollten Sie dies nicht gewesen sein, so melden Sie sich bitter per Kontaktformular bei uns. + +Hier sind Ihre Daten: +--------------------- +Benuzter-Id: +$userId +--------------------- +Benutzername: +$userName +--------------------- +Anrede: +$contactPersonalTitle +--------------------- +Titel: +$contactTitle +--------------------- +Vorname: +$contactFirstName +--------------------- +Nachname: +$contactFamilyName +--------------------- +Straße + Hausnummer: +$contactStreet $contactHouseNumber +--------------------- +PLZ, Wohnort: +$contactZipCode $contactCity +--------------------- +Geburtsdatum: +$contactBirthday +--------------------- +Email-Adresse: +$contactEmailAddress +--------------------- + +Wenn Sie sich anmelden möchten, so müssen Sie Ihren Account bestätigen. Bitte klicken Sie oder kopieren Sie den unten stehenden Link in Ihren Browser: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +Falls der Link nicht funktioniert, rufen Sie bitte folgenden auf und lassen sich einen neuen Link zuschicken: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/de/registration_1.vm b/src/java/templates/de/registration_1.vm new file mode 100644 index 0000000..c0e5baa --- /dev/null +++ b/src/java/templates/de/registration_1.vm @@ -0,0 +1,53 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie hatten sich eben ($userCreated) bei uns angemeldet. Sollten Sie dies nicht gewesen sein, so melden Sie sich bitter per Kontaktformular bei uns. + +Hier sind Ihre Daten: +--------------------- +Benuzter-Id: +$userId +--------------------- +Benutzername: +$userName +--------------------- +Anrede: +$contactPersonalTitle +--------------------- +Titel: +$contactTitle +--------------------- +Vorname: +$contactFirstName +--------------------- +Nachname: +$contactFamilyName +--------------------- +Straße + Hausnummer: +$contactStreet $contactHouseNumber +--------------------- +PLZ, Wohnort: +$contactZipCode $contactCity +--------------------- +Geburtsdatum: +$contactBirthday +--------------------- +Email-Adresse: +$contactEmailAddress +--------------------- + +Wenn Sie sich anmelden möchten, so müssen Sie Ihren Account bestätigen. Bitte klicken Sie oder kopieren Sie den unten stehenden Link in Ihren Browser: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +Falls der Link nicht funktioniert, rufen Sie bitte folgenden auf und lassen sich einen neuen Link zuschicken: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/de/resend_confirmation_link.vm b/src/java/templates/de/resend_confirmation_link.vm new file mode 100644 index 0000000..6782f02 --- /dev/null +++ b/src/java/templates/de/resend_confirmation_link.vm @@ -0,0 +1,21 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie hatten soeben ($userUpdated) einen neuen Bestätigungslink angefordert. Die Anmeldung war $userCreated . + +Hier ist der neue Link: +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +Falls der Link nicht funktioniert, rufen Sie bitte folgenden auf und lassen sich einen neuen Link zuschicken: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +Sollten Sie dies bereits getan haben und nicht weiterkommen, so melden Sie sich bitte bei uns. + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/de/resend_confirmation_link_1.vm b/src/java/templates/de/resend_confirmation_link_1.vm new file mode 100644 index 0000000..6782f02 --- /dev/null +++ b/src/java/templates/de/resend_confirmation_link_1.vm @@ -0,0 +1,21 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie hatten soeben ($userUpdated) einen neuen Bestätigungslink angefordert. Die Anmeldung war $userCreated . + +Hier ist der neue Link: +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +Falls der Link nicht funktioniert, rufen Sie bitte folgenden auf und lassen sich einen neuen Link zuschicken: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +Sollten Sie dies bereits getan haben und nicht weiterkommen, so melden Sie sich bitte bei uns. + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/de/user_password_change.vm b/src/java/templates/de/user_password_change.vm new file mode 100644 index 0000000..1757a45 --- /dev/null +++ b/src/java/templates/de/user_password_change.vm @@ -0,0 +1,13 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie haben soeben Ihr Zugangspasswort geändert. Das alte Passwort ist somit nicht mehr gültig. Aus Sicherheitsgründen kann Ihr neuesd Passwort hier nicht mit gesendet werden. + +----------------------------------- +Ihr Benutzername: $userName +Benutzer-Id: $userId +----------------------------------- + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/de/user_password_change_1.vm b/src/java/templates/de/user_password_change_1.vm new file mode 100644 index 0000000..1757a45 --- /dev/null +++ b/src/java/templates/de/user_password_change_1.vm @@ -0,0 +1,13 @@ +Hallo $contactPersonalTitle $contactFirstName $contactFamilyName, + +Sie haben soeben Ihr Zugangspasswort geändert. Das alte Passwort ist somit nicht mehr gültig. Aus Sicherheitsgründen kann Ihr neuesd Passwort hier nicht mit gesendet werden. + +----------------------------------- +Ihr Benutzername: $userName +Benutzer-Id: $userId +----------------------------------- + +Mit freundlichen Grüßen + +Kontaktmöglichkeit und Impressum: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_account_confirmed.vm b/src/java/templates/en/user_account_confirmed.vm new file mode 100644 index 0000000..b19185f --- /dev/null +++ b/src/java/templates/en/user_account_confirmed.vm @@ -0,0 +1,10 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +You have just ($userUpdated) confirmed your account. Thank you. + +You can now login with your username $userName and password into the member area. + +Best regards + +Contact us: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_account_confirmed_1.vm b/src/java/templates/en/user_account_confirmed_1.vm new file mode 100644 index 0000000..b19185f --- /dev/null +++ b/src/java/templates/en/user_account_confirmed_1.vm @@ -0,0 +1,10 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +You have just ($userUpdated) confirmed your account. Thank you. + +You can now login with your username $userName and password into the member area. + +Best regards + +Contact us: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_password_change.vm b/src/java/templates/en/user_password_change.vm new file mode 100644 index 0000000..07c1ec2 --- /dev/null +++ b/src/java/templates/en/user_password_change.vm @@ -0,0 +1,13 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +You have just changed your password. Your old password is no longer valid. For security reasons your new password is not included in this email. + +----------------------------------- +Your user name: $userName +User id: $userId +----------------------------------- + +Best regards + +Contact us: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_password_change_1.vm b/src/java/templates/en/user_password_change_1.vm new file mode 100644 index 0000000..07c1ec2 --- /dev/null +++ b/src/java/templates/en/user_password_change_1.vm @@ -0,0 +1,13 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +You have just changed your password. Your old password is no longer valid. For security reasons your new password is not included in this email. + +----------------------------------- +Your user name: $userName +User id: $userId +----------------------------------- + +Best regards + +Contact us: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_registration.vm b/src/java/templates/en/user_registration.vm new file mode 100644 index 0000000..f38cffe --- /dev/null +++ b/src/java/templates/en/user_registration.vm @@ -0,0 +1,53 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +You have just ($userCreated) registered. If this wasn't you, please contact us immediately. + +Here is your data: +--------------------- +User id: +$userId +--------------------- +User name: +$userName +--------------------- +Personal title: +$contactPersonalTitle +--------------------- +Academical title: +$contactTitle +--------------------- +First name: +$contactFirstName +--------------------- +Family name: +$contactFamilyName +--------------------- +Street + house number: +$contactStreet $contactHouseNumber +--------------------- +ZIP code + city: +$contactZipCode $contactCity +--------------------- +Date of birth: +$contactBirthday +--------------------- +Email address: +$contactEmailAddress +--------------------- + +If you want to register, you have confirm your account. Please click on following link or copy it into your browser: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +If the above link is not working, please visit following link and send out a new link: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +Best regards + +Contact us: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_registration_1.vm b/src/java/templates/en/user_registration_1.vm new file mode 100644 index 0000000..f38cffe --- /dev/null +++ b/src/java/templates/en/user_registration_1.vm @@ -0,0 +1,53 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +You have just ($userCreated) registered. If this wasn't you, please contact us immediately. + +Here is your data: +--------------------- +User id: +$userId +--------------------- +User name: +$userName +--------------------- +Personal title: +$contactPersonalTitle +--------------------- +Academical title: +$contactTitle +--------------------- +First name: +$contactFirstName +--------------------- +Family name: +$contactFamilyName +--------------------- +Street + house number: +$contactStreet $contactHouseNumber +--------------------- +ZIP code + city: +$contactZipCode $contactCity +--------------------- +Date of birth: +$contactBirthday +--------------------- +Email address: +$contactEmailAddress +--------------------- + +If you want to register, you have confirm your account. Please click on following link or copy it into your browser: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +If the above link is not working, please visit following link and send out a new link: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +Best regards + +Contact us: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_resend_confirmation_link.vm b/src/java/templates/en/user_resend_confirmation_link.vm new file mode 100644 index 0000000..fcc12ec --- /dev/null +++ b/src/java/templates/en/user_resend_confirmation_link.vm @@ -0,0 +1,21 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +you have just ($userUpdated) requested a new confirmation link. Your registration happened on $userCreated . + +Here is your new link: +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +If the link is not working, please visit following link and send a new link to this email address.: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +If you have already tried this and you are stuck here, please contact us. + +Best regards + +Contact us: +$baseUrl/imprint.xhtml diff --git a/src/java/templates/en/user_resend_confirmation_link_1.vm b/src/java/templates/en/user_resend_confirmation_link_1.vm new file mode 100644 index 0000000..fcc12ec --- /dev/null +++ b/src/java/templates/en/user_resend_confirmation_link_1.vm @@ -0,0 +1,21 @@ +Hello $contactPersonalTitle $contactFirstName $contactFamilyName, + +you have just ($userUpdated) requested a new confirmation link. Your registration happened on $userCreated . + +Here is your new link: +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/user_confirm_account.xhtml?confirmKey=$userConfirmKey +- - - - - - - - - - - - - - - - - - - - - + +If the link is not working, please visit following link and send a new link to this email address.: + +- - - - - - - - - - - - - - - - - - - - - +$baseUrl/guest/user/resend_link.xhtml +- - - - - - - - - - - - - - - - - - - - - + +If you have already tried this and you are stuck here, please contact us. + +Best regards + +Contact us: +$baseUrl/imprint.xhtml