partially support for template email added

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/invites-common-library@148502 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-05-11 17:50:54 +00:00
parent 13c9d216ac
commit 0ec56ee80c
4 changed files with 30 additions and 113 deletions

View File

@ -18,7 +18,7 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

View File

@ -1,6 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error

13
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>invites-common-library</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>
gCube Invites Common Library is a common library containing shared code for Inviting external users to portal VREs.
@ -26,7 +26,7 @@
<properties>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.target>1.8</maven.compiler.target>
<liferay.version>6.2.5</liferay.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -53,6 +53,11 @@
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal.mailing</groupId>
<artifactId>email-templates-library</artifactId>
<version>[1.0.0-SNAPSHOT,)</version>
</dependency>
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
@ -104,8 +109,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>

View File

@ -17,6 +17,9 @@ import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Invite;
import org.gcube.portal.databook.shared.InviteOperationResult;
import org.gcube.portal.databook.shared.InviteStatus;
import org.gcube.portal.mailing.message.Recipient;
import org.gcube.portal.mailing.service.EmailTemplateService;
import org.gcube.portal.mailing.templates.TemplatedJoinMeInvite;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
@ -24,11 +27,6 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
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.LoggerFactory;
@ -103,24 +101,28 @@ public class InvitesManager {
String lastName,
String email,
String vreDescription) {
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(request);
String fromFullName = currUser.getFullname();
PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currUser = pContext.getCurrentUser(request);
String gatewayURL = pContext.getGatewayURL(request);
String gatewayName = pContext.getGatewayName(request);
try {
String subject = "Join me on " + vreName;
String subject = "Join me on " + vreName + " VRE";
long groupId = PortalContext.getConfiguration().getCurrentGroupId(request);
final String linkToAcceptInvite = portalURL + PortalContext.getConfiguration().getSiteLandingPagePath(request)+"/explore?siteId="+groupId;
final String linkToCreateAccount = portalURL + "/?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&saveLastPath=false&_58_struts_action=%2Flogin%2Fcreate_account";
EmailNotification mailToAdmin = new EmailNotification(
email ,
EmailTemplateService.send(
subject,
getHTMLEmail(name, lastName, email, fromFullName, vreName, vreDescription, linkToAcceptInvite, linkToCreateAccount),
request);
mailToAdmin.sendEmail();
_log.debug("Sent message successfully to " + email );
new TemplatedJoinMeInvite(gatewayName, gatewayURL, currUser, name, vreName, vreDescription, linkToAcceptInvite, linkToCreateAccount),
request,
new Recipient(email));
_log.debug("Join Me Invite email message sent successfully to " + email );
} catch (Exception mex) {
mex.printStackTrace();
_log.error("Sent message ERROR to " + email );
@ -128,97 +130,7 @@ public class InvitesManager {
}
return true;
}
/**
*
* @param aslSession
* @param portalUrl the url of the portal
* @param name the name of the invited person
* @param lastName the last name of the invited person
* @param email the email address of the invite person
* @param fromFullName who is inviting
* @param vreName the name of the environment where you are inviting the person
* @param vreDescription the description of the environment where you are inviting the person
* @return the email text
*/
private String getHTMLEmail(
String name,
String lastName,
String email,
String fromFullName,
String vreName,
String vreDescription,
String linkToAcceptInvite,
String linkToCreateAccount) {
linkToAcceptInvite = " <a href=\"" + linkToAcceptInvite + "\">" + linkToAcceptInvite + "</a> ";
linkToCreateAccount = " <a href=\"" + linkToCreateAccount + "\">" + linkToCreateAccount + "</a> ";
StringBuilder body = new StringBuilder();
body.append("<div style=\"color:#000; font-size:13px; font-family:'lucida grande',tahoma,verdana,arial,sans-serif;\">")
.append("Dear " + name)
.append(", <p>")
.append(fromFullName).append(" has invited you to " + vreName + ", you can find a brief description below:")
.append("</p>")
.append("<p>").append(vreDescription)
.append("</p>")
.append("<p>To accept the invite just follow this link: " + linkToAcceptInvite)
.append("</p>")
.append("</p>")
.append("Please note: if you do not have an account yet, sign up first: " + linkToCreateAccount)
.append("</p>")
.append("</div>");
return body.toString();
}
/**
* Convert html into simple text
*
*/
protected static String convertHTML2Text(String html) {
if (html == null) {
return null;
}
String removedMarkup = html.replaceAll("&amp;", "&");
removedMarkup = removedMarkup.replaceAll("&gt;", ">");
removedMarkup = removedMarkup.replaceAll("&lt;", "<");
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;
}
private static ArrayList<String> getAdministratorsEmails(String scope) {
LiferayUserManager userManager = new LiferayUserManager();
LiferayGroupManager groupManager = new LiferayGroupManager();