Removed SNL dependencies

This commit is contained in:
Ahmed Salah Tawfik Ibrahim 2024-01-25 18:34:17 +01:00
parent 1ef4a03b19
commit 87b15df81d
15 changed files with 283 additions and 339 deletions

View File

@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [v3.0.0] - 2023-12-15
- Feature #26194: News Feed portlet: remove elastic search client
- Feature #26515: Removed SNL dependency
## [v2.8.4] - 2022-05-15

12
pom.xml
View File

@ -86,23 +86,11 @@
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-library-stubs</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-client</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0)</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.gcube.socialnetworking</groupId>

View File

@ -1,7 +1,7 @@
package org.gcube.portlets.user.newsfeed.client;
import org.gcube.portal.databook.shared.ClientPost;
import org.gcube.portal.databook.shared.JSON;
import org.gcube.social_networking.socialnetworking.model.shared.ClientPost;
import org.gcube.social_networking.socialnetworking.model.shared.JSON;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;

View File

@ -3,10 +3,10 @@ package org.gcube.portlets.user.newsfeed.client;
import java.util.ArrayList;
import java.util.HashSet;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.Like;
import org.gcube.portal.databook.shared.ShowUserStatisticAction;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.social_networking.socialnetworking.model.shared.Like;
import org.gcube.social_networking.socialnetworking.model.shared.ShowUserStatisticAction;
import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
import org.gcube.portlets.user.newsfeed.shared.MorePostsBean;
import org.gcube.portlets.user.newsfeed.shared.OperationResult;
@ -21,19 +21,19 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
*/
@RemoteServiceRelativePath("newsServlet")
public interface NewsService extends RemoteService {
ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int feedsNoPerCategory);
ArrayList<EnhancedPost> getAllUpdateUserFeeds(int feedsNoPerCategory);
ArrayList<EnhancedFeed> getOnlyConnectionsUserPosts();
ArrayList<EnhancedPost> getOnlyConnectionsUserPosts();
ArrayList<EnhancedFeed> getOnlyMyUserPosts();
ArrayList<EnhancedPost> getOnlyMyUserPosts();
ArrayList<EnhancedFeed> getOnlyLikedPosts();
ArrayList<EnhancedPost> getOnlyLikedPosts();
ArrayList<EnhancedFeed> getPostsByHashtag(String hashtag);
ArrayList<EnhancedPost> getPostsByHashtag(String hashtag);
ArrayList<EnhancedFeed> getPostsByQuery(String query, int from, int quantity);
ArrayList<EnhancedPost> getPostsByQuery(String query, int from, int quantity);
ArrayList<EnhancedFeed> getPostsRelatedToUserStatistics(ShowUserStatisticAction action, int from, int quantity);
ArrayList<EnhancedPost> getPostsRelatedToUserStatistics(ShowUserStatisticAction action, int from, int quantity);
MorePostsBean getMorePosts(int from, int quantity);
@ -57,7 +57,7 @@ public interface NewsService extends RemoteService {
UserSettings getUserSettings();
EnhancedFeed getSinglePost(String postKey);
EnhancedPost getSinglePost(String postKey);
ArrayList<ItemBean> getOrganizationUsers();
}

View File

@ -3,10 +3,10 @@ package org.gcube.portlets.user.newsfeed.client;
import java.util.ArrayList;
import java.util.HashSet;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.Like;
import org.gcube.portal.databook.shared.ShowUserStatisticAction;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.social_networking.socialnetworking.model.shared.Like;
import org.gcube.social_networking.socialnetworking.model.shared.ShowUserStatisticAction;
import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
import org.gcube.portlets.user.newsfeed.shared.MorePostsBean;
import org.gcube.portlets.user.newsfeed.shared.OperationResult;
@ -21,10 +21,10 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
public interface NewsServiceAsync {
void getAllUpdateUserFeeds(int feedsNoPerCategory,
AsyncCallback<ArrayList<EnhancedFeed>> callback);
AsyncCallback<ArrayList<EnhancedPost>> callback);
void getOnlyConnectionsUserPosts(
AsyncCallback<ArrayList<EnhancedFeed>> callback);
AsyncCallback<ArrayList<EnhancedPost>> callback);
void like(String postid, String postText, String postOwnerId,
AsyncCallback<Boolean> callback);
@ -32,7 +32,7 @@ public interface NewsServiceAsync {
void getAllLikesByPost(String postid,
AsyncCallback<ArrayList<Like>> callback);
void getOnlyMyUserPosts(AsyncCallback<ArrayList<EnhancedFeed>> callback);
void getOnlyMyUserPosts(AsyncCallback<ArrayList<EnhancedPost>> callback);
void getUserSettings(AsyncCallback<UserSettings> callback);
@ -50,9 +50,9 @@ public interface NewsServiceAsync {
void editComment(String text, Comment toEdit, HashSet<MentionedDTO> mentionedUsers, AsyncCallback<OperationResult> callback);
void getOnlyLikedPosts(AsyncCallback<ArrayList<EnhancedFeed>> callback);
void getOnlyLikedPosts(AsyncCallback<ArrayList<EnhancedPost>> callback);
void getSinglePost(String postKey, AsyncCallback<EnhancedFeed> callback);
void getSinglePost(String postKey, AsyncCallback<EnhancedPost> callback);
void getMorePosts(int from, int quantity,
AsyncCallback<MorePostsBean> callback);
@ -63,12 +63,12 @@ public interface NewsServiceAsync {
void getOrganizationUsers(AsyncCallback<ArrayList<ItemBean>> callback);
void getPostsByHashtag(String hashtag,
AsyncCallback<ArrayList<EnhancedFeed>> callback);
AsyncCallback<ArrayList<EnhancedPost>> callback);
void getPostsByQuery(String query, int from, int quantity,
AsyncCallback<ArrayList<EnhancedFeed>> callback);
AsyncCallback<ArrayList<EnhancedPost>> callback);
void getPostsRelatedToUserStatistics(ShowUserStatisticAction action, int from, int quantity,
AsyncCallback<ArrayList<EnhancedFeed>> callback);
AsyncCallback<ArrayList<EnhancedPost>> callback);
}

View File

@ -2,7 +2,7 @@ package org.gcube.portlets.user.newsfeed.client.event;
import java.util.HashSet;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.portlets.user.newsfeed.client.ui.TweetTemplate;
import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;

View File

