All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aoindustries.website.signup.MinimalConfirmationCompletedActionHelper Maven / Gradle / Ivy

/*
 * aoweb-struts-core - Core API for legacy Struts-based site framework with AOServ Platform control panels.
 * Copyright (C) 2009-2013, 2015, 2016, 2017, 2018, 2019  AO Industries, Inc.
 *     [email protected]
 *     7262 Bull Pen Cir
 *     Mobile, AL 36695
 *
 * This file is part of aoweb-struts-core.
 *
 * aoweb-struts-core is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aoweb-struts-core 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with aoweb-struts-core.  If not, see .
 */
package com.aoindustries.website.signup;

import com.aoindustries.aoserv.client.AOServConnector;
import com.aoindustries.aoserv.client.billing.PackageDefinition;
import com.aoindustries.aoserv.client.reseller.Brand;
import com.aoindustries.encoding.ChainWriter;
import com.aoindustries.net.HostAddress;
import com.aoindustries.util.i18n.ThreadLocale;
import com.aoindustries.website.Mailer;
import com.aoindustries.website.SiteSettings;
import com.aoindustries.website.Skin;
import static com.aoindustries.website.signup.ApplicationResources.accessor;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionServlet;

/**
 * @author  AO Industries, Inc.
 */
final public class MinimalConfirmationCompletedActionHelper {

	/**
	 * Make no instances.
	 */
	private MinimalConfirmationCompletedActionHelper() {}

	public static void sendSupportSummaryEmail(
		ActionServlet servlet,
		HttpServletRequest request,
		String pkey,
		String statusKey,
		SiteSettings siteSettings,
		PackageDefinition packageDefinition,
		SignupBusinessForm signupBusinessForm,
		SignupTechnicalForm signupTechnicalForm,
		SignupBillingInformationForm signupBillingInformationForm
	) {
		try {
			sendSummaryEmail(servlet, request, pkey, statusKey, siteSettings.getBrand().getAowebStrutsSignupAdminAddress(), siteSettings, packageDefinition, signupBusinessForm, signupTechnicalForm, signupBillingInformationForm);
		} catch(Exception err) {
			servlet.log("Unable to send sign up details to support admin address", err);
		}
	}

	/**
	 * Sends the customer emails and stores the successAddresses and failureAddresses as request attributes.
	 */
	public static void sendCustomerSummaryEmails(
		ActionServlet servlet,
		HttpServletRequest request,
		String pkey,
		String statusKey,
		SiteSettings siteSettings,
		PackageDefinition packageDefinition,
		SignupBusinessForm signupBusinessForm,
		SignupTechnicalForm signupTechnicalForm,
		SignupBillingInformationForm signupBillingInformationForm
	) {
		Set addresses = new HashSet<>();
		addresses.add(signupTechnicalForm.getBaEmail());
		addresses.add(signupBillingInformationForm.getBillingEmail());
		Set successAddresses = new HashSet<>();
		Set failureAddresses = new HashSet<>();
		Iterator I=addresses.iterator();
		while(I.hasNext()) {
			String address=I.next();
			boolean success = sendSummaryEmail(servlet, request, pkey, statusKey, address, siteSettings, packageDefinition, signupBusinessForm, signupTechnicalForm, signupBillingInformationForm);
			if(success) successAddresses.add(address);
			else failureAddresses.add(address);
		}

		// Store request attributes
		request.setAttribute("successAddresses", successAddresses);
		request.setAttribute("failureAddresses", failureAddresses);
	}

	/**
	 * Sends a summary email and returns true if successful.
	 */
	private static boolean sendSummaryEmail(
		ActionServlet servlet,
		HttpServletRequest request,
		String pkey,
		String statusKey,
		String recipient,
		SiteSettings siteSettings,
		PackageDefinition packageDefinition,
		SignupBusinessForm signupBusinessForm,
		SignupTechnicalForm signupTechnicalForm,
		SignupBillingInformationForm signupBillingInformationForm
	) {
		try {
			// Find the locale and related resource bundles
			Locale userLocale = ThreadLocale.get();
			String charset = Skin.getCharacterSet(userLocale);

			// Generate the email contents
			CharArrayWriter cout = new CharArrayWriter();
			ChainWriter emailOut = new ChainWriter(cout);
			String htmlLang = ServerConfirmationCompletedActionHelper.getHtmlLang(userLocale);
			emailOut.print("\n"
					+ "\n"
						 + "\n"
						 + "    \n");
			// Embed the text-only style sheet
			InputStream cssIn = servlet.getServletContext().getResourceAsStream("/textskin/global.css");
			if(cssIn!=null) {
				try {
					emailOut.print("    \n");
				} finally {
					cssIn.close();
				}
			} else {
				servlet.log("Warning: Unable to find resource: /global/textskin.css");
			}
			emailOut.print("\n"
						 + "\n"
						 + "\n"
						 + "    \n"
						 + "    \n");
			SignupSelectPackageActionHelper.printConfirmation(emailOut, packageDefinition);
			AOServConnector rootConn = siteSettings.getRootAOServConnector();
			emailOut.print("    \n"
						 + "    \n");
			SignupBusinessActionHelper.printConfirmation(emailOut, rootConn, signupBusinessForm);
			emailOut.print("    \n"
						 + "    \n");
			SignupTechnicalActionHelper.printConfirmation(emailOut, rootConn, signupTechnicalForm);
			emailOut.print("    \n"
						 + "    \n");
			SignupBillingInformationActionHelper.printConfirmation(emailOut, signupBillingInformationForm);
			emailOut.print("
\n" + " ").print(accessor.getMessage(statusKey, pkey)).print("
\n" + "
\n" + " ").print(accessor.getMessage("serverConfirmationCompleted.belowIsSummary")).print("
\n" + "
\n" + "
").print(accessor.getMessage("steps.selectPackage.label")).print("
 
").print(accessor.getMessage("steps.businessInfo.label")).print("
 
").print(accessor.getMessage("steps.technicalInfo.label")).print("
 
").print(accessor.getMessage("steps.billingInformation.label")).print("
\n" + "\n" + "\n"); emailOut.flush(); // Send the email Brand brand = siteSettings.getBrand(); Mailer.sendEmail( HostAddress.valueOf(brand.getSignupEmailAddress().getDomain().getAOServer().getHostname()), "text/html", charset, brand.getSignupEmailAddress().toString(), brand.getSignupEmailDisplay(), Collections.singletonList(recipient), accessor.getMessage("serverConfirmationCompleted.email.subject", pkey), cout.toString() ); return true; } catch(RuntimeException | IOException | SQLException | MessagingException err) { servlet.log("Unable to send sign up details to "+recipient, err); return false; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy