diff --git a/.classpath b/.classpath
index ac1b581..4bc4d8b 100644
--- a/.classpath
+++ b/.classpath
@@ -1,12 +1,12 @@
-
+
-
+
@@ -39,5 +39,5 @@
-
+
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index 4e48db0..4272280 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -5,13 +5,10 @@
-
+
uses
-
- uses
-
-
+
uses
diff --git a/pom.xml b/pom.xml
index 95a268e..072673f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,3 @@
-
@@ -13,7 +12,7 @@
org.gcube.portlets.user
news-feed
war
- 2.1.0-SNAPSHOT
+ 2.2.0-SNAPSHOT
gCube News Feed Portlet
@@ -66,8 +65,8 @@
compile
- org.gcube.portal
- custom-portal-handler
+ org.gcube.core
+ common-scope
provided
@@ -84,11 +83,7 @@
com.github.gwtbootstrap
gwt-bootstrap
-
- org.gcube.applicationsupportlayer
- aslcore
- provided
-
+
org.gcube.applicationsupportlayer
aslsocial
@@ -155,7 +150,7 @@
org.gcube.portlets.widgets
session-checker
- [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)
+ [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)
org.gcube.portlets.widgets
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java
index 868af1a..ed7ec63 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java
@@ -1,13 +1,7 @@
package org.gcube.portlets.user.newsfeed.client;
-import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapter;
-import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException;
-import net.eliasbalasis.tibcopagebus4gwt.client.PageBusEvent;
-import net.eliasbalasis.tibcopagebus4gwt.client.PageBusListener;
-
import org.gcube.portal.databook.shared.ClientFeed;
import org.gcube.portal.databook.shared.ClientFeed.ClientFeedJsonizer;
-import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import org.gcube.portlets.user.newsfeed.client.event.PageBusEvents;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import org.jsonmaker.gwt.client.Jsonizer;
@@ -15,10 +9,13 @@ import org.jsonmaker.gwt.client.base.Defaults;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.Window.Location;
-import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
+import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapter;
+import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException;
+import net.eliasbalasis.tibcopagebus4gwt.client.PageBusEvent;
+import net.eliasbalasis.tibcopagebus4gwt.client.PageBusListener;
+
/**
* Entry point classes define onModuleLoad()
.
*/
@@ -30,15 +27,7 @@ public class NewsFeed implements EntryPoint {
public void onModuleLoad() {
- ClientScopeHelper.getService().setScope(Location.getHref(), new AsyncCallback() {
- @Override
- public void onSuccess(Boolean result) {
- init();
- }
- @Override
- public void onFailure(Throwable caught) {
- }
- });
+ init();
}
public void init() {
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java
index cf7252e..410f4bf 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java
@@ -58,5 +58,5 @@ public interface NewsService extends RemoteService {
EnhancedFeed getSingleFeed(String feedKey);
- ArrayList getOrganizationUsers(String currentScope);
+ ArrayList getOrganizationUsers();
}
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java
index 39282dc..ef657a3 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java
@@ -59,8 +59,7 @@ public interface NewsServiceAsync {
void unlike(String feedid, String feedText, String feedOwnerId,
AsyncCallback callback);
- void getOrganizationUsers(String currentScope,
- AsyncCallback> callback);
+ void getOrganizationUsers(AsyncCallback> callback);
void getFeedsByHashtag(String hashtag,
AsyncCallback> callback);
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
index f6df59c..b928cc7 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
@@ -357,9 +357,6 @@ public class NewsFeedPanel extends Composite {
showFeedTimelineSource = result.isShowTimelineSourceLabel();
isInfrastructure = true;
}
- // else
- // mainPanel.addStyleName("framed");
-
}
});
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SuperPosedTextArea.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SuperPosedTextArea.java
index f428fee..111bbaa 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SuperPosedTextArea.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SuperPosedTextArea.java
@@ -60,7 +60,7 @@ public class SuperPosedTextArea extends TextArea {
//needed to give unique identifiers to the Area (for the jQuery plugin)
areaId = "postTextArea"+Random.nextInt();
- newsService.getOrganizationUsers(NewsFeedPanel.getCurrentScope(), new AsyncCallback>() {
+ newsService.getOrganizationUsers(new AsyncCallback>() {
@Override
public void onSuccess(ArrayList users) {
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
index 07195b2..fc3d790 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
@@ -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 true
if it is, false
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 getAllUpdateUserFeeds(int feedsNoPerCategory) {
- String userName = getASLSession().getUsername();
+
ArrayList toMerge = new ArrayList();
HashMap feedsMap = new HashMap();
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 OrganizationFeeds = (ArrayList) 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 OrganizationFeeds = (ArrayList) store.getRecentFeedsByVRE(vreid, feedsNoPerCategory);
+ for (Feed feed : OrganizationFeeds) {
+ feedsMap.put(feed.getKey(), feed);
}
}
-
- //Portal Feeds
- ArrayList portalFeeds = (ArrayList) 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 OrganizationFeeds = (ArrayList) 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));
- }
+ //Portal Feeds
+ ArrayList portalFeeds = (ArrayList) store.getAllPortalPrivacyLevelFeeds();
+ for (Feed feed : portalFeeds) {
+ 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 OrganizationFeeds = (ArrayList) 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));
+ }
+
//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 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 getOnlyConnectionsUserFeeds() {
ArrayList toMerge = new ArrayList();
HashMap feedsMap = new HashMap();
- 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 userFriendsIds = (ArrayList)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 userFriendsIds = (ArrayList)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 toReturn = new ArrayList();
- //return only 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 toReturn = new ArrayList();
+ //return only 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 toMerge = new ArrayList();
HashMap feedsMap = new HashMap();
- 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 organizationFeeds;
RangeFeeds rangeFeeds = null;
@@ -580,57 +511,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
ArrayList 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 getEclipseResult(String userName, int feedsNoPerCategory, boolean onlyConnections) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, ColumnNameNotFoundException, FeedIDNotFoundException {
- ArrayList toMerge = new ArrayList();
- HashMap feedsMap = new HashMap();
-
- ArrayList OrganizationFeeds = (ArrayList) 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 userFeeds = (ArrayList) store.getRecentFeedsByUser(userName, 10);
- // for (Feed feed : userFeeds)
- // feedsMap.put(feed.getKey(), feed);
- // // //Portal Feeds
- // ArrayList portalFeeds = (ArrayList) store.getAllPortalPrivacyLevelFeeds();
- // for (Feed feed : portalFeeds)
- // feedsMap.put(feed.getKey(), feed);
- // }
- // //UserFriends Feeds
- // ArrayList userFriendsIds = (ArrayList)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 getOnlyMyUserFeeds() {
- String userName = getASLSession().getUsername();
+ PortalContext pContext = PortalContext.getConfiguration();
+ String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
_log.trace("getOnly UserFeeds for " + userName);
ArrayList userFeeds = null;
try {
@@ -644,7 +529,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override
public ArrayList getOnlyLikedFeeds() {
- String userName = getASLSession().getUsername();
+ PortalContext pContext = PortalContext.getConfiguration();
+ String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
_log.trace("getLiked Feeds for " + userName);
ArrayList 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 enhanceFeeds(ArrayList toEnhance, int commentsNumberPerFeed) {
ArrayList toReturn = new ArrayList();
- 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 likedFeeds = (ArrayList) store.getAllLikedFeedIdsByUser(getASLSession().getUsername());
+ ArrayList likedFeeds = (ArrayList) 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 getOrganizationUsers(String currentScope) {
- ArrayList toReturn = Utils.getDisplayableItemBeans(currentScope, getASLSession().getUsername(), isWithinPortal());
+ public ArrayList getOrganizationUsers() {
+ PortalContext pContext = PortalContext.getConfiguration();
+ String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
+ String currentScope = pContext.getCurrentScope(getThreadLocalRequest());
+ ArrayList 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();
else {
- ArrayList allUsers = Utils.getDisplayableItemBeans("/"+PortalContext.getConfiguration().getInfrastructureName(), getASLSession().getUsername(), isWithinPortal());
+ PortalContext pContext = PortalContext.getConfiguration();
+ String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
+ ArrayList allUsers = Utils.getDisplayableItemBeans("/"+PortalContext.getConfiguration().getInfrastructureName(), userName, isWithinPortal());
ArrayList toReturn = new ArrayList();
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 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;
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/portlet/NewsFeedPortlet.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/portlet/NewsFeedPortlet.java
index e25b84b..44472fa 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/server/portlet/NewsFeedPortlet.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/portlet/NewsFeedPortlet.java
@@ -10,7 +10,6 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
-import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -18,7 +17,6 @@ public class NewsFeedPortlet extends GenericPortlet {
private static final Logger _log = LoggerFactory.getLogger(NewsFeedPortlet.class);
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
- ScopeHelper.setContext(request);
_log.debug("NewsFeedPortlet context set");
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/NewsFeed_view.jsp");
dispatcher.include(request, response);
diff --git a/src/test/java/org/gcube/portlets/user/newsfeed/test/TestForDeploy.java b/src/test/java/org/gcube/portlets/user/newsfeed/test/TestForDeploy.java
deleted file mode 100644
index 6ff0ff2..0000000
--- a/src/test/java/org/gcube/portlets/user/newsfeed/test/TestForDeploy.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.gcube.portlets.user.newsfeed.test;
-
-import static org.junit.Assert.assertTrue;
-
-import org.gcube.portlets.user.newsfeed.server.NewsServiceImpl;
-import org.junit.Test;
-
-public class TestForDeploy {
-
- @Test
- public void testUserIsTestUser() {
- NewsServiceImpl serviceImpl = new NewsServiceImpl();
- String username = serviceImpl.getDevelopmentUser();
- System.out.println("username for deploy is: " + username);
- assertTrue(username.compareTo("test.user") == 0);
- System.out.println("Test OK!");
- }
-
-}