@ -11,14 +11,16 @@ import javax.mail.internet.AddressException;
import javax.servlet.http.HttpServletRequest ;
import org.gcube.common.portal.PortalContext ;
import org.gcube.common.portal.mailing.EmailNotification ;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl ;
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.EmailAddress ;
import org.gcube.portal.mailing.message.Recipient ;
import org.gcube.portal.mailing.message.RecipientType ;
import org.gcube.portal.mailing.service.EmailTemplateService ;
import org.gcube.portal.mailing.templates.TemplateUserHasInvited ;
import org.gcube.portal.mailing.templates.TemplatedJoinMeInvite ;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault ;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException ;
@ -80,8 +82,8 @@ public class InvitesManager {
try {
String vreName = PortalContext . getConfiguration ( ) . getCurrentGroupName ( request ) ;
result = store . saveInvite ( invite ) ;
emailResult = sendInviteEmail ( request , vreName, portalSenderEmail , portalURL , name , lastN ame, email , vreDescription ) ;
notifyInviteSent ( request , username , currScope , invite , vreName ) ;
emailResult = sendInviteEmail ( request , currUser, vreName , n ame, email , vreDescription ) ;
notifyInviteSent ( request , c urrU ser, currScope , invite , vreName ) ;
} catch ( AddressException e ) {
_log . error ( "Email not valid " + e . getMessage ( ) ) ;
@ -94,16 +96,13 @@ public class InvitesManager {
private Boolean sendInviteEmail (
HttpServletRequest request ,
GCubeUser currUser ,
String vreName ,
String portalSenderEmail ,
String portalURL ,
String name ,
String lastName ,
String email ,
String vreDescription ) {
PortalContext pContext = PortalContext . getConfiguration ( ) ;
GCubeUser currUser = pContext . getCurrentUser ( request ) ;
String gatewayURL = pContext . getGatewayURL ( request ) ;
String gatewayName = pContext . getGatewayName ( request ) ;
@ -112,14 +111,14 @@ public class InvitesManager {
String subject = "Join me on " + vreName + " VRE" ;
long groupId = PortalContext . getConfiguration ( ) . getCurrentGroupId ( request ) ;
final String linkToAcceptInvite = portal URL + PortalContext . getConfiguration ( ) . getSiteLandingPagePath ( request ) + "/explore?siteId=" + groupId ;
final String linkToCreateAccount = portal URL + "/?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" ;
final String linkToAcceptInvite = gateway URL + PortalContext . getConfiguration ( ) . getSiteLandingPagePath ( request ) + "/explore?siteId=" + groupId ;
final String linkToCreateAccount = gateway URL + "/?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" ;
EmailTemplateService . send (
subject ,
new TemplatedJoinMeInvite ( gatewayName , gatewayURL , currUser , name , vreName , vreDescription , linkToAcceptInvite , linkToCreateAccount ) ,
request ,
new Recipient ( email ) );
new Recipient ( email ) , new Recipient ( new EmailAddress ( currUser . getEmail ( ) ) , RecipientType . CC ) );
_log . debug ( "Join Me Invite email message sent successfully to " + email ) ;
@ -130,6 +129,31 @@ public class InvitesManager {
}
return true ;
}
/ * *
*
* @param request
* @param username
* @param scope
* @param invite
* @param vreName
* /
public static void notifyInviteSent ( HttpServletRequest request , GCubeUser currUser , String scope , Invite invite , String vreName ) {
List < Recipient > adminRecipients = new ArrayList < > ( ) ;
for ( String email : getAdministratorsEmails ( scope ) ) {
adminRecipients . add ( new Recipient ( email ) ) ;
}
String gatewayURL = PortalContext . getConfiguration ( ) . getGatewayURL ( request ) ;
String gatewayName = PortalContext . getConfiguration ( ) . getGatewayName ( request ) ;
String subject = new StringBuffer ( "invite was sent on " ) . append ( vreName ) . append ( " by " ) . append ( invite . getSenderFullName ( ) ) . toString ( ) ;
EmailTemplateService . send (
subject ,
new TemplateUserHasInvited ( currUser , invite . getInvitedEmail ( ) , vreName , gatewayName , gatewayURL ) ,
request ,
adminRecipients . toArray ( new Recipient [ adminRecipients . size ( ) ] ) ) ;
}
private static ArrayList < String > getAdministratorsEmails ( String scope ) {
LiferayUserManager userManager = new LiferayUserManager ( ) ;
@ -173,27 +197,5 @@ public class InvitesManager {
return adminEmailsList ;
}
/ * *
*
* @param scope .
* @param optionalMessage .
* /
public static void notifyInviteSent ( HttpServletRequest request , String username , String scope , Invite invite , String vreName ) {
ArrayList < String > adminEmails = getAdministratorsEmails ( scope ) ;
StringBuffer body = new StringBuffer ( ) ;
body . append ( "<p>Dear manager of " + scope + ",<br />this email message was automatically generated by " + PortalContext . getConfiguration ( ) . getGatewayURL ( request ) + " to inform you that " ) ;
body . append ( "</p>" ) ;
body . append ( "<p>" ) ;
body . append ( "<b>" + invite . getSenderFullName ( ) + " (" + invite . getSenderUserId ( ) + ")</b> has invited " + invite . getInvitedEmail ( ) + " to the following environment:" ) ;
body . append ( "<br /><br />" ) ;
body . append ( "<b>" + scope + "</b>" ) ;
body . append ( "</p>" ) ;
String [ ] allMails = new String [ adminEmails . size ( ) ] ;
adminEmails . toArray ( allMails ) ;
EmailNotification mailToAdmin = new EmailNotification ( allMails , "An invite was sent on " + vreName + " by " + invite . getSenderFullName ( ) , body . toString ( ) , request ) ;
mailToAdmin . sendEmail ( ) ;
}
}