|
|
|
@ -1,13 +1,14 @@
|
|
|
|
|
package org.gcube.portlets.user.gcubeloggedin.server;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
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;
|
|
|
|
@ -17,9 +18,6 @@ import org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
|
|
|
@ -30,6 +28,7 @@ import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
@ -106,9 +105,9 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
|
|
|
|
|
|
|
|
|
|
_log.trace("CURRENT ORG SET IN SESSION: " + currSite.getGroupName());
|
|
|
|
|
|
|
|
|
|
long nowInMillis = new Date().getTime();
|
|
|
|
|
|
|
|
|
|
String name = currSite.getGroupName();
|
|
|
|
|
String logoURL = "/image/layout_set_logo?img_id="+currSite.getLogoId()+"&t="+nowInMillis;
|
|
|
|
|
String logoURL = gm.getGroupLogoURL(currSite.getLogoId());
|
|
|
|
|
String desc = "";
|
|
|
|
|
//set the description for the vre
|
|
|
|
|
if (currSite.getDescription() != null)
|
|
|
|
@ -190,6 +189,127 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isLeaveButtonAvailable(String portalURL) {
|
|
|
|
|
|
|
|
|
|
if(isWithinPortal()){
|
|
|
|
|
String friendlyURL = ScopeServiceImpl.extractOrgFriendlyURL(portalURL);
|
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
|
|
|
|
GCubeGroup currSite = null;
|
|
|
|
|
try {
|
|
|
|
|
List<GCubeGroup> groups = gm.listGroups();
|
|
|
|
|
for (GCubeGroup g : groups) {
|
|
|
|
|
if (g.getFriendlyURL().compareTo(friendlyURL) == 0) {
|
|
|
|
|
long groupId = g.getGroupId();
|
|
|
|
|
String scopeToSet = gm.getInfrastructureScope(groupId);
|
|
|
|
|
getASLSession().setScope(scopeToSet);
|
|
|
|
|
_log.info("GOT Selected Research Environment: " + scopeToSet);
|
|
|
|
|
currSite = g;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
Boolean isMandatory = false;
|
|
|
|
|
try{
|
|
|
|
|
isMandatory = (Boolean) gm.readCustomAttr(currSite.getGroupId(), org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys.MANDATORY.getKeyName());
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
_log.error("Unable to evaluate if the leave button can be added for the current group " + currSite.getGroupName(), e);
|
|
|
|
|
}
|
|
|
|
|
_log.debug("Is Leave button available in vre " + currSite.getGroupName() + " ? " + isMandatory);
|
|
|
|
|
return !isMandatory;
|
|
|
|
|
}else return true;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*@return the redirect url if everything goes ok, null otherwise
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String removeUserFromVRE() {
|
|
|
|
|
String username = getASLSession().getUsername();
|
|
|
|
|
if (username.compareTo("test.user") == 0)
|
|
|
|
|
return null;
|
|
|
|
|
_log.debug("Going to remove user from the current Group: " + getCurrentGroupID() + ". Username is: " + username);
|
|
|
|
|
UserManager userM = new LiferayUserManager();
|
|
|
|
|
try {
|
|
|
|
|
userM.dismissUserFromGroup(getCurrentGroupID(), userM.getUserId(username));
|
|
|
|
|
sendUserUnregisteredNotification(username, getASLSession().getScope(),
|
|
|
|
|
PortalContext.getConfiguration().getGatewayURL(getThreadLocalRequest()),
|
|
|
|
|
PortalContext.getConfiguration().getGatewayName(getThreadLocalRequest()));
|
|
|
|
|
return "/";
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get the current group ID
|
|
|
|
|
*
|
|
|
|
|
* @return the current group ID or null if an exception is thrown
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @throws CurrentGroupRetrievalException
|
|
|
|
|
*/
|
|
|
|
|
private long getCurrentGroupID(){
|
|
|
|
|
GroupManager groupM = new LiferayGroupManager();
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
_log.debug("The current group NAME is --> " + session.getGroupName());
|
|
|
|
|
try {
|
|
|
|
|
return groupM.getGroupId(session.getGroupName());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return true if you're running into the portal, false if in development
|
|
|
|
|
*/
|
|
|
|
|
private boolean isWithinPortal() {
|
|
|
|
|
try {
|
|
|
|
|
UserLocalServiceUtil.getService();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
|
|
|
|
_log.trace("Development Mode ON");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param scope .
|
|
|
|
|
* @param optionalMessage .
|
|
|
|
|
*/
|
|
|
|
|
public void sendUserUnregisteredNotification(String username, String scope, String portalbasicurl, String gatewayName) {
|
|
|
|
|
ArrayList<String> adminEmails = getAdministratorsEmails(scope);
|
|
|
|
|
UserManager um = new LiferayUserManager();
|
|
|
|
|
GCubeUser currUser = null;
|
|
|
|
|
try {
|
|
|
|
|
currUser = um.getUserByUsername(username);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
String name = currUser.getFirstName();
|
|
|
|
|
String lastname = currUser.getLastName();
|
|
|
|
|
|
|
|
|
|
StringBuffer body = new StringBuffer();
|
|
|
|
|
body.append("<p>Dear manager of "+ scope +",<br />this email message was automatically generated by " + portalbasicurl +" to inform you that ");
|
|
|
|
|
body.append("</p>");
|
|
|
|
|
body.append("<p>");
|
|
|
|
|
body.append("<b>"+name + " " + lastname +"</b> has left the following environment: ");
|
|
|
|
|
body.append("<br /><br />");
|
|
|
|
|
body.append("<b>" + scope+"</b>");
|
|
|
|
|
body.append("<br />");
|
|
|
|
|
body.append("<br />");
|
|
|
|
|
body.append("<b>Username: </b>" + username);
|
|
|
|
|
body.append("<br />");
|
|
|
|
|
body.append("<b>e-mail: </b>" + currUser.getEmail());
|
|
|
|
|
body.append("</p>");
|
|
|
|
|
|
|
|
|
|
String[] allMails = new String[adminEmails.size()];
|
|
|
|
|
|
|
|
|
|
adminEmails.toArray(allMails);
|
|
|
|
|
|
|
|
|
|
EmailNotification mailToAdmin = new EmailNotification(allMails , "Unregistration from VRE", body.toString(), getThreadLocalRequest());
|
|
|
|
|
|
|
|
|
|
mailToAdmin.sendEmail();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|