@ -5,19 +5,17 @@ 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 ;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject.UserBelongingClient ;
import org.gcube.portlets.user.gcubeloggedin.shared.VREClient ;
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.impl.LiferayGroupManager ;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager ;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager ;
@ -37,34 +35,22 @@ import com.liferay.portal.service.UserLocalServiceUtil;
public class LoggedinServiceImpl extends RemoteServiceServlet implements LoggedinService {
private static final Logger _log = LoggerFactory . getLogger ( LoggedinServiceImpl . class ) ;
private static final String VRE_MANAGER_ROLE = "VRE-Manager" ;
/ * *
* the current ASLSession
* @return .
* /
private ASLSession getASLSession ( ) {
String sessionID = this . getThreadLocalRequest ( ) . getSession ( ) . getId ( ) ;
String user = ( String ) this . getThreadLocalRequest ( ) . getSession ( ) . getAttribute ( ScopeHelper . USERNAME_ATTRIBUTE ) ;
if ( user = = null ) {
_log . warn ( "LOGGEDIN PORTLET: USER IS NULL \n\n SESSION ID READ: " + sessionID ) ;
user = "test.user" ;
_log . warn ( "session ID= *" + sessionID + "* user= *" + user + "*" ) ;
}
return SessionManager . getInstance ( ) . getASLSession ( sessionID , user ) ;
}
private PortalContext context = PortalContext . getConfiguration ( ) ;
/ * *
* return the current selected VRE
* /
public VObject getSelectedRE ( String portalURL ) {
ASLSession aslSession = getASLSession ( ) ;
String friendlyURL = ScopeServiceImpl . extractOrgFriendlyURL ( portalURL ) ;
long currGroupId = context . getCurrentGroupId ( getThreadLocalRequest ( ) ) ;
GroupManager gm = new LiferayGroupManager ( ) ;
GCubeGroup currGroup = null ;
try {
currGroup = gm . getGroup ( currGroupId ) ;
} catch ( UserManagementSystemException | GroupRetrievalFault e1 ) {
e1 . printStackTrace ( ) ;
}
String friendlyURL = currGroup . getFriendlyURL ( ) ;
_log . debug ( "curr group: " + currGroup . getGroupName ( ) + " friendlyURL = " + friendlyURL ) ;
if ( friendlyURL = = null ) { //the URL is not a portal URL, we are in devmode.
return new VREClient ( "Test VRE Name" , "" , "" +
"Fishery and Aquaculture Resources Management (FARM) Virtual Organisation</b> The FARM Virtual Organisation is the <b><i>dynamic group of individuals</i></b> and/or <b><i>institutions</i></b> defined around a set of <b><i>sharing rules</i></b> in which <b><i>resource providers</i></b> and <b><i>consumers</i></b> specify clearly and carefully just what is shared, who is allowed to share, and the conditions under which sharing occurs to serve the needs of the <b><i>Fisheries and Aquaculture Resources Management</i></b>. "
@ -79,39 +65,15 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
, "http://placehold.it/300x200" , "" , UserBelongingClient . BELONGING , false , true , true ) ;
}
_log . trace ( "getting Selected Research Environment" ) ;
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 ( ) ;
}
/ * *
* set the current ORG bean in session
* /
aslSession . setAttribute ( ScopeHelper . CURR_ORG , currSite ) ;
aslSession . setGroupModelInfos ( currSite . getGroupName ( ) , currSite . getGroupId ( ) ) ;
_log . trace ( "CURRENT ORG SET IN SESSION: " + currSite . getGroupName ( ) ) ;
String name = currSite . getGroupName ( ) ;
String logoURL = gm . getGroupLogoURL ( currSite . getLogoId ( ) ) ;
String name = currGroup . getGroupName ( ) ;
String logoURL = gm . getGroupLogoURL ( currGroup . getLogoId ( ) ) ;
String desc = "" ;
//set the description for the vre
if ( curr Site . getDescription ( ) ! = null )
desc = curr Site . getDescription ( ) ;
if ( currGroup . getDescription ( ) ! = null )
desc = currGroup . getDescription ( ) ;
return new VREClient ( name , "" , desc , logoURL , "" , UserBelongingClient . BELONGING , false , false , isCurrUserVREManager ( ) ) ;
}
@ -120,15 +82,14 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* @return
* /
private boolean isCurrUserVREManager ( ) {
ASLSession session = getASLSession ( ) ;
long userId ;
try {
userId = new LiferayUserManager ( ) . getUserId ( session . getUsername ( ) ) ;
long groupId = new LiferayGroupManager ( ) . getGroupIdFromInfrastructureScope ( session . getScope ( ) ) ;
userId = context . getCurrentUser ( getThreadLocalRequest ( ) ) . getUserId ( ) ;
long groupId = context . getCurrentGroupId ( getThreadLocalRequest ( ) ) ;
RoleManager rm = new LiferayRoleManager ( ) ;
long roleId = rm . getRoleIdByName ( VRE_MANAGER_RO LE) ;
long roleId = rm . getRoleIdByName ( GCubeRole. VRE_MANAGER_LAB EL ) ;
boolean toReturn = rm . hasRole ( userId , groupId , roleId ) ;
_log . debug ( "User " + session . getUsername ( ) + " is " + VRE_MANAGER_ROLE + " for " + session . getScope ( ) + "? -> " + toReturn ) ;
return toReturn ;
} catch ( Exception e ) {
@ -179,11 +140,9 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
@Override
public String saveVREDescription ( String toSave ) {
try {
String scope = getASLSession ( ) . getScope ( ) ;
GroupManager gm = new LiferayGroupManager ( ) ;
long groupId = gm . getGroupIdFromInfrastructureScope ( scope ) ;
return gm . updateGroupDescription ( groupId , toSave ) ;
try {
long groupId = context . getCurrentGroupId ( getThreadLocalRequest ( ) ) ;
return new LiferayGroupManager ( ) . updateGroupDescription ( groupId , toSave ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
@ -193,30 +152,22 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
public boolean isLeaveButtonAvailable ( String portalURL ) {
if ( isWithinPortal ( ) ) {
String friendlyURL = ScopeServiceImpl . extractOrgFriendlyURL ( portalURL ) ;
long currGroupId = context . getCurrentGroupId ( getThreadLocalRequest ( ) ) ;
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 ( ) ;
GCubeGroup currGroup = null ;
try {
currGroup = gm . getGroup ( currGroupId ) ;
} catch ( UserManagementSystemException | GroupRetrievalFault e1 ) {
e1 . printStackTrace ( ) ;
}
Boolean isMandatory = false ;
try {
isMandatory = ( Boolean ) gm . readCustomAttr ( curr Site . getGroupId ( ) , org . gcube . vomanagement . usermanagement . model . CustomAttributeKeys . MANDATORY . getKeyName ( ) ) ;
isMandatory = ( Boolean ) gm . readCustomAttr ( currGroup . 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 " + curr Site . getGroupName ( ) , e ) ;
_log . error ( "Unable to evaluate if the leave button can be added for the current group " + currGroup . getGroupName ( ) , e ) ;
}
_log . debug ( "Is Leave button available in vre " + curr Site . getGroupName ( ) + " ? " + isMandatory ) ;
_log . debug ( "Is Leave button available in vre " + currGroup . getGroupName ( ) + " ? " + isMandatory ) ;
return ! isMandatory ;
} else return true ;
}
@ -225,14 +176,15 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* /
@Override
public String removeUserFromVRE ( ) {
String username = getASLSession ( ) . getUsername ( ) ;
String username = context . getCurrentUser ( getThreadLocalRequest ( ) ) . getUsername ( ) ;
String scope = context . getCurrentScope ( getThreadLocalRequest ( ) ) ;
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 , getASLSe ssion( ) . getS cope( ) ,
sendUserUnregisteredNotification ( username , scope,
PortalContext . getConfiguration ( ) . getGatewayURL ( getThreadLocalRequest ( ) ) ,
PortalContext . getConfiguration ( ) . getGatewayName ( getThreadLocalRequest ( ) ) ) ;
@ -249,16 +201,8 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi
* @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 ;
private long getCurrentGroupID ( ) {
return context . getCurrentGroupId ( getThreadLocalRequest ( ) ) ;
}
/ * *
*