@ -7,19 +7,20 @@ import java.util.HashMap;
import java.util.HashSet;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder;
import org.gcube.portal.databook.shared.Attachment;
import org.gcube.portal.databook.shared.ClientAttachment;
import org.gcube.portal.databook.shared.ClientPost;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.FeedType;
import org.gcube.portal.databook.shared.Like;
import org.gcube.portal.databook.shared.PrivacyLevel;
import org.gcube.portal.databook.shared.ShowUserStatisticAction;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.social_networking.socialnetworking.model.client.GCubeSocialNetworking;
import org.gcube.social_networking.socialnetworking.model.client.util.Encoder;
import org.gcube.social_networking.socialnetworking.model.shared.Attachment;
import org.gcube.social_networking.socialnetworking.model.shared.ClientAttachment;
import org.gcube.social_networking.socialnetworking.model.shared.ClientPost;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.social_networking.socialnetworking.model.shared.Post;
import org.gcube.social_networking.socialnetworking.model.shared.PostType;
import org.gcube.social_networking.socialnetworking.model.shared.Like;
import org.gcube.social_networking.socialnetworking.model.shared.PrivacyLevel;
import org.gcube.social_networking.socialnetworking.model.shared.ShowUserStatisticAction;
import org.gcube.social_networking.socialnetworking.model.shared.UserInfo;
import org.gcube.portlets.user.newsfeed.client.FilterType;
import org.gcube.portlets.user.newsfeed.client.NewsService;
import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
@ -156,9 +157,9 @@ public class NewsFeedPanel extends Composite {
//needed to know the next range start
private Integer fromStartingPoint;
private ArrayList<EnhancedFeed> allUpdates = new ArrayList<EnhancedFeed>();
private ArrayList<EnhancedPost> allUpdates = new ArrayList<EnhancedPost>();
private ArrayList<EnhancedFeed> tempCacheNewUpdates = new ArrayList<EnhancedFeed>();
private ArrayList<EnhancedPost> tempCacheNewUpdates = new ArrayList<EnhancedPost>();
/**
* events binder
@ -447,14 +448,14 @@ public class NewsFeedPanel extends Composite {
*/
private void showSinglePost(String postKey) {
newsPanel.clear();
newsService.getSinglePost(postKey, new AsyncCallback<EnhancedFeed>() {
newsService.getSinglePost(postKey, new AsyncCallback<EnhancedPost>() {
@Override
public void onSuccess(EnhancedFeed result) {
if (result.getFeed().getType() == FeedType.DISABLED) {
public void onSuccess(EnhancedPost result) {
if (result.getPost().getType() == PostType.DISABLED) {
final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
String usrLink = "<a class=\"link\" href=\""+profilePageURL+"?"+
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
Encoder.encode(result.getFeed().getEntityId())+"\">"+result.getFeed().getFullName()+
Encoder.encode(result.getPost().getEntityId())+"\">"+result.getPost().getFullName()+
"</a> ";
newsPanel.add(new HTML("<div class=\"nofeed-message\"><div style=\"padding-top: 90px;\">" +
"We're sorry, "+ usrLink +" removed the post in the meantime!</div></div>"));
@ -495,23 +496,23 @@ public class NewsFeedPanel extends Composite {
* is open at infra level the first tab stops checking for updates
*/
if (result.getCurrentScope().compareTo(currentScope) == 0) {
newsService.getAllUpdateUserFeeds(NewsConstants.FEEDS_NO_PER_CATEGORY, new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getAllUpdateUserFeeds(NewsConstants.FEEDS_NO_PER_CATEGORY, new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
public void onSuccess(ArrayList<EnhancedPost> feeds) {
if (feeds != null && allUpdates.size() > 0) {
Date myLastUpdateTime = allUpdates.get(0).getFeed().getTime(); //this is the last update in the View
GWT.log("Last Mine: "+allUpdates.get(0).getFeed().getDescription());
Date myLastUpdateTime = allUpdates.get(0).getPost().getTime(); //this is the last update in the View
GWT.log("Last Mine: "+allUpdates.get(0).getPost().getDescription());
GWT.log("Last Retr.: "+feeds.get(0).getFeed().getDescription());
GWT.log("Last Retr.: "+feeds.get(0).getPost().getDescription());
tempCacheNewUpdates = new ArrayList<EnhancedFeed>(); //need to clear it everytime i check (in case someone deleted the updated in the meanwhile)
tempCacheNewUpdates = new ArrayList<EnhancedPost>(); //need to clear it everytime i check (in case someone deleted the updated in the meanwhile)
//check if there are new updates (enter the while) and put them in a temporary cache for displaying on user click
int i = 0;
while (i < feeds.size() && feeds.get(i).getFeed().getTime().after(myLastUpdateTime)) {
while (i < feeds.size() && feeds.get(i).getPost().getTime().after(myLastUpdateTime)) {
tempCacheNewUpdates.add(feeds.get(i));
i++;
}
@ -562,9 +563,9 @@ public class NewsFeedPanel extends Composite {
* is open at infra level the first tab stops checking for updates
*/
if (result.getCurrentScope().compareTo(currentScope) == 0) {
newsService.getPostsByHashtag(hashtag, new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getPostsByHashtag(hashtag, new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> posts) {
public void onSuccess(ArrayList<EnhancedPost> posts) {
filterPanelWrapper.setVisible(false);
newsPanel.clear();
if (posts != null) {
@ -579,7 +580,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
newsPanel.add(new ResultsFor("results for", hashtag));
for (EnhancedFeed feed : posts) {
for (EnhancedPost feed : posts) {
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
}
if (posts.size() < 5) {
@ -629,10 +630,10 @@ public class NewsFeedPanel extends Composite {
* is open at infra level the first tab stops checking for updates
*/
if (result.getCurrentScope().compareTo(currentScope) == 0) {
newsService.getPostsRelatedToUserStatistics(relatedFeedsToUserStatisticsToShow, from, to, new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getPostsRelatedToUserStatistics(relatedFeedsToUserStatisticsToShow, from, to, new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> posts) {
public void onSuccess(ArrayList<EnhancedPost> posts) {
filterPanelWrapper.setVisible(false);
newsPanel.clear();
@ -649,7 +650,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
newsPanel.add(new ResultsFor("", actionToPrint));
for (EnhancedFeed feed : posts) {
for (EnhancedPost feed : posts) {
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
// save them (they will be used when asking more feeds)
allUpdates.add(feed);
@ -706,9 +707,9 @@ public class NewsFeedPanel extends Composite {
* is open at infra level the first tab stops checking for updates
*/
if (result.getCurrentScope().compareTo(currentScope) == 0) {
newsService.getPostsByQuery(query, from, to, new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getPostsByQuery(query, from, to, new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> posts) {
public void onSuccess(ArrayList<EnhancedPost> posts) {
filterPanelWrapper.setVisible(false);
newsPanel.clear();
if (posts != null) {
@ -724,7 +725,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
newsPanel.add(new ResultsFor("Results for query: ", query));
for (EnhancedFeed feed : posts) {
for (EnhancedPost feed : posts) {
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
// save them (they will be used when asking more feeds)
allUpdates.add(feed);
@ -766,7 +767,7 @@ public class NewsFeedPanel extends Composite {
//need to put them in reverse order;
for (int i = tempCacheNewUpdates.size(); i > 0; i--) {
EnhancedFeed feed = tempCacheNewUpdates.get(i-1);
EnhancedPost feed = tempCacheNewUpdates.get(i-1);
final TweetTemplate tt = new TweetTemplate(myUserInfo, feed, eventBus, true);
newsPanel.insert(tt, 0); //insert in the view
allUpdates.add(0, feed); //insert in the model
@ -787,17 +788,13 @@ public class NewsFeedPanel extends Composite {
/**
* used when adding directly a feed from the UI (IPC)
* @param userid
* @param fullName
* @param thumbURL
* @param description
*/
public void addJustAddedFeed(ClientPost cFeed) {
// build up the feed
Feed feed = new Feed(
Post feed = new Post(
cFeed.key,
FeedType.SHARE,
PostType.SHARE,
cFeed.userid,
cFeed.time,
"",
@ -817,7 +814,7 @@ public class NewsFeedPanel extends Composite {
feed.setMultiFileUpload(multiAttachments);
//false because he could not have liked this yet and true because is the current user's
EnhancedFeed toAdd = new EnhancedFeed(feed, false, true);
EnhancedPost toAdd = new EnhancedPost(feed, false, true);
ArrayList<Attachment> attachments = null;
if (multiAttachments) {
@ -861,9 +858,9 @@ public class NewsFeedPanel extends Composite {
*/
public void showAllUpdatesFeeds() {
showLoader();
newsService.getAllUpdateUserFeeds(NewsConstants.FEEDS_NO_PER_CATEGORY, new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getAllUpdateUserFeeds(NewsConstants.FEEDS_NO_PER_CATEGORY, new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
public void onSuccess(ArrayList<EnhancedPost> feeds) {
newsPanel.clear();
if (feeds != null) {
if (feeds.size() == 0) {
@ -884,7 +881,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
for (EnhancedFeed feed : feeds) {
for (EnhancedPost feed : feeds) {
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
allUpdates.add(feed); //in the model
}
@ -932,14 +929,14 @@ public class NewsFeedPanel extends Composite {
int start = allUpdates.size();
GWT.log("StartingPoint = " + start);
newsService.getPostsByQuery(currentQuery, start, SEARCHED_FEEDS_TO_SHOW , new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getPostsByQuery(currentQuery, start, SEARCHED_FEEDS_TO_SHOW , new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> posts){
public void onSuccess(ArrayList<EnhancedPost> posts){
newsPanel.remove(showMoreUpdatesPanel);
if (posts != null) {
GWT.log("There are " + posts.size() + " more feeds");
for (EnhancedFeed feed : posts) {
for (EnhancedPost feed : posts) {
// avoid to insert same data
if(!isFeedPresent(feed)){
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
@ -976,14 +973,14 @@ public class NewsFeedPanel extends Composite {
int start = allUpdates.size();
GWT.log("StartingPoint = " + start);
newsService.getPostsRelatedToUserStatistics(relatedFeedsToUserStatisticsToShow, start, FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW , new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getPostsRelatedToUserStatistics(relatedFeedsToUserStatisticsToShow, start, FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW , new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> posts){
public void onSuccess(ArrayList<EnhancedPost> posts){
newsPanel.remove(showMoreUpdatesPanel);
if (posts != null) {
GWT.log("There are " + posts.size() + " more feeds");
for (EnhancedFeed feed : posts) {
for (EnhancedPost feed : posts) {
// avoid to insert same data
if(!isFeedPresent(feed)){
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
@ -1039,7 +1036,7 @@ public class NewsFeedPanel extends Composite {
if (rangeFeeds.getPosts() != null) {
fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
int c = 1;
for (EnhancedFeed post : rangeFeeds.getPosts()) {
for (EnhancedPost post : rangeFeeds.getPosts()) {
if (!isFeedPresent(post)) { //avoid possible duplicates
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, post, eventBus)); //in the view
allUpdates.add(post); //in the model
@ -1086,9 +1083,9 @@ public class NewsFeedPanel extends Composite {
return false;
}
private boolean isFeedPresent(EnhancedFeed toCheck) {
for (EnhancedFeed feed : allUpdates) {
if (feed.getFeed().getKey().compareTo(toCheck.getFeed().getKey()) == 0)
private boolean isFeedPresent(EnhancedPost toCheck) {
for (EnhancedPost feed : allUpdates) {
if (feed.getPost().getKey().compareTo(toCheck.getPost().getKey()) == 0)
return true;
}
return false;
@ -1098,9 +1095,9 @@ public class NewsFeedPanel extends Composite {
*/
public void showOnlyConnectionsFeeds() {
showLoader();
newsService.getOnlyConnectionsUserPosts(new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getOnlyConnectionsUserPosts(new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> feeds) {
public void onSuccess(ArrayList<EnhancedPost> feeds) {
if (feeds != null) {
newsPanel.clear();
if (feeds.size() == 0) {
@ -1114,7 +1111,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHeight("");
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
for (EnhancedFeed feed : feeds)
for (EnhancedPost feed : feeds)
newsPanel.add(new TweetTemplate(false, false, myUserInfo, feed, eventBus));
if (feeds.size() < 5) {
newsPanel.add(new Image(spacer));
@ -1138,9 +1135,9 @@ public class NewsFeedPanel extends Composite {
*/
public void showOnlyMyPosts() {
showLoader();
newsService.getOnlyMyUserPosts(new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getOnlyMyUserPosts(new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> posts) {
public void onSuccess(ArrayList<EnhancedPost> posts) {
if (posts != null) {
newsPanel.clear();
if (posts.size() == 0) {
@ -1153,7 +1150,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHeight("");
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
for (EnhancedFeed feed : posts)
for (EnhancedPost feed : posts)
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus));
if (posts.size() < 5) {
newsPanel.add(new Image(spacer));
@ -1177,9 +1174,9 @@ public class NewsFeedPanel extends Composite {
*/
public void showOnlyLikedPosts() {
showLoader();
newsService.getOnlyLikedPosts(new AsyncCallback<ArrayList<EnhancedFeed>>() {
newsService.getOnlyLikedPosts(new AsyncCallback<ArrayList<EnhancedPost>>() {
@Override
public void onSuccess(ArrayList<EnhancedFeed> posts) {
public void onSuccess(ArrayList<EnhancedPost> posts) {
if (posts != null) {
newsPanel.clear();
if (posts.size() == 0) {
@ -1192,7 +1189,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHeight("");
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
for (EnhancedFeed feed : posts)
for (EnhancedPost feed : posts)
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus));
if (posts.size() < 5) {
newsPanel.add(new Image(spacer));
@ -1219,22 +1216,22 @@ public class NewsFeedPanel extends Composite {
GWT.log(" number of posts " + allUpdates.size());
ArrayList<Comment> latestComments = new ArrayList<>();
//thePostsMap is need so that later it is faster to get the post by id
HashMap<String, EnhancedFeed> theCommentedPostsMap = new HashMap<>();
for (EnhancedFeed post : allUpdates) {
HashMap<String, EnhancedPost> theCommentedPostsMap = new HashMap<>();
for (EnhancedPost post : allUpdates) {
ArrayList<Comment> postComments = post.getComments();
if (postComments != null && !postComments.isEmpty()) {
theCommentedPostsMap.put(post.getFeed().getKey(), post);
theCommentedPostsMap.put(post.getPost().getKey(), post);
Comment latest = postComments.get(postComments.size()-1);
latestComments.add(latest); //get the latest
}
}
//sort the comments
Collections.sort(latestComments, Collections.reverseOrder());
ArrayList<EnhancedFeed> sortedPostsByLatestComment = new ArrayList<>();
ArrayList<EnhancedPost> sortedPostsByLatestComment = new ArrayList<>();
// evaluate unique posts' ids
HashSet<String> postIds = new HashSet<String>();
for (Comment comment : latestComments) {
String postId = comment.getFeedid();
String postId = comment.getPostid();
if(!postIds.contains(postId)){
postIds.add(postId);
sortedPostsByLatestComment.add(theCommentedPostsMap.get(postId));
@ -1242,8 +1239,8 @@ public class NewsFeedPanel extends Composite {
}
//at this point the sortedPostsByLatestComment list contains only the commented posts in the right order
//we need to add the remaining posts of the page in the latest post order
for (EnhancedFeed post : allUpdates) {
if (!theCommentedPostsMap.containsKey(post.getFeed().getKey()))
for (EnhancedPost post : allUpdates) {
if (!theCommentedPostsMap.containsKey(post.getPost().getKey()))
sortedPostsByLatestComment.add(post);
}
newsPanel.clear();
@ -1257,7 +1254,7 @@ public class NewsFeedPanel extends Composite {
newsPanel.setHeight("");
newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
for (EnhancedFeed feed : sortedPostsByLatestComment)
for (EnhancedPost feed : sortedPostsByLatestComment)
newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus));
if (sortedPostsByLatestComment.size() < 5) {
newsPanel.add(new Image(spacer));

View File

@ -1,8 +1,8 @@
package org.gcube.portlets.user.newsfeed.client.ui;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.UserInfo;
import org.gcube.portlets.user.gcubewidgets.client.elements.Div;
import org.gcube.portlets.user.newsfeed.client.event.AddCommentEvent;
import org.gcube.portlets.user.newsfeed.client.event.EditCommentEvent;
@ -74,7 +74,7 @@ public class AddCommentTemplate extends Composite {
/**
* called on edit comment
* @param caller
* @param editText
* @param toEdit
*/
public AddCommentTemplate(TweetTemplate caller, Comment toEdit, HTMLPanel commentPanel) {
initWidget(uiBinder.createAndBindUi(this));
@ -166,7 +166,7 @@ public class AddCommentTemplate extends Composite {
/**
* called when pasting. it tries to avoid pasting long non spaced strings
* @param linkToCheck
* @param textToCheck
*/
private boolean checkTextLength(String textToCheck) {

View File

@ -1,6 +1,6 @@
package org.gcube.portlets.user.newsfeed.client.ui;
import org.gcube.portal.databook.shared.Attachment;
import org.gcube.social_networking.socialnetworking.model.shared.Attachment;
import org.gcube.portlets.widgets.imagepreviewerwidget.client.EnhancedImage;
import org.gcube.portlets.widgets.imagepreviewerwidget.client.ui.Carousel;

View File

@ -3,9 +3,9 @@ package org.gcube.portlets.user.newsfeed.client.ui;
import java.util.Date;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.client.GCubeSocialNetworking;
import org.gcube.social_networking.socialnetworking.model.client.util.Encoder;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.portlets.user.newsfeed.client.event.DeleteCommentEvent;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;

View File

@ -8,13 +8,13 @@ import java.util.Date;
import java.util.Iterator;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder;
import org.gcube.portal.databook.shared.Attachment;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.social_networking.socialnetworking.model.client.GCubeSocialNetworking;
import org.gcube.social_networking.socialnetworking.model.client.util.Encoder;
import org.gcube.social_networking.socialnetworking.model.shared.Attachment;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.social_networking.socialnetworking.model.shared.Post;
import org.gcube.social_networking.socialnetworking.model.shared.UserInfo;
import org.gcube.portlets.user.newsfeed.client.event.AddLikeEvent;
import org.gcube.portlets.user.newsfeed.client.event.DeletePostEvent;
import org.gcube.portlets.user.newsfeed.client.event.OpenPostEvent;
@ -66,7 +66,7 @@ public class TweetTemplate extends Composite {
private static final int MAX_SHOWTEXT_LENGTH = 612;
private EnhancedFeed myPost;
private EnhancedPost myPost;
private UserInfo myUserInfo;
private HandlerManager eventBus;
@ -129,12 +129,11 @@ public class TweetTemplate extends Composite {
* used when fetching tweets from server
* @param myUserInfo
* @param myPost
* @param isUsers
* @param displaySingle tells if you're displaying a single fedd or not
* @param eventBus
*/
@SuppressWarnings("deprecation")
public TweetTemplate(boolean displaySingle, boolean showTimelineSource, UserInfo myUserInfo, EnhancedFeed myPost, HandlerManager eventBus) {
public TweetTemplate(boolean displaySingle, boolean showTimelineSource, UserInfo myUserInfo, EnhancedPost myPost, HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
commentsNo.getElement().getStyle().setPaddingTop(0, Unit.PX);
likesNo.getElement().getStyle().setPaddingTop(0, Unit.PX);
@ -147,8 +146,8 @@ public class TweetTemplate extends Composite {
this.vreSourceInMetadata.setVisible(false);
this.separator.setVisible(false);
this.myPost = myPost;
isAppPost = myPost.getFeed().isApplicationFeed();
Feed post = myPost.getFeed();
isAppPost = myPost.getPost().isApplicationPost();
Post post = myPost.getPost();
this.eventBus = eventBus;
this.isUsers = myPost.isUsers();
this.carousel = new Carousel();
@ -417,12 +416,12 @@ public class TweetTemplate extends Composite {
/**
* used when getting tweets from the client
* @param myUserInfo
* @param feed
* @param post
* @param eventBus
* @param hidden
*/
public TweetTemplate(UserInfo myUserInfo, EnhancedFeed feed, HandlerManager eventBus, boolean hidden) {
this(false, false, myUserInfo, feed, eventBus);
public TweetTemplate(UserInfo myUserInfo, EnhancedPost post, HandlerManager eventBus, boolean hidden) {
this(false, false, myUserInfo, post, eventBus);
contentArea.getElement().getParentElement().getParentElement().setClassName("div-table-col content hidden");
}
@ -462,7 +461,7 @@ public class TweetTemplate extends Composite {
@UiHandler("seeMore")
void onSeeMoreClick(ClickEvent e) {
String postText = myPost.getFeed().getDescription();
String postText = myPost.getPost().getDescription();
postText = postText.replaceAll("&amp;","&");
contentArea.setHTML(postText);
@ -486,19 +485,19 @@ public class TweetTemplate extends Composite {
//if is not liked
if (!likeArea.getText().equals(NewsFeedPanel.LIKED_LABEL)) {
try {
int cur = Integer.parseInt(myPost.getFeed().getLikesNo());
int cur = Integer.parseInt(myPost.getPost().getLikesNo());
cur++;
if (cur == 1) {
myPost.getFeed().setLikesNo("1");
myPost.getPost().setLikesNo("1");
likesNo.setText("1");
likesNo.setTitle("People who have " + NewsFeedPanel.LIKED_LABEL + " this");
likesNo.setVisible(true);
} else {
myPost.getFeed().setLikesNo(""+cur);
myPost.getPost().setLikesNo(""+cur);
likesNo.setText(""+cur);
likesNo.setVisible(true);
}
eventBus.fireEvent(new AddLikeEvent(this, myPost.getFeed().getKey()));
eventBus.fireEvent(new AddLikeEvent(this, myPost.getPost().getKey()));
setFavoritedUI(true);
}
catch (NumberFormatException ex) {
@ -506,19 +505,19 @@ public class TweetTemplate extends Composite {
}
} else {
//it is liked
int cur = Integer.parseInt(myPost.getFeed().getLikesNo());
int cur = Integer.parseInt(myPost.getPost().getLikesNo());
cur--;
if (cur == 0) {
myPost.getFeed().setLikesNo("0");
myPost.getPost().setLikesNo("0");
likesNo.setText("");
likesNo.setVisible(false);
likesNo.setTitle("");
} else {
myPost.getFeed().setLikesNo(""+cur);
myPost.getPost().setLikesNo(""+cur);
likesNo.setText(""+cur);
likesNo.setVisible(true);
}
eventBus.fireEvent(new UnLikeEvent(this, myPost.getFeed().getKey()));
eventBus.fireEvent(new UnLikeEvent(this, myPost.getPost().getKey()));
setFavoritedUI(false);
}
}
@ -569,7 +568,7 @@ public class TweetTemplate extends Composite {
@UiHandler("likesNo")
void onSeeLikes(ClickEvent e) {
eventBus.fireEvent(new SeeLikesEvent(myPost.getFeed().getKey()));
eventBus.fireEvent(new SeeLikesEvent(myPost.getPost().getKey()));
}
@UiHandler("commentsNo")
@ -589,7 +588,7 @@ public class TweetTemplate extends Composite {
this.commentingDisabled = commenting;
}
public String getFeedKey() {
return myPost.getFeed().getKey();
return myPost.getPost().getKey();
}
public void remove(Widget w) {
@ -671,11 +670,11 @@ public class TweetTemplate extends Composite {
}
public String getMyFeedUserId() {
return myPost.getFeed().getEntityId();
return myPost.getPost().getEntityId();
}
public String getMyFeedText() {
return myPost.getFeed().getDescription();
return myPost.getPost().getDescription();
}
public boolean isAppFeed() {
@ -698,7 +697,7 @@ public class TweetTemplate extends Composite {
* @return the context (scope) of the Post
*/
public String getVREContext() {
return this.myPost.getFeed().getVreid();
return this.myPost.getPost().getVreid();
}
/**

View File

@ -25,22 +25,15 @@ import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Attachment;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.Like;
import org.gcube.portal.databook.shared.RangeFeeds;
import org.gcube.portal.databook.shared.ShowUserStatisticAction;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException;
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException;
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
import org.gcube.social_networking.social_networking_client_library.LibClient;
import org.gcube.social_networking.socialnetworking.model.shared.Attachment;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
import org.gcube.social_networking.socialnetworking.model.shared.Post;
import org.gcube.social_networking.socialnetworking.model.shared.Like;
import org.gcube.social_networking.socialnetworking.model.shared.RangePosts;
import org.gcube.social_networking.socialnetworking.model.shared.ShowUserStatisticAction;
import org.gcube.social_networking.socialnetworking.model.shared.UserInfo;
import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.CommentNotificationsThread;
import org.gcube.portal.notifications.thread.LikeNotificationsThread;
@ -98,20 +91,24 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
/**
* Cassandra client
*/
private DatabookStore store;
private LibClient libClient;
private final static int MAX_POSTS_NO = 30;
public void init() {
store = new DBCassandraAstyanaxImpl();
try {
libClient = new LibClient();
} catch (Exception e) {
throw new RuntimeException(e);
}
APP_ID = this.getClass().getName();
}
public void destroy() {
/*public void destroy() {
store.closeConnection();
}
}*/
/**
*
* @return true if you're running into the portal, false if in development
@ -177,10 +174,10 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
@Override
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int postsNoPerCategory) {
public ArrayList<EnhancedPost> getAllUpdateUserFeeds(int postsNoPerCategory) {
ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
ArrayList<Post> toMerge = new ArrayList<Post>();
HashMap<String, Post> feedsMap = new HashMap<String, Post>();
try {
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
_log.info("****** retrieving posts for user: " + currUser.getUsername());
@ -195,16 +192,16 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
if (gm.isVRE(group.getGroupId())) {
String vreid = gm.getInfrastructureScope(group.getGroupId()); //get the scope
_log.debug("Reading posts for VRE: " + vreid);
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE(vreid, postsNoPerCategory);
for (Feed post : OrganizationFeeds) {
ArrayList<Post> OrganizationFeeds = (ArrayList<Post>) libClient.getRecentPostsByVRELib(vreid, postsNoPerCategory);
for (Post post : OrganizationFeeds) {
feedsMap.put(post.getKey(), post);
}
}
}
//Portal Feeds
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
for (Feed post : portalFeeds) {
ArrayList<Post> portalFeeds = (ArrayList<Post>) libClient.getAllPortalPrivacyLevelPostsLib();
for (Post post : portalFeeds) {
feedsMap.put(post.getKey(), post);
}
}
@ -213,8 +210,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
PortalContext context = PortalContext.getConfiguration();
String vreid = context.getCurrentScope(getThreadLocalRequest());
_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 post : OrganizationFeeds) {
ArrayList<Post> OrganizationFeeds = (ArrayList<Post>) libClient.getRecentPostsByVRELib(vreid, (NewsConstants.FEEDS_MAX_PER_CATEGORY));
for (Post post : OrganizationFeeds) {
feedsMap.put(post.getKey(), post);
}
}
@ -226,21 +223,15 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
//sort the posts in reverse chronological order
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<Feed> toReturn = new ArrayList<Feed>();
ArrayList<Post> toReturn = new ArrayList<Post>();
//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));
else {
return enhanceFeeds(toMerge, 2);
return enhancePosts(toMerge, 2);
}
return enhanceFeeds(toReturn, 2);
} catch (PrivacyLevelTypeNotFoundException e) {
_log.error("Privacy Level not Found " + e.getMessage());
} catch (FeedTypeNotFoundException e) {
_log.error("Feed Type not Found " + e.getMessage());
} catch (ColumnNameNotFoundException e) {
_log.error("Column name not Found " + e.getMessage());
return enhancePosts(toReturn, 2);
} catch (Exception e) {
e.printStackTrace();
}
@ -252,7 +243,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* @param hashtag the hashtag to look for including '#'
*/
@Override
public ArrayList<EnhancedFeed> getPostsByHashtag(String hashtag) {
public ArrayList<EnhancedPost> getPostsByHashtag(String hashtag) {
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
String currentScope = pContext.getCurrentScope(getThreadLocalRequest());
@ -266,8 +257,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
try {
ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
ArrayList<Post> toMerge = new ArrayList<Post>();
HashMap<String, Post> feedsMap = new HashMap<String, Post>();
String lowerCaseHashtag = hashtag.toLowerCase();
// the contexts of the user
@ -296,8 +287,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
_log.debug("Contexts for hashtags is " + contexts);
for (String context : contexts) {
ArrayList<Feed> posts = (ArrayList<Feed>) store.getVREFeedsByHashtag(context, lowerCaseHashtag);
for (Feed post : posts) {
ArrayList<Post> posts = (ArrayList<Post>) libClient.getVREPostsByHashtagLib(context, lowerCaseHashtag);
for (Post post : posts) {
feedsMap.put(post.getKey(), post);
}
}
@ -309,21 +300,15 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
//sort the posts in reverse chronological order
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<Feed> toReturn = new ArrayList<Feed>();
ArrayList<Post> toReturn = new ArrayList<Post>();
//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));
else {
return enhanceFeeds(toMerge, 2);
return enhancePosts(toMerge, 2);
}
return enhanceFeeds(toReturn, 2);
} catch (PrivacyLevelTypeNotFoundException e) {
_log.error("Privacy Level not Found ", e);
} catch (FeedTypeNotFoundException e) {
_log.error("Feed Type not Found ", e);
} catch (ColumnNameNotFoundException e) {
_log.error("Column name not Found ", e);
return enhancePosts(toReturn, 2);
} catch (Exception e) {
_log.error("Error while retrieving posts for hashtag ", e);
}
@ -331,7 +316,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
@Override
public ArrayList<EnhancedFeed> getPostsByQuery(String query, int from, int quantity) {
public ArrayList<EnhancedPost> getPostsByQuery(String query, int from, int quantity) {
_log.debug("\n\n IN getPostsByQuery ");
@ -369,26 +354,26 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
FullTextSearchClient sClient = new FullTextSearchClient();
List<EnhancedFeed> enhancedFeeds = sClient.search(query, from, quantity);
List<EnhancedPost> enhancedFeeds = sClient.search(query, from, quantity);
// query elastic search
//escl.search(query, vres, from, quantity);
// retrieve the ids of liked posts by the user
List<String> likedPosts = store.getAllLikedPostIdsByUser(userName);
List<String> likedPosts = libClient.getAllLikedPostIdsByUserLib(userName);
// update fields "liked" and "isuser"
for (EnhancedFeed enhancedFeed : enhancedFeeds) {
for (EnhancedPost enhancedFeed : enhancedFeeds) {
if(isUsers(enhancedFeed.getFeed(), userName))
if(isUsers(enhancedFeed.getPost(), userName))
enhancedFeed.setUsers(true);
if(likedPosts.contains(enhancedFeed.getFeed().getKey()))
if(likedPosts.contains(enhancedFeed.getPost().getKey()))
enhancedFeed.setLiked(true);
}
return (ArrayList<EnhancedFeed>) enhancedFeeds;
return (ArrayList<EnhancedPost>) enhancedFeeds;
}catch (Exception e) {
e.printStackTrace();
@ -401,17 +386,18 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* return only the user connection posts
*/
@Override
public ArrayList<EnhancedFeed> getOnlyConnectionsUserPosts() {
ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
public ArrayList<EnhancedPost> getOnlyConnectionsUserPosts() {
/*ArrayList<Post> toMerge = new ArrayList<Post>();
HashMap<String, Post> feedsMap = new HashMap<String, Post>();
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
try {
//UserFriends Feeds
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
//implement in client and ws
ArrayList<String> userFriendsIds = (ArrayList<String>)libClient.getFriendsLib(userName);
for (String userid : userFriendsIds) {
for (Feed post : store.getRecentFeedsByUser(userid, NewsConstants.FEEDS_NO_PER_CATEGORY)) {
for (Post post : libClient.getRecentPostsByUserLib(userid, NewsConstants.FEEDS_NO_PER_CATEGORY)) {
feedsMap.put(post.getKey(), post);
}
}
@ -419,23 +405,23 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
toMerge.add(feedsMap.get(key));
}
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<Feed> toReturn = new ArrayList<Feed>();
ArrayList<Post> toReturn = new ArrayList<Post>();
//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));
else
return enhanceFeeds(toMerge, 2);
return enhancePosts(toMerge, 2);
} catch (PrivacyLevelTypeNotFoundException e) {
_log.error("Privacy Level not Found " + e.getMessage());
} catch (FeedTypeNotFoundException e) {
} catch (PostTypeNotFoundException e) {
_log.error("Feed Type not Found " + e.getMessage());
} catch (ColumnNameNotFoundException e) {
_log.error("Column name not Found " + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}*/
return null;
}
@ -443,43 +429,42 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* return only one post with all the comments
*/
@Override
public EnhancedFeed getSinglePost(String postKey) {
Feed post = null;
public EnhancedPost getSinglePost(String postKey) {
Post post = null;
try {
if (postKey != null) {
post = store.readFeed(postKey);
post = libClient.readPostLib(postKey);
if (post != null) {
ArrayList<Feed> toEnhance = new ArrayList<Feed>();
ArrayList<Post> toEnhance = new ArrayList<Post>();
toEnhance.add(post);
return enhanceFeeds(toEnhance, -1).get(0); //-1 all the comments
return enhancePosts(toEnhance, -1).get(0); //-1 all the comments
}
}
} catch (Exception e) {
_log.debug("Error while trying to fetch post with key " + postKey + " returning nothing");
return new EnhancedFeed();
return new EnhancedPost();
}
return new EnhancedFeed();
return new EnhancedPost();
}
/**
* 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 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) {
ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
ArrayList<Post> toMerge = new ArrayList<Post>();
HashMap<String, Post> feedsMap = new HashMap<String, Post>();
PortalContext pContext = PortalContext.getConfiguration();
String vreid = pContext.getCurrentScope(getThreadLocalRequest());
_log.debug("\n\nAsking more post for Timeline " + vreid + " from " + start + " get other " + quantity);
ArrayList<Feed> organizationFeeds;
RangeFeeds rangeFeeds = null;
ArrayList<Post> organizationFeeds;
RangePosts rangeFeeds = null;
try {
rangeFeeds = store.getRecentFeedsByVREAndRange(vreid, start, quantity);
organizationFeeds = rangeFeeds.getFeeds();
rangeFeeds = libClient.getRecentPostsByVREAndRangeLib(vreid, start, quantity);
organizationFeeds = rangeFeeds.getPosts();
if (organizationFeeds != null) {
for (Feed post : organizationFeeds) {
for (Post post : organizationFeeds) {
feedsMap.put(post.getKey(), post);
}
}
@ -494,38 +479,39 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
//sort the posts in reverse chronological order
Collections.sort(toMerge, Collections.reverseOrder());
ArrayList<EnhancedFeed> toReturn = enhanceFeeds(toMerge, 2);
return new MorePostsBean(rangeFeeds.getLastReturnedFeedTimelineIndex(), toReturn);
ArrayList<EnhancedPost> toReturn = enhancePosts(toMerge, 2);
return new MorePostsBean(rangeFeeds.getLastReturnedPostTimelineIndex(), toReturn);
}
@Override
public ArrayList<EnhancedFeed> getOnlyMyUserPosts() {
public ArrayList<EnhancedPost> getOnlyMyUserPosts() {
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
_log.trace("getOnly UserFeeds for " + userName);
ArrayList<Feed> userFeeds = null;
ArrayList<Post> userFeeds = null;
try {
userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 15);
userFeeds = (ArrayList<Post>) libClient.getRecentPostsByUserLib(userName, 15);
} catch (Exception e) {
_log.error("Could not read recent posts for this user " + userName);
}
Collections.sort(userFeeds, Collections.reverseOrder());
return enhanceFeeds(userFeeds, 2);
return enhancePosts(userFeeds, 2);
}
@Override
public ArrayList<EnhancedFeed> getOnlyLikedPosts() {
public ArrayList<EnhancedPost> getOnlyLikedPosts() {
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
_log.trace("getLiked Feeds for " + userName);
ArrayList<Feed> userFeeds = null;
ArrayList<Post> userFeeds = null;
try {
userFeeds = (ArrayList<Feed>) store.getAllLikedFeedsByUser(userName, 25);
//need to define this function and endpoint in ws and client
userFeeds = (ArrayList<Post>) libClient.getAllLikedPostsByUserLib(userName, 25);
} catch (Exception e) {
_log.error("Could not read liked posts for this user " + userName);
}
Collections.sort(userFeeds, Collections.reverseOrder());
return enhanceFeeds(userFeeds, 2);
return enhancePosts(userFeeds, 2);
}
@Override
@ -539,12 +525,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
Like toLike = new Like(UUID.randomUUID().toString(), user.getUsername(),
new Date(), postid, user.getFullName(), user.getAvatarId());
try {
likeCommitResult = store.like(toLike);
} catch (FeedIDNotFoundException e) {
_log.error("Post not Found for this like " + e.getMessage());
return false;
}
likeCommitResult = libClient.likeLib(toLike);
//if the like was correctly delivered notify users involved
if (likeCommitResult) {
PortalContext pContext = PortalContext.getConfiguration();
@ -570,19 +551,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override
public boolean unlike(String postid, String postText, String postOwnerId) {
UserInfo user = getUserSettings().getUserInfo();
try {
for (Like like : store.getAllLikesByFeed(postid)) {
if (like.getUserid().compareTo(user.getUsername()) == 0) {
_log.trace("Trying unlike of " + postText + " for " + user.getFullName());
store.unlike(user.getUsername(), like.getKey(), postid);
return true;
}
}
} catch (FeedIDNotFoundException | PrivacyLevelTypeNotFoundException | FeedTypeNotFoundException | ColumnNameNotFoundException | LikeIDNotFoundException e) {
_log.error("Either Post or Like not Found " + e.getMessage());
return false;
}
UserInfo user = getUserSettings().getUserInfo();
for (Like like : libClient.getAllLikesByPostLib(postid)) {
if (like.getUserid().compareTo(user.getUsername()) == 0) {
_log.trace("Trying unlike of " + postText + " for " + user.getFullName());
libClient.unlikeLib(user.getUsername(), like.getKey(), postid);
return true;
}
}
return false;
}
/**
@ -617,23 +593,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
Comment comment = new Comment(UUID.randomUUID().toString(), user.getUsername(),
new Date(), feedid, escapedCommentText, user.getFullName(), user.getAvatarId());
try {
if (store.addComment(comment))
commentCommitResult = true;
} catch (FeedIDNotFoundException e) {
_log.error("Related post not found for this comment " + e.getMessage());
return new OperationResult(false, "Related post not found for this comment", comment);
}
if (libClient.addCommentLib(comment))
commentCommitResult = true;
try {
if (hashtags != null && !hashtags.isEmpty())
store.saveHashTagsComment(comment.getKey(), store.readFeed(comment.getFeedid()).getVreid(), hashtags);
} catch (CommentIDNotFoundException
| PrivacyLevelTypeNotFoundException
| FeedTypeNotFoundException | FeedIDNotFoundException
| ColumnNameNotFoundException e1) {
_log.error("Unable to save hashtags for this comment " + e1.getMessage());
}
if (hashtags != null && !hashtags.isEmpty())
libClient.saveHashTagsCommentLib(comment.getKey(), libClient.readPostLib(comment.getPostid()).getVreid(), hashtags);
//if the comment was correctly delivered && is not an app feed notify users involved
if (commentCommitResult && isWithinPortal()) {
@ -656,7 +620,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
likesThread.start();
//notify the other users who commented this post (excluding the ones above)
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(store, new LiferayUserManager(), user.getUsername(), comment.getFeedid(), escapedCommentText, nm, feedOwnerId, comment.getKey(), favorites));
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(new LiferayUserManager(), user.getUsername(), comment.getPostid(), escapedCommentText, nm, feedOwnerId, comment.getKey(), favorites));
commentsNotificationthread.start();
//send the notification to the mentioned users, if any
@ -705,7 +669,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
toPass.add(new GenericItemBean(userBean.getId(), userBean.getName(), userBean.getAlternativeName(), userBean.getThumbnailURL()));
}
Thread thread = new Thread(new MentionNotificationsThread(comment.getFeedid(), escapedCommentText, nm, null, toPass));
Thread thread = new Thread(new MentionNotificationsThread(comment.getPostid(), escapedCommentText, nm, null, toPass));
thread.start();
}
}
@ -723,16 +687,16 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return new OperationResult(false, "Session Expired", null);
}
String vreIdFeed = store.readFeed(toEdit.getFeedid()).getVreid();
String vreIdFeed = libClient.readPostLib(toEdit.getPostid()).getVreid();
// get old hashtags and delete them
String oldText = store.readCommentById(toEdit.getKey()).getText();
String oldText = libClient.readCommentByIdLib(toEdit.getKey()).getText();
_log.debug("Old text for this comment is " + oldText);
System.out.println("Old text for this comment is " + oldText);
List<String> oldHashtags = Utils.getHashTags(Utils.removeHTMLFromText(oldText));
if (oldHashtags != null && !oldHashtags.isEmpty()) {
_log.debug("The comment has hashtags, attempting to delete them ... " + oldHashtags.toString());
boolean deletedHashtag = store.deleteHashTagsComment(toEdit.getKey(), vreIdFeed, oldHashtags);
boolean deletedHashtag = libClient.deleteHashTagsCommentLib(toEdit.getKey(), vreIdFeed, oldHashtags);
_log.debug("deletedHashtag? " + deletedHashtag);
}
@ -752,12 +716,12 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
List<String> newHashtags = messageParser.getHashtags();
if (newHashtags != null && !newHashtags.isEmpty())
store.saveHashTagsComment(toEdit.getKey(), vreIdFeed, newHashtags);
libClient.saveHashTagsCommentLib(toEdit.getKey(), vreIdFeed, newHashtags);
edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
toEdit.getTime(), toEdit.getFeedid(), escapedCommentText, user.getFullName(), user.getAvatarId(), true, new Date());
toEdit.getTime(), toEdit.getPostid(), escapedCommentText, user.getFullName(), user.getAvatarId(), true, new Date());
commentCommitResult = store.editComment(edited);
commentCommitResult = libClient.editCommentLib(edited);
if (commentCommitResult) {
PortalContext pContext = PortalContext.getConfiguration();
@ -811,7 +775,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
toPass.add(new GenericItemBean(userBean.getId(), userBean.getName(), userBean.getAlternativeName(), userBean.getThumbnailURL()));
}
Thread thread = new Thread(new MentionNotificationsThread(toEdit.getFeedid(), escapedCommentText, nm, null, toPass));
Thread thread = new Thread(new MentionNotificationsThread(toEdit.getPostid(), escapedCommentText, nm, null, toPass));
thread.start();
}
}
@ -831,8 +795,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
*
* @return
*/
private ArrayList<EnhancedFeed> enhanceFeeds(ArrayList<Feed> toEnhance, int commentsNumberPerFeed) {
ArrayList<EnhancedFeed> toReturn = new ArrayList<EnhancedFeed>();
private ArrayList<EnhancedPost> enhancePosts(ArrayList<Post> toEnhance, int commentsNumberPerFeed) {
ArrayList<EnhancedPost> toReturn = new ArrayList<EnhancedPost>();
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
@ -842,24 +806,20 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
String siteLandinPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
String tokenTosubstitute = siteLandinPagePath.replace("/group/", "");
ArrayList<String> likedFeeds = (ArrayList<String>) store.getAllLikedFeedIdsByUser(userName);
ArrayList<String> likedFeeds = (ArrayList<String>) libClient.getAllLikedPostIdsByUserLib(userName);
boolean skip = false;
for (Feed feed : toEnhance) {
for (Post feed : toEnhance) {
//patch needed for maintaining mention link backward compatibility (they point to /group/data-e-infrastructure-gateway/profile)
String currPostText = feed.getDescription().replace(LINK_TO_REPLACE,tokenTosubstitute);
feed.setDescription(currPostText);
boolean isMultiFileUpload = feed.isMultiFileUpload();
ArrayList<Attachment> attachments = new ArrayList<Attachment>();
if (isMultiFileUpload) {
try {
attachments = (ArrayList<Attachment>) store.getAttachmentsByFeedId(feed.getKey());
} catch (FeedIDNotFoundException e) {
_log.error("It looks like sth wrong with this feedid having attachments, could not find feedId = " + feed.getKey() + "\n" + e.getMessage());
}
}
attachments = (ArrayList<Attachment>) libClient.getAttachmentsByPostIdLib(feed.getKey());
}
skip = false;
if (! feed.isApplicationFeed()) {
if (! feed.isApplicationPost()) {
String thumb = getUserImagePortraitUrlLocal(feed.getEntityId());
if (thumb == null) {
_log.warn(feed.getEntityId() + " is not avaialble on this portal, skipping this feed: " + feed.getKey());
@ -879,12 +839,12 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
if (!skip) {
if (commentsNo == 0) {
EnhancedFeed toAdd = null;
EnhancedPost toAdd = null;
//create the enhanced feed
if (feed.isApplicationFeed()) {
toAdd = new EnhancedFeed(feed, liked, checkisAdminUser());
if (feed.isApplicationPost()) {
toAdd = new EnhancedPost(feed, liked, checkisAdminUser());
} else
toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName));
toAdd = new EnhancedPost(feed, liked, isUsers(feed, userName));
toAdd.setAttachments(attachments);
toReturn.add(toAdd);
} else {
@ -895,7 +855,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
int currCommentsNumber = comments.size();
//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, attachments);
EnhancedPost toAdd = new EnhancedPost(feed, liked, isUsers(feed, userName), comments, attachments);
toReturn.add(toAdd);
} else {
//need to get the last two
@ -903,7 +863,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
for (int i = currCommentsNumber -commentsNumberPerFeed; i < currCommentsNumber; i++) {
comments2Attach.add(comments.get(i));
}
EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName), comments2Attach, attachments);
EnhancedPost toAdd = new EnhancedPost(feed, liked, isUsers(feed, userName), comments2Attach, attachments);
toReturn.add(toAdd);
}
}
@ -917,7 +877,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
/**
* this method is needed because user images portrait change id depending on the portal instance
* e.g. a post made from iMarine portal would not show the avatarIMage in D4Science.org
* @param screenname
* @return the url of the image portrait for this portal instance
*/
private String getUserImagePortraitUrlLocal(String screenName) {
@ -935,7 +894,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override
public ArrayList<Like> getAllLikesByPost(String postid) {
ArrayList<Like> toReturn = (ArrayList<Like>) store.getAllLikesByFeed(postid);
ArrayList<Like> toReturn = (ArrayList<Like>) libClient.getAllLikesByPostLib(postid);
_log.trace("Asking likes for " + postid);
for (Like like : toReturn) {
String thumb = getUserImagePortraitUrlLocal(like.getUserid());
@ -948,7 +907,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
@Override
public ArrayList<Comment> getAllCommentsByPost(String postid) {
_log.trace("Asking comments for " + postid);
ArrayList<Comment> toReturn = (ArrayList<Comment>) store.getAllCommentByFeed(postid);
ArrayList<Comment> toReturn = (ArrayList<Comment>) libClient.getAllCommentsByPostIdLib(postid);
for (Comment comment : toReturn) {
String thumb = getUserImagePortraitUrlLocal(comment.getUserid());
comment.setThumbnailURL(thumb == null ? "" : thumb);
@ -961,16 +920,16 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
_log.trace("Attempting to delete comment " + commentid);
try {
// get hashtags, if any, and delete them
Comment toDelete = store.readCommentById(commentid);
String vreIdFeed = store.readFeed(toDelete.getFeedid()).getVreid();
Comment toDelete = libClient.readCommentByIdLib(commentid);
String vreIdFeed = libClient.readPostLib(toDelete.getPostid()).getVreid();
List<String> hashtags = Utils.getHashTags(Utils.removeHTMLFromText(toDelete.getText()));
if (hashtags != null && !hashtags.isEmpty()) {
_log.debug("The comment has hashtags, attempting to delete them ... " + hashtags.toString());
boolean deletedHashtag = store.deleteHashTagsComment(toDelete.getKey(), vreIdFeed, hashtags);
boolean deletedHashtag = libClient.deleteHashTagsCommentLib(toDelete.getKey(), vreIdFeed, hashtags);
_log.debug("deletedHashtag? " + deletedHashtag);
}
_log.debug("Attempting to delete comment " + commentid);
return store.deleteComment(commentid, feedid);
return libClient.deleteCommentLib(commentid, feedid);
} catch (Exception e) {
_log.error("Failed to delete comment " + commentid);
return false;
@ -980,14 +939,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
public boolean deletePost(String postid) {
_log.debug("Called delete post " + postid);
try {
Feed toDelete = store.readFeed(postid);
Post toDelete = libClient.readPostLib(postid);
// delete comments and hastags as well
boolean hasComments = Integer.parseInt(toDelete.getCommentsNo()) > 0;
if(hasComments){
_log.debug("Deleting post comments and their hashtags");
List<Comment> comments = store.getAllCommentByFeed(postid);
List<Comment> comments = libClient.getAllCommentsByPostIdLib(postid);
for (Comment comment : comments) {
deleteComment(comment.getKey(), postid);
}
@ -996,11 +955,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
List<String> hashtags = Utils.getHashTags(Utils.removeHTMLFromText(toDelete.getDescription()));
if (hashtags != null && !hashtags.isEmpty()) {
_log.debug("The post has hashtags, attempting to delete them ... " + hashtags.toString());
boolean deletedHashtag = store.deleteHashTags(postid, toDelete.getVreid(), hashtags);
boolean deletedHashtag = libClient.deleteHashTagsLib(postid, toDelete.getVreid(), hashtags);
_log.debug("deletedHashtag? " + deletedHashtag);
}
_log.debug("Attempting to delete post " + postid);
return store.deleteFeed(postid);
return libClient.deletePostLib(postid);
} catch (Exception e) {
_log.debug("Failed to delete post " + postid);
@ -1060,7 +1019,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* @param username
* @return true if this feed is of the current user
*/
private boolean isUsers(Feed tocheck, String username) {
private boolean isUsers(Post tocheck, String username) {
return (tocheck.getEntityId().equals(username));
}
@ -1112,7 +1071,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
/**
* tell if the user is a portal administrator or not
* @param username
* @return true if is admin
* @throws SystemException
* @throws PortalException
@ -1185,7 +1143,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
@Override
public ArrayList<EnhancedFeed> getPostsRelatedToUserStatistics(
public ArrayList<EnhancedPost> getPostsRelatedToUserStatistics(
ShowUserStatisticAction action, int from, int quantity) {
PortalContext pContext = PortalContext.getConfiguration();
@ -1201,37 +1159,38 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
Calendar oneYearAgo = Calendar.getInstance();
oneYearAgo.set(Calendar.YEAR, oneYearAgo.get(Calendar.YEAR) - 1);
ArrayList<Feed> feeds = null;
ArrayList<Post> feeds = null;
switch(action){
case POSTS_MADE_BY_USER:
feeds = (ArrayList<Feed>) store.getRecentFeedsByUserAndDate(userid, oneYearAgo.getTimeInMillis());
feeds = (ArrayList<Post>) libClient.getRecentPostsByUserAndDateLib(userid, oneYearAgo.getTimeInMillis());
break;
case LIKES_MADE_BY_USER:
feeds = (ArrayList<Feed>) store.getRecentLikedFeedsByUserAndDate(userid, oneYearAgo.getTimeInMillis());
//need to implement it in client and ws
feeds = (ArrayList<Post>) libClient.getRecentLikedPostsByUserAndDateLib(userid, oneYearAgo.getTimeInMillis());
break;
case COMMENTS_MADE_BY_USER:
feeds = (ArrayList<Feed>) store.getRecentCommentedFeedsByUserAndDate(userid, oneYearAgo.getTimeInMillis());
feeds = (ArrayList<Post>) libClient.getRecentCommentedPostsByUserAndDateLib(userid, oneYearAgo.getTimeInMillis());
break;
case LIKES_GOT_BY_USER:
feeds = (ArrayList<Feed>) store.getRecentFeedsByUserAndDate(userid, oneYearAgo.getTimeInMillis());
Iterator<Feed> feedsIteratorLikes = feeds.iterator();
feeds = (ArrayList<Post>) libClient.getRecentPostsByUserAndDateLib(userid, oneYearAgo.getTimeInMillis());
Iterator<Post> feedsIteratorLikes = feeds.iterator();
while (feedsIteratorLikes.hasNext()) {
Feed feed = (Feed) feedsIteratorLikes.next();
Post feed = (Post) feedsIteratorLikes.next();
if(Integer.parseInt(feed.getLikesNo()) == 0)
feedsIteratorLikes.remove();
}
break;
case COMMENTS_GOT_BY_USER:
feeds = (ArrayList<Feed>) store.getRecentFeedsByUserAndDate(userid, oneYearAgo.getTimeInMillis());
Iterator<Feed> feedsIteratorComments = feeds.iterator();
feeds = (ArrayList<Post>) libClient.getRecentPostsByUserAndDateLib(userid, oneYearAgo.getTimeInMillis());
Iterator<Post> feedsIteratorComments = feeds.iterator();
while (feedsIteratorComments.hasNext()) {
Feed feed = (Feed) feedsIteratorComments.next();
Post feed = (Post) feedsIteratorComments.next();
if(Integer.parseInt(feed.getCommentsNo()) == 0)
feedsIteratorComments.remove();
}
break;
default : return new ArrayList<EnhancedFeed>();
default : return new ArrayList<EnhancedPost>();
}
@ -1258,9 +1217,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
// filter
Iterator<Feed> iteratorScope = feeds.iterator();
Iterator<Post> iteratorScope = feeds.iterator();
while (iteratorScope.hasNext()) {
Feed feed = (Feed) iteratorScope.next();
Post feed = (Post) iteratorScope.next();
if(!contexts.contains(feed.getVreid()))
iteratorScope.remove();
}
@ -1268,8 +1227,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
// sort the list, retrieve elements in the range and enhance the feeds
Collections.sort(feeds, Collections.reverseOrder());
int upperIndex = (from + quantity) >= feeds.size() ? feeds.size() : from + quantity;
feeds = new ArrayList<Feed>(feeds.subList(from, upperIndex));
return enhanceFeeds(feeds, -1);
feeds = new ArrayList<Post>(feeds.subList(from, upperIndex));
return enhancePosts(feeds, -1);
}catch(Exception e){
_log.error("Error while retrieving feeds for user " + userid + " and action " + action.toString(), e);

View File

@ -3,19 +3,19 @@ package org.gcube.portlets.user.newsfeed.shared;
import java.io.Serializable;
import java.util.ArrayList;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.social_networking.socialnetworking.model.shared.EnhancedPost;
@SuppressWarnings("serial")
public class MorePostsBean implements Serializable {
private int lastReturnedPostTimelineIndex;
private ArrayList<EnhancedFeed> posts;
private ArrayList<EnhancedPost> posts;
public MorePostsBean() {
super();
}
public MorePostsBean(int lastReturnedFeedTimelineIndex,
ArrayList<EnhancedFeed> feeds) {
ArrayList<EnhancedPost> feeds) {
super();
this.lastReturnedPostTimelineIndex = lastReturnedFeedTimelineIndex;
this.posts = feeds;
@ -27,10 +27,10 @@ public class MorePostsBean implements Serializable {
public void setLastReturnedFeedTimelineIndex(int lastReturnedFeedTimelineIndex) {
this.lastReturnedPostTimelineIndex = lastReturnedFeedTimelineIndex;
}
public ArrayList<EnhancedFeed> getPosts() {
public ArrayList<EnhancedPost> getPosts() {
return posts;
}
public void setPosts(ArrayList<EnhancedFeed> posts) {
public void setPosts(ArrayList<EnhancedPost> posts) {
this.posts = posts;
}

View File

@ -1,6 +1,6 @@
package org.gcube.portlets.user.newsfeed.shared;
import org.gcube.portal.databook.shared.Comment;
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
import com.google.gwt.user.client.rpc.IsSerializable;

View File

@ -1,6 +1,6 @@
package org.gcube.portlets.user.newsfeed.shared;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.social_networking.socialnetworking.model.shared.UserInfo;
import com.google.gwt.user.client.rpc.IsSerializable;