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