/*
- * Copyright (C) 2016 Roland Häder
+ * 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;
*/
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/pizzaservice-queue-factory"); //NOI18N
-
- // Lookup queue
- this.queue = (Queue) context.lookup("jms/pizzaservice-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
*/
}
/**
- * Returnes a managed instance from given mobile number
+ * 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
}
/**
- * Returnes a managed instance from given land-line number
+ * 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
*/
}
/**
- * Returnes a managed instance from given fax number
+ * 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
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) {
+ } else if (null == user) {
// Throw NPE
throw new NullPointerException("user is null"); //NOI18N
} else if (user.getUserId() == null) {
} 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().getContactGender() == null) {
+ } else if (user.getUserContact().getContactPersonalTitle() == null) {
// Throw NPE again
- throw new NullPointerException("user.userContact.contactGender is null"); //NOI18N
+ 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
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
}
/**
- * 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 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