r1649 - in trunk/src/main: java/cc/kune/core/server/mail java/cc/kune/core/server/manager/impl java/cc/kune/core/server/notifier java/cc/kune/core/server/properties java/cc/kune/core/shared/dto java/cc/kune/gspace/client/options/general java/cc/kune/wave/server resources
Author: vjrj_ Date: 2011-12-27 19:32:08 +0100 (Tue, 27 Dec 2011) New Revision: 1649 Added: trunk/src/main/resources/mail-notif-template.html Modified: trunk/src/main/java/cc/kune/core/server/mail/MailService.java trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java trunk/src/main/java/cc/kune/core/server/notifier/NotifyServiceDefault.java trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java trunk/src/main/java/cc/kune/core/shared/dto/UserSimpleDTO.java trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPanel.java trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralView.java trunk/src/main/java/cc/kune/wave/server/WaveEmailNotifier.java trunk/src/main/resources/kune.properties Log: NEW - # 164: NotificationManager in server side http://kune.ourproject.org/issues/ticket/164 Modified: trunk/src/main/java/cc/kune/core/server/mail/MailService.java =================================================================== --- trunk/src/main/java/cc/kune/core/server/mail/MailService.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/core/server/mail/MailService.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -24,6 +24,34 @@ public interface MailService { /** + * Sends email + * + * @param subject + * the email subject + * @param body + * the body of the email in text or html format + * @param from + * the sender + * @param tos + * the recipients + */ + void send(FormatedString subject, FormatedString body, boolean isHtml, String... tos); + + /** + * Sends email + * + * @param subject + * the email subject + * @param body + * the body of the email in text or html format + * @param from + * the sender + * @param tos + * the recipients + */ + void send(String from, FormatedString subject, FormatedString body, boolean isHtml, String... tos); + + /** * Sends html email with default site "from" * * @param subject Modified: trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java =================================================================== --- trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -97,7 +97,14 @@ props.put("mail.smtp.host", smtpServer); } - private void send(final String from, final FormatedString subject, final FormatedString body, + @Override + public void send(final FormatedString subject, final FormatedString body, final boolean isHtml, + final String... tos) { + send(smtpDefaultFrom, subject, body, isHtml, tos); + } + + @Override + public void send(final String from, final FormatedString subject, final FormatedString body, final boolean isHtml, final String... tos) { if (smtpSkip) { return; Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java =================================================================== --- trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -371,6 +371,7 @@ final String longName = userDTO.getName(); final String email = userDTO.getEmail(); final Group userGroup = user.getUserGroup(); + user.setEmailNotifFreq(userDTO.getEmailNotifFreq()); // We don't allow to change shortName because we cannot change shotNames in // wave accounts // if (!shortName.equals(user.getShortName())) { Modified: trunk/src/main/java/cc/kune/core/server/notifier/NotifyServiceDefault.java =================================================================== --- trunk/src/main/java/cc/kune/core/server/notifier/NotifyServiceDefault.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/core/server/notifier/NotifyServiceDefault.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -1,24 +1,33 @@ package cc.kune.core.server.notifier; +import java.io.File; +import java.io.IOException; + import javax.persistence.NoResultException; +import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import cc.kune.common.client.utils.TextUtils; import cc.kune.core.server.mail.MailService; import cc.kune.core.server.mail.MailServiceDefault.FormatedString; import cc.kune.core.server.manager.I18nTranslationManager; import cc.kune.core.server.manager.UserManager; +import cc.kune.core.server.properties.KuneProperties; import cc.kune.core.server.xmpp.XmppManager; +import cc.kune.core.shared.domain.dto.EmailNotificationFrequency; import cc.kune.domain.User; import cc.kune.wave.server.KuneWaveService; +import com.google.common.base.Preconditions; import com.google.inject.Inject; import com.google.inject.Singleton; @Singleton public class NotifyServiceDefault implements NotifyService { public static final Log LOG = LogFactory.getLog(NotifyServiceDefault.class); + private final String emailTemplate; private final I18nTranslationManager i18n; private final MailService mailService; private final UserManager userManager; @@ -27,12 +36,17 @@ @Inject public NotifyServiceDefault(final MailService mailService, final KuneWaveService waveService, - final XmppManager xmppManager, final UserManager userManager, final I18nTranslationManager i18n) { + final XmppManager xmppManager, final UserManager userManager, final I18nTranslationManager i18n, + final KuneProperties kuneProperties) throws IOException { this.mailService = mailService; this.waveService = waveService; this.xmppManager = xmppManager; this.userManager = userManager; this.i18n = i18n; + emailTemplate = FileUtils.readFileToString(new File( + kuneProperties.get(KuneProperties.SITE_EMAIL_TEMPLATE))); + Preconditions.checkNotNull(emailTemplate); + Preconditions.checkArgument(TextUtils.notEmpty(emailTemplate)); } @Override @@ -50,12 +64,14 @@ final String subjectTranslation = i18n.getTranslation(user.getLanguage().getCode(), subject.getTemplate(), ""); if (subjectTranslation != null) { - subject.setTemplate(subjectTranslation); + // Right now commented because we are only testing + // subject.setTemplate(subjectTranslation); } final String bodyTranslation = i18n.getTranslation(user.getLanguage().getCode(), body.getTemplate(), ""); if (bodyTranslation != null) { - body.setTemplate(bodyTranslation); + // Right now commented because we are only testing + // body.setTemplate(bodyTranslation); } switch (notifyType) { case chat: @@ -63,11 +79,11 @@ String.format("<b>%s</b>%s", subject.getString(), body.getString())); break; case email: - final String email = user.getEmail(); - if (isHtml) { - mailService.sendHtml(subject, body, email); + if (user.getEmailNotifFreq().equals(EmailNotificationFrequency.immediately)) { + mailService.send(subject, FormatedString.build(emailTemplate.replace("%s", body.getString())), + isHtml, user.getEmail()); } else { - mailService.sendPlain(subject, body, email); + // TODO: handle other types of notifications frequencies } break; case wave: Modified: trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java =================================================================== --- trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -49,6 +49,7 @@ String SITE_DB_USER = "kune.db.user"; String SITE_DEF_LICENSE = "kune.default.license"; String SITE_DOMAIN = "kune.site.domain"; + String SITE_EMAIL_TEMPLATE = "kune.site.email.template"; String SITE_GROUP_AVAILABLE_TOOLS = "kune.tools.groupSiteAvailableTools"; String SITE_GROUP_REGIST_ENABLED_TOOLS = "kune.tools.groupRegisEnabledTools"; String SITE_LOGO_URL = "kune.sitelogourl"; Modified: trunk/src/main/java/cc/kune/core/shared/dto/UserSimpleDTO.java =================================================================== --- trunk/src/main/java/cc/kune/core/shared/dto/UserSimpleDTO.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/core/shared/dto/UserSimpleDTO.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -19,6 +19,7 @@ */ package cc.kune.core.shared.dto; +import cc.kune.core.shared.domain.dto.EmailNotificationFrequency; import cc.kune.core.shared.domain.utils.StateToken; import com.google.gwt.user.client.rpc.IsSerializable; @@ -32,6 +33,7 @@ private String shortName; private StateToken stateToken; private TimeZoneDTO timezone; + private EmailNotificationFrequency emailNotifFreq; public UserSimpleDTO() { this(null, null, null, null, null); @@ -157,4 +159,12 @@ return "UserSimpleDTO(" + shortName + ")"; } + public EmailNotificationFrequency getEmailNotifFreq() { + return emailNotifFreq; + } + + public void setEmailNotifFreq(EmailNotificationFrequency emailNotifFreq) { + this.emailNotifFreq = emailNotifFreq; + } + } Modified: trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPanel.java =================================================================== --- trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPanel.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPanel.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -26,6 +26,7 @@ import cc.kune.core.shared.dto.I18nLanguageSimpleDTO; import cc.kune.gspace.client.i18n.LanguageSelectorPanel; +import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign; import com.extjs.gxt.ui.client.widget.form.TextField; import com.google.inject.Inject; @@ -33,6 +34,7 @@ public class UserOptGeneralPanel extends EntityOptGeneralPanel implements UserOptGeneralView { private static final String LONG_NAME_FIELD = "k-uogp-lname"; + private final CheckBox emailNotifField; private final LanguageSelectorPanel langSelector; private final TextField<String> longName; @@ -48,6 +50,9 @@ langSelector.setLabelAlign(LabelAlign.LEFT); langSelector.setLangSeparator(":"); add(langSelector); + emailNotifField = new CheckBox(); + emailNotifField.setFieldLabel(i18n.t("Email notifications")); + add(emailNotifField); } @Override @@ -60,6 +65,14 @@ return longName.getValue(); } + public boolean isEmailNofifField() { + return emailNotifField.getValue(); + } + + public void setEmailNofifField(final boolean value) { + emailNotifField.setValue(value); + } + @Override public void setLanguage(final I18nLanguageSimpleDTO language) { langSelector.setLanguage(language); Modified: trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java =================================================================== --- trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -28,6 +28,7 @@ import cc.kune.core.client.state.StateManager; import cc.kune.core.client.state.UserSignInEvent; import cc.kune.core.client.state.UserSignInEvent.UserSignInHandler; +import cc.kune.core.shared.domain.dto.EmailNotificationFrequency; import cc.kune.core.shared.dto.I18nLanguageSimpleDTO; import cc.kune.core.shared.dto.StateAbstractDTO; import cc.kune.core.shared.dto.UserDTO; @@ -74,6 +75,8 @@ final UserSimpleDTO currentUser = session.getCurrentUser(); userView.setLongName(currentUser.getName()); userView.setLanguage(I18nLanguageSimpleDTO.create(currentUser.getLanguage())); + userView.setEmailNofifField(currentUser.getEmailNotifFreq().equals( + EmailNotificationFrequency.immediately)); } @Override @@ -86,6 +89,8 @@ final String longName = userView.getLongName(); user.setName(longName); final I18nLanguageSimpleDTO lang = userView.getLanguage(); + user.setEmailNotifFreq(userView.isEmailNofifField() ? EmailNotificationFrequency.immediately + : EmailNotificationFrequency.no); userService.get().updateUser(session.getUserHash(), user, userView.getLanguage(), new AsyncCallbackSimple<StateAbstractDTO>() { @Override Modified: trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralView.java =================================================================== --- trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralView.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralView.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -27,6 +27,10 @@ String getLongName(); + boolean isEmailNofifField(); + + void setEmailNofifField(boolean value); + void setLanguage(I18nLanguageSimpleDTO language); void setLongName(String longName); Modified: trunk/src/main/java/cc/kune/wave/server/WaveEmailNotifier.java =================================================================== --- trunk/src/main/java/cc/kune/wave/server/WaveEmailNotifier.java 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/java/cc/kune/wave/server/WaveEmailNotifier.java 2011-12-27 18:32:08 UTC (rev 1649) @@ -57,7 +57,7 @@ final String address = user.getAddress(); if (partUtils.isLocal(address)) { final String userName = partUtils.getAddressName(address); - if (!usersOnline.isLogged(userName)) { + if (true || !usersOnline.isLogged(userName)) { notifyService.send(NotifyType.email, FormatedString.build("You have a new message"), body, true, userName); notifyService.send(NotifyType.chat, FormatedString.build("New message"), body, true, Modified: trunk/src/main/resources/kune.properties =================================================================== --- trunk/src/main/resources/kune.properties 2011-12-27 01:32:05 UTC (rev 1648) +++ trunk/src/main/resources/kune.properties 2011-12-27 18:32:08 UTC (rev 1649) @@ -28,7 +28,12 @@ kune.site.smtp.defaultfrom = noreply@localhost # If we should avoid the use of smtp (use only for avoid emails during development) kune.site.smtp.skip = false +# This file will we the html used to send emails to users. +# We'll substitute the first %s by the body of the notification. +# You can put this file in /etc/kune +kune.site.email.template = src/main/resources/mail-notif-template.html + ### Database # Persistence name, choose between: Added: trunk/src/main/resources/mail-notif-template.html =================================================================== --- trunk/src/main/resources/mail-notif-template.html (rev 0) +++ trunk/src/main/resources/mail-notif-template.html 2011-12-27 18:32:08 UTC (rev 1649) @@ -0,0 +1,121 @@ +<table bgcolor="#f1f1f1" border="0" cellpadding="0" cellspacing="0" + height="100%" width="100%"> + <tbody> + <tr> + <td align="center" valign="top"> + <div style="text-align: justify;"> </div> + <table border="0" cellpadding="0" cellspacing="0" + width="751"> + <tbody> + <tr> + <td style="padding: 10px 0pt 10px 10px; font-family: + Arial,Helvetica,sans-serif; font-size: 11px; color: + rgb(136, 136, 136);" align="left"> + <div style="text-align: center;"> Images not + displaying + properly? Add <a + href="mailto:[email protected]" + style="color: rgb(64, 137, 187);">[email protected]</a> + to your + address book. </div> + </td> + </tr> + <tr> + <td style="border: 1px solid rgb(156, 156, 156); + padding: 5px; -moz-border-radius-topleft: 5px ! + important; -moz-border-radius-topright: 5px ! + important; -moz-border-radius-bottomright: 5px ! + important; -moz-border-radius-bottomleft: 5px ! + important;" align="left" bgcolor="#ffffff"> + <div style="border: 7px solid rgb(198, 168, 141); + -moz-border-radius-topleft: 5px ! important; + -moz-border-radius-topright: 5px ! important; + -moz-border-radius-bottomright: 5px ! important; + -moz-border-radius-bottomleft: 5px ! important;"> + <table style="border-radius: 3px 3px 3px 3px ! + important;" border="0" cellpadding="0" + cellspacing="0" width="725"> + <tbody> + <tr> + <td style="padding: 0pt 0pt 20px;"> + <div style="text-align: justify;"> </div> + <table border="0" cellpadding="0" + cellspacing="0" height="50" width="725"> + <tbody> + <tr> + <td style="font-family: + Arial,Helvetica,sans-serif; + font-size: 14px; color: rgb(51, + 51, 51); padding: 0px 0px 20px + 20px;" align="left" valign="top" + width="297"><br> + <a + href="http://FIXME-yoursite-url/" + target="_blank"><img + style="border-top: 0px solid; + border-bottom: 0px solid; + -moz-border-top-colors: none; + -moz-border-right-colors: + none; + -moz-border-bottom-colors: + none; -moz-border-left-colors: + none; -moz-border-image: + none;" moz-do-not-send="true" + src="ws/logo-big-home.png#FIXME-logo" alt="your + site name FIXME" align="top" + border="0" height="41" + width="287"></a></td> + <td + style="border-bottom-left-radius: 10px; font-family: + Arial,Helvetica,sans-serif; background-color: rgb(244, 214, 188); + font-size: 12px; color: rgb(102, + 102, 102); line-height: 17px; + padding: 20px;" align="left" + valign="top" + width="143"> + <p style="margin: 0pt 0pt 8px; + font-size: 15px; color: rgb(85, + 85, 85);"> <b>Some Info FIXME:</b></p> + <br> + </td> + </tr> + </tbody> + </table> + </td> + </tr> + <tr> + <td style="padding: 20px; font-family: Arial,Helvetica,sans-serif;" valign="top"><br> + <br> + %s<br> + <br> + <br> + </td> + </tr> + <tr> + <td style="border-top-width: 1px; + border-top-style: solid; border-top-color: + rgb(214, 214, 214); background-color: + rgb(255, 245, 237); font-family: + Arial,Helvetica,sans-serif; font-size: + 11px; color: rgb(102, 102, 102); + line-height: 17px; padding: 5px 10px;" + bgcolor="#ffb380"> To ensure this email + always reaches your inbox, please add <a + href="mailto:[email protected]">[email protected]</a> + to your address book. If you prefer not to + receive this emails in the future, please + update your + preferences in <a href="http://FIXME">this + link</a>.</td> + </tr> + </tbody> + </table> + </div> + </td> + </tr> + </tbody> + </table> + </td> + </tr> + </tbody> + </table> \ No newline at end of file
participants (1)
-
Vicente J. Ruiz Jurado