integrated with centralized email notification

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gcube-loggedin@128317 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Massimiliano Assante 8 years ago
parent 2502e41f0b
commit 6981a11ea7

@ -6,7 +6,7 @@
<dependent-module archiveName="gcube-widgets-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="session-checker-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependent-module archiveName="session-checker-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

@ -1,95 +0,0 @@
package org.gcube.portlets.user.gcubeloggedin.server;
import java.util.Date;
import java.util.Properties;
import javax.mail.Address;
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.log4j.Logger;
/**
* A class for sending email
*
* @author Panagiota Koltsida, NKUA
*
*/
public class EmailNotification {
/**
* The sender of the email
*/
private String emailSender;
/**
* The recipients of the email
*/
private String emailrecipients[];
/**
* Email's subject
*/
private String emailSubject;
/**
* Email's body message
*/
private String emailBody;
/** Logger */
private static Logger logger = Logger.getLogger(EmailNotification.class);
/**
* Class's constructor
*
* @param sender
* @param recipients
* @param subject
* @param body
*/
public EmailNotification(String sender, String recipients[], String subject, String body) {
this.emailSender = sender;
this.emailrecipients = recipients;
this.emailSubject = subject;
this.emailBody = body;
}
public void sendEmail() {
Properties props = System.getProperties();
String mailServiceHost = "localhost";
props.put("mail.smtp.host", mailServiceHost);
String mailServicePort = "25";
props.put("mail.smtp.port", mailServicePort);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Message mimeMessage = new MimeMessage(session);
try {
// EMAIL SENDER
Address from = new InternetAddress(emailSender);
mimeMessage.setFrom(from);
// EMAIL RECIPIENTS
for (int i=0; i<emailrecipients.length; i++) {
Address address = new InternetAddress(emailrecipients[i]);
mimeMessage.addRecipient(Message.RecipientType.TO, address);
}
mimeMessage.setSubject(emailSubject);
// mimeMessage.setText(emailBody);
mimeMessage.setContent(emailBody, "text/html");
mimeMessage.setSentDate(new Date());
Transport.send(mimeMessage);
} catch (Exception e) {
e.printStackTrace();
logger.error("Failed to send the email message.", e);
}
}
}

@ -8,6 +8,7 @@ import java.util.Set;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.portal.mailing.EmailNotification;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject;
@ -123,17 +124,19 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
if (currSite.getDescription() != null)
desc = currSite.getDescription();
System.out.println(" **** debuggaaa");
Boolean isRequestBasedGroup = false;
Boolean isMandatory = false;
try {
isMandatory = (Boolean) gm.readCustomAttr(currSite.getGroupId(), org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys.MANDATORY.getKeyName());
isRequestBasedGroup = currSite.isRequestBasedGroup();
} catch (Exception e) {
e.printStackTrace();
isMandatory = false;
isRequestBasedGroup = false;
return new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, isMandatory, isRequestBasedGroup);
}
VREClient vre = new VREClient(
name, "", desc, logoURL, "", UserBelongingClient.BELONGING,
isMandatory,
currSite.isRequestBasedGroup());
VREClient vre = new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, isMandatory, isRequestBasedGroup);
return vre;
}
/**
@ -225,7 +228,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* @param scope .
* @param optionalMessage .
*/
public static void sendUserUnregisteredNotification(String username, String scope, String portalbasicurl, String gatewayName) {
public void sendUserUnregisteredNotification(String username, String scope, String portalbasicurl, String gatewayName) {
ArrayList<String> adminEmails = getAdministratorsEmails(scope);
UserManager um = new LiferayUserManager();
GCubeUser currUser = null;
@ -250,17 +253,12 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
body.append("<br />");
body.append("<b>e-mail: </b>" + currUser.getEmail());
body.append("</p>");
body.append("<p>");
body.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"+
" information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. " +
"If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message.");
body.append("</p>");
String[] allMails = new String[adminEmails.size()];
adminEmails.toArray(allMails);
EmailNotification mailToAdmin = new EmailNotification("no-reply@d4science.org", allMails , "[" + gatewayName + "] - unregistration from VRE", body.toString());
EmailNotification mailToAdmin = new EmailNotification(allMails , "unregistration from VRE", body.toString(), getThreadLocalRequest());
mailToAdmin.sendEmail();
}

Loading…
Cancel
Save