[pal-cvs 3759] [1494] added notification feature.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 12月 2日 (火) 14:51:41 JST


Revision: 1494
          http://svn.sourceforge.jp/view?root=pal&view=rev&rev=1494
Author:   shinsuke
Date:     2008-12-02 14:51:41 +0900 (Tue, 02 Dec 2008)

Log Message:
-----------
added notification feature.

Modified Paths:
--------------
    timecard/trunk/.classpath
    timecard/trunk/pom.xml
    timecard/trunk/src/main/java/jp/sf/pal/timecard/TimecardConstants.java
    timecard/trunk/src/main/java/jp/sf/pal/timecard/action/EmployeeAction.java
    timecard/trunk/src/main/java/jp/sf/pal/timecard/service/ReportService.java
    timecard/trunk/src/main/resources/application.properties
    timecard/trunk/src/main/resources/application_ja.properties

Added Paths:
-----------
    timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/LocaleUtil.java
    timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/NotificationUtil.java
    timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/VelocityUtil.java
    timecard/trunk/src/main/webapp/WEB-INF/template/
    timecard/trunk/src/main/webapp/WEB-INF/template/daily-report-request.vm
    timecard/trunk/src/main/webapp/WEB-INF/template/ja/
    timecard/trunk/src/main/webapp/WEB-INF/template/ja/daily-report-request.vm
    timecard/trunk/src/main/webapp/WEB-INF/template/ja/monthly-report-request.vm
    timecard/trunk/src/main/webapp/WEB-INF/template/monthly-report-request.vm


-------------- next part --------------
Modified: timecard/trunk/.classpath
===================================================================
--- timecard/trunk/.classpath	2008-12-02 03:38:50 UTC (rev 1493)
+++ timecard/trunk/.classpath	2008-12-02 05:51:41 UTC (rev 1494)
@@ -43,4 +43,7 @@
   <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.1_spec/1.0/geronimo-jta_1.1_spec-1.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/seasar/dao/s2-dao/1.0.48/s2-dao-1.0.48.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/seasar/dao/s2-dao-tiger/1.0.48/s2-dao-tiger-1.0.48.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/velocity/velocity/1.5/velocity-1.5.jar"/>
+  <classpathentry kind="var" path="M2_REPO/javax/mail/mail/1.4.1/mail-1.4.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1.1/activation-1.1.1.jar"/>
 </classpath>

Modified: timecard/trunk/pom.xml
===================================================================
--- timecard/trunk/pom.xml	2008-12-02 03:38:50 UTC (rev 1493)
+++ timecard/trunk/pom.xml	2008-12-02 05:51:41 UTC (rev 1494)
@@ -65,6 +65,12 @@
       <name>The Seasar Foundation Maven2 Repository</name>
       <url>http://maven.seasar.org/maven2</url>
     </repository>
+    <repository>
+      <id>maven-repository.dev.java.net</id>
+      <name>java.net Maven2 Repository</name>
+      <url>https://maven-repository.dev.java.net/nonav/repository/</url>
+      <layout>legacy</layout>
+    </repository>
   </repositories>
   <dependencies>
     <dependency>
@@ -193,6 +199,22 @@
       <artifactId>s2-dao-tiger</artifactId>
       <version>1.0.48</version>
     </dependency>
+<!-- Mail -->
+    <dependency>
+      <groupId>org.apache.velocity</groupId>
+      <artifactId>velocity</artifactId>
+      <version>1.5</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+      <version>1.4.1</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.activation</groupId>
+      <artifactId>activation</artifactId>
+      <version>1.1.1</version>
+    </dependency>
 <!-- Removed from war -->
     <dependency>
 <!-- needed by validator(validwhen) -->

Modified: timecard/trunk/src/main/java/jp/sf/pal/timecard/TimecardConstants.java
===================================================================
--- timecard/trunk/src/main/java/jp/sf/pal/timecard/TimecardConstants.java	2008-12-02 03:38:50 UTC (rev 1493)
+++ timecard/trunk/src/main/java/jp/sf/pal/timecard/TimecardConstants.java	2008-12-02 05:51:41 UTC (rev 1494)
@@ -99,4 +99,10 @@
     public static final String TIME_HOLIDAYS = "time.holidays";
 
     public static final String DEFAULT_MANAGER = "default.manager";
