2013-01-26 20:02:51 +01:00
|
|
|
package org.gcube.portlets.user.shareupdates.server;
|
|
|
|
|
2014-01-27 19:08:15 +01:00
|
|
|
import java.io.File;
|
2013-01-26 20:02:51 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
|
|
|
import java.util.ArrayList;
|
2014-10-02 19:47:15 +02:00
|
|
|
import java.util.Collections;
|
2013-01-26 20:02:51 +01:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2014-10-02 19:47:15 +02:00
|
|
|
import java.util.Map;
|
2013-01-26 20:02:51 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.apache.commons.validator.routines.UrlValidator;
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
|
|
import org.gcube.application.framework.core.session.SessionManager;
|
2013-04-18 11:44:10 +02:00
|
|
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
|
|
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
2014-01-21 18:43:03 +01:00
|
|
|
import org.gcube.applicationsupportlayer.social.storage.UriResolverReaderParameter;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2013-09-26 15:44:21 +02:00
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
|
|
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
2014-01-21 18:43:03 +01:00
|
|
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
|
|
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
|
|
|
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
|
|
|
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
|
2015-07-06 15:11:58 +02:00
|
|
|
import org.gcube.portal.custom.communitymanager.impl.OrganizationManagerImpl;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
|
|
|
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
2016-01-15 18:24:52 +01:00
|
|
|
import org.gcube.portal.databook.shared.Attachment;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.portal.databook.shared.ClientFeed;
|
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
|
import org.gcube.portal.databook.shared.FeedType;
|
|
|
|
import org.gcube.portal.databook.shared.PrivacyLevel;
|
|
|
|
import org.gcube.portal.databook.shared.UserInfo;
|
|
|
|
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
2015-12-21 18:33:23 +01:00
|
|
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
|
|
|
import org.gcube.portal.notifications.thread.MentionNotificationsThread;
|
|
|
|
import org.gcube.portal.notifications.thread.PostNotificationsThread;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.portlets.user.shareupdates.client.ShareUpdateService;
|
2014-01-30 16:39:42 +01:00
|
|
|
import org.gcube.portlets.user.shareupdates.client.view.ShareUpdateForm;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.portlets.user.shareupdates.server.opengraph.OpenGraph;
|
2014-10-02 19:47:15 +02:00
|
|
|
import org.gcube.portlets.user.shareupdates.shared.HashTagAndOccurrence;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.portlets.user.shareupdates.shared.LinkPreview;
|
2016-01-15 18:24:52 +01:00
|
|
|
import org.gcube.portlets.user.shareupdates.shared.UploadedFile;
|
2013-04-11 18:46:58 +02:00
|
|
|
import org.gcube.portlets.user.shareupdates.shared.UserSettings;
|
2014-10-02 19:47:15 +02:00
|
|
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
2013-04-16 23:49:16 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
|
2013-04-16 23:49:16 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
|
2013-01-26 20:02:51 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GroupModel;
|
2013-04-16 23:49:16 +02:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.UserModel;
|
2013-09-26 15:44:21 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2013-01-26 20:02:51 +01:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
import com.liferay.portal.kernel.exception.PortalException;
|
|
|
|
import com.liferay.portal.kernel.exception.SystemException;
|
|
|
|
import com.liferay.portal.kernel.util.WebKeys;
|
|
|
|
import com.liferay.portal.model.Organization;
|
|
|
|
import com.liferay.portal.model.Role;
|
|
|
|
import com.liferay.portal.service.OrganizationLocalServiceUtil;
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
import com.liferay.portal.theme.ThemeDisplay;
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
public class ShareUpdateServiceImpl extends RemoteServiceServlet implements ShareUpdateService {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final String ADMIN_ROLE = "Administrator";
|
2014-05-09 17:05:42 +02:00
|
|
|
|
|
|
|
public static final String TEST_USER = "test.user";
|
2014-01-21 18:43:03 +01:00
|
|
|
|
|
|
|
private static final String STORAGE_OWNER = "gCubeSocialFramework";
|
|
|
|
public static final String UPLOAD_DIR = "/social-framework-uploads";
|
2014-03-05 00:38:20 +01:00
|
|
|
private static final String NEWS_FEED_PORTLET_CLASSNAME = "org.gcube.portlets.user.newsfeed.server.NewsServiceImpl";
|
2015-07-06 17:12:40 +02:00
|
|
|
private final static String ATTR_TO_CHECK = "Postnotificationviaemail";
|
2016-01-15 18:24:52 +01:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-09-26 15:44:21 +02:00
|
|
|
private static Logger _log = LoggerFactory.getLogger(ShareUpdateServiceImpl.class);
|
2013-01-26 20:02:51 +01:00
|
|
|
/**
|
2014-01-21 18:43:03 +01:00
|
|
|
* The Cassandra store interface
|
2013-01-26 20:02:51 +01:00
|
|
|
*/
|
|
|
|
private DatabookStore store;
|
|
|
|
/**
|
|
|
|
* connect to cassandra at startup
|
|
|
|
*/
|
|
|
|
public void init() {
|
2014-01-27 19:08:15 +01:00
|
|
|
store = new DBCassandraAstyanaxImpl();
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void destroy() {
|
|
|
|
store.closeConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the current ASLSession
|
|
|
|
* @return the session
|
|
|
|
*/
|
|
|
|
private ASLSession getASLSession() {
|
|
|
|
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
|
|
|
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
|
|
|
if (user == null) {
|
|
|
|
_log.warn("USER IS NULL setting test.user and Running OUTSIDE PORTAL");
|
2014-03-22 19:03:30 +01:00
|
|
|
user = getDevelopmentUser();
|
2015-04-27 16:52:29 +02:00
|
|
|
SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE");
|
2014-05-09 17:05:42 +02:00
|
|
|
}
|
2013-01-26 20:02:51 +01:00
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
|
|
|
}
|
2014-03-22 19:03:30 +01:00
|
|
|
public String getDevelopmentUser() {
|
2014-05-09 17:05:42 +02:00
|
|
|
String user = TEST_USER;
|
2016-01-20 10:36:24 +01:00
|
|
|
// user = "costantino.perciante";
|
2014-03-22 19:03:30 +01:00
|
|
|
return user;
|
|
|
|
}
|
2014-05-09 17:05:42 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return true if you're running into the portal, false if in development
|
|
|
|
*/
|
|
|
|
private boolean isWithinPortal() {
|
|
|
|
try {
|
|
|
|
UserLocalServiceUtil.getService();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
|
|
|
_log.trace("Development Mode ON");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2013-04-17 17:29:44 +02:00
|
|
|
/**
|
2016-01-15 18:24:52 +01:00
|
|
|
* Share post that could contain a link preview.
|
2013-04-17 17:29:44 +02:00
|
|
|
*/
|
2016-01-15 18:24:52 +01:00
|
|
|
@Override
|
|
|
|
public ClientFeed sharePostWithLinkPreview(String postText, FeedType feedType, PrivacyLevel pLevel,
|
|
|
|
String vreId, LinkPreview preview, String urlThumbnail, ArrayList<String> mentionedUserFullNames, boolean notifyGroup) {
|
2013-10-03 12:16:57 +02:00
|
|
|
|
2016-01-18 10:26:36 +01:00
|
|
|
|
|
|
|
_log.debug("Writing a new post with text " + postText);
|
2016-01-15 18:24:52 +01:00
|
|
|
// escape text
|
2014-04-01 15:00:37 +02:00
|
|
|
String escapedFeedText = TextTransfromUtils.escapeHtmlAndTransformUrl(postText);
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
// get hashtags
|
2014-10-06 14:16:44 +02:00
|
|
|
List<String> hashtags = TextTransfromUtils.getHashTags(postText);
|
|
|
|
if (hashtags != null && !hashtags.isEmpty())
|
|
|
|
escapedFeedText = TextTransfromUtils.convertHashtagsAnchorHTML(escapedFeedText, hashtags);
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
// retrieve mentioned users
|
2014-10-02 19:47:15 +02:00
|
|
|
ArrayList<ItemBean> mentionedUsers = null;
|
2013-07-10 17:39:14 +02:00
|
|
|
if (mentionedUserFullNames != null && ! mentionedUserFullNames.isEmpty()) {
|
|
|
|
mentionedUsers = getSelectedUserIds(mentionedUserFullNames);
|
2014-04-01 15:00:37 +02:00
|
|
|
escapedFeedText = TextTransfromUtils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers);
|
2013-07-10 17:39:14 +02:00
|
|
|
}
|
2013-10-03 12:16:57 +02:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
// get session
|
2013-04-18 11:44:10 +02:00
|
|
|
ASLSession session = getASLSession();
|
|
|
|
String username = session.getUsername();
|
2013-01-26 20:02:51 +01:00
|
|
|
String email = username+"@isti.cnr.it";
|
|
|
|
String fullName = username+" FULL";
|
2016-01-15 18:24:52 +01:00
|
|
|
String thumbnailAvatarURL = "images/Avatar_default.png";
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2014-05-09 17:05:42 +02:00
|
|
|
boolean withinPortal = isWithinPortal();
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2014-05-09 17:05:42 +02:00
|
|
|
if (withinPortal && username.compareTo(TEST_USER) != 0) {
|
2013-01-26 20:02:51 +01:00
|
|
|
try {
|
2013-04-11 18:46:58 +02:00
|
|
|
UserInfo user = getUserSettings().getUserInfo();
|
2013-01-26 20:02:51 +01:00
|
|
|
email = user.getEmailaddress();
|
|
|
|
fullName = user.getFullName();
|
2016-01-15 18:24:52 +01:00
|
|
|
thumbnailAvatarURL = user.getAvatarId();
|
2013-01-26 20:02:51 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-03-22 17:32:46 +01:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
// get data from the preview of the link
|
2014-01-30 16:39:42 +01:00
|
|
|
String linkTitle = preview.getTitle();
|
|
|
|
String linkDesc = preview.getDescription();
|
|
|
|
String host = preview.getHost();
|
|
|
|
String url = preview.getUrl();
|
2014-04-04 16:08:04 +02:00
|
|
|
if (urlThumbnail == null)
|
|
|
|
urlThumbnail = "null";
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2013-04-09 17:12:10 +02:00
|
|
|
Date feedDate = new Date();
|
2016-01-15 18:24:52 +01:00
|
|
|
|
|
|
|
//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(),
|
2016-01-18 10:26:36 +01:00
|
|
|
toShare.getUriThumbnail(), toShare.getLinkHost(), null);
|
2016-01-15 18:24:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
//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<GenericItemBean> toPass = new ArrayList<GenericItemBean>();
|
|
|
|
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<UploadedFile> uploadedFiles,
|
|
|
|
ArrayList<String> mentionedUserFullNames, boolean notifyGroup, boolean saveCopyWokspace) {
|
|
|
|
|
2016-01-18 10:26:36 +01:00
|
|
|
_log.debug("Incoming text is " + feedText);
|
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
// escape text
|
|
|
|
String escapedFeedText = TextTransfromUtils.escapeHtmlAndTransformUrl(feedText);
|
|
|
|
|
|
|
|
// get the list of hashtags
|
|
|
|
List<String> hashtags = TextTransfromUtils.getHashTags(feedText);
|
|
|
|
if (hashtags != null && !hashtags.isEmpty())
|
|
|
|
escapedFeedText = TextTransfromUtils.convertHashtagsAnchorHTML(escapedFeedText, hashtags);
|
|
|
|
|
|
|
|
// get the list of mentioned users
|
|
|
|
ArrayList<ItemBean> 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 10:36:24 +01:00
|
|
|
// Managing attachments: the first one will use the same fields of a link preview.
|
2016-01-15 18:24:52 +01:00
|
|
|
// If more than one attachments are present, they will be saved as Attachment objects.
|
|
|
|
// In this way we can handle retro-compatibility.
|
|
|
|
|
|
|
|
List<Attachment> attachments = null;
|
|
|
|
|
|
|
|
String firstAttachmentName = "",
|
|
|
|
firstAttachmentDescription = "",
|
|
|
|
firstAttachmentFormat = "",
|
|
|
|
firstAttachmentDownloadUrl = "",
|
2016-01-18 10:26:36 +01:00
|
|
|
firstAttachmenturlThumbnail = "null";
|
2016-01-15 18:24:52 +01:00
|
|
|
|
|
|
|
if(uploadedFiles.size() > 0){
|
|
|
|
|
2016-01-20 10:36:24 +01:00
|
|
|
// retrieve the first element (and remove it)
|
2016-01-15 18:24:52 +01:00
|
|
|
UploadedFile firstAttachment = uploadedFiles.get(0);
|
|
|
|
|
|
|
|
firstAttachmentName = firstAttachment.getFileName();
|
|
|
|
firstAttachmentDescription = firstAttachment.getDescription();
|
|
|
|
firstAttachmentFormat = firstAttachment.getFormat();
|
|
|
|
firstAttachmentDownloadUrl = firstAttachment.getDownloadUrl();
|
2016-01-18 14:46:58 +01:00
|
|
|
firstAttachmenturlThumbnail =
|
|
|
|
firstAttachment.getThumbnailUrl() != null ?
|
|
|
|
firstAttachment.getThumbnailUrl() : firstAttachmenturlThumbnail;
|
|
|
|
|
2016-01-20 10:36:24 +01:00
|
|
|
// check if there are more files
|
2016-01-18 14:46:58 +01:00
|
|
|
if(uploadedFiles.size() > 1){
|
|
|
|
|
|
|
|
attachments = new ArrayList<>();
|
|
|
|
|
2016-01-20 10:36:24 +01:00
|
|
|
for (int i = 1; i < uploadedFiles.size(); i++){
|
|
|
|
UploadedFile file = uploadedFiles.get(i);
|
|
|
|
|
2016-01-18 14:46:58 +01:00
|
|
|
attachments.add(new Attachment(
|
|
|
|
UUID.randomUUID().toString(),
|
|
|
|
file.getDownloadUrl(),
|
|
|
|
file.getFileName(),
|
|
|
|
file.getDescription(),
|
2016-01-20 10:36:24 +01:00
|
|
|
file.getThumbnailUrl() == null ? "null" : file.getThumbnailUrl(),
|
2016-01-18 14:46:58 +01:00
|
|
|
file.getFormat())
|
2016-01-20 10:36:24 +01:00
|
|
|
);
|
2016-01-18 14:46:58 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-15 18:24:52 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// evaluate the date (this will be the date of the post)
|
|
|
|
Date feedDate = new Date();
|
|
|
|
|
2014-01-30 16:39:42 +01:00
|
|
|
//this means the user has shared a file without text in it.
|
|
|
|
String textToPost = "";
|
2014-05-15 18:01:32 +02:00
|
|
|
if (escapedFeedText.trim().compareTo(ShareUpdateForm.NO_TEXT_FILE_SHARE) == 0) {
|
2016-01-15 18:24:52 +01:00
|
|
|
textToPost = TextTransfromUtils.convertFileNameAnchorHTML(textToPost);
|
2014-01-30 16:39:42 +01:00
|
|
|
} else {
|
2014-03-31 19:02:52 +02:00
|
|
|
textToPost = escapedFeedText;
|
2014-01-30 16:39:42 +01:00
|
|
|
}
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2014-05-09 17:05:42 +02:00
|
|
|
//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();
|
|
|
|
}
|
2014-03-22 17:32:46 +01:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
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{
|
2013-01-26 20:02:51 +01:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
toShare = new Feed(
|
|
|
|
UUID.randomUUID().toString(), feedType, username, feedDate,
|
|
|
|
vreScope2Set, firstAttachmentDownloadUrl, firstAttachmenturlThumbnail,
|
|
|
|
textToPost, pLevel, fullName, email, thumbnailAvatarURL,
|
|
|
|
firstAttachmentName, firstAttachmentDescription, firstAttachmentFormat);
|
2014-01-30 16:39:42 +01:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
// 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);
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
//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) {
|
2014-05-09 17:05:42 +02:00
|
|
|
_log.trace("Attempting to write onto " + vreScope2Set);
|
2013-01-26 20:02:51 +01:00
|
|
|
try {
|
2014-05-09 17:05:42 +02:00
|
|
|
store.saveFeedToVRETimeline(toShare.getKey(), vreScope2Set);
|
2014-10-17 16:29:23 +02:00
|
|
|
if (hashtags != null && !hashtags.isEmpty())
|
|
|
|
store.saveHashTags(toShare.getKey(), vreScope2Set, hashtags);
|
2013-01-26 20:02:51 +01:00
|
|
|
} catch (FeedIDNotFoundException e) {
|
2014-05-09 17:05:42 +02:00
|
|
|
_log.error("Error writing onto VRES Time Line" + vreScope2Set);
|
2013-01-26 20:02:51 +01:00
|
|
|
} //save the feed
|
2014-05-09 17:05:42 +02:00
|
|
|
_log.trace("Success writing onto " + vreScope2Set);
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
if (!result) return null;
|
|
|
|
|
2013-04-18 11:44:10 +02:00
|
|
|
//everything went fine
|
2013-04-09 17:12:10 +02:00
|
|
|
ClientFeed cf = new ClientFeed(toShare.getKey(), toShare.getType().toString(), username, feedDate, toShare.getUri(),
|
2016-01-15 18:24:52 +01:00
|
|
|
TextTransfromUtils.replaceAmpersand(toShare.getDescription()), fullName, email, thumbnailAvatarURL, toShare.getLinkTitle(), toShare.getLinkDescription(),
|
2016-01-18 10:26:36 +01:00
|
|
|
toShare.getUriThumbnail(), toShare.getLinkHost(), attachments);
|
2014-03-22 17:32:46 +01:00
|
|
|
|
|
|
|
|
2014-03-05 00:38:20 +01:00
|
|
|
//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);
|
2014-11-03 19:35:26 +01:00
|
|
|
Thread thread = new Thread(new PostNotificationsThread(toShare.getKey(), textToPost, ""+session.getGroupId(), nm, hashtags));
|
2014-03-05 00:38:20 +01:00
|
|
|
thread.start();
|
2014-03-22 17:32:46 +01:00
|
|
|
|
2014-03-05 00:38:20 +01:00
|
|
|
}
|
|
|
|
//send the notification to the mentioned users
|
2013-07-10 17:39:14 +02:00
|
|
|
if (mentionedUsers != null && mentionedUsers.size() > 0) {
|
2013-04-18 11:44:10 +02:00
|
|
|
NotificationsManager nm = new ApplicationNotificationsManager(session);
|
2015-12-21 18:33:23 +01:00
|
|
|
ArrayList<GenericItemBean> toPass = new ArrayList<GenericItemBean>();
|
|
|
|
for (ItemBean u : mentionedUsers) {
|
|
|
|
toPass.add(new GenericItemBean(u.getId(), u.getName(), u.getAlternativeName(), u.getThumbnailURL()));
|
|
|
|
}
|
|
|
|
Thread thread = new Thread(new MentionNotificationsThread(toShare.getKey(), textToPost, nm, toPass));
|
2013-04-18 11:44:10 +02:00
|
|
|
thread.start();
|
|
|
|
}
|
2014-03-22 17:32:46 +01:00
|
|
|
|
2016-01-15 18:24:52 +01:00
|
|
|
//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();
|
|
|
|
}
|
2014-01-30 16:39:42 +01:00
|
|
|
}
|
2013-10-03 12:16:57 +02:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
return cf;
|
2013-04-17 17:29:44 +02:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
2016-01-15 18:24:52 +01:00
|
|
|
|
|
|
|
|
2014-01-30 16:39:42 +01:00
|
|
|
@Override
|
2013-04-11 18:46:58 +02:00
|
|
|
public UserSettings getUserSettings() {
|
2013-01-26 20:02:51 +01:00
|
|
|
try {
|
2013-04-11 18:46:58 +02:00
|
|
|
ASLSession session = getASLSession();
|
|
|
|
String username = session.getUsername();
|
2013-01-26 20:02:51 +01:00
|
|
|
String email = username+"@isti.cnr.it";
|
|
|
|
String fullName = username+" FULL";
|
2014-05-09 17:05:42 +02:00
|
|
|
String thumbnailURL = "images/Avatar_default.png";
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2014-05-09 17:05:42 +02:00
|
|
|
if (isWithinPortal() && username.compareTo(TEST_USER) != 0) {
|
2015-07-06 15:11:58 +02:00
|
|
|
long companyId = OrganizationsUtil.getCompany().getCompanyId();
|
|
|
|
com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(companyId, username);
|
2016-01-15 18:24:52 +01:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
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);
|
2016-01-15 18:24:52 +01:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
String accountURL = themeDisplay.getURLMyAccount().toString();
|
|
|
|
HashMap<String, String> vreNames = getUserVreNames(username);
|
2013-04-11 18:46:58 +02:00
|
|
|
|
|
|
|
UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, isAdmin(), vreNames);
|
2016-01-15 18:24:52 +01:00
|
|
|
|
2015-07-06 17:12:40 +02:00
|
|
|
UserSettings toReturn = new UserSettings(userInfo, 0, session.getScopeName(), isInfrastructureScope(), isNotificationViaEmailEnabled(session));
|
2013-01-26 20:02:51 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
else {
|
2014-03-22 17:32:46 +01:00
|
|
|
_log.info("Returning test USER = " + session.getUsername());
|
2013-01-26 20:02:51 +01:00
|
|
|
HashMap<String, String> fakeVreNames = new HashMap<String, String>();
|
2014-03-31 19:02:52 +02:00
|
|
|
fakeVreNames.put("/gcube/devsec/devVRE","devVRE");
|
2013-04-11 18:46:58 +02:00
|
|
|
//fakeVreNames.put("/gcube/devNext/NexNext","NexNext");
|
2013-04-17 17:29:44 +02:00
|
|
|
|
2014-03-22 17:32:46 +01:00
|
|
|
UserInfo user = new UserInfo(session.getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames);
|
2015-07-06 15:11:58 +02:00
|
|
|
return new UserSettings(user, 0, session.getScopeName(), false, true);
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-04-11 18:46:58 +02:00
|
|
|
return new UserSettings();
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
2016-01-15 18:24:52 +01:00
|
|
|
|
2015-07-06 17:12:40 +02:00
|
|
|
private boolean isNotificationViaEmailEnabled(ASLSession session) throws PortalException, SystemException {
|
|
|
|
Organization currOrg = OrganizationLocalServiceUtil.getOrganization(session.getGroupId());
|
2015-10-05 19:12:25 +02:00
|
|
|
return OrganizationManagerImpl.readOrganizationCustomAttribute(session.getUsername(), currOrg, ATTR_TO_CHECK);
|
2015-07-06 15:11:58 +02:00
|
|
|
}
|
2016-01-15 18:24:52 +01:00
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
/**
|
|
|
|
* generate a preview of the file, upload the file on the storage and shorts the link
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public LinkPreview checkUploadedFile(String fileName, String fileabsolutePathOnServer) {
|
2014-01-21 18:43:03 +01:00
|
|
|
LinkPreview toReturn = null;
|
|
|
|
|
|
|
|
String randomUploadFolderName = UUID.randomUUID().toString();
|
|
|
|
String remoteFilePath = UPLOAD_DIR + "/" + randomUploadFolderName + "/" + fileName;
|
2014-01-27 19:08:15 +01:00
|
|
|
//get the Storage Client
|
2014-01-21 18:43:03 +01:00
|
|
|
String currScope = ScopeProvider.instance.get();
|
|
|
|
ScopeProvider.instance.set("/"+PortalContext.getConfiguration().getInfrastructureName());
|
|
|
|
IClient storageClient = new StorageClient(STORAGE_OWNER, AccessType.SHARED, MemoryType.PERSISTENT).getClient();
|
|
|
|
ScopeProvider.instance.set(currScope);
|
2014-03-22 17:32:46 +01:00
|
|
|
|
2014-01-21 18:43:03 +01:00
|
|
|
String httpURL = "";
|
2015-04-27 16:52:29 +02:00
|
|
|
String smpURI = "";
|
2016-01-18 10:26:36 +01:00
|
|
|
if (isWithinPortal()) {
|
|
|
|
//get the url to show, before actually uploading it
|
|
|
|
smpURI = storageClient.getUrl(true).RFile(remoteFilePath); //"http://ciccio.com";
|
|
|
|
|
|
|
|
//The storage uploader Thread starts here asyncronously
|
|
|
|
Thread thread = new Thread(new UploadToStorageThread(storageClient, fileName, fileabsolutePathOnServer, remoteFilePath));
|
|
|
|
thread.start();
|
|
|
|
}
|
2014-01-27 19:08:15 +01:00
|
|
|
|
2014-01-17 19:21:35 +01:00
|
|
|
try {
|
2014-04-01 15:00:37 +02:00
|
|
|
String mimeType = FilePreviewer.getMimeType(new File(fileabsolutePathOnServer), fileName);
|
2014-01-21 18:43:03 +01:00
|
|
|
UriResolverReaderParameter resolver = new UriResolverReaderParameter();
|
|
|
|
//get the url to show (though it could not be ready for download at this stage)
|
2014-01-27 19:08:15 +01:00
|
|
|
httpURL = resolver.resolveAsUriRequest(smpURI, fileName, mimeType, true);
|
|
|
|
|
|
|
|
switch (mimeType) {
|
|
|
|
case "application/pdf":
|
|
|
|
toReturn = FilePreviewer.getPdfPreview(fileName, fileabsolutePathOnServer, httpURL, mimeType);
|
|
|
|
break;
|
|
|
|
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
2014-01-28 19:32:14 +01:00
|
|
|
mimeType = "application/wordprocessor";
|
2014-01-30 16:39:42 +01:00
|
|
|
return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType);
|
2014-01-27 19:08:15 +01:00
|
|
|
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
|
2014-01-28 19:32:14 +01:00
|
|
|
mimeType = "application/spreadsheet";
|
2014-01-30 16:39:42 +01:00
|
|
|
return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType);
|
2014-01-28 19:32:14 +01:00
|
|
|
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
|
|
mimeType = "application/presentation";
|
2014-01-30 16:39:42 +01:00
|
|
|
return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType);
|
2014-01-28 19:32:14 +01:00
|
|
|
case "image/png":
|
|
|
|
case "image/gif":
|
|
|
|
case "image/tiff":
|
|
|
|
case "image/jpg":
|
|
|
|
case "image/jpeg":
|
|
|
|
case "image/bmp":
|
|
|
|
toReturn = FilePreviewer.getImagePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType);
|
|
|
|
break;
|
2014-01-27 19:08:15 +01:00
|
|
|
default:
|
|
|
|
return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType);
|
2014-01-21 18:43:03 +01:00
|
|
|
|
2014-01-27 19:08:15 +01:00
|
|
|
}
|
2014-03-22 17:32:46 +01:00
|
|
|
|
2014-01-20 19:35:57 +01:00
|
|
|
} catch (Exception e) {
|
2014-01-21 18:43:03 +01:00
|
|
|
_log.error("Error while resolving or previewing file");
|
2014-01-17 19:21:35 +01:00
|
|
|
e.printStackTrace();
|
2015-04-27 16:52:29 +02:00
|
|
|
try {
|
|
|
|
return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, "Error During upload on Server!");
|
|
|
|
} catch (Exception e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
2016-01-15 18:24:52 +01:00
|
|
|
|
2014-01-21 18:43:03 +01:00
|
|
|
}
|
2014-01-20 19:35:57 +01:00
|
|
|
|
2014-01-21 18:43:03 +01:00
|
|
|
_log.debug("smpURI=" + smpURI);
|
|
|
|
_log.debug("Returning httpURL=" + httpURL);
|
|
|
|
return toReturn;
|
2014-01-20 19:35:57 +01:00
|
|
|
}
|
2013-01-26 20:02:51 +01:00
|
|
|
/**
|
|
|
|
* tries the following in the indicated order for Populating the Link preview
|
|
|
|
* Open Graph protocol
|
|
|
|
* Meta "title" and "description" tags
|
|
|
|
* Best guess from page content (not recommended)
|
|
|
|
*
|
|
|
|
* Schema.org microdata <-- This is still a TODO
|
|
|
|
*/
|
2014-04-01 15:00:37 +02:00
|
|
|
@Override
|
2013-01-26 20:02:51 +01:00
|
|
|
public LinkPreview checkLink(String linkToCheck) {
|
|
|
|
LinkPreview toReturn = null;
|
|
|
|
_log.info("to check " + linkToCheck);
|
|
|
|
//look for a url in text
|
2014-04-01 15:00:37 +02:00
|
|
|
linkToCheck = TextTransfromUtils.extractURL(linkToCheck);
|
2013-01-26 20:02:51 +01:00
|
|
|
if (linkToCheck == null)
|
|
|
|
return null; //no url
|
|
|
|
|
|
|
|
String[] schemes = {"http","https"};
|
|
|
|
UrlValidator urlValidator = new UrlValidator(schemes);
|
|
|
|
if (! urlValidator.isValid(linkToCheck)) {
|
|
|
|
_log.warn("url is NOT valid, returning nothing");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
_log.debug("url is valid");
|
|
|
|
|
|
|
|
URL pageURL;
|
|
|
|
URLConnection siteConnection = null;
|
|
|
|
try {
|
|
|
|
pageURL = new URL(linkToCheck);
|
|
|
|
if (pageURL.getProtocol().equalsIgnoreCase("https")) {
|
|
|
|
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
|
|
|
|
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
|
2014-04-01 15:00:37 +02:00
|
|
|
TextTransfromUtils.trustAllHTTPSConnections();
|
2013-01-26 20:02:51 +01:00
|
|
|
siteConnection = (HttpsURLConnection) pageURL.openConnection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
siteConnection = (HttpURLConnection) pageURL.openConnection();
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
_log.error("url is not valid");
|
|
|
|
return null;
|
|
|
|
} catch (IOException e) {
|
|
|
|
_log.error("url is not reachable");
|
|
|
|
return null;
|
|
|
|
}
|
2014-03-22 17:32:46 +01:00
|
|
|
//pretend you're a browser (make my request from Java more “browsery-like”.)
|
|
|
|
siteConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
|
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
String title;
|
|
|
|
String description;
|
|
|
|
ArrayList<String> imageUrls = new ArrayList<String>();
|
|
|
|
//get the host from the url
|
|
|
|
String host = pageURL.getHost().replaceAll("www.", "");
|
|
|
|
|
|
|
|
//try openGraph First
|
|
|
|
OpenGraph ogLink = null;
|
|
|
|
try {
|
|
|
|
ogLink = new OpenGraph(linkToCheck, true, siteConnection);
|
|
|
|
if (ogLink == null || ogLink.getContent("title") == null) {
|
|
|
|
//there is no OpenGraph for this link
|
|
|
|
_log.info("No OpenGraph Found, going Best guess from page content") ;
|
2014-04-01 15:00:37 +02:00
|
|
|
toReturn = TextTransfromUtils.getInfoFromHTML(siteConnection, pageURL, linkToCheck, host);
|
2013-01-26 20:02:51 +01:00
|
|
|
} else {
|
|
|
|
//there is OpenGraph
|
2014-03-31 11:18:22 +02:00
|
|
|
_log.info("OpenGraph Found") ;
|
2013-01-26 20:02:51 +01:00
|
|
|
title = ogLink.getContent("title");
|
|
|
|
description = (ogLink.getContent("description") != null) ? ogLink.getContent("description") : "";
|
|
|
|
description = ((description.length() > 256) ? description.substring(0, 256)+"..." : description);
|
2013-11-06 16:09:30 +01:00
|
|
|
//look for the image ask the guesser if not present
|
2014-03-31 11:18:22 +02:00
|
|
|
if (ogLink.getContent("image") != null) {
|
2014-04-01 15:00:37 +02:00
|
|
|
String imageUrl = TextTransfromUtils.getImageUrlFromSrcAttribute(pageURL, ogLink.getContent("image"));
|
2014-03-31 11:18:22 +02:00
|
|
|
imageUrls.add(imageUrl);
|
|
|
|
_log.trace("OpenGraph getImage = " +imageUrl) ;
|
|
|
|
}
|
2013-01-26 20:02:51 +01:00
|
|
|
else {
|
2014-03-31 11:18:22 +02:00
|
|
|
_log.trace("OpenGraph No Image, trying manuale parsing");
|
2014-04-01 15:00:37 +02:00
|
|
|
ArrayList<String> images = TextTransfromUtils.getImagesWithCleaner(pageURL);
|
2013-01-26 20:02:51 +01:00
|
|
|
if (! images.isEmpty())
|
|
|
|
imageUrls = images;
|
|
|
|
}
|
|
|
|
toReturn = new LinkPreview(title, description, linkToCheck, host, imageUrls);
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2013-01-26 20:02:51 +01:00
|
|
|
/**
|
2014-04-01 15:00:37 +02:00
|
|
|
* return the id as key and the names as value of the vre a user is subscribed to
|
|
|
|
* @param username
|
|
|
|
* @return the id as key and the names as value of the vre a user is subscribed to
|
2013-01-26 20:02:51 +01:00
|
|
|
*/
|
2014-04-01 15:00:37 +02:00
|
|
|
private HashMap<String, String> getUserVreNames(String username) {
|
|
|
|
HashMap<String, String> toReturn = new HashMap<String, String>();
|
2015-04-27 16:52:29 +02:00
|
|
|
for (GroupModel vre : getUserVREs(username)) {
|
|
|
|
if (vre.getGroupName().compareTo(getASLSession().getGroupName())==0)
|
|
|
|
toReturn.put(vre.getGroupId(), vre.getGroupName());
|
|
|
|
}
|
|
|
|
// }
|
2014-04-01 15:00:37 +02:00
|
|
|
|
2014-03-22 17:32:46 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
/**
|
2014-04-01 15:00:37 +02:00
|
|
|
* tell if the user is a portal administrator or not
|
|
|
|
* @param username
|
|
|
|
* @return true if is admin
|
|
|
|
* @throws SystemException
|
|
|
|
* @throws PortalException
|
2014-03-22 17:32:46 +01:00
|
|
|
*/
|
2014-04-01 15:00:37 +02:00
|
|
|
private boolean isAdmin() throws PortalException, SystemException {
|
|
|
|
com.liferay.portal.model.User currUser = OrganizationsUtil.validateUser(getASLSession().getUsername());
|
|
|
|
List<Organization> organizations = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount());
|
|
|
|
Organization rootOrganization = null;
|
|
|
|
for (Organization organization : organizations) {
|
|
|
|
if (organization.getName().equals(OrganizationsUtil.getRootOrganizationName() ) ) {
|
|
|
|
rootOrganization = organization;
|
2014-03-22 17:32:46 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-04-01 15:00:37 +02:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
_log.trace("root: " + rootOrganization.getName() );
|
|
|
|
return (hasRole(ADMIN_ROLE, rootOrganization.getName(), currUser));
|
2014-03-22 17:32:46 +01:00
|
|
|
}
|
2014-04-01 15:00:37 +02:00
|
|
|
catch (NullPointerException e) {
|
|
|
|
_log.error("Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder");
|
|
|
|
return false;
|
2014-03-22 17:32:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-01 15:00:37 +02:00
|
|
|
*
|
|
|
|
* @param rolename
|
|
|
|
* @param organizationName
|
|
|
|
* @param user
|
|
|
|
* @return
|
|
|
|
* @throws SystemException
|
2014-03-31 11:18:22 +02:00
|
|
|
*/
|
2014-04-01 15:00:37 +02:00
|
|
|
private boolean hasRole(String rolename, String organizationName, com.liferay.portal.model.User user) throws SystemException {
|
|
|
|
for (Role role : user.getRoles())
|
|
|
|
if (role.getName().compareTo(rolename) == 0 )
|
|
|
|
return true;
|
|
|
|
return false;
|
2014-03-31 11:18:22 +02:00
|
|
|
}
|
2013-01-26 20:02:51 +01:00
|
|
|
/**
|
2014-04-01 15:00:37 +02:00
|
|
|
*
|
|
|
|
* @param username
|
|
|
|
* @return
|
2013-01-26 20:02:51 +01:00
|
|
|
*/
|
2014-04-01 15:00:37 +02:00
|
|
|
private ArrayList<GroupModel> getUserVREs(String username) {
|
|
|
|
ArrayList<GroupModel> toReturn = new ArrayList<GroupModel>();
|
|
|
|
com.liferay.portal.model.User currUser;
|
|
|
|
try {
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
|
|
|
currUser = OrganizationsUtil.validateUser(username);
|
|
|
|
for (Organization org : currUser.getOrganizations())
|
|
|
|
if (gm.isVRE(org.getOrganizationId()+"")) {
|
|
|
|
GroupModel toAdd = gm.getGroup(""+org.getOrganizationId());
|
|
|
|
toReturn.add(toAdd);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
_log.error("Failed reading User VREs for : " + username);
|
|
|
|
e.printStackTrace();
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
return toReturn;
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
2014-04-01 15:00:37 +02:00
|
|
|
|
|
|
|
private String getScopeByOrganizationId(String vreid) {
|
|
|
|
GroupManager gm = new LiferayGroupManager();
|
|
|
|
try {
|
|
|
|
return gm.getScope(vreid);
|
|
|
|
} catch (Exception e) {
|
|
|
|
_log.error("Could not find a scope for this VREid: " + vreid);
|
|
|
|
return null;
|
|
|
|
}
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|
2014-04-01 15:00:37 +02:00
|
|
|
|
2013-04-11 18:46:58 +02:00
|
|
|
/**
|
|
|
|
* Indicates whether the scope is the whole infrastructure.
|
|
|
|
* @return <code>true</code> if it is, <code>false</code> otherwise.
|
|
|
|
*/
|
|
|
|
private boolean isInfrastructureScope() {
|
2013-09-26 15:44:21 +02:00
|
|
|
ScopeBean scope = new ScopeBean(getASLSession().getScope());
|
|
|
|
return scope.is(Type.INFRASTRUCTURE);
|
2013-04-11 18:46:58 +02:00
|
|
|
}
|
2013-04-16 23:49:16 +02:00
|
|
|
|
2013-04-17 17:29:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return the screennames of the addressee (user logins e.g. pino.pini)
|
|
|
|
*/
|
2014-10-02 19:47:15 +02:00
|
|
|
public ArrayList<ItemBean> getSelectedUserIds(ArrayList<String> fullNames) {
|
2013-04-17 17:29:44 +02:00
|
|
|
if (fullNames == null)
|
2014-10-02 19:47:15 +02:00
|
|
|
return new ArrayList<ItemBean>();
|
2013-04-17 17:29:44 +02:00
|
|
|
else {
|
2014-10-02 19:47:15 +02:00
|
|
|
ArrayList<ItemBean> allUsers = getPortalUsers();
|
|
|
|
ArrayList<ItemBean> toReturn = new ArrayList<ItemBean>();
|
2013-04-17 17:29:44 +02:00
|
|
|
for (String fullName : fullNames)
|
2014-10-02 19:47:15 +02:00
|
|
|
for (ItemBean puser : allUsers) {
|
|
|
|
if (puser.getAlternativeName().compareTo(fullName) == 0) {
|
2013-07-10 17:39:14 +02:00
|
|
|
toReturn.add(puser);
|
2013-04-17 17:29:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 23:49:16 +02:00
|
|
|
@Override
|
2014-10-02 19:47:15 +02:00
|
|
|
public ArrayList<ItemBean> getPortalUsers() {
|
2014-04-10 17:56:29 +02:00
|
|
|
ASLSession session = getASLSession();
|
2014-05-09 17:05:42 +02:00
|
|
|
boolean withinPortal = false;
|
|
|
|
if (isWithinPortal() && session.getUsername().compareTo(TEST_USER) != 0) {
|
|
|
|
withinPortal = true;
|
|
|
|
}
|
2014-04-10 17:56:29 +02:00
|
|
|
return getOrganizationUsers(session.getScope(), session.getUsername(), withinPortal);
|
|
|
|
}
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2014-10-02 19:47:15 +02:00
|
|
|
@Override
|
|
|
|
public ArrayList<ItemBean> getHashtags() {
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
String scope = session.getScope();
|
|
|
|
_log.error("getting hashtags for " + scope);
|
|
|
|
Map<String, Integer> map = store.getVREHashtagsWithOccurrence(scope);
|
|
|
|
ArrayList<HashTagAndOccurrence> toSort = new ArrayList<HashTagAndOccurrence>();
|
|
|
|
_log.trace("Got " + map.keySet().size() + " hashtags");
|
|
|
|
for (String hashtag : map.keySet()) {
|
|
|
|
toSort.add(new HashTagAndOccurrence(hashtag, map.get(hashtag)));
|
|
|
|
}
|
|
|
|
Collections.sort(toSort, Collections.reverseOrder());
|
|
|
|
ArrayList<ItemBean> toReturn = new ArrayList<>();
|
|
|
|
for (HashTagAndOccurrence wrapper : toSort) {
|
2014-10-06 14:16:44 +02:00
|
|
|
String hashtag = wrapper.getHashtag();
|
2014-10-02 19:47:15 +02:00
|
|
|
toReturn.add(new ItemBean(hashtag, hashtag, hashtag, null));
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2014-04-10 17:56:29 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param session the Asl Session
|
|
|
|
* @param withinPortal true when is on Liferay portal
|
|
|
|
* @return the users belonging to the current organization (scope)
|
|
|
|
*/
|
2014-10-02 19:47:15 +02:00
|
|
|
public static ArrayList<ItemBean> getOrganizationUsers(String scope, String currUser, boolean withinPortal) {
|
|
|
|
ArrayList<ItemBean> portalUsers = new ArrayList<ItemBean>();
|
2013-04-16 23:49:16 +02:00
|
|
|
try {
|
|
|
|
if (withinPortal) {
|
|
|
|
UserManager um = new LiferayUserManager();
|
2013-10-03 12:16:57 +02:00
|
|
|
GroupManager gm = new LiferayGroupManager();
|
2014-04-10 17:56:29 +02:00
|
|
|
ScopeBean sb = new ScopeBean(scope);
|
|
|
|
List<UserModel> users = null;
|
2015-04-27 16:52:29 +02:00
|
|
|
|
2014-04-10 17:56:29 +02:00
|
|
|
if (sb.is(Type.INFRASTRUCTURE))
|
|
|
|
users = um.listUsersByGroup(gm.getRootVO().getGroupId());
|
|
|
|
else if (sb.is(Type.VRE)) { //must be in VRE
|
|
|
|
//get the name from the scope
|
|
|
|
String orgName = scope.substring(scope.lastIndexOf("/")+1, scope.length());
|
|
|
|
//ask the users
|
|
|
|
users = um.listUsersByGroup(gm.getGroupId(orgName));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_log.error("Error, you must be in SCOPE VRE OR INFRASTURCTURE, you are in VO SCOPE returning no users");
|
|
|
|
return portalUsers;
|
|
|
|
}
|
2013-10-03 12:16:57 +02:00
|
|
|
for (UserModel user : users) {
|
2014-02-13 16:35:43 +01:00
|
|
|
if (user.getScreenName().compareTo("test.user") != 0 && user.getScreenName().compareTo(currUser) != 0) { //skip test.user & current user
|
2013-04-16 23:49:16 +02:00
|
|
|
String thumbnailURL = "";
|
2013-10-03 12:16:57 +02:00
|
|
|
com.liferay.portal.model.UserModel lifeUser = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), user.getScreenName());
|
|
|
|
thumbnailURL = "/image/user_male_portrait?img_id="+lifeUser.getPortraitId();
|
2014-10-02 19:47:15 +02:00
|
|
|
portalUsers.add(new ItemBean(user.getUserId(), user.getScreenName(), user.getFullname(), thumbnailURL));
|
2013-04-16 23:49:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { //test users
|
2014-10-02 19:47:15 +02:00
|
|
|
portalUsers.add(new ItemBean("12111", "massimiliano.assante", "Test User #1", ""));
|
|
|
|
portalUsers.add(new ItemBean("14111", "massimiliano.assante", "Test Second User #2", ""));
|
|
|
|
portalUsers.add(new ItemBean("11511", "massimiliano.assante", "Test Third User", ""));
|
|
|
|
portalUsers.add(new ItemBean("11611", "massimiliano.assante", "Test Fourth User", ""));
|
|
|
|
portalUsers.add(new ItemBean("11711", "massimiliano.assante", "Test Fifth User", ""));
|
|
|
|
portalUsers.add(new ItemBean("11811", "massimiliano.assante", "Test Sixth User", ""));
|
|
|
|
portalUsers.add(new ItemBean("15811", "massimiliano.assante", "Ninth Testing User", ""));
|
|
|
|
portalUsers.add(new ItemBean("15811", "massimiliano.assante", "Eighth Testing User", ""));
|
|
|
|
portalUsers.add(new ItemBean("11211", "giogio.giorgi", "Seventh Test User", ""));
|
|
|
|
portalUsers.add(new ItemBean("2222", "pino.pinetti", "Tenth Testing User", ""));
|
2013-04-16 23:49:16 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
_log.error("Error in server get all contacts ", e);
|
|
|
|
}
|
|
|
|
return portalUsers;
|
|
|
|
}
|
2013-01-26 20:02:51 +01:00
|
|
|
}
|