|
|
|
@ -19,17 +19,12 @@ import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
|
|
|
|
|
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.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
|
|
|
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
|
|
|
|
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.scopemanager.scopehelper.ScopeHelper;
|
|
|
|
|
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
|
import org.gcube.portal.databook.shared.Attachment;
|
|
|
|
@ -60,6 +55,7 @@ import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientI
|
|
|
|
|
import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientInterface;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.TeamRetrievalFault;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
|
|
|
@ -89,9 +85,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
private static final String REFRESH_TIME = "REFRESH_TIME";
|
|
|
|
|
|
|
|
|
|
private static final String SESSION_ADMIN_ATTR = "SESSION_ADMIN_ATTR";
|
|
|
|
|
private static final String USER_SETTINGS_ATTR = "USER_SETTINGS_ATTR";
|
|
|
|
|
|
|
|
|
|
public static final String TEST_SCOPE = "/gcube/devNext/NextNext";
|
|
|
|
|
|
|
|
|
|
private String APP_ID;
|
|
|
|
|
|
|
|
|
@ -124,31 +118,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
public void destroy() {
|
|
|
|
|
store.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* the current ASLSession
|
|
|
|
|
* @return the session
|
|
|
|
|
*/
|
|
|
|
|
private ASLSession getASLSession() {
|
|
|
|
|
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
|
|
|
|
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
|
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
|
|
|
|
|
user = getDevelopmentUser();
|
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, user).setScope(TEST_SCOPE);
|
|
|
|
|
}
|
|
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* when packaging test will fail if the user is not set to test.user
|
|
|
|
|
* @return .
|
|
|
|
|
*/
|
|
|
|
|
public String getDevelopmentUser() {
|
|
|
|
|
String user = NewsConstants.TEST_USER;
|
|
|
|
|
// user = "costantino.perciante";
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return true if you're running into the portal, false if in development
|
|
|
|
@ -168,53 +137,28 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public UserSettings getUserSettings() {
|
|
|
|
|
if (getUserSettingsFromSession() != null)
|
|
|
|
|
return getUserSettingsFromSession();
|
|
|
|
|
try {
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
String username = session.getUsername();
|
|
|
|
|
String email = username+"@isti.cnr.it";
|
|
|
|
|
String fullName = username+" FULL";
|
|
|
|
|
String thumbnailURL = "images/Avatar_default.png";
|
|
|
|
|
PortalContext context = PortalContext.getConfiguration();
|
|
|
|
|
GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest());
|
|
|
|
|
String username = currUser.getUsername();
|
|
|
|
|
String email = currUser.getEmail();
|
|
|
|
|
String fullName = currUser.getFullname();
|
|
|
|
|
String thumbnailURL = currUser.getUserAvatarURL();
|
|
|
|
|
|
|
|
|
|
boolean isDevelopment = false;
|
|
|
|
|
try {
|
|
|
|
|
UserLocalServiceUtil.getService();
|
|
|
|
|
}
|
|
|
|
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
|
|
|
|
isDevelopment = true;
|
|
|
|
|
}
|
|
|
|
|
String groupName = context.getCurrentGroupName(getThreadLocalRequest());
|
|
|
|
|
|
|
|
|
|
if (username.compareTo(NewsConstants.TEST_USER) != 0 && !isDevelopment) {
|
|
|
|
|
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;
|
|
|
|
|
final String profilePageURL =
|
|
|
|
|
GCubePortalConstants.PREFIX_GROUP_URL +
|
|
|
|
|
PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest())+
|
|
|
|
|
GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
|
|
|
|
String accountURL = profilePageURL;
|
|
|
|
|
|
|
|
|
|
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, email, accountURL, true, isAdmin(), null);
|
|
|
|
|
CustomConfiguration config = getUserConfiguration();
|
|
|
|
|
UserSettings toReturn = new UserSettings(userInfo, config.getRefreshTime(), groupName, config.getVreLabel(), isInfrastructureScope(), config.isShowTimelineSource());
|
|
|
|
|
return toReturn;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
accountURL = "";
|
|
|
|
|
}catch (NullPointerException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
_log.info("Returning test USER");
|
|
|
|
|
CustomConfiguration config = getUserConfiguration();
|
|
|
|
|
UserInfo user = new UserInfo(session.getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, null);
|
|
|
|
|
return new UserSettings(user, config.getRefreshTime(), session.getScopeName(), config.getVreLabel(), isInfrastructureScope(), config.isShowTimelineSource());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -225,78 +169,66 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
/**
|
|
|
|
|
* Indicates whether the scope is the whole infrastructure.
|
|
|
|
|
* @return <code>true</code> if it is, <code>false</code> otherwise.
|
|
|
|
|
* @throws GroupRetrievalFault
|
|
|
|
|
* @throws UserManagementSystemException
|
|
|
|
|
*/
|
|
|
|
|
private boolean isInfrastructureScope() {
|
|
|
|
|
boolean toReturn = false;
|
|
|
|
|
try {
|
|
|
|
|
ScopeBean scope = new ScopeBean(getASLSession().getScope());
|
|
|
|
|
toReturn = scope.is(Type.INFRASTRUCTURE);
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
catch (NullPointerException e) {
|
|
|
|
|
_log.error("NullPointerException in isInfrastructureScope returning false");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
private boolean isInfrastructureScope() throws UserManagementSystemException, GroupRetrievalFault {
|
|
|
|
|
PortalContext context = PortalContext.getConfiguration();
|
|
|
|
|
String scope = context.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
|
|
|
|
|
long groupId = context.getCurrentGroupId(getThreadLocalRequest());
|
|
|
|
|
boolean isInfrastructureScope = new LiferayGroupManager().isRootVO(groupId);
|
|
|
|
|
_log.debug("isInfrastructureScope? " + scope + " groupId=" + groupId + " ? i say " + isInfrastructureScope);
|
|
|
|
|
return isInfrastructureScope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int feedsNoPerCategory) {
|
|
|
|
|
String userName = getASLSession().getUsername();
|
|
|
|
|
|
|
|
|
|
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
|
|
|
|
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
|
|
|
|
try {
|
|
|
|
|
if (!isWithinPortal()) {
|
|
|
|
|
return getEclipseResult(userName, feedsNoPerCategory, false);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
|
|
|
|
|
//this check just return nothing if that happens
|
|
|
|
|
if (userName.compareTo("test.user") == 0) {
|
|
|
|
|
_log.debug("Found " + userName + " returning nothing");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_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 (GCubeGroup group : gm.listGroupsByUserAndSite(currUser.getUserId(), getThreadLocalRequest().getServerName())) {
|
|
|
|
|
if (gm.isVRE(group.getGroupId())) {
|
|
|
|
|
String vreid = gm.getInfrastructureScope(group.getGroupId()); //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);
|
|
|
|
|
}
|
|
|
|
|
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
|
|
|
|
_log.info("****** retrieving posts for user: " + currUser.getScreenName());
|
|
|
|
|
/**
|
|
|
|
|
* this handles the case where the portlet is deployed outside of VREs (regular)
|
|
|
|
|
*/
|
|
|
|
|
if (isInfrastructureScope()) {
|
|
|
|
|
_log.debug("****** risInfrastructureScope() = true");
|
|
|
|
|
//VRE Feeds
|
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
|
|
|
|
for (GCubeGroup group : gm.listGroupsByUserAndSite(currUser.getUserId(), getThreadLocalRequest().getServerName())) {
|
|
|
|
|
if (gm.isVRE(group.getGroupId())) {
|
|
|
|
|
String vreid = gm.getInfrastructureScope(group.getGroupId()); //get the scope
|
|
|
|
|
_log.debug("Reading feeds for VRE: " + vreid);
|
|
|
|
|
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, feedsNoPerCategory);
|
|
|
|
|
for (Feed feed : OrganizationFeeds) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Portal Feeds
|
|
|
|
|
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
|
|
|
|
|
for (Feed feed : portalFeeds) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
}
|
|
|
|
|
//Portal Feeds
|
|
|
|
|
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
|
|
|
|
|
for (Feed feed : portalFeeds) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
}
|
|
|
|
|
//else must be in a VRE scope
|
|
|
|
|
else {
|
|
|
|
|
String vreid = getASLSession().getScopeName();
|
|
|
|
|
_log.trace("News Feed in VRE, Reading feeds for VRE: " + vreid);
|
|
|
|
|
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, (NewsConstants.FEEDS_MAX_PER_CATEGORY));
|
|
|
|
|
for (Feed feed : OrganizationFeeds) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//else must be in a VRE scope
|
|
|
|
|
else {
|
|
|
|
|
PortalContext context = PortalContext.getConfiguration();
|
|
|
|
|
String vreid = context.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
_log.trace("News Feed in VRE, Reading feeds for VRE: " + vreid);
|
|
|
|
|
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, (NewsConstants.FEEDS_MAX_PER_CATEGORY));
|
|
|
|
|
for (Feed feed : OrganizationFeeds) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String key: feedsMap.keySet()) {
|
|
|
|
|
toMerge.add(feedsMap.get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String key: feedsMap.keySet()) {
|
|
|
|
|
toMerge.add(feedsMap.get(key));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//sort the feeds in reverse chronological order
|
|
|
|
|
Collections.sort(toMerge, Collections.reverseOrder());
|
|
|
|
|
|
|
|
|
@ -330,9 +262,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<EnhancedFeed> getFeedsByHashtag(String hashtag) {
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
String userName = session.getUsername();
|
|
|
|
|
String currentScope = session.getScopeName();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
String currentScope = pContext.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
|
|
|
|
|
//in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
|
|
|
|
|
//this check just return nothing if that happens
|
|
|
|
@ -418,12 +350,12 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
String userName = session.getUsername();
|
|
|
|
|
String currentScope = session.getScopeName();
|
|
|
|
|
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
String currentScope = pContext.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
|
|
|
|
|
//this check just return nothing if that happens
|
|
|
|
|
if (userName.compareTo(NewsConstants.TEST_USER) == 0) {
|
|
|
|
@ -484,31 +416,29 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
public ArrayList<EnhancedFeed> getOnlyConnectionsUserFeeds() {
|
|
|
|
|
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
|
|
|
|
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
|
|
|
|
String userName = getASLSession().getUsername();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (! isWithinPortal()) {
|
|
|
|
|
return getEclipseResult(userName, NewsConstants.FEEDS_NO_PER_CATEGORY, true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//UserFriends Feeds
|
|
|
|
|
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
|
|
|
|
|
for (String userid : userFriendsIds) {
|
|
|
|
|
for (Feed feed : store.getRecentFeedsByUser(userid, NewsConstants.FEEDS_NO_PER_CATEGORY)) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
}
|
|
|
|
|
//UserFriends Feeds
|
|
|
|
|
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
|
|
|
|
|
for (String userid : userFriendsIds) {
|
|
|
|
|
for (Feed feed : store.getRecentFeedsByUser(userid, NewsConstants.FEEDS_NO_PER_CATEGORY)) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
}
|
|
|
|
|
for (String key: feedsMap.keySet()) {
|
|
|
|
|
toMerge.add(feedsMap.get(key));
|
|
|
|
|
}
|
|
|
|
|
Collections.sort(toMerge, Collections.reverseOrder());
|
|
|
|
|
ArrayList<Feed> toReturn = new ArrayList<Feed>();
|
|
|
|
|
//return only <MAX_FEEDS_NO> feeds
|
|
|
|
|
if (toMerge.size() > MAX_FEEDS_NO)
|
|
|
|
|
for (int i = 0; i < MAX_FEEDS_NO; i++)
|
|
|
|
|
toReturn.add(toMerge.get(i));
|
|
|
|
|
else
|
|
|
|
|
return enhanceFeeds(toMerge, 2);
|
|
|
|
|
}
|
|
|
|
|
for (String key: feedsMap.keySet()) {
|
|
|
|
|
toMerge.add(feedsMap.get(key));
|
|
|
|
|
}
|
|
|
|
|
Collections.sort(toMerge, Collections.reverseOrder());
|
|
|
|
|
ArrayList<Feed> toReturn = new ArrayList<Feed>();
|
|
|
|
|
//return only <MAX_FEEDS_NO> feeds
|
|
|
|
|
if (toMerge.size() > MAX_FEEDS_NO)
|
|
|
|
|
for (int i = 0; i < MAX_FEEDS_NO; i++)
|
|
|
|
|
toReturn.add(toMerge.get(i));
|
|
|
|
|
else
|
|
|
|
|
return enhanceFeeds(toMerge, 2);
|
|
|
|
|
|
|
|
|
|
} catch (PrivacyLevelTypeNotFoundException e) {
|
|
|
|
|
_log.error("Privacy Level not Found " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -555,7 +485,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
public MoreFeedsBean getMoreFeeds(int start, int quantity) {
|
|
|
|
|
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
|
|
|
|
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
|
|
|
|
String vreid = getASLSession().getScope();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String vreid = pContext.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
_log.debug("\n\nAsking more feed for Timeline " + vreid + " from " + start + " get other " + quantity);
|
|
|
|
|
ArrayList<Feed> organizationFeeds;
|
|
|
|
|
RangeFeeds rangeFeeds = null;
|
|
|
|
@ -580,57 +511,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
ArrayList<EnhancedFeed> toReturn = enhanceFeeds(toMerge, 2);
|
|
|
|
|
return new MoreFeedsBean(rangeFeeds.getLastReturnedFeedTimelineIndex(), toReturn);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* just for testing purposes
|
|
|
|
|
*
|
|
|
|
|
* @param userName
|
|
|
|
|
* @return
|
|
|
|
|
* @throws PrivacyLevelTypeNotFoundException
|
|
|
|
|
* @throws FeedTypeNotFoundException
|
|
|
|
|
* @throws ColumnNameNotFoundException
|
|
|
|
|
* @throws FeedIDNotFoundException
|
|
|
|
|
*/
|
|
|
|
|
private ArrayList<EnhancedFeed> getEclipseResult(String userName, int feedsNoPerCategory, boolean onlyConnections) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
|
|
|
|
|
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
|
|
|
|
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
|
|
|
|
|
|
|
|
|
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(TEST_SCOPE, feedsNoPerCategory*3);
|
|
|
|
|
for (Feed feed : OrganizationFeeds) {
|
|
|
|
|
feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
_log.trace("Reading desc: " + feed.getDescription());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (! onlyConnections) {
|
|
|
|
|
// //User Own Feeds
|
|
|
|
|
// ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10);
|
|
|
|
|
// for (Feed feed : userFeeds)
|
|
|
|
|
// feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
// // //Portal Feeds
|
|
|
|
|
// ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
|
|
|
|
|
// for (Feed feed : portalFeeds)
|
|
|
|
|
// feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
// }
|
|
|
|
|
// //UserFriends Feeds
|
|
|
|
|
// ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
|
|
|
|
|
// for (String userid : userFriendsIds) {
|
|
|
|
|
// for (Feed feed : store.getRecentFeedsByUser(userid, 10)) {
|
|
|
|
|
// feedsMap.put(feed.getKey(), feed);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
for (String key: feedsMap.keySet()) {
|
|
|
|
|
toMerge.add(feedsMap.get(key));
|
|
|
|
|
}
|
|
|
|
|
for (Feed feed : toMerge) {
|
|
|
|
|
feed.setThumbnailURL("http://127.0.0.1:8888/images/Avatar_default.png");
|
|
|
|
|
}
|
|
|
|
|
//sort the feeds in reverse chronological order
|
|
|
|
|
Collections.sort(toMerge, Collections.reverseOrder());
|
|
|
|
|
return enhanceFeeds(toMerge, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<EnhancedFeed> getOnlyMyUserFeeds() {
|
|
|
|
|
String userName = getASLSession().getUsername();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
_log.trace("getOnly UserFeeds for " + userName);
|
|
|
|
|
ArrayList<Feed> userFeeds = null;
|
|
|
|
|
try {
|
|
|
|
@ -644,7 +529,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<EnhancedFeed> getOnlyLikedFeeds() {
|
|
|
|
|
String userName = getASLSession().getUsername();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
_log.trace("getLiked Feeds for " + userName);
|
|
|
|
|
ArrayList<Feed> userFeeds = null;
|
|
|
|
|
try {
|
|
|
|
@ -676,11 +562,13 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
}
|
|
|
|
|
//if the like was correctly delivered notify users involved
|
|
|
|
|
if (likeCommitResult) {
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String currScope = pContext.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
//if the user who liked this post is not the user who posted it notify the poster user (Feed owner)
|
|
|
|
|
if (! user.getUsername().equals(feedOwnerId)) {
|
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
|
new SocialNetworkingSite(getThreadLocalRequest()),
|
|
|
|
|
getASLSession().getScopeName(),
|
|
|
|
|
currScope,
|
|
|
|
|
new SocialNetworkingUser(username, user.getEmailaddress(), user.getFullName(), user.getAvatarId()),
|
|
|
|
|
APP_ID);
|
|
|
|
|
boolean nResult = nm.notifyLikedFeed(feedOwnerId, feedid, Utils.escapeHtml(feedText));
|
|
|
|
@ -747,10 +635,12 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
}
|
|
|
|
|
//if the comment was correctly delivered && is not an app feed notify users involved
|
|
|
|
|
if (commentCommitResult && isWithinPortal()) {
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String currScope = pContext.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
//if the user who commented this post is not the user who posted it notify the poster user (Feed owner)
|
|
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(
|
|
|
|
|
new SocialNetworkingSite(getThreadLocalRequest()),
|
|
|
|
|
getASLSession().getScopeName(),
|
|
|
|
|
currScope,
|
|
|
|
|
new SocialNetworkingUser(user.getUsername(), user.getEmailaddress(), user.getFullName(), user.getAvatarId()),
|
|
|
|
|
APP_ID);
|
|
|
|
|
if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
|
|
|
@ -849,8 +739,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
*/
|
|
|
|
|
private ArrayList<EnhancedFeed> enhanceFeeds(ArrayList<Feed> toEnhance, int commentsNumberPerFeed) {
|
|
|
|
|
ArrayList<EnhancedFeed> toReturn = new ArrayList<EnhancedFeed>();
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
String username = session.getUsername();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//patch needed for maintaining mention link backward compatibility (they point to /group/data-e-infrastructure-gateway/profile)
|
|
|
|
@ -858,7 +748,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
String siteLandinPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
|
|
|
|
|
String tokenTosubstitute = siteLandinPagePath.replace("/group/", "");
|
|
|
|
|
|
|
|
|
|
ArrayList<String> likedFeeds = (ArrayList<String>) store.getAllLikedFeedIdsByUser(getASLSession().getUsername());
|
|
|
|
|
ArrayList<String> likedFeeds = (ArrayList<String>) store.getAllLikedFeedIdsByUser(userName);
|
|
|
|
|
boolean skip = false;
|
|
|
|
|
for (Feed feed : toEnhance) {
|
|
|
|
|
//patch needed for maintaining mention link backward compatibility (they point to /group/data-e-infrastructure-gateway/profile)
|
|
|
|
@ -900,7 +790,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
if (feed.isApplicationFeed()) {
|
|
|
|
|
toAdd = new EnhancedFeed(feed, liked, checkisAdminUser());
|
|
|
|
|
} else
|
|
|
|
|
toAdd = new EnhancedFeed(feed, liked, isUsers(feed, username));
|
|
|
|
|
toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName));
|
|
|
|
|
toAdd.setAttachments(attachments);
|
|
|
|
|
toReturn.add(toAdd);
|
|
|
|
|
} else {
|
|
|
|
@ -911,7 +801,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
int currCommentsNumber = comments.size();
|
|
|
|
|
//if comments are less than $commentsNumberPerFeed they are the more recent, -1 return all the comments
|
|
|
|
|
if (currCommentsNumber < commentsNumberPerFeed || commentsNumberPerFeed == -1) {
|
|
|
|
|
EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, username), comments, attachments);
|
|
|
|
|
EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName), comments, attachments);
|
|
|
|
|
toReturn.add(toAdd);
|
|
|
|
|
} else {
|
|
|
|
|
//need to get the last two
|
|
|
|
@ -919,14 +809,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
for (int i = currCommentsNumber -commentsNumberPerFeed; i < currCommentsNumber; i++) {
|
|
|
|
|
comments2Attach.add(comments.get(i));
|
|
|
|
|
}
|
|
|
|
|
EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, username), comments2Attach, attachments);
|
|
|
|
|
EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName), comments2Attach, attachments);
|
|
|
|
|
toReturn.add(toAdd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
_log.trace("ENHANCED FEEDS TOTAL= " + toReturn.size() + " for user: " + username);
|
|
|
|
|
_log.trace("ENHANCED FEEDS TOTAL= " + toReturn.size() + " for user: " + userName);
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1002,23 +892,15 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<ItemBean> getOrganizationUsers(String currentScope) {
|
|
|
|
|
ArrayList<ItemBean> toReturn = Utils.getDisplayableItemBeans(currentScope, getASLSession().getUsername(), isWithinPortal());
|
|
|
|
|
public ArrayList<ItemBean> getOrganizationUsers() {
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
String currentScope = pContext.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
ArrayList<ItemBean> toReturn = Utils.getDisplayableItemBeans(currentScope, userName, isWithinPortal());
|
|
|
|
|
_log.trace("Returning " + toReturn.size() + " users for scope " + currentScope);
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserSettings getUserSettingsFromSession() {
|
|
|
|
|
try {
|
|
|
|
|
return (UserSettings) getASLSession().getAttribute(USER_SETTINGS_ATTR);
|
|
|
|
|
} catch (ClassCastException e) { //handle the hot deploy
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setUserSettingsInSession(UserSettings user) {
|
|
|
|
|
getASLSession().setAttribute(USER_SETTINGS_ATTR, user);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* tell if a feed is belonging to the current user or not
|
|
|
|
|
* @param tocheck
|
|
|
|
@ -1034,17 +916,17 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
* @return true if the user is a portal administrator or not
|
|
|
|
|
*/
|
|
|
|
|
private boolean checkisAdminUser() {
|
|
|
|
|
if (getASLSession().getAttribute(SESSION_ADMIN_ATTR) == null) {
|
|
|
|
|
if (getThreadLocalRequest().getSession().getAttribute(SESSION_ADMIN_ATTR) == null) {
|
|
|
|
|
boolean isAdmin = false;
|
|
|
|
|
try {
|
|
|
|
|
isAdmin = isAdmin();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
getASLSession().setAttribute(SESSION_ADMIN_ATTR, isAdmin);
|
|
|
|
|
getThreadLocalRequest().getSession().setAttribute(SESSION_ADMIN_ATTR, isAdmin);
|
|
|
|
|
return isAdmin;
|
|
|
|
|
}
|
|
|
|
|
return (Boolean) getASLSession().getAttribute(SESSION_ADMIN_ATTR);
|
|
|
|
|
return (Boolean) getThreadLocalRequest().getSession().getAttribute(SESSION_ADMIN_ATTR);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
@ -1054,7 +936,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
if (fullNames == null)
|
|
|
|
|
return new ArrayList<ItemBean>();
|
|
|
|
|
else {
|
|
|
|
|
ArrayList<ItemBean> allUsers = Utils.getDisplayableItemBeans("/"+PortalContext.getConfiguration().getInfrastructureName(), getASLSession().getUsername(), isWithinPortal());
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
ArrayList<ItemBean> allUsers = Utils.getDisplayableItemBeans("/"+PortalContext.getConfiguration().getInfrastructureName(), userName, isWithinPortal());
|
|
|
|
|
ArrayList<ItemBean> toReturn = new ArrayList<ItemBean>();
|
|
|
|
|
for (String fullName : fullNames)
|
|
|
|
|
for (ItemBean puser : allUsers) {
|
|
|
|
@ -1077,7 +961,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
if (! isWithinPortal())
|
|
|
|
|
return false;
|
|
|
|
|
try {
|
|
|
|
|
GCubeUser curUser = new LiferayUserManager().getUserByUsername(getASLSession().getUsername());
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
GCubeUser curUser = pContext.getCurrentUser(getThreadLocalRequest());
|
|
|
|
|
return new LiferayRoleManager().isAdmin(curUser.getUserId());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
@ -1143,9 +1028,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|
|
|
|
public ArrayList<EnhancedFeed> getFeedsRelatedToUserStatistics(
|
|
|
|
|
ShowUserStatisticAction action, int from, int quantity) {
|
|
|
|
|
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
String userid = session.getUsername();
|
|
|
|
|
String scope = session.getScope();
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
String userid = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
|
|
|
|
|
String scope = pContext.getCurrentScope(getThreadLocalRequest());
|
|
|
|
|
|
|
|
|
|
if(userid == NewsConstants.TEST_USER)
|
|
|
|
|
return null;
|
|
|
|
|