minor refactoring

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@178778 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2019-03-29 08:53:52 +00:00
parent efdd3f6282
commit 7a3d0f1fbe
1 changed files with 37 additions and 38 deletions

View File

@ -188,7 +188,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
@Override
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int feedsNoPerCategory) {
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int postsNoPerCategory) {
ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
@ -205,28 +205,28 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
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);
_log.debug("Reading posts for VRE: " + vreid);
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, postsNoPerCategory);
for (Feed post : OrganizationFeeds) {
feedsMap.put(post.getKey(), post);
}
}
}
//Portal Feeds
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
for (Feed feed : portalFeeds) {
feedsMap.put(feed.getKey(), feed);
for (Feed post : portalFeeds) {
feedsMap.put(post.getKey(), post);
}
}
//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);
_log.trace("News Feed in VRE, Reading posts 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 (Feed post : OrganizationFeeds) {
feedsMap.put(post.getKey(), post);
}
}
@ -234,11 +234,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
toMerge.add(feedsMap.get(key));
}
//sort the feeds in reverse chronological order
//sort the posts in reverse chronological order
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<Feed> toReturn = new ArrayList<Feed>();
//return only <MAX_FEEDS_NO> feeds
//return only <MAX_FEEDS_NO> posts
if (toMerge.size() > MAX_POSTS_NO)
for (int i = 0; i < MAX_POSTS_NO; i++)
toReturn.add(toMerge.get(i));
@ -262,7 +262,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
/**
* return the feeds having the hashtag passed as param the user has access on
* return the posts having the hashtag passed as param the user has access on
* @param hashtag the hashtag to look for including '#'
*/
@Override
@ -310,9 +310,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
_log.debug("Contexts for hashtags is " + contexts);
for (String context : contexts) {
ArrayList<Feed> feeds = (ArrayList<Feed>) store.getVREFeedsByHashtag(context, lowerCaseHashtag);
for (Feed feed : feeds) {
feedsMap.put(feed.getKey(), feed);
ArrayList<Feed> posts = (ArrayList<Feed>) store.getVREFeedsByHashtag(context, lowerCaseHashtag);
for (Feed post : posts) {
feedsMap.put(post.getKey(), post);
}
}
@ -320,11 +320,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
toMerge.add(feedsMap.get(key));
}
//sort the feeds in reverse chronological order
//sort the posts in reverse chronological order
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<Feed> toReturn = new ArrayList<Feed>();
//return only <MAX_FEEDS_NO> feeds
//return only <MAX_FEEDS_NO> posts
if (toMerge.size() > MAX_POSTS_NO)
for (int i = 0; i < MAX_POSTS_NO; i++)
toReturn.add(toMerge.get(i));
@ -339,7 +339,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
} catch (ColumnNameNotFoundException e) {
_log.error("Column name not Found ", e);
} catch (Exception e) {
_log.error("Error while retrieving feeds for hashtag ", e);
_log.error("Error while retrieving posts for hashtag ", e);
}
return null;
}
@ -389,7 +389,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
// query elastic search
List<EnhancedFeed> enhancedFeeds = escl.search(query, vres, from, quantity);
// retrieve the ids of liked feeds by the user
// retrieve the ids of liked posts by the user
List<String> likedFeeds = store.getAllLikedFeedIdsByUser(userName);
// update fields "liked" and "isuser"
@ -413,7 +413,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
/**
* return only the user connection feeds
* return only the user connection posts
*/
@Override
public ArrayList<EnhancedFeed> getOnlyConnectionsUserPosts() {
@ -426,8 +426,8 @@ 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, NewsConstants.FEEDS_NO_PER_CATEGORY)) {
feedsMap.put(feed.getKey(), feed);
for (Feed post : store.getRecentFeedsByUser(userid, NewsConstants.FEEDS_NO_PER_CATEGORY)) {
feedsMap.put(post.getKey(), post);
}
}
for (String key: feedsMap.keySet()) {
@ -435,7 +435,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<Feed> toReturn = new ArrayList<Feed>();
//return only <MAX_FEEDS_NO> feeds
//return only <MAX_FEEDS_NO> posts
if (toMerge.size() > MAX_POSTS_NO)
for (int i = 0; i < MAX_POSTS_NO; i++)
toReturn.add(toMerge.get(i));
@ -458,17 +458,17 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
/**
* return only one feed with all the comments
* return only one post with all the comments
*/
@Override
public EnhancedFeed getSinglePost(String postKey) {
Feed feed = null;
Feed post = null;
try {
if (postKey != null) {
feed = store.readFeed(postKey);
if (feed != null) {
post = store.readFeed(postKey);
if (post != null) {
ArrayList<Feed> toEnhance = new ArrayList<Feed>();
toEnhance.add(feed);
toEnhance.add(post);
return enhanceFeeds(toEnhance, -1).get(0); //-1 all the comments
}
}
@ -479,10 +479,10 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return new EnhancedFeed();
}
/**
* MoreFeedsBean contains the timeline index of the last returned valid feed (because if you delete a feed is stays on in the timeline and is marked deleted)
* MorePostsBean contains the timeline index of the last returned valid post (because if you delete a feed is stays on in the timeline and is marked deleted)
* and contains the Feeds
* @param strat the range start (most recent feeds for this vre) has to be greater than 0
* @param quantity the number of most recent feeds for this vre starting from "start" param
* @param strat the range start (most recent posts for this vre) has to be greater than 0
* @param quantity the number of most recent posts for this vre starting from "start" param
*/
@Override
public MorePostsBean getMorePosts(int start, int quantity) {
@ -490,16 +490,15 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
PortalContext pContext = PortalContext.getConfiguration();
String vreid = pContext.getCurrentScope(getThreadLocalRequest());
_log.debug("\n\nAsking more feed for Timeline " + vreid + " from " + start + " get other " + quantity);
_log.debug("\n\nAsking more post for Timeline " + vreid + " from " + start + " get other " + quantity);
ArrayList<Feed> organizationFeeds;
RangeFeeds rangeFeeds = null;
try {
rangeFeeds = store.getRecentFeedsByVREAndRange(vreid, start, quantity);
organizationFeeds = rangeFeeds.getFeeds();
if (organizationFeeds != null) {
for (Feed feed : organizationFeeds) {
feedsMap.put(feed.getKey(), feed);
//System.out.println("->\n"+feed.getDescription());
for (Feed post : organizationFeeds) {
feedsMap.put(post.getKey(), post);
}
}
}
@ -511,7 +510,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
for (String key: feedsMap.keySet()) {
toMerge.add(feedsMap.get(key));
}
//sort the feeds in reverse chronological order
//sort the posts in reverse chronological order
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<EnhancedFeed> toReturn = enhanceFeeds(toMerge, 2);
return new MorePostsBean(rangeFeeds.getLastReturnedFeedTimelineIndex(), toReturn);
@ -602,7 +601,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return false;
}
/**
* @param feedid the id of the commented feed
* @param feedid the id of the commented post
* @param commentText the comment text
* @param feedOwnerId the username of the user who created the post that was commented
*/