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 885c4fe..827b4ce 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
@@ -14,6 +14,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
+import javax.net.ssl.HttpsURLConnection;
+
import org.apache.commons.validator.routines.UrlValidator;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
@@ -33,6 +35,7 @@ import org.gcube.portal.custom.communitymanager.impl.OrganizationManagerImpl;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
+import org.gcube.portal.databook.shared.Attachment;
import org.gcube.portal.databook.shared.ClientFeed;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.FeedType;
@@ -47,6 +50,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.UploadedFile;
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
import org.gcube.vomanagement.usermanagement.GroupManager;
@@ -67,8 +71,6 @@ import com.liferay.portal.model.Role;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
-import com.sun.net.ssl.HttpsURLConnection;
-
/**
* The server side implementation of the RPC service.
*/
@@ -85,6 +87,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
public static final String UPLOAD_DIR = "/social-framework-uploads";
private static final String NEWS_FEED_PORTLET_CLASSNAME = "org.gcube.portlets.user.newsfeed.server.NewsServiceImpl";
private final static String ATTR_TO_CHECK = "Postnotificationviaemail";
+
/**
*
*/
@@ -121,7 +124,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
public String getDevelopmentUser() {
String user = TEST_USER;
-// user = "massimiliano.assante";
+ user = "costantino.perciante";
return user;
}
/**
@@ -140,29 +143,35 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
/**
- *
+ * Share post that could contain a link preview.
*/
- public ClientFeed share(String postText, FeedType feedType, PrivacyLevel pLevel,
- String vreId, LinkPreview preview, String urlThumbnail, ArrayList mentionedUserFullNames,String fileName, String filePathOnServer, boolean notifyGroup) {
+ @Override
+ public ClientFeed sharePostWithLinkPreview(String postText, FeedType feedType, PrivacyLevel pLevel,
+ String vreId, LinkPreview preview, String urlThumbnail, ArrayList mentionedUserFullNames, boolean notifyGroup) {
+
+ _log.debug("Writing a new post with text " + postText);
+ // escape text
String escapedFeedText = TextTransfromUtils.escapeHtmlAndTransformUrl(postText);
+ // get hashtags
List hashtags = TextTransfromUtils.getHashTags(postText);
if (hashtags != null && !hashtags.isEmpty())
escapedFeedText = TextTransfromUtils.convertHashtagsAnchorHTML(escapedFeedText, hashtags);
+ // retrieve mentioned users
ArrayList mentionedUsers = null;
if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
mentionedUsers = getSelectedUserIds(mentionedUserFullNames);
escapedFeedText = TextTransfromUtils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers);
}
-
+ // get session
ASLSession session = getASLSession();
String username = session.getUsername();
String email = username+"@isti.cnr.it";
String fullName = username+" FULL";
- String thumbnailURL = "images/Avatar_default.png";
+ String thumbnailAvatarURL = "images/Avatar_default.png";
boolean withinPortal = isWithinPortal();
@@ -171,12 +180,13 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
UserInfo user = getUserSettings().getUserInfo();
email = user.getEmailaddress();
fullName = user.getFullName();
- thumbnailURL = user.getAvatarId();
+ thumbnailAvatarURL = user.getAvatarId();
} catch (Exception e) {
e.printStackTrace();
}
}
+ // get data from the preview of the link
String linkTitle = preview.getTitle();
String linkDesc = preview.getDescription();
String host = preview.getHost();
@@ -185,10 +195,171 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
urlThumbnail = "null";
Date feedDate = new Date();
+
+ //get the VRE scope if single channel post
+ String vreScope2Set = "";
+ if (pLevel == PrivacyLevel.SINGLE_VRE && vreId != null && vreId.compareTo("") != 0) {
+ vreScope2Set = (withinPortal) ? getScopeByOrganizationId(vreId) : session.getScope();
+ }
+
+ // build the feed to share (and save on cassandra)
+ Feed toShare = new Feed(UUID.randomUUID().toString(), feedType, username, feedDate,
+ vreScope2Set, url, urlThumbnail, escapedFeedText, pLevel, fullName, email, thumbnailAvatarURL, linkTitle, linkDesc, host);
+
+ _log.info("Attempting to save Feed with text: " + escapedFeedText + " Level: " + pLevel + " Timeline="+vreScope2Set);
+
+ boolean result = store.saveUserFeed(toShare);
+
+ //need to put the feed into VRES Timeline too
+ if (pLevel == PrivacyLevel.VRES) {
+ _log.trace("PrivacyLevel was set to VRES attempting to write onto User's VRES Timelines");
+ for (GroupModel vre : getUserVREs(username)) {
+ String vreScope = getScopeByOrganizationId(vre.getGroupId());
+ _log.trace("Attempting to write onto " + vreScope);
+ try {
+ store.saveFeedToVRETimeline(toShare.getKey(), vreScope);
+ } catch (FeedIDNotFoundException e) {
+ _log.error("Error writing onto VRES Time Line" + vreScope);
+ } //save the feed
+ _log.trace("Success writing onto " + vreScope);
+ }
+
+ }
+ //share on a single VRE Timeline
+ //receives a VreId(groupId) get the scope from the groupId
+ else if (pLevel == PrivacyLevel.SINGLE_VRE && vreId != null && vreId.compareTo("") != 0) {
+ _log.trace("Attempting to write onto " + vreScope2Set);
+ try {
+ store.saveFeedToVRETimeline(toShare.getKey(), vreScope2Set);
+ if (hashtags != null && !hashtags.isEmpty())
+ store.saveHashTags(toShare.getKey(), vreScope2Set, hashtags);
+ } catch (FeedIDNotFoundException e) {
+ _log.error("Error writing onto VRES Time Line" + vreScope2Set);
+ } //save the feed
+ _log.trace("Success writing onto " + vreScope2Set);
+ }
+ if (!result) return null;
+
+ //everything went fine
+ ClientFeed cf = new ClientFeed(toShare.getKey(), toShare.getType().toString(), username, feedDate, toShare.getUri(),
+ TextTransfromUtils.replaceAmpersand(toShare.getDescription()), fullName, email, thumbnailAvatarURL, toShare.getLinkTitle(), toShare.getLinkDescription(),
+ toShare.getUriThumbnail(), toShare.getLinkHost());
+
+
+ //send the notification about this posts to everyone in the group if notifyGroup is true
+ if (pLevel == PrivacyLevel.SINGLE_VRE && vreId != null && vreId.compareTo("") != 0 && notifyGroup) {
+ NotificationsManager nm = new ApplicationNotificationsManager(session, NEWS_FEED_PORTLET_CLASSNAME);
+ Thread thread = new Thread(new PostNotificationsThread(toShare.getKey(), escapedFeedText, ""+session.getGroupId(), nm, hashtags));
+ thread.start();
+
+ }
+ //send the notification to the mentioned users
+ if (mentionedUsers != null && mentionedUsers.size() > 0) {
+ NotificationsManager nm = new ApplicationNotificationsManager(session);
+ ArrayList toPass = new ArrayList();
+ for (ItemBean u : mentionedUsers) {
+ toPass.add(new GenericItemBean(u.getId(), u.getName(), u.getAlternativeName(), u.getThumbnailURL()));
+ }
+ Thread thread = new Thread(new MentionNotificationsThread(toShare.getKey(), escapedFeedText, nm, toPass));
+ thread.start();
+ }
+
+ return cf;
+
+ }
+
+
+ /**
+ * Share a post with at least one attachment.
+ */
+ @Override
+ public ClientFeed sharePostWithAttachments(String feedText, FeedType feedType,
+ PrivacyLevel pLevel, String vreId, ArrayList uploadedFiles,
+ ArrayList mentionedUserFullNames, boolean notifyGroup, boolean saveCopyWokspace) {
+
+ // escape text
+ String escapedFeedText = TextTransfromUtils.escapeHtmlAndTransformUrl(feedText);
+
+ // get the list of hashtags
+ List hashtags = TextTransfromUtils.getHashTags(feedText);
+ if (hashtags != null && !hashtags.isEmpty())
+ escapedFeedText = TextTransfromUtils.convertHashtagsAnchorHTML(escapedFeedText, hashtags);
+
+ // get the list of mentioned users
+ ArrayList mentionedUsers = null;
+ if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
+ mentionedUsers = getSelectedUserIds(mentionedUserFullNames);
+ escapedFeedText = TextTransfromUtils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers);
+ }
+
+ ASLSession session = getASLSession();
+ String username = session.getUsername();
+ String email = username+"@isti.cnr.it";
+ String fullName = username+" FULL";
+ String thumbnailAvatarURL = "images/Avatar_default.png";
+
+ boolean withinPortal = isWithinPortal();
+
+ if (withinPortal && username.compareTo(TEST_USER) != 0) {
+ try {
+ UserInfo user = getUserSettings().getUserInfo();
+ email = user.getEmailaddress();
+ fullName = user.getFullName();
+ thumbnailAvatarURL = user.getAvatarId();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ // Managing attachments: the first one (if any) will use the same fields of a link preview.
+ // If more than one attachments are present, they will be saved as Attachment objects.
+ // In this way we can handle retro-compatibility.
+
+ List attachments = null;
+
+ String firstAttachmentName = "",
+ firstAttachmentDescription = "",
+ firstAttachmentFormat = "",
+ firstAttachmentDownloadUrl = "",
+ firstAttachmenturlThumbnail = "";
+
+ if(uploadedFiles.size() > 0){
+
+ // retrieve the first element
+ UploadedFile firstAttachment = uploadedFiles.get(0);
+
+ firstAttachmentName = firstAttachment.getFileName();
+ firstAttachmentDescription = firstAttachment.getDescription();
+ firstAttachmentFormat = firstAttachment.getFormat();
+ firstAttachmentDownloadUrl = firstAttachment.getDownloadUrl();
+ firstAttachmenturlThumbnail = firstAttachment.getThumbnailUrl();
+
+ if(uploadedFiles.size() > 1){
+
+ attachments = new ArrayList<>();
+
+ // check if there are more files
+ for (UploadedFile file : uploadedFiles) {
+ attachments.add(new Attachment(
+ UUID.randomUUID().toString(),
+ file.getDownloadUrl(),
+ file.getFileName(),
+ file.getDescription(),
+ file.getThumbnailUrl(),
+ file.getFormat())
+ );
+ }
+ }
+
+ }
+
+ // evaluate the date (this will be the date of the post)
+ Date feedDate = new Date();
+
//this means the user has shared a file without text in it.
String textToPost = "";
if (escapedFeedText.trim().compareTo(ShareUpdateForm.NO_TEXT_FILE_SHARE) == 0) {
- textToPost = TextTransfromUtils.convertFileNameAnchorHTML(url);
+ textToPost = TextTransfromUtils.convertFileNameAnchorHTML(textToPost);
} else {
textToPost = escapedFeedText;
//System.out.println("textToPost=" + textToPost);
@@ -200,13 +371,36 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
vreScope2Set = (withinPortal) ? getScopeByOrganizationId(vreId) : session.getScope();
}
- Feed toShare = new Feed(UUID.randomUUID().toString(), feedType, username, feedDate,
- vreScope2Set, url, urlThumbnail, textToPost, pLevel, fullName, email, thumbnailURL, linkTitle, linkDesc, host);
+ Feed toShare = null;
+ boolean result;
+ if(uploadedFiles.size() <= 1){
+ toShare = new Feed(
+ UUID.randomUUID().toString(), feedType, username, feedDate,
+ vreScope2Set, firstAttachmentDownloadUrl, firstAttachmenturlThumbnail,
+ textToPost, pLevel, fullName, email, thumbnailAvatarURL,
+ firstAttachmentName, firstAttachmentDescription, firstAttachmentFormat);
+
+ // save the feed itself
+ result = store.saveUserFeed(toShare);
+ }
+ else{
+
+ toShare = new Feed(
+ UUID.randomUUID().toString(), feedType, username, feedDate,
+ vreScope2Set, firstAttachmentDownloadUrl, firstAttachmenturlThumbnail,
+ textToPost, pLevel, fullName, email, thumbnailAvatarURL,
+ firstAttachmentName, firstAttachmentDescription, firstAttachmentFormat);
+
+ // set the field multiFileUpload to true
+ toShare.setMultiFileUpload(true);
+
+ // save the feed itself plus the attachments
+ result = store.saveUserFeed(toShare, attachments);
+
+ }
_log.info("Attempting to save Feed with text: " + textToPost + " Level: " + pLevel + " Timeline="+vreScope2Set);
- boolean result = store.saveUserFeed(toShare);
-
//need to put the feed into VRES Timeline too
if (pLevel == PrivacyLevel.VRES) {
_log.trace("PrivacyLevel was set to VRES attempting to write onto User's VRES Timelines");
@@ -238,7 +432,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
//everything went fine
ClientFeed cf = new ClientFeed(toShare.getKey(), toShare.getType().toString(), username, feedDate, toShare.getUri(),
- TextTransfromUtils.replaceAmpersand(toShare.getDescription()), fullName, email, thumbnailURL, toShare.getLinkTitle(), toShare.getLinkDescription(),
+ TextTransfromUtils.replaceAmpersand(toShare.getDescription()), fullName, email, thumbnailAvatarURL, toShare.getLinkTitle(), toShare.getLinkDescription(),
toShare.getUriThumbnail(), toShare.getLinkHost());
@@ -260,17 +454,25 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
thread.start();
}
- //it means I also should upload a copy on the user's Workspace root folder
- if (fileName != null && filePathOnServer != null) {
- //The workspace uploader Thread starts here asyncronously
- Thread thread = new Thread(new UploadToWorkspaceThread(fullName, username, fileName, filePathOnServer));
- thread.start();
+ //it means I also should upload a copy of the files on the user's Workspace root folder
+ if (saveCopyWokspace) {
+ for(UploadedFile file: uploadedFiles){
+ new Thread(
+ new UploadToWorkspaceThread(
+ fullName,
+ username,
+ file.getFileName(),
+ file.getFileAbsolutePathOnServer()))
+ .start();
+ }
}
return cf;
}
+
+
@Override
public UserSettings getUserSettings() {
try {
@@ -283,17 +485,17 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
if (isWithinPortal() && username.compareTo(TEST_USER) != 0) {
long companyId = OrganizationsUtil.getCompany().getCompanyId();
com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(companyId, username);
-
+
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
fullName = user.getFirstName() + " " + user.getLastName();
email = user.getEmailAddress();
ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY);
-
+
String accountURL = themeDisplay.getURLMyAccount().toString();
HashMap vreNames = getUserVreNames(username);
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, isAdmin(), vreNames);
-
+
UserSettings toReturn = new UserSettings(userInfo, 0, session.getScopeName(), isInfrastructureScope(), isNotificationViaEmailEnabled(session));
return toReturn;
}
@@ -312,12 +514,12 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
return new UserSettings();
}
-
+
private boolean isNotificationViaEmailEnabled(ASLSession session) throws PortalException, SystemException {
Organization currOrg = OrganizationLocalServiceUtil.getOrganization(session.getGroupId());
return OrganizationManagerImpl.readOrganizationCustomAttribute(session.getUsername(), currOrg, ATTR_TO_CHECK);
}
-
+
/**
* generate a preview of the file, upload the file on the storage and shorts the link
*/
@@ -335,14 +537,14 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
String httpURL = "";
String smpURI = "";
- if (isWithinPortal()) {
- //get the url to show, before actually uploading it
- smpURI = storageClient.getUrl(true).RFile(remoteFilePath);
+ //if (isWithinPortal()) {
+ //get the url to show, before actually uploading it
+ smpURI = "http://ciccio.com";//storageClient.getUrl(true).RFile(remoteFilePath);
- //The storage uploader Thread starts here asyncronously
- Thread thread = new Thread(new UploadToStorageThread(storageClient, fileName, fileabsolutePathOnServer, remoteFilePath));
- thread.start();
- }
+ //The storage uploader Thread starts here asyncronously
+ //Thread thread = new Thread(new UploadToStorageThread(storageClient, fileName, fileabsolutePathOnServer, remoteFilePath));
+ //thread.start();
+ //}
try {
String mimeType = FilePreviewer.getMimeType(new File(fileabsolutePathOnServer), fileName);
@@ -384,7 +586,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
} catch (Exception e1) {
e1.printStackTrace();
}
-
+
}
_log.debug("smpURI=" + smpURI);
@@ -571,10 +773,6 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
}
-
-
-
-
/**
* Indicates whether the scope is the whole infrastructure.
* @return true if it is, false otherwise.
@@ -688,8 +886,4 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
return portalUsers;
}
-
-
-
-
}
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/shared/LinkPreview.java b/src/main/java/org/gcube/portlets/user/shareupdates/shared/LinkPreview.java
index 5bbad9e..5f0bab1 100644
--- a/src/main/java/org/gcube/portlets/user/shareupdates/shared/LinkPreview.java
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/shared/LinkPreview.java
@@ -5,17 +5,17 @@ import java.util.ArrayList;
@SuppressWarnings("serial")
/**
- * This class is used for link preview (both actual links and attachments)
+ * This class is used for link preview (and when a file is attached)
* @author Costantino Perciante at ISTI-CNR
*
*/
public class LinkPreview implements Serializable {
- private String title;
+ private String title; //in case of a file, it is the name of the file itself
private String description;
private String url;
private String host;
- private ArrayList imageUrls;
+ private ArrayList imageUrls; // in case of a file, the first element is the image related to the format (pdf, jpg..)
public LinkPreview() {
diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/shared/UploadedFile.java b/src/main/java/org/gcube/portlets/user/shareupdates/shared/UploadedFile.java
new file mode 100644
index 0000000..12e7ba8
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/shareupdates/shared/UploadedFile.java
@@ -0,0 +1,107 @@
+package org.gcube.portlets.user.shareupdates.shared;
+
+import java.io.Serializable;
+
+/**
+ * Information of an already uploaded file.
+ * @author Costantino Perciante at ISTI-CNR
+ */
+public class UploadedFile implements Serializable{
+
+ /**
+ * Generated UUID
+ */
+ private static final long serialVersionUID = 1690771870370846188L;
+
+ // name of the file
+ private String fileName;
+
+ // path on the server of this file (tomcat tmp)
+ private String fileAbsolutePathOnServer;
+
+ // a description of the file (its content for a pdf, size for images)
+ private String description;
+
+ // when showing a file, this is the url that can be used for download
+ private String downloadUrl;
+
+ // thumbnail url related to the type of file (pdf, png, jpg)
+ private String thumbnailUrl;
+
+ // mime type (pdf, jpg ecc..)
+ private String format;
+
+ public UploadedFile() {
+ super();
+ }
+
+ public UploadedFile(String fileName, String fileAbsolutePathOnServer,
+ String description, String downloadUrl, String thumbnailUrl,
+ String mime) {
+ super();
+ this.fileName = fileName;
+ this.fileAbsolutePathOnServer = fileAbsolutePathOnServer;
+ this.description = description;
+ this.downloadUrl = downloadUrl;
+ this.thumbnailUrl = thumbnailUrl;
+ this.format = mime;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public String getFileAbsolutePathOnServer() {
+ return fileAbsolutePathOnServer;
+ }
+
+ public void setFileAbsolutePathOnServer(String fileAbsolutePathOnServer) {
+ this.fileAbsolutePathOnServer = fileAbsolutePathOnServer;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getDownloadUrl() {
+ return downloadUrl;
+ }
+
+ public void setDownloadUrl(String downloadUrl) {
+ this.downloadUrl = downloadUrl;
+ }
+
+ public String getThumbnailUrl() {
+ return thumbnailUrl;
+ }
+
+ public void setThumbnailUrl(String thumbnailUrl) {
+ this.thumbnailUrl = thumbnailUrl;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setMime(String format) {
+ this.format = format;
+ }
+
+ @Override
+ public String toString() {
+ return "UploadedFile [fileName=" + fileName
+ + ", fileAbsolutePathOnServer=" + fileAbsolutePathOnServer
+ + ", description=" + description + ", downloadUrl="
+ + downloadUrl + ", thumbnailUrl=" + thumbnailUrl + ", format="
+ + format + "]";
+ }
+
+}
|