@ -21,10 +21,12 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager ;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager ;
import org.gcube.applicationsupportlayer.social.NotificationsManager ;
import org.gcube.common.portal.GCubePortalConstants ;
import org.gcube.common.portal.PortalContext ;
import org.gcube.common.scope.impl.ScopeBean ;
import org.gcube.common.scope.impl.ScopeBean.Type ;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil ;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper ;
import org.gcube.portal.databook.client.GCubeSocialNetworking ;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl ;
import org.gcube.portal.databook.server.DatabookStore ;
import org.gcube.portal.databook.shared.Attachment ;
@ -43,6 +45,7 @@ import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.CommentNotificationsThread ;
import org.gcube.portal.notifications.thread.LikeNotificationsThread ;
import org.gcube.portal.notifications.thread.MentionNotificationsThread ;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper ;
import org.gcube.portlets.user.newsfeed.client.NewsService ;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean ;
import org.gcube.portlets.user.newsfeed.shared.NewsConstants ;
@ -51,21 +54,22 @@ import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean ;
import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientImpl ;
import org.gcube.vomanagement.usermanagement.GroupManager ;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager ;
import org.gcube.vomanagement.usermanagement.UserManager ;
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 ;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup ;
import org.gcube.vomanagement.usermanagement.model.GCubeUser ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import com.google.gwt.user.client.Window.Location ;
import com.google.gwt.user.server.rpc.RemoteServiceServlet ;
import com.liferay.portal.kernel.exception.PortalException ;
import com.liferay.portal.kernel.exception.SystemException ;
import com.liferay.portal.kernel.util.WebKeys ;
import com.liferay.portal.model.Organization ;
import com.liferay.portal.model.Role ;
import com.liferay.portal.model.User ;
import com.liferay.portal.model.UserModel ;
import com.liferay.portal.service.OrganizationLocalServiceUtil ;
import com.liferay.portal.service.UserLocalServiceUtil ;
import com.liferay.portal.theme.ThemeDisplay ;
/ * *
* The server side implementation of the RPC service .
@ -74,10 +78,7 @@ import com.liferay.portal.theme.ThemeDisplay;
public class NewsServiceImpl extends RemoteServiceServlet implements NewsService {
private static final Logger _log = LoggerFactory . getLogger ( NewsServiceImpl . class ) ;
/ * *
*
* /
private static final String ADMIN_ROLE = "Administrator" ;
private static final String VRE_LABEL = "VRE_LABEL" ;
private static final String SHOW_TIMELINE_SOURCE = "SHOW_TIMELINE_SOURCE" ;
private static final String REFRESH_TIME = "REFRESH_TIME" ;
@ -139,7 +140,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* /
public String getDevelopmentUser ( ) {
String user = NewsConstants . TEST_USER ;
// user = "costantino.perciante";
// user = "costantino.perciante";
return user ;
}
/ * *
@ -179,18 +180,24 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
if ( username . compareTo ( NewsConstants . TEST_USER ) ! = 0 & & ! isDevelopment ) {
UserModel user = UserLocalServiceUtil . getUserByScreenName ( OrganizationsUtil . getCompany ( ) . getCompanyId ( ) , username ) ;
thumbnailURL = "/image/user_male_portrait?img_id=" + user . getPortraitId ( ) ;
fullName = user . getFirstName ( ) + " " + user . getLastName ( ) ;
email = user . getEmailAddress ( ) ;
String accountURL = "" ;
UserManager um = new LiferayUserManager ( ) ;
GCubeUser user = um . getUserByUsername ( username ) ;
thumbnailURL = user . getUserAvatarURL ( ) ;
fullName = user . getFullname ( ) ;
email = user . getEmail ( ) ;
final String profilePageURL =
GCubePortalConstants . PREFIX_GROUP_URL +
PortalContext . getConfiguration ( ) . getSiteLandingPagePath ( getThreadLocalRequest ( ) ) +
GCubePortalConstants . USER_PROFILE_FRIENDLY_URL ;
String accountURL = profilePageURL ;
try {
ThemeDisplay themeDisplay = ( ThemeDisplay ) this . getThreadLocalRequest ( ) . getSession ( ) . getAttribute ( WebKeys . THEME_DISPLAY ) ;
accountURL = themeDisplay . getURLMyAccount ( ) . toString ( ) ;
accountURL = "" ;
} catch ( NullPointerException e ) {
e . printStackTrace ( ) ;
}
UserInfo userInfo = new UserInfo ( username , fullName , thumbnailURL , user . getEmailAddress ( ) , accountURL , true , isAdmin ( ) , null ) ;
UserInfo userInfo = new UserInfo ( username , fullName , thumbnailURL , user . getEmail ( ) , accountURL , true , isAdmin ( ) , null ) ;
CustomConfiguration config = getUserConfiguration ( ) ;
UserSettings toReturn = new UserSettings ( userInfo , config . getRefreshTime ( ) , session . getScopeName ( ) , config . getVreLabel ( ) , isInfrastructureScope ( ) , config . isShowTimelineSource ( ) ) ;
setUserSettingsInSession ( toReturn ) ;
@ -243,18 +250,20 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return null ;
}
_log . info ( "****** retrieving feeds for user: " + userName ) ;
User currUser = OrganizationsUtil . validateUser ( userName ) ;
_log . info ( "****** retrieving posts for user: " + userName ) ;
UserManager um = new LiferayUserManager ( ) ;
GCubeUser currUser = um . getUserByUsername ( userName ) ;
/ * *
* this handles the case where the portlet is deployed outside of VREs ( regular )
* /
if ( isInfrastructureScope ( ) ) {
_log . info ( "****** risInfrastructureScope() = true" ) ;
//VRE Feeds
GroupManager gm = new LiferayGroupManager ( ) ;
for ( Organization org : currUser . getOrganizations ( ) ) {
if ( gm . isVRE ( org. getOrganizationId ( ) + "" ) ) {
String vreid = gm . get Scope( "" + org . getOrganization Id( ) ) ; //get the scope
_log . trace ( "Reading feeds for VRE: " + vreid ) ;
for ( GCubeGroup group : gm . listGroupsByUser ( currUser . getUserId ( ) ) ) {
if ( gm . isVRE ( group. getGroupId ( ) ) ) {
String vreid = gm . get InfrastructureScope( group . getGroup Id( ) ) ; //get the scope
_log . info ( "Reading feeds for VRE: " + vreid ) ;
ArrayList < Feed > OrganizationFeeds = ( ArrayList < Feed > ) store . getRecentFeedsByVRE ( vreid , feedsNoPerCategory ) ;
for ( Feed feed : OrganizationFeeds ) {
feedsMap . put ( feed . getKey ( ) , feed ) ;
@ -328,16 +337,18 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
String lowerCaseHashtag = hashtag . toLowerCase ( ) ;
/ * *
* this handles the case where the portlet is deployed outside of VREs ( regular )
* /
if ( isInfrastructureScope ( ) ) {
User currUser = OrganizationsUtil . validateUser ( userName ) ;
UserManager um = new LiferayUserManager ( ) ;
GCubeUser currUser = um . getUserByUsername ( userName ) ;
//VRE Feeds
for ( Organization org : currUser . getOrganizations ( ) ) {
GroupManager gm = new LiferayGroupManager ( ) ;
if ( gm . isVRE ( org. getOrganizationId ( ) + "" ) ) {
String vreid = gm . get Scope( "" + org . getOrganization Id( ) ) ; //get the scope
GroupManager gm = new LiferayGroupManager ( ) ;
for ( GCubeGroup group : gm . listGroupsByUser ( currUser . getUserId ( ) ) ) {
if ( gm . isVRE ( group. getGroupId ( ) ) ) {
String vreid = gm . get InfrastructureScope( group . getGroup Id( ) ) ; //get the scope
ArrayList < Feed > feeds = ( ArrayList < Feed > ) store . getVREFeedsByHashtag ( vreid , lowerCaseHashtag ) ;
for ( Feed feed : feeds ) {
feedsMap . put ( feed . getKey ( ) , feed ) ;
@ -410,11 +421,13 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
Set < String > vres = new HashSet < String > ( ) ;
if ( isInfrastructureScope ( ) ) {
User currUser = OrganizationsUtil . validateUser ( userName ) ;
for ( Organization org : currUser . getOrganizations ( ) ) {
GroupManager gm = new LiferayGroupManager ( ) ;
if ( gm . isVRE ( org . getOrganizationId ( ) + "" ) ) {
String vreid = gm . getScope ( "" + org . getOrganizationId ( ) ) ; //get the scope
UserManager um = new LiferayUserManager ( ) ;
GCubeUser currUser = um . getUserByUsername ( userName ) ;
//VRE Feeds
GroupManager gm = new LiferayGroupManager ( ) ;
for ( GCubeGroup group : gm . listGroupsByUser ( currUser . getUserId ( ) ) ) {
if ( gm . isVRE ( group . getGroupId ( ) ) ) {
String vreid = gm . getInfrastructureScope ( group . getGroupId ( ) ) ; //get the scope
vres . add ( vreid ) ;
}
}
@ -701,7 +714,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
ArrayList < ItemBean > mentionedUsers = null ;
if ( mentionedUserFullNames ! = null & & ! mentionedUserFullNames . isEmpty ( ) ) {
mentionedUsers = getSelectedUserIds ( mentionedUserFullNamesList ) ;
escapedCommentText = Utils . convertMentionPeopleAnchorHTML ( escapedCommentText , mentionedUsers );
escapedCommentText = Utils . convertMentionPeopleAnchorHTML ( escapedCommentText , mentionedUsers , getThreadLocalRequest ( ) );
}
Comment comment = new Comment ( UUID . randomUUID ( ) . toString ( ) , user . getUsername ( ) ,
@ -857,20 +870,13 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
if ( ! isWithinPortal ( ) ) {
return "" ;
}
StringBuilder thumbnailURL = new StringBuilder ( "/image/user_male_portrait?img_id=" ) ;
User user = null ;
String thumbnailURL = "" ;
try {
user = UserLocalServiceUtil . getUserByScreenName ( OrganizationsUtil . getCompany ( ) . getCompanyId ( ) , screenName ) ;
}
catch ( com . liferay . portal . NoSuchUserException ex ) {
return null ;
}
catch ( PortalException e ) {
e . printStackTrace ( ) ;
} catch ( SystemException e ) {
thumbnailURL = new LiferayUserManager ( ) . getUserByUsername ( screenName ) . getUserAvatarURL ( ) ;
} catch ( UserManagementSystemException | UserRetrievalFault e ) {
e . printStackTrace ( ) ;
}
return thumbnailURL .append ( user . getPortraitId ( ) ) . toString ( ) ;
return thumbnailURL ;
}
@Override
@ -992,7 +998,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
if ( fullNames = = null )
return new ArrayList < ItemBean > ( ) ;
else {
ArrayList < ItemBean > allUsers = Utils . getOrganizationUsers ( "/" + OrganizationsUtil. getRootOrganization Name( ) , getASLSession ( ) . getUsername ( ) , isWithinPortal ( ) ) ;
ArrayList < ItemBean > allUsers = Utils . getOrganizationUsers ( "/" + PortalContext. getConfiguration ( ) . getInfrastructure Name( ) , getASLSession ( ) . getUsername ( ) , isWithinPortal ( ) ) ;
ArrayList < ItemBean > toReturn = new ArrayList < ItemBean > ( ) ;
for ( String fullName : fullNames )
for ( ItemBean puser : allUsers ) {
@ -1014,40 +1020,16 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
private boolean isAdmin ( ) throws PortalException , SystemException {
if ( ! isWithinPortal ( ) )
return false ;
try {
User currUser = OrganizationsUtil . validateUser ( getASLSession ( ) . getUsername ( ) ) ;
List < Organization > organizations = OrganizationLocalServiceUtil . getOrganizations ( 0 , OrganizationLocalServiceUtil . getOrganizationsCount ( ) ) ;
Organization rootOrganization = null ;
for ( Organization organization : organizations ) {
if ( organization . getName ( ) . equals ( OrganizationsUtil . getRootOrganizationName ( ) ) ) {
rootOrganization = organization ;
break ;
}
}
_log . trace ( "root: " + rootOrganization . getName ( ) ) ;
return ( hasRole ( ADMIN_ROLE , rootOrganization . getName ( ) , currUser ) ) ;
GCubeUser curUser = new LiferayUserManager ( ) . getUserByUsername ( getASLSession ( ) . getUsername ( ) ) ;
return new LiferayRoleManager ( ) . isAdmin ( curUser . getUserId ( ) ) ;
}
catch ( NullPointer Exception e ) {
_log . error ( "C annot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder ") ;
catch ( Exception e ) {
_log . error ( "Could not check if the user is an Administrator, returning false" ) ;
return false ;
}
}
/ * *
*
* @param rolename
* @param organizationName
* @param user
* @return
* @throws SystemException
* /
private boolean hasRole ( String rolename , String organizationName , User user ) throws SystemException {
for ( Role role : user . getRoles ( ) )
if ( role . getName ( ) . compareTo ( rolename ) = = 0 )
return true ;
return false ;
}
/ * *
* utilty method that convert a URL in a text into a clickable link into the browser
*