[pal-cvs 2885] [629] replaced email notification feature.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2007年 10月 14日 (日) 22:13:01 JST


Revision: 629
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=629
Author:   shinsuke
Date:     2007-10-14 22:13:00 +0900 (Sun, 14 Oct 2007)

Log Message:
-----------
replaced email notification feature.

Modified Paths:
--------------
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/filter/UserRegistrationFilter.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CustomerServiceImpl.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/signup/SignupConfirmAction.java
    pompei/portlets/pompei-core/trunk/src/main/resources/appMessages.properties

Added Paths:
-----------
    pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/notification/signup/
    pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/notification/signup/user-signup.vm

Removed Paths:
-------------
    pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/userreg/email/userRegistrationEmail.vm


-------------- next part --------------
Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/PompeiConstants.java	2007-10-14 13:13:00 UTC (rev 629)
@@ -238,8 +238,6 @@
 
     public static final String USER_SECRET_ANSWER = "user.secret.answer";
 
-    public static final String EMAIL_SUBJECT_USER_REGISTRATION = "email.subject.registration";
-
     public static final String ADMINISTRATOR_EMAIL = "administratorEmail";
 
     public static final String DEFAULT_ADMINISTRATOR_EMAIL = "root****@pal*****";
@@ -248,6 +246,10 @@
 
     public static final String DEFAULT_ORDER_NOTIFICATION_PATH = "/notification/order/";
 
+    public static final String SIGNUP_NOTIFICATION_PATH = "signupNotificationPath";
+
+    public static final String DEFAULT_SIGNUP_NOTIFICATION_PATH = "/notification/signup/";
+
     public static final String DEFAULT_TEMPLATE_PATH = "/WEB-INF/template/";
 
     public static final String SMTP_HOST = "smtpHost";

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/filter/UserRegistrationFilter.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/filter/UserRegistrationFilter.java	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/filter/UserRegistrationFilter.java	2007-10-14 13:13:00 UTC (rev 629)
@@ -100,37 +100,6 @@
         // user params
         userRegistrationParams = new HashMap<String, Object>();
 
-        String templateLocation = portletConfig
-                .getInitParameter(PompeiConstants.EMAIL_TEMPLATE_LOCATION);
-        if (templateLocation == null) {
-            templateLocation = PompeiConstants.DEFAULT_TEMPLATE_LOCATION;
-        }
-        templateLocation = portletContext.getRealPath(templateLocation);
-        userRegistrationParams.put(PompeiConstants.EMAIL_TEMPLATE_LOCATION,
-                templateLocation);
-
-        String templateName = portletConfig
-                .getInitParameter(PompeiConstants.EMAIL_TEMPLATE_NAME);
-        if (templateName == null) {
-            templateName = PompeiConstants.DEFAULT_TEMPLATE_NAME;
-        }
-        userRegistrationParams.put(PompeiConstants.EMAIL_TEMPLATE_NAME,
-                templateName);
-
-        ArrayList<String> roots = new ArrayList<String>(1);
-        roots.add(templateLocation);
-
-        try {
-            JetspeedTemplateLocator templateLocator = new JetspeedTemplateLocator(
-                    roots, "email", portletContext.getRealPath("/"));
-            templateLocator.start();
-            userRegistrationParams.put(PompeiConstants.TEMPLATE_LOCATOR,
-                    templateLocator);
-        } catch (FileNotFoundException e) {
-            throw new PortletException("Could not start the template locator.",
-                    e);
-        }
-
         // roles
         List<String> roles = getInitParameterList(portletConfig,
                 PompeiConstants.ROLES);

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CustomerServiceImpl.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CustomerServiceImpl.java	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CustomerServiceImpl.java	2007-10-14 13:13:00 UTC (rev 629)
@@ -1,14 +1,21 @@
 package jp.sf.pal.pompei.service.impl;
 
+import java.io.StringWriter;
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Properties;
 import java.util.StringTokenizer;
 
 import javax.faces.context.FacesContext;
-import javax.portlet.PortletConfig;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
 
 import jp.sf.pal.common.CommonException;
 import jp.sf.pal.pompei.PompeiConstants;
@@ -30,6 +37,7 @@
 import jp.sf.pal.pompei.service.CustomerService;
 import jp.sf.pal.pompei.util.SystemUtil;
 import jp.sf.pal.pompei.util.UserRegistrationUtil;
