Massimiliano Assante 2015-05-18 14:30:22 +00:00
parent 16142838e4
commit 83fdc36da6
7 changed files with 104 additions and 32 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/news-feed-1.9.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/news-feed-1.9.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -31,5 +31,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/news-feed-1.9.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/news-feed-1.9.1-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>news-feed</artifactId>
<packaging>war</packaging>
<version>1.9.0-SNAPSHOT</version>
<version>1.9.1-SNAPSHOT</version>
<name>gCube News Feed Portlet</name>
<description>

View File

@ -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<String> mentionedUsers, String feedOwnerId, boolean isAppFeed);
OperationResult comment(String feedid, String text, ArrayList<String> mentionedUsers, String feedOwnerId, boolean isAppFeed);
Comment editComment(Comment toEdit);
OperationResult editComment(Comment toEdit);
ArrayList<Like> getAllLikesByFeed(String feedid);

View File

@ -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<String> mentionedUsers,
String feedOwnerId, boolean isAppFeed,
AsyncCallback<Comment> callback);
AsyncCallback<OperationResult> callback);
void getAllCommentsByFeed(String feedid,
AsyncCallback<ArrayList<Comment>> callback);
@ -44,7 +45,7 @@ public interface NewsServiceAsync {
void deleteFeed(String feedid, AsyncCallback<Boolean> callback);
void editComment(Comment toEdit, AsyncCallback<Comment> callback);
void editComment(Comment toEdit, AsyncCallback<OperationResult> callback);
void getOnlyLikedFeeds(AsyncCallback<ArrayList<EnhancedFeed>> callback);

View File

@ -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<String> mentionedUsers) {
newsService.comment(owner.getFeedKey(), text, mentionedUsers, owner.getMyFeedUserId(), owner.isAppFeed(), new AsyncCallback<Comment>() {
newsService.comment(owner.getFeedKey(), text, mentionedUsers, owner.getMyFeedUserId(), owner.isAppFeed(), new AsyncCallback<OperationResult>() {
@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<Comment>() {
newsService.editComment(edited, new AsyncCallback<OperationResult>() {
@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();

View File

@ -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<String> mentionedUserFullNames, String feedOwnerId, boolean isAppFeed) {
public OperationResult comment(String feedid, String commentText, ArrayList<String> 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);
}
/**

View File

@ -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;
}
}