Enhanced efficiency when retrieving mentioned users or groups in posts

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@165229 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2018-03-18 16:49:46 +00:00
parent 576d1b197e
commit 1d3bdaba47
8 changed files with 129 additions and 31 deletions

View File

@ -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="share-updates"/>
</wb-module>

View File

@ -2,7 +2,8 @@
<Changeset component="org.gcube.portlets-user.shareupdates.2-6-0"
date="2018-02-07">
<Change>restyled checkbox for notifications</Change>
<Change>Removed depcreated TIBCO Pagebus library and replaces with Liferay's IPC Client Side</Change>
<Change>Removed deprecated TIBCO Pagebus library and replaces with Liferay's IPC Client Side</Change>
<Change>Enhanced efficiency when retrieving mentioned users or groups in posts</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.shareupdates.2-5-0"
date="2017-12-07">

View File

@ -6,6 +6,7 @@ import org.gcube.portal.databook.shared.ClientFeed;
import org.gcube.portal.databook.shared.FeedType;
import org.gcube.portal.databook.shared.PrivacyLevel;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
import org.gcube.portlets.user.shareupdates.shared.MentionedDTO;
import org.gcube.portlets.user.shareupdates.shared.UploadedFile;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
@ -19,9 +20,13 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("shareupdateServlet")
public interface ShareUpdateService extends RemoteService {
ClientFeed sharePostWithLinkPreview(String feedText, FeedType type, PrivacyLevel pLevel, Long vreOrgId, LinkPreview preview, String urlThumbnail, ArrayList<String> mentionedUsers, boolean notifyGroup);
ClientFeed sharePostWithLinkPreview
(String feedText, FeedType type, PrivacyLevel pLevel, Long vreOrgId, LinkPreview preview,
String urlThumbnail, ArrayList<MentionedDTO> mentionedUsers, boolean notifyGroup);
ClientFeed sharePostWithAttachments(String feedText, FeedType type, PrivacyLevel pLevel, Long vreOrgId,ArrayList<UploadedFile> uploadedFiles, ArrayList<String> mentionedUsers, boolean notifyGroup, boolean saveCopyWokspace);
ClientFeed sharePostWithAttachments
(String feedText, FeedType type, PrivacyLevel pLevel, Long vreOrgId,ArrayList<UploadedFile> uploadedFiles,
ArrayList<MentionedDTO> mentionedUsers, boolean notifyGroup, boolean saveCopyWokspace);
UserSettings getUserSettings();

View File

@ -6,6 +6,7 @@ import org.gcube.portal.databook.shared.ClientFeed;
import org.gcube.portal.databook.shared.FeedType;
import org.gcube.portal.databook.shared.PrivacyLevel;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
import org.gcube.portlets.user.shareupdates.shared.MentionedDTO;
import org.gcube.portlets.user.shareupdates.shared.UploadedFile;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
@ -30,13 +31,13 @@ public interface ShareUpdateServiceAsync {
void sharePostWithLinkPreview(String feedText, FeedType type,
PrivacyLevel pLevel, Long vreOrgId, LinkPreview preview,
String urlThumbnail, ArrayList<String> mentionedUsers, boolean notifyGroup,
String urlThumbnail, ArrayList<MentionedDTO> mentionedUsers, boolean notifyGroup,
AsyncCallback<ClientFeed> callback);
void sharePostWithAttachments(String feedText, FeedType type,
PrivacyLevel pLevel, Long vreOrgId,
ArrayList<UploadedFile> uploadedFiles,
ArrayList<String> mentionedUsers, boolean notifyGroup,
ArrayList<MentionedDTO> mentionedUsers, boolean notifyGroup,
boolean saveCopyWokspace, AsyncCallback<ClientFeed> callback);
}

View File

@ -12,6 +12,7 @@ import org.gcube.portlets.user.shareupdates.client.ShareUpdateService;
import org.gcube.portlets.user.shareupdates.client.ShareUpdateServiceAsync;
import org.gcube.portlets.user.shareupdates.client.ShareUpdates;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
import org.gcube.portlets.user.shareupdates.shared.MentionedDTO;
import org.gcube.portlets.user.shareupdates.shared.UploadedFile;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import org.gcube.portlets.widgets.fileupload.client.events.FileTooLargeEvent;
@ -481,15 +482,14 @@ public class ShareUpdateForm extends Composite {
* @param mentionedUsers list of users mentioned in the text (if any)
* @param postContent the type of post
*/
private void postTweet(String textToPost, ArrayList<String> mentionedUsers, PostContent postContent) {
private void postTweet(String textToPost, ArrayList<MentionedDTO> mentionedUsers, PostContent postContent) {
// escape html text
String toShareText = escapeHtml(textToPost);
if (! checkTextLength(toShareText)) {
Window.alert("We found a single word containing more than 50 chars and it's not a link, is it meaningful?");
return;
}
// disable text edit and submission button
enableSubmitButtons(false);
shareTextArea.setEnabled(false);

View File

@ -8,6 +8,7 @@ import java.util.HashSet;
import org.gcube.portlets.user.shareupdates.client.ShareUpdateService;
import org.gcube.portlets.user.shareupdates.client.ShareUpdateServiceAsync;
import org.gcube.portlets.user.shareupdates.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;
@ -15,6 +16,8 @@ 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.Node;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
@ -25,6 +28,7 @@ import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.TextArea;
/**
* @author massi
*
@ -39,7 +43,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 ArrayList<String> hashtags = new ArrayList<String>();
/**
@ -162,8 +166,9 @@ public class SuperPosedTextArea extends TextArea {
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>");
}
for (String hashtag : hashtags) {
@ -195,7 +200,10 @@ public class SuperPosedTextArea extends TextArea {
}
if (triggerChar == '@') {
GWT.log("GOT @ EVENT! "+ 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);
@ -208,13 +216,21 @@ public class SuperPosedTextArea extends TextArea {
});
}
public ArrayList<String> getMentionedUsers() {
ArrayList<String> toReturn = new ArrayList<String>();
for (String mentionedUser : mentionedUsers) {
if (getText().contains(mentionedUser))
toReturn.add(mentionedUser);
public ArrayList<MentionedDTO> getMentionedUsers() {
NodeList<Element> elems = DOM.getElementById("highlighter").getElementsByTagName("span");
ArrayList<MentionedDTO> toReturn = new ArrayList<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 toReturn;
}

View File

@ -51,6 +51,7 @@ import org.gcube.portlets.user.shareupdates.client.view.ShareUpdateForm;
import org.gcube.portlets.user.shareupdates.server.opengraph.OpenGraph;
import org.gcube.portlets.user.shareupdates.shared.HashTagAndOccurrence;
import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
import org.gcube.portlets.user.shareupdates.shared.MentionedDTO;
import org.gcube.portlets.user.shareupdates.shared.UploadedFile;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
@ -67,6 +68,7 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeTeam;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -122,7 +124,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
*/
@Override
public ClientFeed sharePostWithLinkPreview(String postText, FeedType feedType, PrivacyLevel pLevel,
Long vreOrgId, LinkPreview preview, String urlThumbnail, ArrayList<String> mentionedUserFullNames, boolean notifyGroup) {
Long vreOrgId, LinkPreview preview, String urlThumbnail, ArrayList<MentionedDTO> mentionedItems, boolean notifyGroup) {
// escape text
String escapedFeedText = Utils.escapeHtmlAndTransformUrl(postText);
@ -134,8 +136,8 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
// retrieve mentioned users
ArrayList<ItemBean> mentionedUsers = null;
if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
mentionedUsers = getSelectedUserIds(mentionedUserFullNames);
if (mentionedItems != null && ! mentionedItems.isEmpty()) {
mentionedUsers = getMentionsBean(mentionedItems);
escapedFeedText = Utils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers, getThreadLocalRequest());
}
@ -158,7 +160,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
urlThumbnail = FilePreviewer.saveThumbnailOnFTPAndGetUrl(urlThumbnail, context.getCurrentScope(getThreadLocalRequest()));
Date feedDate = new Date();
//get the VRE scope if single channel post
String vreScope2Set = "";
if (pLevel == PrivacyLevel.SINGLE_VRE && vreOrgId != null) {
@ -232,7 +234,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
@Override
public ClientFeed sharePostWithAttachments(String feedText, FeedType feedType,
PrivacyLevel pLevel, Long vreOrgId, ArrayList<UploadedFile> uploadedFiles,
ArrayList<String> mentionedUserFullNames, boolean notifyGroup, boolean saveCopyWokspace) {
ArrayList<MentionedDTO> mentionedItems, boolean notifyGroup, boolean saveCopyWokspace) {
// escape text
String escapedFeedText = Utils.escapeHtmlAndTransformUrl(feedText);
@ -244,8 +246,8 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
// get the list of mentioned users
ArrayList<ItemBean> mentionedUsers = null;
if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
mentionedUsers = getSelectedUserIds(mentionedUserFullNames);
if (mentionedItems != null && ! mentionedItems.isEmpty()) {
mentionedUsers = getMentionsBean(mentionedItems);
escapedFeedText = Utils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers, getThreadLocalRequest());
}
@ -788,13 +790,13 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
HashMap<String, String> toReturn = new HashMap<String, String>();
PortalContext context = PortalContext.getConfiguration();
String groupName = context.getCurrentGroupName(getThreadLocalRequest());
//for dev
if (!isWithinPortal()) {
toReturn.put(""+context.getCurrentGroupId(getThreadLocalRequest()), groupName);
return toReturn;
}
for (GCubeGroup vre : getUserVREs(username)) {
if (vre.getGroupName().compareTo(groupName)==0)
toReturn.put(vre.getGroupId()+"", vre.getGroupName());
@ -844,10 +846,32 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
return scope.is(Type.INFRASTRUCTURE);
}
/**
*
* @return the screennames of the addressee (user logins e.g. pino.pini)
*/
public 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;
}
public ArrayList<ItemBean> getSelectedUserIds(ArrayList<String> fullNames) {
if (fullNames == null)
return new ArrayList<ItemBean>();

View File

@ -0,0 +1,48 @@
package org.gcube.portlets.user.shareupdates.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 + "]";
}
}