+import jp.sf.pal.pompei.util.VelocityUtil;
 
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.PortalReservedParameters;
@@ -43,6 +51,8 @@
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.security.User;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
 
 public class CustomerServiceImpl implements CustomerService {
 
@@ -173,8 +183,6 @@
         String password = userInfo.remove(PompeiConstants.USER_PASSWORD);
         String verifyPassword = userInfo
                 .remove(PompeiConstants.USER_VERIFY_PASSWORD);
-        String emailSubject = userInfo
-                .remove(PompeiConstants.EMAIL_SUBJECT_USER_REGISTRATION);
         if (!UserRegistrationUtil
                 .getBoolean(PompeiConstants.FORCE_GENERATED_PASSWORD)) {
             if (password == null || password.equals("")) {
@@ -304,25 +312,29 @@
 
             try {
                 // template
-                String templ = getTemplatePath(FacesContext
-                        .getCurrentInstance());
-
-                if (templ == null) {
-                    cancelToAddCustomer(userInfo, customer, addressBook);
-                    throw new CommonException(
-                            "error.registration_completed_but_could_not_find_template",
-                            "Email template is not available.");
-                }
-                SystemUtil
-                        .getPortalAdministration()
-                        .sendEmail(
-                                (PortletConfig) FacesContext
-                                        .getCurrentInstance()
-                                        .getExternalContext().getRequestMap()
-                                        .get("javax.portlet.PortletConfig"),
-                                userInfo
-                                        .get(PompeiConstants.USER_BUSINESS_INFO_ONLINE_EMAIL),
-                                emailSubject, templ, userInfo);
+                //                String templ = getTemplatePath(FacesContext
+                //                        .getCurrentInstance());
+                //
+                //                if (templ == null) {
+                //                    cancelToAddCustomer(userInfo, customer, addressBook);
+                //                    throw new CommonException(
+                //                            "error.registration_completed_but_could_not_find_template",
+                //                            "Email template is not available.");
+                //                }
+                //                SystemUtil
+                //                        .getPortalAdministration()
+                //                        .sendEmail(
+                //                                (PortletConfig) FacesContext
+                //                                        .getCurrentInstance()
+                //                                        .getExternalContext().getRequestMap()
+                //                                        .get("javax.portlet.PortletConfig"),
+                //                                userInfo
+                //                                        .get(PompeiConstants.USER_BUSINESS_INFO_ONLINE_EMAIL),
+                //                                emailSubject, templ, userInfo);
+                //TODO move user-signup.vm to init-param
+                sendSignupMail(userInfo, userInfo
+                        .get(PompeiConstants.USER_BUSINESS_INFO_ONLINE_EMAIL),
+                        SystemUtil.getAdministratorEmail(), "user-signup.vm");
             } catch (Exception e) {
                 cancelToAddCustomer(userInfo, customer, addressBook);
                 throw new CommonException(
@@ -333,6 +345,55 @@
 
     }
 
+    private void sendSignupMail(Map<String, String> userInfo, String to,
+            String from, String templateName) throws Exception {
+        // set velocity context
+        VelocityContext context = new VelocityContext();
+        context.put("map", userInfo);
+
+        VelocityUtil.init();
+        StringWriter sw = new StringWriter();
+        String templatePath = SystemUtil
+                .getSignupNotificationTemplatePath(templateName);
+        // TODO i18n: encoding
+        Template template = VelocityUtil.getTemplate(templatePath, "UTF-8");
+
+        template.merge(context, sw);
+
+        String content = sw.toString();
+        if (content == null) {
+            throw new CommonException("signup.content.is.null");
+        }
+        int index = content.indexOf("\n");
+        String subject = null;
+        String body = null;
+        if (index != -1) {
+            subject = content.substring(0, index);
+            body = content.substring(index);
+        } else {
+            // TODO should throw exception?
+            subject = content;
+            body = content;
+        }
+
+        Properties props = System.getProperties();
+        // set smtp server
+        props.put("mail.smtp.host", SystemUtil.getSmtpHost());
+        Session session = Session.getDefaultInstance(props, null);
+        MimeMessage mimeMessage = new MimeMessage(session);
+        mimeMessage.setFrom(new InternetAddress(from));
+        mimeMessage.setRecipients(Message.RecipientType.TO, to);
+        //TODO i18n: encoding
+        mimeMessage.setSubject(subject, "iso-2022-jp");
+        //TODO i18n: encoding
+        mimeMessage.setText(body, "iso-2022-jp");
+        mimeMessage.setHeader("Content-Type", "text/plain");
+        mimeMessage.setSentDate(new Date());
+
+        Transport.send(mimeMessage);
+
+    }
+
     protected void cancelToAddCustomer(Map<String, String> userInfo,
             Customer customer, AddressBook addressBook) {
         try {
@@ -361,38 +422,6 @@
         }
     }
 
-    private String getTemplatePath(FacesContext facesContext) {
-        JetspeedTemplateLocator templateLocator = UserRegistrationUtil
-                .getTemplateLocator();
-        String templateLocation = UserRegistrationUtil
-                .getString(PompeiConstants.EMAIL_TEMPLATE_LOCATION);
-        String templateName = UserRegistrationUtil
-                .getString(PompeiConstants.EMAIL_TEMPLATE_NAME);
-        if (templateLocator == null) {
-            return templateLocation + PATH_SEPARATOR + templateName;
-        }
-
-        RequestContext requestContext = (RequestContext) facesContext
-                .getExternalContext().getRequestMap().get(
-                        PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
-        Locale locale = facesContext.getViewRoot().getLocale();
-
-        try {
-            LocatorDescriptor locator = templateLocator
-                    .createLocatorDescriptor("email");
-            locator.setName(templateName);
-            locator.setMediaType(requestContext.getMediaType());
-            locator.setLanguage(locale.getLanguage());
-            locator.setCountry(locale.getCountry());
-            TemplateDescriptor template = templateLocator
-                    .locateTemplate(locator);
-
-            return template.getAppRelativePath();
-        } catch (TemplateLocatorException e) {
-            return templateLocation + PATH_SEPARATOR + templateName;
-        }
-    }
-
     private List<String> parseCSVList(String csv) {
         List<String> csvList = new ArrayList<String>();
         if (csv != null) {

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/util/SystemUtil.java	2007-10-14 13:13:00 UTC (rev 629)
@@ -63,6 +63,16 @@
         return path + templateName;
     }
 
+    public static String getSignupNotificationTemplatePath(String templateName) {
+        String path = getPortletConfig().getInitParameter(
+                PompeiConstants.SIGNUP_NOTIFICATION_PATH);
+        if (path == null) {
+            path = PompeiConstants.DEFAULT_SIGNUP_NOTIFICATION_PATH;
+        }
+        // TODO i18n locale fallback
+        return path + templateName;
+    }
+
     public static String getMessageDigest(String str) throws CommonException {
         if (str == null) {
             str = "";

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/signup/SignupConfirmAction.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/signup/SignupConfirmAction.java	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/signup/SignupConfirmAction.java	2007-10-14 13:13:00 UTC (rev 629)
@@ -146,11 +146,6 @@
         userInfo.put("user.bdate", convertNotNull(getSignupConfirmPage()
                 .getDayOfBirth().toString()));
 
-        // set email title
-        userInfo.put(PompeiConstants.EMAIL_SUBJECT_USER_REGISTRATION,
-                getSignupConfirmPage().getLabelHelper().getLabelValue(
-                        PompeiConstants.EMAIL_SUBJECT_USER_REGISTRATION));
-
         try {
             getCustomerService().addCustomer(userInfo, customer, addressBook);
         } catch (CommonException e) {

Modified: pompei/portlets/pompei-core/trunk/src/main/resources/appMessages.properties
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/resources/appMessages.properties	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/resources/appMessages.properties	2007-10-14 13:13:00 UTC (rev 629)
@@ -143,6 +143,7 @@
 error.registration_completed_but_could_not_find_template=\u30b7\u30b9\u30c6\u30e0\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u518d\u5ea6\u3001\u8a66\u3057\u3066\u3082\u3001\u3053\u306e\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u306b\u306f\u7ba1\u7406\u8005\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002
 could.not.create.user.by.system.error=\u30b7\u30b9\u30c6\u30e0\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u7ba1\u7406\u8005\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002
 could.not.insert.customer.data=\u30b7\u30b9\u30c6\u30e0\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u7ba1\u7406\u8005\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002
+signup.content.is.null=\u4f1a\u54e1\u767b\u9332\u901a\u77e5\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u751f\u6210\u3067\u304d\u307e\u305b\u3093\u3002\u7ba1\u7406\u8005\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002
 
 # OrderNotificationSelect.java
 orderformid.is.null=\u6307\u5b9a\u3055\u308c\u305f\u6ce8\u6587ID\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002\u518d\u5ea6\u3001\u8a66\u3057\u3066\u3082\u3001\u3053\u306e\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u306b\u306f\u7ba1\u7406\u8005\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002

Copied: pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/notification/signup/user-signup.vm (from rev 628, pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/userreg/email/userRegistrationEmail.vm)
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/userreg/email/userRegistrationEmail.vm	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/notification/signup/user-signup.vm	2007-10-14 13:13:00 UTC (rev 629)
@@ -0,0 +1,16 @@
+【Pompei】会員登録確認メール
+$!{map.get("user.name.family")} $!{map.get("user.name.given")} 様
+
+Pompei ポータルに登録していただきありがとうございます。
+
+ユーザー名: $!{map.get("user.name")}
+パスワード: $!{map.get("password")}
+
+パスワードは、ログインして変更できます。
+
+以上をよろしくお願いいたします。
+
+-- 
+Pompei ポータル
+http://pal.sourceforge.jp/
+

Deleted: pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/userreg/email/userRegistrationEmail.vm
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/userreg/email/userRegistrationEmail.vm	2007-10-13 22:48:08 UTC (rev 628)
+++ pompei/portlets/pompei-core/trunk/src/main/webapp/WEB-INF/template/userreg/email/userRegistrationEmail.vm	2007-10-14 13:13:00 UTC (rev 629)
@@ -1,15 +0,0 @@
-こんにちは、$!{map.get("user.name.family")} $!{map.get("user.name.given")} さん
-
-Pompei ポータルに登録していただきありがとうございます。
-
-ユーザー名: $!{map.get("user.name")}
-パスワード: $!{map.get("password")}
-
-パスワードは、ログインして変更できます。
-
-以上をよろしくお願いいたします。
-
----
-Pompei ポータル
-http://sourceforge.jp/projects/pal/
-


pal-cvs メーリングリストの案内
Back to archive index