/*
- * Copyright (C) 2016 Roland Haeder
+ * 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
import java.util.Objects;
import java.util.Properties;
import javax.ejb.EJBException;
-import javax.faces.FacesException;
-import javax.jms.Connection;
import javax.jms.JMSException;
-import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
-import javax.jms.Queue;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.Session;
import javax.mail.Address;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
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.cellphone.DialableCellphoneNumber;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
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;
/**
* A helper class for beans that access the database.
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
*/
public abstract class BasePizzaDatabaseBean extends BaseDatabaseBean {
*/
private static final long serialVersionUID = 12_895_410_275_811_963L;
- /**
- * Connection
- */
- private Connection connection;
-
- /**
- * Message producer
- */
- private MessageProducer messageProducer;
-
- /**
- * Mailer message queue
- */
- private Queue queue;
-
- /**
- * Session instance
- */
- private Session session;
-
/**
* Protected constructor
*/
protected BasePizzaDatabaseBean () {
// Call super constructor
- super();
-
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Get factory from JMS resource
- QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/jlandingpage-queue-factory"); //NOI18N
-
- // Lookup queue
- this.queue = (Queue) context.lookup("jms/jlandingpage-email-queue"); //NOI18N
-
- // Create connection
- this.connection = connectionFactory.createConnection();
-
- // Init session instance
- this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // And message producer
- this.messageProducer = this.session.createProducer(this.queue);
- } catch (final NamingException | JMSException e) {
- // Continued to throw
- throw new FacesException(e);
- }
+ super("jms/pizzaservice-queue-factory", "jms/pizzaservice-email-queue"); //NOI18N
}
/**
- * 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
*/
protected void setAllContactPhoneEntriesCreated (final Contact contact) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesCreated: contact={0} - CALLED!", contact)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
// The contact instance must be valid
if (null == contact) {
// Get all phone instances
DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
DialableFaxNumber faxNumber = contact.getContactFaxNumber();
- DialableCellphoneNumber cellphoneNumber = contact.getContactCellphoneNumber();
+ DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntriesCreated: landLineNumber={0},faxNumber={1},cellphoneNumber={2}", landLineNumber, faxNumber, cellphoneNumber)); //NOI18N
+ 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("setAllContactPhoneEntriesCreated: Setting created timestamp for land-line number ..."); //NOI18N
+ 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("setAllContactPhoneEntriesCreated: Setting created timestamp for fax number ..."); //NOI18N
+ 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 ((cellphoneNumber instanceof DialableCellphoneNumber) && (cellphoneNumber.getPhoneId() == null)) {
+ if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() == null)) {
// Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ..."); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: Setting created timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
// Set updated timestamp
- cellphoneNumber.setPhoneEntryCreated(new GregorianCalendar());
+ mobileNumber.setPhoneEntryCreated(new GregorianCalendar());
}
// Trace message
- this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesCreated: EXIT!"); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesCreated: EXIT!", this.getClass().getSimpleName())); //NOI18N
}
/**
- * Returnes a detached instance from given cellphone instance
+ * Returns a managed instance from given mobile number
* <p>
- * @param cellphoneNumber Cellphone instance
- * @param fetchedNumber Found cellphone number in database
+ * @param mobileNumber Mobile instance
+ * @param fetchedNumber Found mobile number in database
* <p>
- * @return Detached instance
+ * @return Managed instance
*/
- protected DialableCellphoneNumber getDetached (final DialableCellphoneNumber cellphoneNumber, final DialableCellphoneNumber fetchedNumber) {
+ protected DialableMobileNumber getManaged (final DialableMobileNumber mobileNumber, final DialableMobileNumber fetchedNumber) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: cellphoneNumber={0},fetchedNumber={1} - CALLED!", cellphoneNumber, fetchedNumber)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: mobileNumber={1},fetchedNumber={2} - CALLED!", this.getClass().getSimpleName(), mobileNumber, fetchedNumber)); //NOI18N
// Should be valid
- if (null == cellphoneNumber) {
+ if (null == mobileNumber) {
// Throw NPE
- throw new NullPointerException("cellphoneNumber is null"); //NOI18N
+ 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("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
-
- // Init query instance
- DialableCellphoneNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
// Default is null
- DialableCellphoneNumber detachedNumber = null;
+ DialableMobileNumber managedNumber = null;
// Is there a difference?
- if (!PhoneUtils.isSameCellphoneNumber(cellphoneNumber, fetchedNumber)) {
+ if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
// Merge this entry
- detachedNumber = this.getEntityManager().merge(foundNumber);
-
- // Copy all
+ managedNumber = this.getEntityManager().merge(fetchedNumber);
}
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
// Return it
- return detachedNumber;
+ return managedNumber;
}
/**
- * Returnes a detached instance from given land-line instance
+ * Returns a managed instance from given land-line number
* <p>
* @param landLineNumber Land-line instance
- * @param fetchedNumber Found land-line number in database
+ * @param fetchedNumber Found land-line number in database
* <p>
- * @return Detached instance
+ * @return Managed instance
*/
- protected DialableLandLineNumber getDetached (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
+ protected DialableLandLineNumber getManaged (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber fetchedNumber) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: landLineNumber={0},fetchedNumber={1} - CALLED!", landLineNumber, fetchedNumber)); //NOI18N
+ 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("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
-
- // Init query instance
- DialableLandLineNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
// Default is null
- DialableLandLineNumber detachedNumber = null;
+ DialableLandLineNumber managedNumber = null;
// Is there a difference?
if (!PhoneUtils.isSameLandLineNumber(landLineNumber, fetchedNumber)) {
// Merge this entry
- detachedNumber = this.getEntityManager().merge(foundNumber);
+ managedNumber = this.getEntityManager().merge(fetchedNumber);
}
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
// Return it
- return detachedNumber;
+ return managedNumber;
}
/**
- * Returnes a detached instance from given fax instance
+ * Returns a managed instance from given fax number
* <p>
- * @param faxNumber Fax instance
+ * @param faxNumber Fax instance
* @param fetchedNumber Found fax number in database
* <p>
- * @return Detached instance
+ * @return Managed instance
*/
- protected DialableFaxNumber getDetached (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
+ protected DialableFaxNumber getManaged (final DialableFaxNumber faxNumber, final DialableFaxNumber fetchedNumber) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: faxNumber={0},fetchedNumber={1} - CALLED!", faxNumber, fetchedNumber)); //NOI18N
+ 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("getDetached: fetchedNumber.phoneId={0}", fetchedNumber.getPhoneId())); //NOI18N
-
- // Init query instance
- DialableFaxNumber foundNumber = this.getEntityManager().find(fetchedNumber.getClass(), fetchedNumber.getPhoneId());
-
- // Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("getDetached: foundNumber={0}", foundNumber)); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: fetchedNumber.phoneId={1}", this.getClass().getSimpleName(), fetchedNumber.getPhoneId())); //NOI18N
// Default is null
- DialableFaxNumber detachedNumber = null;
+ DialableFaxNumber managedNumber = null;
// Is there a difference?
if (!PhoneUtils.isSameFaxNumber(faxNumber, fetchedNumber)) {
// Merge this entry
- detachedNumber = this.getEntityManager().merge(foundNumber);
+ managedNumber = this.getEntityManager().merge(fetchedNumber);
}
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("getDetached: detachedNumber={0} - EXIT!", detachedNumber)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getDetached: managedNumber={1} - EXIT!", this.getClass().getSimpleName(), managedNumber)); //NOI18N
// Return it
- return detachedNumber;
+ return managedNumber;
}
/**
- * Merges given contact's data
+ * Get back a managed instance from given user
* <p>
- * @param contact Contact instance to merge
+ * @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>
+ * @param detachedContact Contact instance to merge
* <p>
* @return Detached contact instance
*/
- protected Contact mergeContactData (final Contact contact) {
+ protected Contact mergeContactData (final Contact detachedContact) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: contact={0} - CALLED!", contact)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: contact={1} - CALLED!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
// The contact instance must be valid
- if (null == contact) {
+ if (null == detachedContact) {
// Throw NPE again
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
+ throw new NullPointerException("detachedContact is null"); //NOI18N
+ } else if (detachedContact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
+ throw new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
+ } else if (detachedContact.getContactId() < 1) {
// Not valid
- throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
}
- // Set updated timestamp
- contact.setContactUpdated(new GregorianCalendar());
-
// Get contact from it and find it
- Contact foundContact = this.getEntityManager().find(contact.getClass(), contact.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.", contact.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("updateUserPersonalData: contact.contactId={0}", foundContact.getContactId())); //NOI18N
+ 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()));
+ }
- // Merge contact instance
- Contact detachedContact = this.getEntityManager().merge(foundContact);
+ // 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
- detachedContact.copyAll(contact);
+ ContactUtils.copyAll(detachedContact, managedContact);
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactData: detachedContact={0} - EXIT!", detachedContact)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.mergeContactData: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
// Return detached contact
- return detachedContact;
+ return managedContact;
}
/**
* <p>
* @param detachedContact Detached contact instance
*/
- protected void mergeContactsCellphoneLandLineFaxNumbers (final Contact detachedContact) {
+ protected void mergeContactsMobileLandLineFaxNumbers (final Contact detachedContact) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeContactsCellphoneLandLineFaxNumbers: detachedContact={0} - CALLED!", detachedContact)); //NOI18N
+ 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 new NullPointerException("detachedContact.contactId is null"); //NOI18N //NOI18N
} else if (detachedContact.getContactId() < 1) {
// Not valid
- throw new IllegalStateException(MessageFormat.format("detachedContact.contactId={0} is not valid.", detachedContact.getContactId())); //NOI18N
+ throw new IllegalStateException(MessageFormat.format("{0}.detachedContact.contactId={1} is not valid.", this.getClass().getSimpleName(), detachedContact.getContactId())); //NOI18N
}
// Get all instances
- DialableCellphoneNumber cellphone = detachedContact.getContactCellphoneNumber();
+ DialableMobileNumber cellphone = detachedContact.getContactMobileNumber();
DialableLandLineNumber landLine = detachedContact.getContactLandLineNumber();
DialableFaxNumber fax = detachedContact.getContactFaxNumber();
// Is there a cellphone instance set?
- if (cellphone instanceof DialableCellphoneNumber) {
+ 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
- DialableCellphoneNumber foundCellphone = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
-
- // Should be there
- assert (foundCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", foundCellphone.getPhoneId()); //NOI18N
-
- // Then merge it, too
- DialableCellphoneNumber detachedCellphone = this.getEntityManager().merge(foundCellphone);
+ DialableMobileNumber foundMobile = this.getEntityManager().find(cellphone.getClass(), cellphone.getPhoneId());
// Should be there
- assert (detachedCellphone instanceof DialableCellphoneNumber) : MessageFormat.format("Cellphone number with id {0} not found but should be.", detachedCellphone.getPhoneId()); //NOI18N
+ assert (foundMobile instanceof DialableMobileNumber) : MessageFormat.format("Mobile number with id {0} not found but should be.", foundMobile.getPhoneId()); //NOI18N
// Copy all
- detachedCellphone.copyAll(detachedContact.getContactCellphoneNumber());
+ foundMobile.copyAll(detachedContact.getContactMobileNumber());
// Set it back
- detachedContact.setContactCellphoneNumber(detachedCellphone);
+ detachedContact.setContactMobileNumber(foundMobile);
}
// Is there a fax instance set?
// 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 detachedFax = this.getEntityManager().merge(foundFax);
-
- // Should be there
- assert (detachedFax instanceof DialableFaxNumber) : MessageFormat.format("Fax number with id {0} not found but should be.", detachedFax.getPhoneId()); //NOI18N
-
// Copy all
- detachedFax.copyAll(detachedContact.getContactFaxNumber());
+ foundFax.copyAll(detachedContact.getContactFaxNumber());
// Set it back
- detachedContact.setContactFaxNumber(detachedFax);
+ detachedContact.setContactFaxNumber(foundFax);
}
// Is there a fax instance set?
// 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 detachedLandLine = this.getEntityManager().merge(foundLandLine);
-
- // Should be there
- assert (detachedLandLine instanceof DialableLandLineNumber) : MessageFormat.format("Land line number with id {0} not found but should be.", detachedLandLine.getPhoneId()); //NOI18N
-
// Copy all
- detachedLandLine.copyAll(detachedContact.getContactLandLineNumber());
+ foundLandLine.copyAll(detachedContact.getContactLandLineNumber());
// Set it back
- detachedContact.setContactLandLineNumber(detachedLandLine);
+ detachedContact.setContactLandLineNumber(foundLandLine);
}
// Trace message
- this.getLoggerBeanLocal().logTrace("mergeContactsCellphoneLandLineFaxNumbers: EXIT!"); //NOI18N
+ this.getLoggerBeanLocal().logTrace("mergeContactsMobileLandLineFaxNumbers: EXIT!"); //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
emailWrapper.setRecipient(emailAddress);
emailWrapper.setLocale(user.getUserLocale());
emailWrapper.setSubjectLine(subjectLine);
- emailWrapper.setTemplateName(templateName); //NOI18N
+ emailWrapper.setTemplateName(templateName);
emailWrapper.setTemplateVariables(variables);
try {
// Send out email change
- ObjectMessage message = this.session.createObjectMessage();
+ ObjectMessage message = this.getSession().createObjectMessage();
message.setObject(emailWrapper);
// Send message
- this.sendMessage(message, this.messageProducer);
+ this.sendMessage(message);
} catch (final JMSException ex) {
// Throw again
throw new EJBException(ex);
* 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
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntries: contact={0},other={1} - CALLED!", contact, other)); //NOI18N
+ 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) {
}
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactCellphoneNumber={0}", other.getContactCellphoneNumber())); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: other.contactMobileNumber={0}", other.getContactMobileNumber())); //NOI18N
// Is other cellphone not set?
- if ((other.getContactCellphoneNumber() == null) || (PhoneUtils.isSameCellphoneNumber(contact.getContactCellphoneNumber(), other.getContactCellphoneNumber()))) {
+ if ((other.getContactMobileNumber() == null) || (PhoneUtils.isSameMobileNumber(contact.getContactMobileNumber(), other.getContactMobileNumber()))) {
// Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntries: Copying cellphone entry ..."); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntries: Copying cellphone entry ...", this.getClass().getSimpleName())); //NOI18N
// Is the fax number set?
- if (other.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
+ if (other.getContactMobileNumber() instanceof DialableMobileNumber) {
// Copy cellphone number
- contact.setContactCellphoneNumber(this.getDetached(other.getContactCellphoneNumber(), contact.getContactCellphoneNumber()));
+ contact.setContactMobileNumber(this.getManaged(other.getContactMobileNumber(), contact.getContactMobileNumber()));
} else {
// Null it
- contact.setContactCellphoneNumber(null);
+ contact.setContactMobileNumber(null);
}
}
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactLandLineNumber={0}", other.getContactLandLineNumber())); //NOI18N
+ 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("setAllContactPhoneEntries: Copying land-line entry ..."); //NOI18N
+ 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.getDetached(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
+ contact.setContactLandLineNumber(this.getManaged(other.getContactLandLineNumber(), contact.getContactLandLineNumber()));
} else {
// Null it
contact.setContactLandLineNumber(null);
}
// Debug message
- this.getLoggerBeanLocal().logDebug(MessageFormat.format("setAllContactPhoneEntries: other.contactFaxNumber={0}", other.getContactFaxNumber())); //NOI18N
+ 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("setAllContactPhoneEntries: Copying fax entry ..."); //NOI18N
+ 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.getDetached(other.getContactFaxNumber(), contact.getContactFaxNumber()));
+ contact.setContactFaxNumber(this.getManaged(other.getContactFaxNumber(), contact.getContactFaxNumber()));
} else {
// Null it
contact.setContactFaxNumber(null);
}
// Trace message
- this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntries: EXIT!"); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntries: EXIT!", this.getClass().getSimpleName())); //NOI18N
}
/**
- * Updates all contacts's phone entry's updated timestamps
+ * Updates all contact's phone entry's updated timestamps
* <p>
- * @param contact Contact instance to update
- * @param isCellphoneUnlinked 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 isCellphoneUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
+ protected void setAllContactPhoneEntriesUpdated (final Contact contact, final boolean isMobileUnlinked, final boolean isLandlineUnlinked, final boolean isFaxUnlinked) {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("setAllContactPhoneEntriesUpdated: contact={0},isCellphoneUnlinked={1},isLandlineUnlinked={2},isFaxUnlinked={3} - CALLED", contact, isCellphoneUnlinked, isLandlineUnlinked, isFaxUnlinked)); //NOI18N
+ 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) {
// Get all phone instances
DialableLandLineNumber landLineNumber = contact.getContactLandLineNumber();
DialableFaxNumber faxNumber = contact.getContactFaxNumber();
- DialableCellphoneNumber cellphoneNumber = contact.getContactCellphoneNumber();
+ DialableMobileNumber mobileNumber = contact.getContactMobileNumber();
// Flags and instances must be constistent
- if (isCellphoneUnlinked && cellphoneNumber instanceof DialableCellphoneNumber) {
+ if (isMobileUnlinked && mobileNumber instanceof DialableMobileNumber) {
// Bad state
- throw new IllegalStateException("isCellPhoneUnlinked is TRUE, but cellphoneNumber is set."); //NOI18N
+ 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
// Is a phone number instance set?
if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneId() instanceof Long) && (landLineNumber.getPhoneId() > 0)) {
// Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for land-line number ..."); //NOI18N
+ 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("setAllContactPhoneEntriesUpdated: Setting updated timestamp for fax number ..."); //NOI18N
+ 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 ((cellphoneNumber instanceof DialableCellphoneNumber) && (cellphoneNumber.getPhoneId() instanceof Long) && (cellphoneNumber.getPhoneId() > 0)) {
+ if ((mobileNumber instanceof DialableMobileNumber) && (mobileNumber.getPhoneId() instanceof Long) && (mobileNumber.getPhoneId() > 0)) {
// Debug message
- this.getLoggerBeanLocal().logDebug("setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ..."); //NOI18N
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: Setting updated timestamp for cellphone number ...", this.getClass().getSimpleName())); //NOI18N
// Set updated timestamp
- cellphoneNumber.setPhoneEntryUpdated(new GregorianCalendar());
+ mobileNumber.setPhoneEntryUpdated(new GregorianCalendar());
}
// Trace message
- this.getLoggerBeanLocal().logTrace("setAllContactPhoneEntriesUpdated: EXIT!"); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.setAllContactPhoneEntriesUpdated: EXIT!", this.getClass().getSimpleName())); //NOI18N
}
}