diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index 16cc1af..05ae877 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -8,6 +8,9 @@
uses
+
+ uses
+
diff --git a/distro/changelog.xml b/distro/changelog.xml
index 0d99b39..2810899 100644
--- a/distro/changelog.xml
+++ b/distro/changelog.xml
@@ -2,7 +2,8 @@
restyled checkbox for notifications
- Removed depcreated TIBCO Pagebus library and replaces with Liferay's IPC Client Side
+ Removed deprecated TIBCO Pagebus library and replaces with Liferay's IPC Client Side
+ Enhanced efficiency when retrieving mentioned users or groups in posts
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java
index d76ccc6..06be730 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateService.java
@@ -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 mentionedUsers, boolean notifyGroup);
+ ClientFeed sharePostWithLinkPreview
+ (String feedText, FeedType type, PrivacyLevel pLevel, Long vreOrgId, LinkPreview preview,
+ String urlThumbnail, ArrayList mentionedUsers, boolean notifyGroup);
- ClientFeed sharePostWithAttachments(String feedText, FeedType type, PrivacyLevel pLevel, Long vreOrgId,ArrayList uploadedFiles, ArrayList mentionedUsers, boolean notifyGroup, boolean saveCopyWokspace);
+ ClientFeed sharePostWithAttachments
+ (String feedText, FeedType type, PrivacyLevel pLevel, Long vreOrgId,ArrayList uploadedFiles,
+ ArrayList mentionedUsers, boolean notifyGroup, boolean saveCopyWokspace);
UserSettings getUserSettings();
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java
index e9f9191..f753c60 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdateServiceAsync.java
@@ -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 mentionedUsers, boolean notifyGroup,
+ String urlThumbnail, ArrayList mentionedUsers, boolean notifyGroup,
AsyncCallback callback);
void sharePostWithAttachments(String feedText, FeedType type,
PrivacyLevel pLevel, Long vreOrgId,
ArrayList uploadedFiles,
- ArrayList mentionedUsers, boolean notifyGroup,
+ ArrayList mentionedUsers, boolean notifyGroup,
boolean saveCopyWokspace, AsyncCallback callback);
}
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java
index 8685891..3e77b73 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java
@@ -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 mentionedUsers, PostContent postContent) {
-
+ private void postTweet(String textToPost, ArrayList 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);
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java
index 5383b22..489dc43 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/SuperPosedTextArea.java
@@ -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 mentionedUsers = new HashSet();
+ private HashSet mentionedUsers = new HashSet();
private ArrayList hashtags = new ArrayList();
/**
@@ -162,8 +166,9 @@ public class SuperPosedTextArea extends TextArea {
text = textAreaText.replaceAll("(\r\n|\n)","
");
text = text.replaceAll("\\s\\s"," ");
- for (String mentionedUser : mentionedUsers) {
- text = text.replaceAll(mentionedUser,""+mentionedUser+"");
+ for (MentionedDTO mentionedUser : mentionedUsers) {
+ text = text.replaceAll(mentionedUser.value,
+ ""+mentionedUser.value+"");
}
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 getMentionedUsers() {
- ArrayList toReturn = new ArrayList();
- for (String mentionedUser : mentionedUsers) {
- if (getText().contains(mentionedUser))
- toReturn.add(mentionedUser);
+ public ArrayList getMentionedUsers() {
+ NodeList elems = DOM.getElementById("highlighter").getElementsByTagName("span");
+ ArrayList toReturn = new ArrayList();
+ 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;
}
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java
index b944d25..4bc361f 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java
@@ -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 mentionedUserFullNames, boolean notifyGroup) {
+ Long vreOrgId, LinkPreview preview, String urlThumbnail, ArrayList 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 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 uploadedFiles,
- ArrayList mentionedUserFullNames, boolean notifyGroup, boolean saveCopyWokspace) {
+ ArrayList 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 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 toReturn = new HashMap();
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 getMentionsBean(ArrayList mentions) {
+ ArrayList toReturn = new ArrayList();
+ 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 getSelectedUserIds(ArrayList fullNames) {
if (fullNames == null)
return new ArrayList();
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/shared/MentionedDTO.java b/src/main/java/org/gcube/portlets/user/shareupdates/shared/MentionedDTO.java
new file mode 100644
index 0000000..f26adc3
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/shared/MentionedDTO.java
@@ -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 + "]";
+ }
+
+}