removed ASL Session dependency

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@134065 82a268e6-3cf1-43bd-a215-b396298e98cf
Feature/26194
Massimiliano Assante 8 years ago
parent 01ce2cb8b5
commit c1726e2f26

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/news-feed-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/news-feed-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/news-feed-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/news-feed-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -39,5 +39,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/news-feed-2.1.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/news-feed-2.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

@ -5,13 +5,10 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="gcube-widgets-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependent-module archiveName="gcube-widgets-2.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="social-util-library-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/social-util-library/social-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="session-checker-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependent-module archiveName="session-checker-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/session-checker/session-checker">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@ -13,7 +12,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>news-feed</artifactId>
<packaging>war</packaging>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
<name>gCube News Feed Portlet</name>
<description>
@ -66,8 +65,8 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
@ -84,11 +83,7 @@
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
@ -155,7 +150,7 @@
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>

@ -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 <code>onModuleLoad()</code>.
*/
@ -30,15 +27,7 @@ public class NewsFeed implements EntryPoint {
public void onModuleLoad() {
ClientScopeHelper.getService().setScope(Location.getHref(), new AsyncCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
init();
}
@Override
public void onFailure(Throwable caught) {
}
});
init();
}
public void init() {

@ -58,5 +58,5 @@ public interface NewsService extends RemoteService {
EnhancedFeed getSingleFeed(String feedKey);
ArrayList<ItemBean> getOrganizationUsers(String currentScope);
ArrayList<ItemBean> getOrganizationUsers();
}

@ -59,8 +59,7 @@ public interface NewsServiceAsync {
void unlike(String feedid, String feedText, String feedOwnerId,
AsyncCallback<Boolean> callback);
void getOrganizationUsers(String currentScope,
AsyncCallback<ArrayList<ItemBean>> callback);
void getOrganizationUsers(AsyncCallback<ArrayList<ItemBean>> callback);
void getFeedsByHashtag(String hashtag,
AsyncCallback<ArrayList<EnhancedFeed>> callback);

@ -357,9 +357,6 @@ public class NewsFeedPanel extends Composite {
showFeedTimelineSource = result.isShowTimelineSourceLabel();
isInfrastructure = true;
}
// else
// mainPanel.addStyleName("framed");
}
});

@ -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<ArrayList<ItemBean>>() {
newsService.getOrganizationUsers(new AsyncCallback<ArrayList<ItemBean>>() {
@Override
public void onSuccess(ArrayList<ItemBean> users) {

@ -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;

@ -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);

@ -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!");
}
}
Loading…
Cancel
Save