+
+    public static final String SYSTEM_EMAIL = "system.email";
+
+    public static final String DAILY_REPORT_REQUEST_NOTIFICATION_NAME = "daily-report-request.vm";
+
+    public static final String MONTHLY_REPORT_REQUEST_NOTIFICATION_NAME = "monthly-report-request.vm";
 }

Modified: timecard/trunk/src/main/java/jp/sf/pal/timecard/action/EmployeeAction.java
===================================================================
--- timecard/trunk/src/main/java/jp/sf/pal/timecard/action/EmployeeAction.java	2008-12-02 03:38:50 UTC (rev 1493)
+++ timecard/trunk/src/main/java/jp/sf/pal/timecard/action/EmployeeAction.java	2008-12-02 05:51:41 UTC (rev 1494)
@@ -5,12 +5,14 @@
 import java.util.Date;
 import java.util.List;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
 import jp.sf.pal.timecard.TimecardConstants;
 import jp.sf.pal.timecard.common.util.ConfigUtil;
 import jp.sf.pal.timecard.common.util.DateUtil;
 import jp.sf.pal.timecard.common.util.SAStrutsUtil;
+import jp.sf.pal.timecard.common.util.VelocityUtil;
 import jp.sf.pal.timecard.db.exentity.DailyReport;
 import jp.sf.pal.timecard.db.exentity.MonthlyReport;
 import jp.sf.pal.timecard.dxo.DailyReportDxo;
@@ -52,6 +54,8 @@
 
     private transient HttpServletRequest request;
 
+    private transient ServletContext servletContext;
+
     protected String displayList() {
         String username = request.getRemoteUser();
 
@@ -84,6 +88,13 @@
     @Execute(validator = false, input = "error.jsp")
     public String index() {
         ConfigUtil.init(request);
+        try {
+            VelocityUtil.init(servletContext);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            throw new ActionMessagesException("errors.failed_to_init_velocity",
+                    e);
+        }
         return displayList();
     }
 
@@ -331,7 +342,7 @@
         try {
             Long monthlyReportId = Long.parseLong(employeeForm.monthlyReportId);
             MonthlyReport monthlyReport = reportService
-                    .getMonthlyReport(monthlyReportId);
+                    .getMonthlyReportWithUserInfo(monthlyReportId);
             monthlyReport.setUpdatedBy(request.getRemoteUser());
             reportService.fix(monthlyReport, employeeForm.autoFill);
             SAStrutsUtil.addMessage(request, "success.update_daily_report");
@@ -474,4 +485,12 @@
         return minuteItems;
     }
 
+    public ServletContext getServletContext() {
+        return servletContext;
+    }
+
+    public void setServletContext(ServletContext servletContext) {
+        this.servletContext = servletContext;
+    }
+
 }

Added: timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/LocaleUtil.java
===================================================================
--- timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/LocaleUtil.java	                        (rev 0)
+++ timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/LocaleUtil.java	2008-12-02 05:51:41 UTC (rev 1494)
@@ -0,0 +1,22 @@
+package jp.sf.pal.timecard.common.util;
+
+import java.util.Locale;
+
+import org.apache.commons.lang.StringUtils;
+
+public class LocaleUtil {
+    public static Locale parse(String localeName) {
+        if (StringUtils.isEmpty(localeName)) {
+            return null;
+        }
+
+        String[] localeNames = localeName.split("_");
+        if (localeNames.length > 2) {
+            return new Locale(localeNames[0], localeNames[1], localeNames[2]);
+        } else if (localeNames.length == 2) {
+            return new Locale(localeNames[0], localeNames[1]);
+        } else {
+            return new Locale(localeNames[0]);
+        }
+    }
+}


