revised email message, added VRE Description
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/invite-friends-vre@114614 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d4f121dab1
commit
badd703b3b
7
pom.xml
7
pom.xml
|
@ -9,7 +9,7 @@
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<relativePath />
|
<relativePath />
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>invite-friends-vre</artifactId>
|
<artifactId>invite-friends-vre</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
@ -76,6 +76,11 @@
|
||||||
<artifactId>gwt-bootstrap</artifactId>
|
<artifactId>gwt-bootstrap</artifactId>
|
||||||
<version>2.3.2.0</version>
|
<version>2.3.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jsoup</groupId>
|
||||||
|
<artifactId>jsoup</artifactId>
|
||||||
|
<version>1.6.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
|
@ -51,8 +51,7 @@ public class FormViewImpl extends Composite implements FormView, Editor<FormView
|
||||||
|
|
||||||
@UiField TextBox email;
|
@UiField TextBox email;
|
||||||
@UiField TextBox name;
|
@UiField TextBox name;
|
||||||
// @UiField TextBox lastName;
|
|
||||||
//
|
|
||||||
@UiField Button openModal;
|
@UiField Button openModal;
|
||||||
@UiField Button cancelInvite;
|
@UiField Button cancelInvite;
|
||||||
@UiField Button sendInvite;
|
@UiField Button sendInvite;
|
||||||
|
@ -64,9 +63,7 @@ public class FormViewImpl extends Composite implements FormView, Editor<FormView
|
||||||
ControlGroup nameGroup;
|
ControlGroup nameGroup;
|
||||||
@UiField
|
@UiField
|
||||||
ControlGroup feedbackGroup;
|
ControlGroup feedbackGroup;
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public FormViewImpl(Delegate delegate) {
|
public FormViewImpl(Delegate delegate) {
|
||||||
super();
|
super();
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
@ -95,6 +92,7 @@ public class FormViewImpl extends Composite implements FormView, Editor<FormView
|
||||||
void onUserClick(ClickEvent event) {
|
void onUserClick(ClickEvent event) {
|
||||||
if (!delegate.onSendClick()) {
|
if (!delegate.onSendClick()) {
|
||||||
feedback.setText("We will send the invitation email to: "+email.getText() + " and put you in cc, we'll never email your contacts without your say so.");
|
feedback.setText("We will send the invitation email to: "+email.getText() + " and put you in cc, we'll never email your contacts without your say so.");
|
||||||
|
name.setText("");
|
||||||
modalWindow.show();
|
modalWindow.show();
|
||||||
Timer t = new Timer() {
|
Timer t = new Timer() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,30 +3,29 @@ package org.gcube.portlets.user.invitefriends.server;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.MessagingException;
|
|
||||||
import javax.mail.Multipart;
|
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.Transport;
|
import javax.mail.Transport;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeBodyPart;
|
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.mail.internet.MimeMultipart;
|
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
import org.gcube.application.framework.core.session.SessionManager;
|
||||||
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
||||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||||
import org.gcube.portlets.user.invitefriends.client.InviteService;
|
import org.gcube.portlets.user.invitefriends.client.InviteService;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.nodes.Node;
|
||||||
|
import org.jsoup.nodes.TextNode;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
||||||
import com.liferay.portal.util.PortalUtil;
|
import com.liferay.portal.util.PortalUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +38,7 @@ public class InviteServiceImpl extends RemoteServiceServlet implements InviteSer
|
||||||
private final static String MAIL_SERVICE_HOST = "localhost";
|
private final static String MAIL_SERVICE_HOST = "localhost";
|
||||||
private final static String MAIL_SERVICE_PORT = "25";
|
private final static String MAIL_SERVICE_PORT = "25";
|
||||||
private static final String SENDER_EMAIL = "notificationSenderEmail";
|
private static final String SENDER_EMAIL = "notificationSenderEmail";
|
||||||
private static final String GATEWAY_NAME = "portalinstancename";
|
|
||||||
/**
|
/**
|
||||||
* the current ASLSession
|
* the current ASLSession
|
||||||
* @return the session
|
* @return the session
|
||||||
|
@ -64,7 +63,7 @@ public class InviteServiceImpl extends RemoteServiceServlet implements InviteSer
|
||||||
ASLSession aslSession = getASLSession();
|
ASLSession aslSession = getASLSession();
|
||||||
String vreName = aslSession.getGroupName();
|
String vreName = aslSession.getGroupName();
|
||||||
String fromFullName = aslSession.getUserFullName();
|
String fromFullName = aslSession.getUserFullName();
|
||||||
|
|
||||||
|
|
||||||
Properties props = System.getProperties();
|
Properties props = System.getProperties();
|
||||||
Session session = null;
|
Session session = null;
|
||||||
|
@ -100,11 +99,12 @@ public class InviteServiceImpl extends RemoteServiceServlet implements InviteSer
|
||||||
|
|
||||||
|
|
||||||
private String getTextEmail(String name, String lastName, String email, String fromFullName, String vreName) {
|
private String getTextEmail(String name, String lastName, String email, String fromFullName, String vreName) {
|
||||||
String username = getASLSession().getUsername();
|
|
||||||
String portalUrl = null;
|
String portalUrl = null;
|
||||||
long orgId = getASLSession().getGroupId();
|
String vreDescription = null;
|
||||||
|
long organizationId = getASLSession().getGroupId();
|
||||||
try {
|
try {
|
||||||
portalUrl = PortalUtil.getPortalURL(OrganizationsUtil.getCompany().getVirtualHost(), PortalUtil.getPortalPort(), true);
|
portalUrl = PortalUtil.getPortalURL(OrganizationsUtil.getCompany().getVirtualHost(), PortalUtil.getPortalPort(), true);
|
||||||
|
vreDescription = OrganizationLocalServiceUtil.getOrganization(organizationId).getComments();
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
_log.warn("While trying to send email for invitation to " + email);
|
_log.warn("While trying to send email for invitation to " + email);
|
||||||
|
@ -112,16 +112,16 @@ public class InviteServiceImpl extends RemoteServiceServlet implements InviteSer
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder body = new StringBuilder();
|
StringBuilder body = new StringBuilder();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
body.append("Dear " + name)
|
body.append("Dear " + name)
|
||||||
.append(",\n")
|
.append(",\n")
|
||||||
.append(fromFullName).append(" has invited you to the " + vreName + " Virtual Research Environment.")
|
.append(fromFullName).append(" has invited you to " + vreName + ", you can find a brief description below:")
|
||||||
|
.append("\n")
|
||||||
|
.append("\n").append(convertHTML2Text(vreDescription))
|
||||||
.append("\n\n")
|
.append("\n\n")
|
||||||
.append("To accept the invite just follow this link: " + portalUrl + "/group/data-e-infrastructure-gateway/join-new?orgid="+orgId)
|
.append("To accept the invite just follow this link: " + portalUrl + "/group/data-e-infrastructure-gateway/join-new?orgid="+organizationId)
|
||||||
.append("\n\n")
|
.append("\n\n")
|
||||||
.append("Please note: if you do not have an account yet, please sign up first: " + portalUrl + "/web/guest/home?p_p_id=58&_58_struts_action=%2Flogin%2Fcreate_account")
|
.append("Please note: if you do not have an account yet, sign up first: " + portalUrl + "/web/guest/home?p_p_id=58&_58_struts_action=%2Flogin%2Fcreate_account")
|
||||||
.append("\n\n\n\n")
|
.append("\n\n\n\n")
|
||||||
.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain")
|
.append("WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain")
|
||||||
.append("information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. "
|
.append("information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. "
|
||||||
|
@ -133,33 +133,6 @@ public class InviteServiceImpl extends RemoteServiceServlet implements InviteSer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* read the portal instance name from a property file and returns it
|
|
||||||
*/
|
|
||||||
private static String getPortalInstanceName() {
|
|
||||||
//get the portles to look for from the property file
|
|
||||||
Properties props = new Properties();
|
|
||||||
String toReturn = "";
|
|
||||||
|
|
||||||
try {
|
|
||||||
String propertyfile = OrganizationsUtil.getTomcatFolder()+"conf/gcube-data.properties";
|
|
||||||
File propsFile = new File(propertyfile);
|
|
||||||
FileInputStream fis = new FileInputStream(propsFile);
|
|
||||||
props.load( fis);
|
|
||||||
toReturn = props.getProperty(GATEWAY_NAME);
|
|
||||||
}
|
|
||||||
//catch exception in case properties file does not exist
|
|
||||||
catch(IOException e) {
|
|
||||||
toReturn = "D4science Gateway";
|
|
||||||
_log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default Portal Name " + toReturn);
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
_log.debug("Returning Gateway Name: " + toReturn );
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read the sender email for notifications name from a property file and returns it
|
* read the sender email for notifications name from a property file and returns it
|
||||||
*/
|
*/
|
||||||
|
@ -185,4 +158,50 @@ public class InviteServiceImpl extends RemoteServiceServlet implements InviteSer
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert html into simple text
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected static String convertHTML2Text(String html) {
|
||||||
|
if (html == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String removedMarkup = html.replaceAll("&", "&");
|
||||||
|
removedMarkup = removedMarkup.replaceAll(">", ">");
|
||||||
|
removedMarkup = removedMarkup.replaceAll("<", "<");
|
||||||
|
String text = removedMarkup;
|
||||||
|
try {
|
||||||
|
Document document = Jsoup.parse(removedMarkup);
|
||||||
|
Element body = document.body();
|
||||||
|
text = buildStringFromNode(body).toString();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
_log.error("While converting HTML into text: " +e.getMessage());
|
||||||
|
return removedMarkup;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static StringBuffer buildStringFromNode(Node node) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
|
if (node instanceof TextNode) {
|
||||||
|
TextNode textNode = (TextNode) node;
|
||||||
|
buffer.append(textNode.text().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Node childNode : node.childNodes()) {
|
||||||
|
buffer.append(buildStringFromNode(childNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node instanceof Element) {
|
||||||
|
Element element = (Element) node;
|
||||||
|
String tagName = element.tagName();
|
||||||
|
if ("p".equals(tagName) || "br".equals(tagName) || "div".equals(tagName) || "h1".equals(tagName) || "h2".equals(tagName) || "h3".equals(tagName) || "h4".equals(tagName)) {
|
||||||
|
buffer.append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue