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