From 2aa721710fb5e9764e691cc9e34935bcf380a43e Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Thu, 28 Jan 2016 10:07:42 +0000 Subject: [PATCH] Events sent to user-statistics have been disabled for now. git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@122580 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.wst.common.component | 3 -- .../user/newsfeed/client/NewsFeed.java | 28 +++++++++++-------- .../newsfeed/client/event/PageBusEvents.java | 21 ++++++++++++++ .../newsfeed/client/panels/NewsFeedPanel.java | 27 ++++++++++++------ .../newsfeed/client/ui/TweetTemplate.java | 26 ++++++++--------- 5 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/newsfeed/client/event/PageBusEvents.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 4990fd0..7d33a49 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,9 +4,6 @@ - - uses - diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java index 9402b76..eb1ab1a 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/NewsFeed.java @@ -8,9 +8,9 @@ import net.eliasbalasis.tibcopagebus4gwt.client.PageBusListener; import org.gcube.portal.databook.shared.ClientFeed; import org.gcube.portal.databook.shared.ClientFeed.ClientFeedJsonizer; import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper; +import org.gcube.portlets.user.newsfeed.client.event.PageBusEvents; import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel; import org.jsonmaker.gwt.client.Jsonizer; -import org.jsonmaker.gwt.client.base.Defaults; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; @@ -50,28 +50,34 @@ public class NewsFeed implements EntryPoint { ClientFeed notification = new ClientFeed(); //Subscribe to message and associate subsequent receptions with custom subscriber data try { - pageBusAdapter.PageBusSubscribe("org.gcube.portal.databook.shared", null, null, notification, (Jsonizer)GWT.create(ClientFeedJsonizer.class)); + pageBusAdapter.PageBusSubscribe(PageBusEvents.newPostCreated, null, null, notification, (Jsonizer)GWT.create(ClientFeedJsonizer.class)); } catch (PageBusAdapterException e1) { e1.printStackTrace(); } pageBusAdapter.addPageBusSubscriptionCallbackListener(new PageBusListener() { + @Override public void onPageBusSubscriptionCallback(PageBusEvent event) { - // translate JavaScript message contents and subscriber data to their Java equivalents - try { - ClientFeed feed = (ClientFeed)event.getMessage((Jsonizer)GWT.create(ClientFeedJsonizer.class)); - mainPanel.addJustAddedFeed(feed); - // alert the User statistics portlet to increment the number of user's posts - pageBusAdapter.PageBusPublish("org.gcube.portal.incrementPostCount", "", Defaults.STRING_JSONIZER); + if(event.getSubject().equals(this.getName())){ + // translate JavaScript message contents and subscriber data to their Java equivalents + try { + ClientFeed feed = (ClientFeed)event.getMessage((Jsonizer)GWT.create(ClientFeedJsonizer.class)); + mainPanel.addJustAddedFeed(feed); - } catch (PageBusAdapterException e) { - e.printStackTrace(); + // alert the User statistics portlet to increment the number of user's posts + // TODO + // pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER); + + } catch (PageBusAdapterException e) { + e.printStackTrace(); + } } } + @Override public String getName() { - return null; + return PageBusEvents.newPostCreated; } }); } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/event/PageBusEvents.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/event/PageBusEvents.java new file mode 100644 index 0000000..7a7f658 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/event/PageBusEvents.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.user.newsfeed.client.event; + +/** + * This class contains the events (in a package like format) to which this portlet listens at. + * NOTE: these events are the same in the User-Statistics portlet and the share-updates one. + * @author Costantino Perciante at ISTI-CNR + * (costantino.perciante@isti.cnr.it) + */ +public class PageBusEvents { + + // events in this portlet and user-statistics + public static final String postIncrement = "org.gcube.portal.incrementPostCount"; + public static final String postDecrement = "org.gcube.portal.decrementPostCount"; + public static final String likesIncrement = "org.gcube.portal.incrementLikesGot"; + public static final String likesDecrement = "org.gcube.portal.decrementLikesGot"; + public static final String commentsIncrement = "org.gcube.portal.incrementCommentsGot"; + public static final String commentsDecrement = "org.gcube.portal.decrementCommentsGot"; + + // events in this portlet and the share-updates one + public static final String newPostCreated = "org.gcube.portal.databook.shared"; +} 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 90d5705..0615808 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 @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashSet; -import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException; import org.gcube.portal.databook.client.GCubeSocialNetworking; import org.gcube.portal.databook.client.util.Encoder; @@ -17,7 +16,6 @@ import org.gcube.portal.databook.shared.Like; import org.gcube.portal.databook.shared.PrivacyLevel; import org.gcube.portal.databook.shared.UserInfo; import org.gcube.portlets.user.newsfeed.client.FilterType; -import org.gcube.portlets.user.newsfeed.client.NewsFeed; import org.gcube.portlets.user.newsfeed.client.NewsService; import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync; import org.gcube.portlets.user.newsfeed.client.event.AddCommentEvent; @@ -60,7 +58,6 @@ import org.gcube.portlets.widgets.userselection.client.events.SelectedUserEvent; import org.gcube.portlets.widgets.userselection.client.events.SelectedUserEventHandler; import org.gcube.portlets.widgets.userselection.client.events.UsersFetchedEvent; import org.gcube.portlets.widgets.userselection.shared.ItemSelectableBean; -import org.jsonmaker.gwt.client.base.Defaults; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.RunAsyncCallback; @@ -973,14 +970,15 @@ public class NewsFeedPanel extends Composite { owner.updateCommentsNumberCount(); owner.showAddCommentForm(false); - if(owner.isUser()){ + /*if(owner.isUser()){ + * TODO // alert the User statistics portlet to increment the number of comments got try { - NewsFeed.pageBusAdapter.PageBusPublish("org.gcube.portal.incrementCommentsGot", "", Defaults.STRING_JSONIZER); + NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER); } catch (PageBusAdapterException e) { GWT.log(e.toString()); } - } + }*/ } } else { @@ -1056,14 +1054,14 @@ public class NewsFeedPanel extends Composite { doShowComments(owner, false); owner.updateCommentsNumberCount(); - if(owner.isUser()){ + /*if(owner.isUser()){ TODO // alert the User statistics portlet to decrement the number of comments got try { - NewsFeed.pageBusAdapter.PageBusPublish("org.gcube.portal.decrementCommentsGot", "", Defaults.STRING_JSONIZER); + NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER); } catch (PageBusAdapterException ex) { GWT.log(ex.toString()); } - } + }*/ } else Window.alert("Comment could not be deleted, please try again in a short while."); } @@ -1084,6 +1082,17 @@ public class NewsFeedPanel extends Composite { public void onSuccess(Boolean result) { if (result) { toDelete.removeFromParent(); + + // alert the user-statistics portlet to reduce the number of likes and replies + // there were + /*if(toDelete.isUser()){ + int numComments = toDelete.get + try { + NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER); + } catch (PageBusAdapterException ex) { + GWT.log(ex.toString()); + } + }*/ } else Window.alert("Feed could not be deleted, please try again in a short while."); } diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java index 5f5151f..6e81c65 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java @@ -7,15 +7,12 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException; - 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.Feed; import org.gcube.portal.databook.shared.UserInfo; -import org.gcube.portlets.user.newsfeed.client.NewsFeed; import org.gcube.portlets.user.newsfeed.client.event.AddLikeEvent; import org.gcube.portlets.user.newsfeed.client.event.DeleteFeedEvent; import org.gcube.portlets.user.newsfeed.client.event.OpenFeedEvent; @@ -26,7 +23,6 @@ import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel; import org.gcube.portlets.user.newsfeed.shared.EnhancedFeed; import org.gcube.portlets.widgets.imagepreviewerwidget.client.EnhancedImage; import org.gcube.portlets.widgets.imagepreviewerwidget.client.ui.Carousel; -import org.jsonmaker.gwt.client.base.Defaults; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.RunAsyncCallback; @@ -410,17 +406,17 @@ public class TweetTemplate extends Composite { if (isUsers || myUserInfo.isAdmin()){ eventBus.fireEvent(new DeleteFeedEvent(this)); - if(isUsers){ - try { + /*if(isUsers){ + try { TODO // alert the User statistics portlet to decrement the number of user's posts - NewsFeed.pageBusAdapter.PageBusPublish("org.gcube.portal.decrementPostCount", "", Defaults.STRING_JSONIZER); + NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postDecrement, "", Defaults.STRING_JSONIZER); } catch (PageBusAdapterException e1) { GWT.log("Unable to send this notification " + e1.toString()); } - } + }*/ } else { GWT.log("not belong to user"); @@ -480,17 +476,17 @@ public class TweetTemplate extends Composite { eventBus.fireEvent(new AddLikeEvent(this, myFeed.getFeed().getKey())); setFavoritedUI(true); - // alert the User statistics portlet to increment the number of likes got - if(isUsers){ + // alert the User statistics portlet to increment the number of likes got TODO + /*if(isUsers){ try { NewsFeed.pageBusAdapter.PageBusPublish( - "org.gcube.portal.incrementLikesGot" + PageBusEvents.likesIncrement , "" , Defaults.STRING_JSONIZER); } catch (PageBusAdapterException ex) { GWT.log(e.toString()); } - } + }*/ } catch (NumberFormatException ex) { likeArea.setHTML("Error on the server"); @@ -512,16 +508,16 @@ public class TweetTemplate extends Composite { setFavoritedUI(false); // alert the User statistics portlet to decrement the number of likes got - if(isUsers){ + /*if(isUsers){ TODO try { NewsFeed.pageBusAdapter.PageBusPublish( - "org.gcube.portal.decrementLikesGot" + PageBusEvents.likesDecrement , "" , Defaults.STRING_JSONIZER); } catch (PageBusAdapterException ex) { GWT.log(e.toString()); } - } + }*/ } }