Property changes on: timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/LocaleUtil.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/NotificationUtil.java
===================================================================
--- timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/NotificationUtil.java	                        (rev 0)
+++ timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/NotificationUtil.java	2008-12-02 05:51:41 UTC (rev 1494)
@@ -0,0 +1,125 @@
+package jp.sf.pal.timecard.common.util;
+
+import java.io.StringWriter;
+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 javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.seasar.struts.exception.ActionMessagesException;
+
+public class NotificationUtil {
+
+    public static final String TEMPLATE_ENCODING = "notification.template.encoding";
+
+    public static final String SMTP_HOST = "notification.smtp.host";
+
+    public static final String SUBJECT_ENCODING = "notification.subject.encoding";
+
+    public static final String BODY_ENCODING = "notification.body.encoding";
+
+    private static String[] getTemplates(String templateName, Locale locale) {
+        List<String> templateList = new ArrayList<String>();
+        if (locale != null) {
+            if (locale.getCountry() != null) {
+                templateList.add("/" + locale.getLanguage() + "/"
+                        + locale.getCountry() + "/" + templateName);
+            }
+            templateList.add("/" + locale.getLanguage() + "/" + templateName);
+        }
+        templateList.add("/" + templateName);
+        return templateList.toArray(new String[] {});
+    }
+
+    public static void send(String templateName, Locale locale,
+            String fromEmail, String toEmail, Map<String, Object> paramMap) {
+
+        // set velocity context
+        VelocityContext context = new VelocityContext();
+        for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
+            context.put(entry.getKey(), entry.getValue());
+        }
+
+        StringWriter sw = new StringWriter();
+
+        // TODO i18n: encoding
+        Template template = null;
+        for (String templatePath : getTemplates(templateName, locale)) {
+            try {
+                template = VelocityUtil.getTemplate(templatePath, ConfigUtil
+                        .getString(TEMPLATE_ENCODING, "UTF-8"));
+            } catch (Exception e) {
+                // nothing
+            }
+            if (template != null) {
+                break;
+            }
+        }
+
+        if (template == null) {
+            throw new ActionMessagesException(
+                    "errors.could_not_find_notification_template",
+                    new Object[] { templateName, locale });
+        }
+        try {
+            template.merge(context, sw);
+        } catch (Exception e) {
+            throw new ActionMessagesException(
+                    "errors.could_not_create_notification_content", e);
+        }
+
+        String content = sw.toString();
+        if (content == null) {
+            throw new ActionMessagesException(
+                    "errors.empty_notification_content");
+        }
+
+        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;
+        }
+
+        try {
+            Properties props = System.getProperties();
+            // set smtp server
+            props.put("mail.smtp.host", ConfigUtil.getString(SMTP_HOST,
+                    "localhost"));
+            Session session = Session.getDefaultInstance(props, null);
+            MimeMessage mimeMessage = new MimeMessage(session);
+            mimeMessage.setFrom(new InternetAddress(fromEmail));
+            mimeMessage.setRecipients(Message.RecipientType.TO, toEmail);
+            // TODO i18n: encoding
+            mimeMessage.setSubject(subject, ConfigUtil.getString(
+                    SUBJECT_ENCODING, "UTF-8"));
+            // TODO i18n: encoding
+            mimeMessage.setText(body, ConfigUtil.getString(BODY_ENCODING,
+                    "UTF-8"));
+            mimeMessage.setHeader("Content-Type", "text/plain");
+            mimeMessage.setSentDate(new Date());
+
+            Transport.send(mimeMessage);
+        } catch (Exception e) {
+            throw new ActionMessagesException(
+                    "errors.failed_to_send_notification", new Object[] {
+                            fromEmail, toEmail }, e);
+        }
+
+    }
+}


