diff --git a/.classpath b/.classpath
index 29d03c3..7f855e4 100644
--- a/.classpath
+++ b/.classpath
@@ -1,6 +1,6 @@
-
+
@@ -31,5 +31,5 @@
-
+
diff --git a/pom.xml b/pom.xml
index 4cb96d3..ebd087f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
org.gcube.portlets.user
news-feed
war
- 1.9.0-SNAPSHOT
+ 1.9.1-SNAPSHOT
gCube News Feed Portlet
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java
index 2e9cfad..5a4f025 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsService.java
@@ -6,6 +6,7 @@ import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.Like;
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
+import org.gcube.portlets.user.newsfeed.shared.OperationResult;
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
@@ -37,9 +38,9 @@ public interface NewsService extends RemoteService {
boolean deleteFeed(String feedid);
- Comment comment(String feedid, String text, ArrayList mentionedUsers, String feedOwnerId, boolean isAppFeed);
+ OperationResult comment(String feedid, String text, ArrayList mentionedUsers, String feedOwnerId, boolean isAppFeed);
- Comment editComment(Comment toEdit);
+ OperationResult editComment(Comment toEdit);
ArrayList getAllLikesByFeed(String feedid);
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java
index a9a96bd..1396c83 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsServiceAsync.java
@@ -6,6 +6,7 @@ import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.Like;
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
+import org.gcube.portlets.user.newsfeed.shared.OperationResult;
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
@@ -34,7 +35,7 @@ public interface NewsServiceAsync {
void comment(String feedid, String text, ArrayList mentionedUsers,
String feedOwnerId, boolean isAppFeed,
- AsyncCallback callback);
+ AsyncCallback callback);
void getAllCommentsByFeed(String feedid,
AsyncCallback> callback);
@@ -44,7 +45,7 @@ public interface NewsServiceAsync {
void deleteFeed(String feedid, AsyncCallback callback);
- void editComment(Comment toEdit, AsyncCallback callback);
+ void editComment(Comment toEdit, AsyncCallback callback);
void getOnlyLikedFeeds(AsyncCallback> callback);
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
index b490aa9..93acc3d 100644
--- a/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/panels/NewsFeedPanel.java
@@ -44,9 +44,11 @@ import org.gcube.portlets.user.newsfeed.client.ui.ResultsFor;
import org.gcube.portlets.user.newsfeed.client.ui.ShowMoreFeeds;
import org.gcube.portlets.user.newsfeed.client.ui.SingleComment;
import org.gcube.portlets.user.newsfeed.client.ui.TweetTemplate;
+import org.gcube.portlets.user.newsfeed.server.NewsServiceImpl;
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
import org.gcube.portlets.user.newsfeed.shared.NewsConstants;
+import org.gcube.portlets.user.newsfeed.shared.OperationResult;
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import org.gcube.portlets.widgets.userselection.client.UserSelectionDialog;
@@ -264,7 +266,7 @@ public class NewsFeedPanel extends Composite {
delayMillis = result.getRefreshingTimeInMillis();
vreLabel = result.getVreLabel();
currentScope = result.getCurrentScope();
- if (result.getUserInfo().getUsername().equals("test.user")) {
+ if (result.getUserInfo().getUsername().equals(NewsServiceImpl.TEST_USER)) {
doStopFeedsTimer();
doShowSessionExpired();
}
@@ -407,7 +409,7 @@ public class NewsFeedPanel extends Composite {
}
@Override
public void onSuccess(UserSettings result) {
- if (result.getUserInfo().getUsername().equals("test.user")) {
+ if (result.getUserInfo().getUsername().equals(NewsServiceImpl.TEST_USER)) {
doStopFeedsTimer();
doShowSessionExpired();
}
@@ -474,7 +476,7 @@ public class NewsFeedPanel extends Composite {
}
@Override
public void onSuccess(UserSettings result) {
- if (result.getUserInfo().getUsername().equals("test.user")) {
+ if (result.getUserInfo().getUsername().equals(NewsServiceImpl.TEST_USER)) {
doStopFeedsTimer();
doShowSessionExpired();
} else {
@@ -918,19 +920,25 @@ public class NewsFeedPanel extends Composite {
}
private void doAddComment(final TweetTemplate owner, String text, ArrayList mentionedUsers) {
- newsService.comment(owner.getFeedKey(), text, mentionedUsers, owner.getMyFeedUserId(), owner.isAppFeed(), new AsyncCallback() {
+ newsService.comment(owner.getFeedKey(), text, mentionedUsers, owner.getMyFeedUserId(), owner.isAppFeed(), new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Could not deliver this comment: " + caught.getMessage());
}
@Override
- public void onSuccess(Comment result) {
+ public void onSuccess(OperationResult result) {
if (result != null) {
- owner.addComment(new SingleComment(result, owner, (result.getUserid().equals(myUserInfo.getUsername()))), false);
- owner.setCommentingDisabled(false);
- owner.updateCommentsNumberCount();
- owner.showAddCommentForm(false);
- }
+ if (!result.isSuccess()) {
+ CheckSession.showLogoutDialog();
+ }
+ else {
+ Comment comment = (Comment) result.getObject();
+ owner.addComment(new SingleComment(comment, owner, (comment.getUserid().equals(myUserInfo.getUsername()))), false);
+ owner.setCommentingDisabled(false);
+ owner.updateCommentsNumberCount();
+ owner.showAddCommentForm(false);
+ }
+ }
else {
Window.alert("Could not deliver this comment. Please try again in a short while.");
}
@@ -939,17 +947,23 @@ public class NewsFeedPanel extends Composite {
}
private void doEditComment(final TweetTemplate owner, Comment edited) {
- newsService.editComment(edited, new AsyncCallback() {
+ newsService.editComment(edited, new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Could not edit this comment: " + caught.getMessage());
}
@Override
- public void onSuccess(Comment result) {
+ public void onSuccess(OperationResult result) {
if (result != null) {
- owner.addComment(new SingleComment(result, owner, (result.getUserid().equals(myUserInfo.getUsername()))), true);
- owner.setCommentingDisabled(false);
+ if (!result.isSuccess()) {
+ CheckSession.showLogoutDialog();
+ }
+ else {
+ Comment comment = (Comment) result.getObject();
+ owner.addComment(new SingleComment(comment, owner, (comment.getUserid().equals(myUserInfo.getUsername()))), true);
+ owner.setCommentingDisabled(false);
+ }
}
else {
Window.alert("Could not deliver this comment. Please try again in a short while.");
@@ -993,7 +1007,7 @@ public class NewsFeedPanel extends Composite {
}
@Override
- public void onSuccess(Boolean result) {
+ public void onSuccess(Boolean result) {
if (result) {
doShowComments(owner, false);
owner.updateCommentsNumberCount();
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 ed8beb7..3ba04c1 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
@@ -39,6 +39,7 @@ import org.gcube.portlets.user.newsfeed.client.NewsService;
import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
import org.gcube.portlets.user.newsfeed.shared.NewsConstants;
+import org.gcube.portlets.user.newsfeed.shared.OperationResult;
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
import org.gcube.vomanagement.usermanagement.GroupManager;
@@ -75,8 +76,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
private static final String SESSION_ADMIN_ATTR = "SESSION_ADMIN_ATTR";
private static final String USER_SETTINGS_ATTR = "USER_SETTINGS_ATTR";
- private static final String TEST_USER = "test.user";
- private static final String TEST_SCOPE = "/gcube/devsec/devVRE";
+ public static final String TEST_USER = "test.user";
+ public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
/**
@@ -597,11 +598,14 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* @param feedOwnerId the username of the user who created the post that was commented
*/
@Override
- public Comment comment(String feedid, String commentText, ArrayList mentionedUserFullNames, String feedOwnerId, boolean isAppFeed) {
+ public OperationResult comment(String feedid, String commentText, ArrayList mentionedUserFullNames, String feedOwnerId, boolean isAppFeed) {
boolean commentCommitResult = false;
_log.trace("Trying to add this comment " + commentText);
UserInfo user = getUserSettings().getUserInfo();
-
+
+ if (user.getUsername().compareTo(TEST_USER) == 0) {
+ return new OperationResult(false, "Session Expired", null);
+ }
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(commentText);
@@ -617,9 +621,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
if (store.addComment(comment))
commentCommitResult = true;
} catch (FeedIDNotFoundException e) {
- _log.error("Feed not Found for this comment " + e.getMessage());
+ _log.error("Related post not found for this comment " + e.getMessage());
e.printStackTrace();
- return null;
+ return new OperationResult(false, "Related post not found for this comment", comment);
}
//if the comment was correctly delivered && is not an app feed notify users involved
if (commentCommitResult && isWithinPortal()) {
@@ -645,12 +649,16 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
thread.start();
}
}
- return comment;
+ return new OperationResult(true, "OK", comment);
}
@Override
- public Comment editComment(Comment toEdit) {
+ public OperationResult editComment(Comment toEdit) {
UserInfo user = getUserSettings().getUserInfo();
+ if (user.getUsername().compareTo(TEST_USER) == 0) {
+ return new OperationResult(false, "Session Expired", null);
+ }
+
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
Comment edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
@@ -659,9 +667,9 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
store.editComment(edited);
} catch (Exception e) {
e.printStackTrace();
- return null;
+ return new OperationResult(false, "Exception on the server: " + e.getMessage(), null);
}
- return edited;
+ return new OperationResult(true, "OK", toEdit);
}
/**
diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/shared/OperationResult.java b/src/main/java/org/gcube/portlets/user/newsfeed/shared/OperationResult.java
new file mode 100644
index 0000000..a3553d9
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/newsfeed/shared/OperationResult.java
@@ -0,0 +1,48 @@
+package org.gcube.portlets.user.newsfeed.shared;
+
+import java.io.Serializable;
+
+@SuppressWarnings("serial")
+public class OperationResult implements Serializable {
+
+ private Boolean success;
+ private String message;
+ private Serializable object;
+
+ public OperationResult() {
+ super();
+ }
+
+ public OperationResult(Boolean success, String message, Serializable object) {
+ super();
+ this.success = success;
+ this.message = message;
+ this.object = object;
+ }
+
+ public Boolean isSuccess() {
+ return success;
+ }
+
+ public void setSuccess(Boolean success) {
+ this.success = success;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Serializable getObject() {
+ return object;
+ }
+
+ public void setObject(Serializable object) {
+ this.object = object;
+ }
+
+
+}