From 7a3d0f1fbe3fa043fbb5a22096c3d4708e666c87 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 29 Mar 2019 08:53:52 +0000 Subject: [PATCH] minor refactoring git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@178778 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../user/newsfeed/server/NewsServiceImpl.java | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java index 2453cc9..0ec4849 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java @@ -188,7 +188,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService } @Override - public ArrayList getAllUpdateUserFeeds(int feedsNoPerCategory) { + public ArrayList getAllUpdateUserFeeds(int postsNoPerCategory) { ArrayList toMerge = new ArrayList(); HashMap feedsMap = new HashMap(); @@ -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 OrganizationFeeds = (ArrayList) store.getRecentFeedsByVRE(vreid, feedsNoPerCategory); - for (Feed feed : OrganizationFeeds) { - feedsMap.put(feed.getKey(), feed); + _log.debug("Reading posts for VRE: " + vreid); + ArrayList OrganizationFeeds = (ArrayList) store.getRecentFeedsByVRE(vreid, postsNoPerCategory); + for (Feed post : OrganizationFeeds) { + feedsMap.put(post.getKey(), post); } } } //Portal Feeds ArrayList portalFeeds = (ArrayList) 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 OrganizationFeeds = (ArrayList) 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 toReturn = new ArrayList(); - //return only feeds + //return only 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 feeds = (ArrayList) store.getVREFeedsByHashtag(context, lowerCaseHashtag); - for (Feed feed : feeds) { - feedsMap.put(feed.getKey(), feed); + ArrayList posts = (ArrayList) 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 toReturn = new ArrayList(); - //return only feeds + //return only 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 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 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 getOnlyConnectionsUserPosts() { @@ -426,8 +426,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService //UserFriends Feeds ArrayList userFriendsIds = (ArrayList)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 toReturn = new ArrayList(); - //return only feeds + //return only 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 toEnhance = new ArrayList(); - 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 feedsMap = new HashMap(); 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 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 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 */