|
|
|
@ -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("&", "&");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ArrayList<String> getAdministratorsEmails(String scope) {
|
|
|
|
|
LiferayUserManager userManager = new LiferayUserManager();
|
|
|
|
|
LiferayGroupManager groupManager = new LiferayGroupManager();
|
|
|
|
|