Enhanced efficiency when retrieving mentioned users or groups in comments

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@165232 82a268e6-3cf1-43bd-a215-b396298e98cf
Feature/26194
Massimiliano Assante 6 years ago
parent 5637c271dc
commit 0f74f5dada

@ -8,6 +8,9 @@
<dependent-module archiveName="gcube-widgets-2.2.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/gcube-widgets/gcube-widgets">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="pickitem-widget-1.3.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/pickitem-widget/pickitem-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="news-feed"/>
</wb-module>

@ -11,6 +11,7 @@
<Change>Feature #10192 allow to sort feeds per recent comments</Change>
<Change>Bug #7841 lack of blank space to separate the query term when hashtag is used</Change>
<Change>Support for ticket #11139</Change>
<Change>Enhanced efficiency when retrieving mentioned users or groups in comments</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.news-feed.2-5-0"
date="2017-11-13">

@ -7,6 +7,7 @@ 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.portlets.user.newsfeed.shared.MentionedDTO;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
import org.gcube.portlets.user.newsfeed.shared.OperationResult;
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
@ -45,7 +46,7 @@ public interface NewsService extends RemoteService {
boolean deleteFeed(String feedid);
OperationResult comment(String feedid, String text,
HashSet<String> mentionedUsers, String feedOwnerId,
HashSet<MentionedDTO> mentionedUsers, String feedOwnerId,
boolean isAppFeed);
OperationResult editComment(Comment toEdit);

@ -7,6 +7,7 @@ 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.portlets.user.newsfeed.shared.MentionedDTO;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
import org.gcube.portlets.user.newsfeed.shared.OperationResult;
import org.gcube.portlets.user.newsfeed.shared.UserSettings;
@ -35,7 +36,7 @@ public interface NewsServiceAsync {
void getUserSettings(AsyncCallback<UserSettings> callback);
void comment(String feedid, String text, HashSet<String> mentionedUsers,
void comment(String feedid, String text, HashSet<MentionedDTO> mentionedUsers,
String feedOwnerId, boolean isAppFeed,
AsyncCallback<OperationResult> callback);

@ -3,6 +3,7 @@ package org.gcube.portlets.user.newsfeed.client.event;
import java.util.HashSet;
import org.gcube.portlets.user.newsfeed.client.ui.TweetTemplate;
import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
import com.google.gwt.event.shared.GwtEvent;
@ -13,9 +14,9 @@ public class AddCommentEvent extends GwtEvent<AddCommentEventHandler> {
private TweetTemplate owner;
private String text;
private HashSet<String> mentionedUsers;
private HashSet<MentionedDTO> mentionedUsers;
public AddCommentEvent(TweetTemplate owner, String text, HashSet<String> mentionedUsers) {
public AddCommentEvent(TweetTemplate owner, String text,HashSet<MentionedDTO> mentionedUsers) {
this.owner = owner;
this.text = text;
this.mentionedUsers = mentionedUsers;
@ -29,7 +30,7 @@ public class AddCommentEvent extends GwtEvent<AddCommentEventHandler> {
return text;
}
public HashSet<String> getMentionedUsers() {
public HashSet<MentionedDTO> getMentionedUsers() {
return mentionedUsers;
}

@ -52,6 +52,7 @@ 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.shared.MentionedDTO;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
import org.gcube.portlets.user.newsfeed.shared.NewsConstants;
import org.gcube.portlets.user.newsfeed.shared.OperationResult;
@ -1384,7 +1385,7 @@ public class NewsFeedPanel extends Composite {
});
}
private void doAddComment(final TweetTemplate owner, String text, HashSet<String> mentionedUsers) {
private void doAddComment(final TweetTemplate owner, String text, HashSet<MentionedDTO> mentionedUsers) {
owner.showCommentingPreloader(true);
newsService.comment(owner.getFeedKey(), text, mentionedUsers, owner.getMyFeedUserId(), owner.isAppFeed(), new AsyncCallback<OperationResult>() {
@Override

@ -9,6 +9,7 @@ import java.util.HashSet;
import org.gcube.portlets.user.gcubewidgets.client.elements.Div;
import org.gcube.portlets.user.newsfeed.client.NewsService;
import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
import org.gcube.portlets.widgets.pickitem.client.dialog.PickItemsDialog;
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEvent;
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEventHandler;
@ -16,6 +17,7 @@ import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyCodes;
@ -44,7 +46,7 @@ public class SuperPosedTextArea extends TextArea {
public final static int ARROW_UP = 38;
public final static int ARROW_DOWN = 40;
private HashSet<String> mentionedUsers = new HashSet<String>();
private HashSet<MentionedDTO> mentionedUsers = new HashSet<MentionedDTO>();
private String areaId;
@ -172,12 +174,12 @@ public class SuperPosedTextArea extends TextArea {
// replace all the line braks by <br/>, and all the double spaces by the html version &nbsp;
text = textAreaText.replaceAll("(\r\n|\n)","<br />");
text = text.replaceAll("\\s\\s","&nbsp;&nbsp;");
for (String mentionedUser : mentionedUsers) {
text = text.replaceAll(mentionedUser,"<span class=\"highlightedUser\">"+mentionedUser+"</span>");
}
for (MentionedDTO mentionedUser : mentionedUsers) {
text = text.replaceAll(mentionedUser.value,
"<span id=\""+ mentionedUser.id +"\" title=\""+ mentionedUser.type +"\" class=\"highlightedUser\">"+mentionedUser.value+"</span>");
}
// re-inject the processed text into the div
//DOM.getElementById("comment-highlighter").setInnerHTML(text);
highlighterDIV.getElement().setInnerHTML(text);
}
@ -190,8 +192,12 @@ public class SuperPosedTextArea extends TextArea {
public void onSelectedItem(PickedItemEvent event) {
String toAdd = event.getSelectedItem().getAlternativeName();
mentionedUsers.add(toAdd);
ItemBean ib = event.getSelectedItem();
String type = ib.isItemGroup() ? "team" : "user";
MentionedDTO mToAdd = new MentionedDTO(ib.getId(), ib.getAlternativeName(), type);
mentionedUsers.add(mToAdd);
String preceedingPart = getText().substring(0, event.getItemCursorIndexStart());
String afterPart = getText().substring(event.getItemCursorIndexEnd()+1);
@ -201,14 +207,22 @@ public class SuperPosedTextArea extends TextArea {
});
}
public HashSet<String> getMentionedUsers() {
HashSet<String> toReturn = new HashSet<String>();
for (String mentionedUser : mentionedUsers) {
if (getText().contains(mentionedUser))
toReturn.add(mentionedUser);
public HashSet<MentionedDTO> getMentionedUsers() {
NodeList<Element> elems = highlighterDIV.getElement().getElementsByTagName("span");
HashSet<MentionedDTO> toReturn = new HashSet<MentionedDTO>();
if (elems != null && elems.getLength() > 0) {
int elemsNo = elems.getLength();
for (int i = 0; i < elemsNo; i++) {
Element el = elems.getItem(i);
String id = el.getId();
String type = el.getTitle();
String value = el.getInnerText();
MentionedDTO toAdd = new MentionedDTO(id, value, type);
toReturn.add(toAdd);
GWT.log(toAdd.toString());
}
}
GWT.log(toReturn.toString());
return mentionedUsers;
return toReturn;
}
/**
* return the unique identifier of this textarea, useful for getElementById JS method

@ -46,6 +46,7 @@ import org.gcube.portal.notifications.thread.CommentNotificationsThread;
import org.gcube.portal.notifications.thread.LikeNotificationsThread;
import org.gcube.portal.notifications.thread.MentionNotificationsThread;
import org.gcube.portlets.user.newsfeed.client.NewsService;
import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
import org.gcube.portlets.user.newsfeed.shared.MoreFeedsBean;
import org.gcube.portlets.user.newsfeed.shared.NewsConstants;
import org.gcube.portlets.user.newsfeed.shared.OperationResult;
@ -55,6 +56,7 @@ import org.gcube.social_networking.socialutillibrary.Utils;
import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClient;
import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientImpl;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.RoleManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.TeamRetrievalFault;
@ -605,7 +607,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* @param feedOwnerId the username of the user who created the post that was commented
*/
@Override
public OperationResult comment(String feedid, String commentText, HashSet<String> mentionedUserFullNames, String feedOwnerId, boolean isAppFeed) {
public OperationResult comment(String feedid, String commentText, HashSet<MentionedDTO> mentionedItemsSet, String feedOwnerId, boolean isAppFeed) {
boolean commentCommitResult = false;
_log.trace("Trying to add this comment " + commentText);
UserInfo user = getUserSettings().getUserInfo();
@ -622,12 +624,12 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
escapedCommentText = Utils.convertHashtagsAnchorHTML(escapedCommentText, hashtags);
//copy the set into a list
ArrayList<String> mentionedUserFullNamesList = new ArrayList<String>();
mentionedUserFullNamesList.addAll(mentionedUserFullNames);
ArrayList<MentionedDTO> mentionedItems = new ArrayList<MentionedDTO>();
mentionedItems.addAll(mentionedItemsSet);
ArrayList<ItemBean> mentionedUsers = null;
if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
mentionedUsers = getSelectedUserIds(mentionedUserFullNamesList);
if (mentionedItemsSet != null && ! mentionedItemsSet.isEmpty()) {
mentionedUsers = getMentionsBean(mentionedItems);
escapedCommentText = Utils.convertMentionPeopleAnchorHTML(escapedCommentText, mentionedUsers, getThreadLocalRequest());
}
@ -1029,29 +1031,33 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
/**
*
* @return the screennames of the addressee (user logins e.g. pino.pini)
* @param mentions
* @return
*/
public ArrayList<ItemBean> getSelectedUserIds(ArrayList<String> fullNames) {
if (fullNames == null)
return new ArrayList<ItemBean>();
else {
PortalContext pContext = PortalContext.getConfiguration();
String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
String context = pContext.getCurrentScope(getThreadLocalRequest());
ArrayList<ItemBean> allUsers = Utils.getDisplayableItemBeans(context, userName, isWithinPortal());
ArrayList<ItemBean> toReturn = new ArrayList<ItemBean>();
for (String fullName : fullNames)
for (ItemBean puser : allUsers) {
if (puser.getAlternativeName().compareTo(fullName) == 0) {
toReturn.add(puser);
break;
}
}
private ArrayList<ItemBean> getMentionsBean(ArrayList<MentionedDTO> mentions) {
ArrayList<ItemBean> toReturn = new ArrayList<ItemBean>();
if (mentions == null)
return toReturn;
UserManager um = new LiferayUserManager();
RoleManager rm = new LiferayRoleManager();
try {
for (MentionedDTO mentioned : mentions) {
if (mentioned.getType().equalsIgnoreCase("user")) {
long userId = Long.parseLong(mentioned.id);
GCubeUser user = um.getUserById(userId);
toReturn.add(new ItemBean(user.getUserId()+"", user.getUsername(), user.getFullname(), user.getUserAvatarURL()));
}
else { //is a team
long teamId = Long.parseLong(mentioned.id);
GCubeTeam gCubeTeam = rm.getTeam(teamId);
toReturn.add(new ItemBean(gCubeTeam.getTeamId()+"", gCubeTeam.getTeamName()));
}
}
} catch (Exception e) {
_log.error("getMentionsBean Error: ", e);
}
return toReturn;
}
/**
* tell if the user is a portal administrator or not
* @param username

@ -0,0 +1,48 @@
package org.gcube.portlets.user.newsfeed.shared;
import com.google.gwt.user.client.rpc.IsSerializable;
public class MentionedDTO implements IsSerializable{
public String id, value, type;
public MentionedDTO() {
super();
}
public MentionedDTO(String id, String value, String type) {
super();
this.id = id;
this.value = value;
this.type = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "MentionedDTO [id=" + id + ", value=" + value + ", type=" + type + "]";
}
}
Loading…
Cancel
Save