Property changes on: timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/NotificationUtil.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/VelocityUtil.java
===================================================================
--- timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/VelocityUtil.java	                        (rev 0)
+++ timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/VelocityUtil.java	2008-12-02 05:51:41 UTC (rev 1494)
@@ -0,0 +1,246 @@
+package jp.sf.pal.timecard.common.util;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Properties;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.Template;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.log.Log;
+
+public class VelocityUtil {
+    private static final String DEFAULT_TEMPLATE_PATH = "/WEB-INF/template/";
+
+    private static VelocityEngine velocityEngine;
+
+    public static void init(ServletContext servletContext) throws Exception {
+        if (velocityEngine == null) {
+            velocityEngine = new VelocityEngine();
+
+            Properties props = new Properties();
+            props.setProperty("resource.loader", "FILE");
+            props
+                    .setProperty("FILE.resource.loader.class",
+                            "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
+            props.setProperty("FILE.resource.loader.cache", "true");
+            props.setProperty("FILE.resource.loader.modificationCheckInterval",
+                    "60");
+            // TODO move to config file?
+            props.setProperty("FILE.resource.loader.path", servletContext
+                    .getRealPath(DEFAULT_TEMPLATE_PATH));
+            velocityEngine.init(props);
+        }
+    }
+
+    /**
+     * @param key
+     * @param value
+     * @see org.apache.velocity.app.VelocityEngine#addProperty(java.lang.String,
+     *      java.lang.Object)
+     */
+    public static void addProperty(String key, Object value) {
+        velocityEngine.addProperty(key, value);
+    }
+
+    /**
+     * @param key
+     * @see org.apache.velocity.app.VelocityEngine#clearProperty(java.lang.String)
+     */
+    public static void clearProperty(String key) {
+        velocityEngine.clearProperty(key);
+    }
+
+    /**
+     * @param arg0
+     * @param arg1
+     * @param arg2
+     * @param arg3
+     * @return
+     * @throws ParseErrorException
+     * @throws MethodInvocationException
+     * @throws ResourceNotFoundException
+     * @throws IOException
+     * @see org.apache.velocity.app.VelocityEngine#evaluate(org.apache.velocity.context.Context,
+     *      java.io.Writer, java.lang.String, java.io.Reader)
+     */
+    public static boolean evaluate(Context arg0, Writer arg1, String arg2,
+            Reader arg3) throws ParseErrorException, MethodInvocationException,
+            ResourceNotFoundException, IOException {
+        return velocityEngine.evaluate(arg0, arg1, arg2, arg3);
+    }
+
+    /**
+     * @param context
+     * @param out
+     * @param logTag
+     * @param instring
+     * @return
+     * @throws ParseErrorException
+     * @throws MethodInvocationException
+     * @throws ResourceNotFoundException
+     * @throws IOException
+     * @see org.apache.velocity.app.VelocityEngine#evaluate(org.apache.velocity.context.Context,
+     *      java.io.Writer, java.lang.String, java.lang.String)
+     */
+    public static boolean evaluate(Context context, Writer out, String logTag,
+            String instring) throws ParseErrorException,
+            MethodInvocationException, ResourceNotFoundException, IOException {
+        return velocityEngine.evaluate(context, out, logTag, instring);
+    }
+
+    /**
+     * @param key
+     * @return
+     * @see org.apache.velocity.app.VelocityEngine#getApplicationAttribute(java.lang.Object)
+     */
+    public static Object getApplicationAttribute(Object key) {
+        return velocityEngine.getApplicationAttribute(key);
+    }
+
+    /**
+     * @return
+     * @see org.apache.velocity.app.VelocityEngine#getLog()
+     */
+    public static Log getLog() {
+        return velocityEngine.getLog();
+    }
+
+    /**
+     * @param key
+     * @return
+     * @see org.apache.velocity.app.VelocityEngine#getProperty(java.lang.String)
+     */
+    public static Object getProperty(String key) {
+        return velocityEngine.getProperty(key);
+    }
+
+    /**
+     * @param name
+     * @param encoding
+     * @return
+     * @throws ResourceNotFoundException
+     * @throws ParseErrorException
+     * @throws Exception
+     * @see org.apache.velocity.app.VelocityEngine#getTemplate(java.lang.String,
+     *      java.lang.String)
+     */
+    public static Template getTemplate(String name, String encoding)
+            throws ResourceNotFoundException, ParseErrorException, Exception {
+        return velocityEngine.getTemplate(name, encoding);
+    }
+
+    /**
+     * @param name
+     * @return
+     * @throws ResourceNotFoundException
+     * @throws ParseErrorException
+     * @throws Exception
+     * @see org.apache.velocity.app.VelocityEngine#getTemplate(java.lang.String)
+     */
+    public static Template getTemplate(String name)
+            throws ResourceNotFoundException, ParseErrorException, Exception {
+        return velocityEngine.getTemplate(name);
+    }
+
+    /**
+     * @param arg0
+     * @param arg1
+     * @param arg2
+     * @param arg3
+     * @param arg4
+     * @return
+     * @throws Exception
+     * @see org.apache.velocity.app.VelocityEngine#invokeVelocimacro(java.lang.String,
+     *      java.lang.String, java.lang.String[],
+     *      org.apache.velocity.context.Context, java.io.Writer)
+     */
+    public static boolean invokeVelocimacro(String arg0, String arg1,
+            String[] arg2, Context arg3, Writer arg4) throws Exception {
+        return velocityEngine.invokeVelocimacro(arg0, arg1, arg2, arg3, arg4);
+    }
+
+    /**
+     * @param templateName
+     * @param context
+     * @param writer
+     * @return
+     * @throws ResourceNotFoundException
+     * @throws ParseErrorException
+     * @throws MethodInvocationException
+     * @throws Exception
+     * @see org.apache.velocity.app.VelocityEngine#mergeTemplate(java.lang.String,
+     *      org.apache.velocity.context.Context, java.io.Writer)
+     */
+    public static boolean mergeTemplate(String templateName, Context context,
+            Writer writer) throws ResourceNotFoundException,
+            ParseErrorException, MethodInvocationException, Exception {
+        return velocityEngine.mergeTemplate(templateName, context, writer);
+    }
+
+    /**
+     * @param templateName
+     * @param encoding
+     * @param context
+     * @param writer
+     * @return
+     * @throws ResourceNotFoundException
+     * @throws ParseErrorException
+     * @throws MethodInvocationException
+     * @throws Exception
+     * @see org.apache.velocity.app.VelocityEngine#mergeTemplate(java.lang.String,
+     *      java.lang.String, org.apache.velocity.context.Context,
+     *      java.io.Writer)
+     */
+    public static boolean mergeTemplate(String templateName, String encoding,
+            Context context, Writer writer) throws ResourceNotFoundException,
+            ParseErrorException, MethodInvocationException, Exception {
+        return velocityEngine.mergeTemplate(templateName, encoding, context,
+                writer);
+    }
+
+    /**
+     * @param resourceName
+     * @return
+     * @see org.apache.velocity.app.VelocityEngine#resourceExists(java.lang.String)
+     */
+    public static boolean resourceExists(String resourceName) {
+        return velocityEngine.resourceExists(resourceName);
+    }
+
+    /**
+     * @param key
+     * @param value
+     * @see org.apache.velocity.app.VelocityEngine#setApplicationAttribute(java.lang.Object,
+     *      java.lang.Object)
+     */
+    public static void setApplicationAttribute(Object key, Object value) {
+        velocityEngine.setApplicationAttribute(key, value);
+    }
+
+    /**
+     * @param configuration
+     * @see org.apache.velocity.app.VelocityEngine#setExtendedProperties(org.apache.commons.collections.ExtendedProperties)
+     */
+    public static void setExtendedProperties(ExtendedProperties configuration) {
+        velocityEngine.setExtendedProperties(configuration);
+    }
+
+    /**
+     * @param key
+     * @param value
+     * @see org.apache.velocity.app.VelocityEngine#setProperty(java.lang.String,
+     *      java.lang.Object)
+     */
+    public static void setProperty(String key, Object value) {
+        velocityEngine.setProperty(key, value);
+    }
+
+}


Property changes on: timecard/trunk/src/main/java/jp/sf/pal/timecard/common/util/VelocityUtil.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: timecard/trunk/src/main/java/jp/sf/pal/timecard/service/ReportService.java
===================================================================
--- timecard/trunk/src/main/java/jp/sf/pal/timecard/service/ReportService.java	2008-12-02 03:38:50 UTC (rev 1493)
+++ timecard/trunk/src/main/java/jp/sf/pal/timecard/service/ReportService.java	2008-12-02 05:51:41 UTC (rev 1494)
@@ -6,11 +6,14 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import jp.sf.pal.timecard.TimecardConstants;
 import jp.sf.pal.timecard.common.util.ConfigUtil;
 import jp.sf.pal.timecard.common.util.DateUtil;
+import jp.sf.pal.timecard.common.util.LocaleUtil;
+import jp.sf.pal.timecard.common.util.NotificationUtil;
 import jp.sf.pal.timecard.db.cbean.DailyReportCB;
 import jp.sf.pal.timecard.db.cbean.EmployeeCB;
 import jp.sf.pal.timecard.db.cbean.MonthlyReportCB;
@@ -293,6 +296,34 @@
 
         // update monthly report
         calculateMontlyReport(dailyReport.getMonthlyReportId());
+
+        if (dailyReport.getStatus() == TimecardConstants.REPORT_STATUS_REQUEST) {
+            // notification
+            MonthlyReportCB cb = new MonthlyReportCB();
+            cb.setupSelect_Employee().withUserInfoByUsername();
+            cb.setupSelect_Employee().withUserInfoByManager();
+            cb.query().setId_Equal(dailyReport.getMonthlyReportId());
+            MonthlyReport monthlyReport = monthlyReportBhv.selectEntity(cb);
+            UserInfo employee = monthlyReport.getEmployee()
+                    .getUserInfoByUsername();
+            UserInfo manager = monthlyReport.getEmployee()
+                    .getUserInfoByManager();
+            if (manager != null && manager.getEmail() != null) {
+                String toEmail = manager.getEmail();
+                String fromEmail = ConfigUtil.getString(
+                        TimecardConstants.SYSTEM_EMAIL, toEmail);
+                Locale locale = LocaleUtil.parse(manager.getLocale());
+                Map<String, Object> paramMap = new HashMap<String, Object>();
+                paramMap.put("monthlyReport", monthlyReport);
+                paramMap.put("dailyReport", dailyReport);
+                paramMap.put("employee", employee);
+                paramMap.put("manager", manager);
+                NotificationUtil
+                        .send(
+                                TimecardConstants.DAILY_REPORT_REQUEST_NOTIFICATION_NAME,
+                                locale, fromEmail, toEmail, paramMap);
+            }
+        }
     }
 
     public List<MonthlyWorkingReport> getMonthlyWokringReport(
@@ -514,6 +545,19 @@
 
     }
 
