ready for testing
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@73670 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
51fa610039
commit
b55f18790e
|
@ -16,7 +16,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
|||
*/
|
||||
@RemoteServiceRelativePath("newsServlet")
|
||||
public interface NewsService extends RemoteService {
|
||||
ArrayList<EnhancedFeed> getAllUpdateUserFeeds();
|
||||
ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int feedsNoPerCategory);
|
||||
|
||||
ArrayList<EnhancedFeed> getOnlyConnectionsUserFeeds();
|
||||
|
||||
|
@ -39,4 +39,6 @@ public interface NewsService extends RemoteService {
|
|||
ArrayList<Comment> getAllCommentsByFeed(String feedid);
|
||||
|
||||
UserSettings getUserSettings();
|
||||
|
||||
EnhancedFeed getSingleFeed(String feedKey);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
|
||||
import org.gcube.portal.databook.shared.Comment;
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.databook.shared.UserInfo;
|
||||
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
|
||||
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
|
||||
|
||||
|
@ -15,7 +14,8 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
|||
*/
|
||||
public interface NewsServiceAsync {
|
||||
|
||||
void getAllUpdateUserFeeds(AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
void getAllUpdateUserFeeds(int feedsNoPerCategory,
|
||||
AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
|
||||
void getOnlyConnectionsUserFeeds(
|
||||
AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
|
@ -45,4 +45,6 @@ public interface NewsServiceAsync {
|
|||
|
||||
void getOnlyLikedFeeds(AsyncCallback<ArrayList<EnhancedFeed>> callback);
|
||||
|
||||
void getSingleFeed(String feedKey, AsyncCallback<EnhancedFeed> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -76,6 +76,8 @@ public class NewsFeedPanel extends Composite {
|
|||
private static final String spacer = GWT.getModuleBaseURL() + "../images/feeds-spacer.gif";
|
||||
public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif";
|
||||
|
||||
public static final String GET_OID_PARAMETER = "oid";
|
||||
|
||||
public static final String LIKE_LABEL = "Favorite";
|
||||
public static final String LIKED_LABEL = "Favorited";
|
||||
public static final String COMMENT_LABEL = "Reply";
|
||||
|
@ -87,6 +89,8 @@ public class NewsFeedPanel extends Composite {
|
|||
|
||||
private boolean isFirstTweet = false;
|
||||
|
||||
private static final int feedsNoPerCategory = 10;
|
||||
|
||||
private Image loadingImage;
|
||||
private UserInfo myUserInfo;
|
||||
private FilterType currentFilter;
|
||||
|
@ -196,7 +200,12 @@ public class NewsFeedPanel extends Composite {
|
|||
Window.alert("Your session has expired, please log out and login again");
|
||||
}
|
||||
else {
|
||||
if (getFeedToShowId() != null) {
|
||||
String feedKey = getFeedToShowId();
|
||||
showSingleFeed(feedKey);
|
||||
} else {
|
||||
showAllUpdatesFeeds();
|
||||
}
|
||||
currentFilter = FilterType.ALL_UPDATES;
|
||||
}
|
||||
//adjustments in the UI Depending on the scope
|
||||
|
@ -217,6 +226,7 @@ public class NewsFeedPanel extends Composite {
|
|||
feedsTimer.scheduleRepeating(delayMillis);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -233,11 +243,36 @@ public class NewsFeedPanel extends Composite {
|
|||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* check if it has to show just one feed
|
||||
* @return
|
||||
*/
|
||||
private String getFeedToShowId() {
|
||||
return Window.Location.getParameter(GET_OID_PARAMETER);
|
||||
}
|
||||
private void showSingleFeed(String feedKey) {
|
||||
newsPanel.clear();
|
||||
newsService.getSingleFeed(feedKey, new AsyncCallback<EnhancedFeed>() {
|
||||
@Override
|
||||
public void onSuccess(EnhancedFeed result) {
|
||||
newsPanel.setHeight("");
|
||||
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
||||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||
newsPanel.add(new TweetTemplate(true, myUserInfo, result, eventBus));
|
||||
newsPanel.add(new Image(spacer));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
showProblems();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
/**
|
||||
* check for updates
|
||||
*/
|
||||
private void checkAllUpdatesFeeds() {
|
||||
newsService.getAllUpdateUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
|
||||
newsService.getAllUpdateUserFeeds(feedsNoPerCategory, new AsyncCallback<ArrayList<EnhancedFeed>>() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
|
||||
if (feeds != null && allUpdates.size() > 0) {
|
||||
|
@ -348,7 +383,7 @@ public class NewsFeedPanel extends Composite {
|
|||
*/
|
||||
public void showAllUpdatesFeeds() {
|
||||
showLoader();
|
||||
newsService.getAllUpdateUserFeeds(new AsyncCallback<ArrayList<EnhancedFeed>>() {
|
||||
newsService.getAllUpdateUserFeeds(feedsNoPerCategory, new AsyncCallback<ArrayList<EnhancedFeed>>() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
|
||||
newsPanel.clear();
|
||||
|
@ -365,7 +400,7 @@ public class NewsFeedPanel extends Composite {
|
|||
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
||||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||
for (EnhancedFeed feed : feeds) {
|
||||
newsPanel.add(new TweetTemplate(myUserInfo, feed, eventBus));
|
||||
newsPanel.add(new TweetTemplate(false, myUserInfo, feed, eventBus));
|
||||
allUpdates.add(feed);
|
||||
}
|
||||
if (feeds.size() < 5) {
|
||||
|
@ -411,7 +446,7 @@ public class NewsFeedPanel extends Composite {
|
|||
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
||||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||
for (EnhancedFeed feed : feeds)
|
||||
newsPanel.add(new TweetTemplate(myUserInfo, feed, eventBus));
|
||||
newsPanel.add(new TweetTemplate(false, myUserInfo, feed, eventBus));
|
||||
if (feeds.size() < 5) {
|
||||
newsPanel.add(new Image(spacer));
|
||||
}
|
||||
|
@ -450,7 +485,7 @@ public class NewsFeedPanel extends Composite {
|
|||
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
||||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||
for (EnhancedFeed feed : feeds)
|
||||
newsPanel.add(new TweetTemplate(myUserInfo, feed, eventBus));
|
||||
newsPanel.add(new TweetTemplate(false, myUserInfo, feed, eventBus));
|
||||
if (feeds.size() < 5) {
|
||||
newsPanel.add(new Image(spacer));
|
||||
}
|
||||
|
@ -489,7 +524,7 @@ public class NewsFeedPanel extends Composite {
|
|||
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
|
||||
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
|
||||
for (EnhancedFeed feed : feeds)
|
||||
newsPanel.add(new TweetTemplate(myUserInfo, feed, eventBus));
|
||||
newsPanel.add(new TweetTemplate(false, myUserInfo, feed, eventBus));
|
||||
if (feeds.size() < 5) {
|
||||
newsPanel.add(new Image(spacer));
|
||||
}
|
||||
|
|
|
@ -110,9 +110,10 @@ public class TweetTemplate extends Composite {
|
|||
* @param myUserInfo
|
||||
* @param myFeed
|
||||
* @param isUsers
|
||||
* @param displaySingle tells if you're displaying a single fedd or not
|
||||
* @param eventBus
|
||||
*/
|
||||
public TweetTemplate(UserInfo myUserInfo, EnhancedFeed myFeed, HandlerManager eventBus) {
|
||||
public TweetTemplate(boolean displaySingle, UserInfo myUserInfo, EnhancedFeed myFeed, HandlerManager eventBus) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
this.myUserInfo = myUserInfo;
|
||||
this.myFeed = myFeed;
|
||||
|
@ -187,7 +188,7 @@ public class TweetTemplate extends Composite {
|
|||
}
|
||||
commentsPanel.setStyleName("commentsPanel");
|
||||
if (myFeed.getComments() != null && myFeed.getComments().size() > 0) {
|
||||
if (totalComments > 2) {
|
||||
if (totalComments > 2 && !displaySingle) {
|
||||
showAllComments = getShowAllCommentsLink(totalComments);
|
||||
commentsPanel.add(showAllComments);
|
||||
commentsNo.setStyleName("show-comments-number");
|
||||
|
@ -207,7 +208,7 @@ public class TweetTemplate extends Composite {
|
|||
* @param hidden
|
||||
*/
|
||||
public TweetTemplate(UserInfo myUserInfo, EnhancedFeed feed, HandlerManager eventBus, boolean hidden) {
|
||||
this(myUserInfo, feed, eventBus);
|
||||
this(false, myUserInfo, feed, eventBus);
|
||||
contentArea.getElement().getParentElement().getParentElement().setClassName("div-table-col content hidden");
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
if (user == null) {
|
||||
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
|
||||
user = "test.user";
|
||||
// user = "massimiliano.assante";
|
||||
// user = "luca.frosini";
|
||||
// SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
||||
}
|
||||
else {
|
||||
|
@ -150,8 +150,10 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return getASLSession().getScope().isInfrastructure();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds() {
|
||||
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int feedsNoPerCategory) {
|
||||
String userName = getASLSession().getUsername();
|
||||
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
||||
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
||||
|
@ -179,14 +181,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
if (gm.isVRE(org.getOrganizationId()+"")) {
|
||||
String vreid = gm.getScope(""+org.getOrganizationId()); //get the scope
|
||||
_log.trace("Reading feeds for VRE: " + vreid);
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, 10);
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, feedsNoPerCategory);
|
||||
for (Feed feed : OrganizationFeeds) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
}
|
||||
}
|
||||
}
|
||||
//User Own Feeds
|
||||
ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10);
|
||||
ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, feedsNoPerCategory);
|
||||
for (Feed feed : userFeeds) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
}
|
||||
|
@ -194,7 +196,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
//UserFriends Feeds
|
||||
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
|
||||
for (String userid : userFriendsIds) {
|
||||
for (Feed feed : store.getRecentFeedsByUser(userid, 10)) {
|
||||
for (Feed feed : store.getRecentFeedsByUser(userid, feedsNoPerCategory)) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +211,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
else {
|
||||
String vreid = getASLSession().getScopeName();
|
||||
_log.trace("News Feed in VRE, Reading feeds for VRE: " + vreid);
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, 30);
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, (feedsNoPerCategory*3));
|
||||
for (Feed feed : OrganizationFeeds) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
}
|
||||
|
@ -225,9 +227,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
for (int i = 0; i < MAX_FEEDS_NO; i++)
|
||||
toReturn.add(toMerge.get(i));
|
||||
else {
|
||||
return enhanceFeeds(toMerge);
|
||||
return enhanceFeeds(toMerge, 2);
|
||||
}
|
||||
return enhanceFeeds(toReturn);
|
||||
return enhanceFeeds(toReturn, 2);
|
||||
} catch (PrivacyLevelTypeNotFoundException e) {
|
||||
_log.error("Privacy Level not Found " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
@ -273,7 +275,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
for (int i = 0; i < MAX_FEEDS_NO; i++)
|
||||
toReturn.add(toMerge.get(i));
|
||||
else
|
||||
return enhanceFeeds(toMerge);;
|
||||
return enhanceFeeds(toMerge, 2);
|
||||
}
|
||||
} catch (PrivacyLevelTypeNotFoundException e) {
|
||||
_log.error("Privacy Level not Found " + e.getMessage());
|
||||
|
@ -290,7 +292,27 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return only one feed with all the comments
|
||||
*/
|
||||
@Override
|
||||
public EnhancedFeed getSingleFeed(String feedKey) {
|
||||
Feed feed = null;
|
||||
try {
|
||||
if (feedKey != null) {
|
||||
feed = store.readFeed(feedKey);
|
||||
if (feed != null) {
|
||||
ArrayList<Feed> toEnhance = new ArrayList<Feed>();
|
||||
toEnhance.add(feed);
|
||||
return enhanceFeeds(toEnhance, -1).get(0); //-1 all the comments
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.debug("Error while trying to fetch feed with key " + feedKey + " returning nothing");
|
||||
return new EnhancedFeed();
|
||||
}
|
||||
return new EnhancedFeed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -307,7 +329,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
ArrayList<Feed> toMerge = new ArrayList<Feed>();
|
||||
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
|
||||
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 5);
|
||||
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 10);
|
||||
for (Feed feed : OrganizationFeeds) {
|
||||
feedsMap.put(feed.getKey(), feed);
|
||||
_log.trace("Reading desc: " + feed.getDescription());
|
||||
|
@ -337,7 +359,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
feed.setThumbnailURL("http://127.0.0.1:8888/images/Avatar_default.png");
|
||||
}
|
||||
|
||||
return enhanceFeeds(toMerge);
|
||||
return enhanceFeeds(toMerge, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -350,7 +372,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return enhanceFeeds(userFeeds);
|
||||
return enhanceFeeds(userFeeds, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -363,7 +385,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return enhanceFeeds(userFeeds);
|
||||
return enhanceFeeds(userFeeds, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -417,14 +439,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
||||
boolean result = nm.notifyOwnCommentReply(feedOwnerId, feedid, escapeHtml(commentText));
|
||||
_log.trace("Comment Notification to post owner added? " + result);
|
||||
} else if (!isAppFeed) {
|
||||
//notify the other users who commented this post
|
||||
Thread thread = new Thread(new CommentNotificationsThread(store, user.getUsername(), comment.getFeedid(), commentText, nm, feedOwnerId));
|
||||
thread.start();
|
||||
}
|
||||
//notify the other users who commented this post
|
||||
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(store, user.getUsername(), comment.getFeedid(), commentText, nm, feedOwnerId));
|
||||
commentsNotificationthread.start();
|
||||
|
||||
//if there are other users who liked this post they get notified too, asynchronously with this thread
|
||||
Thread thread = new Thread(new LikeNotificationsThread(commentText, nm, getAllLikesByFeed(feedid)));
|
||||
thread.start();
|
||||
Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, getAllLikesByFeed(feedid)));
|
||||
likesThread.start();
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
@ -450,9 +472,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
/**
|
||||
* this method sorts the Feeds in Chronological Reversed order and adds additional user informations
|
||||
* @param toEnhance
|
||||
* @param } catch (Exception e) { the max number of comments you want to get back, -1 to get all
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ArrayList<EnhancedFeed> enhanceFeeds(ArrayList<Feed> toEnhance) {
|
||||
private ArrayList<EnhancedFeed> enhanceFeeds(ArrayList<Feed> toEnhance, int commentsNumberPerFeed) {
|
||||
ArrayList<EnhancedFeed> toReturn = new ArrayList<EnhancedFeed>();
|
||||
String username = getASLSession().getUsername();
|
||||
//sort the Feeds
|
||||
|
@ -490,18 +514,15 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
|
|||
//sort in chronological order
|
||||
Collections.sort(comments);
|
||||
|
||||
//TODO: retrieve only the first 2 more recents efficiently from the store
|
||||
//only the first two first 2 more recent returned to the client initially
|
||||
|
||||
int currCommentsNumber = comments.size();
|
||||
//if comments are less than 2 they are the more recent
|
||||
if (currCommentsNumber < 2) {
|
||||
//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);
|
||||
toReturn.add(toAdd);
|
||||
} else {
|
||||
//need to get the last two
|
||||
ArrayList<Comment> comments2Attach = new ArrayList<Comment>();
|
||||
for (int i = currCommentsNumber -2; i < currCommentsNumber; i++) {
|
||||
for (int i = currCommentsNumber -commentsNumberPerFeed; i < currCommentsNumber; i++) {
|
||||
comments2Attach.add(comments.get(i));
|
||||
}
|
||||
EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, username), comments2Attach);
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
# Defines the News Feed refreshing time in minutes
|
||||
REFRESH_TIME = 5
|
||||
REFRESH_TIME = 3
|
Loading…
Reference in New Issue