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;
import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
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;
}
/**
- * Updates all contacts's phone entry's created timestamps
+ * Updates all contact's phone entry's created timestamps
* <p>
* @param contact Contact instance to update
*/
/**
* Returns a managed instance from given mobile number
* <p>
- * @param mobileNumber Mobile number
+ * @param mobileNumber Mobile instance
* @param fetchedNumber Found mobile number in database
* <p>
* @return Managed instance
/**
* Returns a managed instance from given land-line number
* <p>
- * @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
* <p>
* @return Managed instance
*/
/**
* Returns a managed instance from given fax number
* <p>
- * @param faxNumber Fax number
+ * @param faxNumber Fax instance
* @param fetchedNumber Found fax number in database
* <p>
* @return Managed instance
return managedNumber;
}
+ /**
+ * Get back a managed instance from given user
+ * <p>
+ * @param user Unmanaged/detached user instance
+ * <p>
+ * @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
* <p>
*/
protected Contact mergeContactData (final Contact detachedContact) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: detachedContact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
// The contact instance must be valid
if (null == detachedContact) {
}
// Get contact from it and find it
- Contact foundContact = this.getEntityManager().getReference(detachedContact.getClass(), detachedContact.getContactId());
+ Contact managedContact = this.getEntityManager().find(detachedContact.getClass(), detachedContact.getContactId());
// Should be found
- assert (foundContact 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.", detachedContact.getContactId()); //NOI18N
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.updateUserPersonalData: foundContact.contactId={1}", this.getClass().getSimpleName(), foundContact.getContactId())); //NOI18N
-
- // Merge contact instance
- Contact managedContact = this.getEntityManager().merge(foundContact);
+ 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) {
managedContact.setContactUpdated(new GregorianCalendar());
// Copy all
- managedContact.copyAll(detachedContact);
+ ContactUtils.copyAll(detachedContact, managedContact);
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
* Sends an email with given subject line, template name to given recipient
* and user data
* <p>
- * @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
} else if (null == emailAddress) {
// Throw NPE
throw new NullPointerException("emailAddress is null"); //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
}
// Prepare mail wrapper
// 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", ""); //NOI18N
+
+ // Is the random password set?
+ if ((randomPassword instanceof String) && (!randomPassword.isEmpty())) {
+ variables.put("randomPassword", randomPassword); //NOI18N
+ }
// Set all
// @TODO Language from message bundle
* should be the same.
* <p>
* @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
/**
* Updates all contact's phone entry's updated timestamps
* <p>
- * @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