+    public MonthlyReport getMonthlyReportWithUserInfo(Long id) {
+        MonthlyReportCB cb = new MonthlyReportCB();
+
+        // setup
+        cb.setupSelect_Employee().withUserInfoByManager();
+        cb.setupSelect_Employee().withUserInfoByUsername();
+
+        cb.query().setId_Equal(id);
+
+        return monthlyReportBhv.selectEntity(cb);
+
+    }
+
     public void store(MonthlyReport monthlyReport) {
         Timestamp now = new Timestamp(new Date().getTime());
         monthlyReport.setUpdatedTime(now);
@@ -617,6 +661,23 @@
         }
 
         calculateMontlyReport(monthlyReport.getId());
+
+        // notification
+        UserInfo employee = monthlyReport.getEmployee().getUserInfoByUsername();
+        UserInfo manager = monthlyReport.getEmployee().getUserInfoByManager();
+        if (manager != null && manager.getEmail() != null) {
+            String toEmail = manager.getEmail();
+            String fromEmail = ConfigUtil.getString(
+                    TimecardConstants.SYSTEM_EMAIL, toEmail);
+            Locale locale = LocaleUtil.parse(manager.getLocale());
+            Map<String, Object> paramMap = new HashMap<String, Object>();
+            paramMap.put("monthlyReport", monthlyReport);
+            paramMap.put("employee", employee);
+            paramMap.put("manager", manager);
+            NotificationUtil.send(
+                    TimecardConstants.MONTHLY_REPORT_REQUEST_NOTIFICATION_NAME,
+                    locale, fromEmail, toEmail, paramMap);
+        }
     }
 
     public EmployeeBhv getEmployeeBhv() {

Modified: timecard/trunk/src/main/resources/application.properties
===================================================================
--- timecard/trunk/src/main/resources/application.properties	2008-12-02 03:38:50 UTC (rev 1493)
+++ timecard/trunk/src/main/resources/application.properties	2008-12-02 05:51:41 UTC (rev 1494)
@@ -54,6 +54,12 @@
 errors.invalid_username= Invalid username.
 errors.failed_to_update_monthly_report=Failed to update the monthly report information.
 
+errors.failed_to_init_velocity=Failed to initialize a notification.
+errors.could_not_find_notification_template=Could not find a notification template({0}) at {1}.
+errors.empty_notification_content=The notification content is empty.
+errors.could_not_create_notification_content=Could not create a notification content.
+errors.failed_to_send_notification=Failed to send a notification from {0} to {1}.
+
 labels.detail=Detail
 labels.create=Create
 labels.update=Update

Modified: timecard/trunk/src/main/resources/application_ja.properties
===================================================================
--- timecard/trunk/src/main/resources/application_ja.properties	2008-12-02 03:38:50 UTC (rev 1493)
+++ timecard/trunk/src/main/resources/application_ja.properties	2008-12-02 05:51:41 UTC (rev 1494)
@@ -47,6 +47,12 @@
 errors.invalid_username= \u7121\u52b9\u306a\u30e6\u30fc\u30b6\u30fc\u540d\u3067\u3059
 errors.failed_to_update_monthly_report=\u6708\u5831\u306e\u66f4\u65b0\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
 
+errors.failed_to_init_velocity=\u901a\u77e5\u6a5f\u80fd\u306e\u521d\u671f\u5316\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
+errors.could_not_find_notification_template={1} \u3067\u901a\u77e5\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8({0}) \u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002
+errors.empty_notification_content=\u901a\u77e5\u5185\u5bb9\u304c\u7a7a\u3067\u3059\u3002
+errors.could_not_create_notification_content=\u901a\u4fe1\u5185\u5bb9\u3092\u4f5c\u6210\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002
+errors.failed_to_send_notification={0} \u304b\u3089 {1} \u3078\u901a\u77e5\u3092\u9001\u4fe1\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002
+
 labels.detail=\u8a73\u7d30
 labels.create=\u4f5c\u6210
 labels.update=\u66f4\u65b0

Added: timecard/trunk/src/main/webapp/WEB-INF/template/daily-report-request.vm
===================================================================
--- timecard/trunk/src/main/webapp/WEB-INF/template/daily-report-request.vm	                        (rev 0)
+++ timecard/trunk/src/main/webapp/WEB-INF/template/daily-report-request.vm	2008-12-02 05:51:41 UTC (rev 1494)
@@ -0,0 +1,31 @@
+TIMECARD: Report Request from ${employee.nameArg0} ${employee.nameArg1}
+${employee.nameArg0} ${employee.nameArg1} requests below:
+
+ Date: ${monthlyReport.year}/${monthlyReport.month}/${dailyReport.date}
+ Content: ##
+#if(${dailyReport.workingType} == 1)Working#end##
+#if(${dailyReport.workingType} == 2)Working on holiday#end##
+#if(${dailyReport.workingType} == 3)Working on holiday(AM)#end##
+#if(${dailyReport.workingType} == 4)Working on holiday(PM)#end##
+#if(${dailyReport.workingType} == 200)Holiday#end##
+#if(${dailyReport.workingType} == 100)Day off#end##
+#if(${dailyReport.workingType} == 101)AM off#end##
+#if(${dailyReport.workingType} == 102)PM off#end##
+#if(${dailyReport.workingType} == 20)Paid holiday#end##
+#if(${dailyReport.workingType} == 21)Paid holiday(AM)#end##
+#if(${dailyReport.workingType} == 22)Paid holiday(PM)#end##
+#if(${dailyReport.workingType} == 30)Bereavement leave#end##
+#if(${dailyReport.workingType} == 31)Bereavement leave(AM)#end##
+#if(${dailyReport.workingType} == 32)Bereavement leave(PM)#end##
+#if(${dailyReport.workingType} == 40)Sick leave#end##
+#if(${dailyReport.workingType} == 41)Sick leave(AM)#end##
+#if(${dailyReport.workingType} == 42)Sick leave(PM)#end##
+#if(${dailyReport.workingType} == 110)Substitute holiday#end##
+#if(${dailyReport.workingType} == 111)Substitute holiday(AM)#end##
+#if(${dailyReport.workingType} == 112)Substitute holiday(PM)#end##
+
+
+Please check and approve the request.
+
+Timecard System
+

Added: timecard/trunk/src/main/webapp/WEB-INF/template/ja/daily-report-request.vm
===================================================================
--- timecard/trunk/src/main/webapp/WEB-INF/template/ja/daily-report-request.vm	                        (rev 0)
+++ timecard/trunk/src/main/webapp/WEB-INF/template/ja/daily-report-request.vm	2008-12-02 05:51:41 UTC (rev 1494)
@@ -0,0 +1,31 @@
+[勤怠] ${employee.nameArg1} ${employee.nameArg0} さんからの申請
+${employee.nameArg1} ${employee.nameArg0} さんが以下の申請をしました。
+
+ 日付: ${monthlyReport.year}/${monthlyReport.month}/${dailyReport.date}
+ 内容: ##
+#if(${dailyReport.workingType} == 1)勤務#end##
+#if(${dailyReport.workingType} == 2)休日勤務#end##
+#if(${dailyReport.workingType} == 3)休日勤務(午前)#end##
+#if(${dailyReport.workingType} == 4)休日勤務(午後)#end##
+#if(${dailyReport.workingType} == 200)休日#end##
+#if(${dailyReport.workingType} == 100)休暇#end##
+#if(${dailyReport.workingType} == 101)休暇(午前)#end##
+#if(${dailyReport.workingType} == 102)休暇(午後)#end##
+#if(${dailyReport.workingType} == 20)有給休暇#end##
+#if(${dailyReport.workingType} == 21)有給休暇(午前)#end##
+#if(${dailyReport.workingType} == 22)有給休暇(午後)#end##
+#if(${dailyReport.workingType} == 30)慶弔休暇#end##
+#if(${dailyReport.workingType} == 31)慶弔休暇(午前)#end##
+#if(${dailyReport.workingType} == 32)慶弔休暇(午後)#end##
+#if(${dailyReport.workingType} == 40)私傷病休暇#end##
+#if(${dailyReport.workingType} == 41)私傷病休暇(午前)#end##
+#if(${dailyReport.workingType} == 42)私傷病休暇(午後)#end##
+#if(${dailyReport.workingType} == 110)代休#end##
+#if(${dailyReport.workingType} == 111)代休(午前)#end##
+#if(${dailyReport.workingType} == 112)代休(午後)#end##
+
+
+申請内容を確認・承認をしてください。
+
+勤怠システム
+

Added: timecard/trunk/src/main/webapp/WEB-INF/template/ja/monthly-report-request.vm
===================================================================
--- timecard/trunk/src/main/webapp/WEB-INF/template/ja/monthly-report-request.vm	                        (rev 0)
+++ timecard/trunk/src/main/webapp/WEB-INF/template/ja/monthly-report-request.vm	2008-12-02 05:51:41 UTC (rev 1494)
@@ -0,0 +1,9 @@
+[勤怠] ${employee.nameArg1} ${employee.nameArg0} さんからの月次確定
+${employee.nameArg1} ${employee.nameArg0} さんが以下の月次確定をしました。
+
+ 日付: ${monthlyReport.year}/${monthlyReport.month}
+
+内容を確認・承認をしてください。
+
+勤怠システム
+

Added: timecard/trunk/src/main/webapp/WEB-INF/template/monthly-report-request.vm
===================================================================
--- timecard/trunk/src/main/webapp/WEB-INF/template/monthly-report-request.vm	                        (rev 0)
+++ timecard/trunk/src/main/webapp/WEB-INF/template/monthly-report-request.vm	2008-12-02 05:51:41 UTC (rev 1494)
@@ -0,0 +1,9 @@
+TIMECARD: Monthly Report Request from ${employee.nameArg0} ${employee.nameArg1}
+${employee.nameArg0} ${employee.nameArg1} sent the following Monthly Report.
+
+ Date: ${monthlyReport.year}/${monthlyReport.month}
+
+Please check and approve the request.
+
+Timecard System
+


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