From b7406d153cc5130ca6b4be2f0646d2dede833115 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Jun 2017 22:50:18 +0200 Subject: [PATCH] Please cherry-pick: - sendEmail() will now accept randomPassword parameter. Set to NULL if you don't want/can set it. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../database/BaseAddressbookDatabaseBean.java | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java b/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java index 387629c..146d263 100644 --- a/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java +++ b/src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java @@ -25,6 +25,7 @@ import javax.jms.JMSException; import javax.jms.ObjectMessage; import javax.mail.Address; 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; @@ -113,7 +114,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { /** * Returns a managed instance from given mobile number *

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

* @return Managed instance @@ -156,8 +157,8 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { /** * Returns a managed instance from given land-line number *

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

* @return Managed instance */ @@ -199,7 +200,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { /** * Returns a managed instance from given fax number *

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

* @return Managed instance @@ -287,58 +288,58 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { /** * Merges given (detached) contact's data *

- * @param detachedContact Contact instance to merge + * @param contact Contact instance to merge *

* @return Detached contact instance */ - protected Contact mergeContactData (final Contact detachedContact) { + protected Contact mergeContactData (final Contact contact) { // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N // The contact instance must be valid - if (null == detachedContact) { + if (null == contact) { // Throw NPE again throw new NullPointerException("detachedContact is null"); //NOI18N - } else if (detachedContact.getContactId() == null) { + } else if (contact.getContactId() == null) { // Throw NPE again throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N - } else if (detachedContact.getContactId() < 1) { + } else if (contact.getContactId() < 1) { // Not valid - throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N + throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), contact.getContactId())); //NOI18N } // Get contact from it and find it - Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId()); + Contact managedContact = this.getEntityManager().find(contact.getClass(), contact.getContactId()); // Should be found - assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", detachedContact.getContactId()); //NOI18N + assert (managedContact instanceof Contact) : MessageFormat.format("Contact with id {0} not found, but should be.", contact.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) { + if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { // Make fax numbers managed - managedContact.setContactFaxNumber(this.getManaged(detachedContact.getContactFaxNumber(), detachedContact.getContactFaxNumber())); + managedContact.setContactFaxNumber(this.getManaged(contact.getContactFaxNumber(), contact.getContactFaxNumber())); } // Is a land-line number set? - if (detachedContact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { // Make land-line numbers managed - managedContact.setContactLandLineNumber(this.getManaged(detachedContact.getContactLandLineNumber(), detachedContact.getContactLandLineNumber())); + managedContact.setContactLandLineNumber(this.getManaged(contact.getContactLandLineNumber(), contact.getContactLandLineNumber())); } // Is a mobile number set? - if (detachedContact.getContactMobileNumber() instanceof DialableMobileNumber) { + if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { // Make mobile numbers managed - managedContact.setContactMobileNumber(this.getManaged(detachedContact.getContactMobileNumber(), detachedContact.getContactMobileNumber())); + managedContact.setContactMobileNumber(this.getManaged(contact.getContactMobileNumber(), contact.getContactMobileNumber())); } // Set updated timestamp managedContact.setContactUpdated(new GregorianCalendar()); // Copy all - managedContact.copyAll(detachedContact); + ContactUtils.copyAll(contact, managedContact); // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N @@ -432,13 +433,15 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { * Sends an email with given subject line, template name to given recipient * and user data *

- * @param subjectLine Subject line - * @param templateName Template name - * @param emailAddress Recipient's email address - * @param user User instance - * @param baseUrl Base URL + * @param subjectLine Subject line + * @param templateName Template name + * @param emailAddress Recipient's email address + * @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 Address emailAddress, final User user, final String baseUrl) { + protected void sendEmail (final String subjectLine, final String templateName, final Address emailAddress, final User user, final String baseUrl, final String randomPassword) { // Trace message this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendEmail: subjectLine={0},templateName={1},emailAddress={2},user={3},baseUrl={4} - CALLED!", subjectLine, templateName, emailAddress, user, baseUrl)); //NOI18N @@ -458,7 +461,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { } else if (null == emailAddress) { // Throw NPE throw new NullPointerException("emailAddress is null"); //NOI18N - }else if (null == user) { + } else if (null == user) { // Throw NPE throw new NullPointerException("user is null"); //NOI18N } else if (user.getUserId() == null) { @@ -496,8 +499,9 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { // Set all values Properties variables = UserUtils.getAllUserFields(user); - // Set base URL + // Set base URL and random password variables.put("baseUrl", baseUrl); //NOI18N + variables.put("randomPassword", randomPassword); //NOI18N // Set all // @TODO Language from message bundle @@ -528,7 +532,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { * should be the same. *

* @param contact Contact to set instances - * @param other Other contact to get instances from + * @param other Other contact to get instances from */ protected void setAllContactPhoneEntries (final Contact contact, final Contact other) { // Trace message @@ -607,13 +611,13 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean { /** * Updates all contact's phone entry's updated timestamps *

- * @param contact Contact instance to update - * @param isMobileUnlinked Whether a cellphone entry has been unlinked in - * contact instance + * @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 + * 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 -- 2.39.5