Compatible with social model 2.0.0
This commit is contained in:
parent
f769c3d1ce
commit
c3f9453653
|
@ -10,6 +10,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
- Removed HomeLibrary Dependency
|
||||
|
||||
- Feature #26536 Removed social networking library dependency
|
||||
|
||||
## [v2.4.0] - 2019-12-30
|
||||
|
||||
- Ported to git
|
||||
|
|
17
pom.xml
17
pom.xml
|
@ -66,6 +66,18 @@
|
|||
<artifactId>aslcore</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--needs to be provided -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.social-networking</groupId>
|
||||
<artifactId>social-service-model</artifactId>
|
||||
<version>[1.2.0-SNAPSHOT, 2.0.0)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.social-networking</groupId>
|
||||
<artifactId>social-service-client</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.applicationsupportlayer</groupId>
|
||||
<artifactId>aslsocial</artifactId>
|
||||
|
@ -75,11 +87,6 @@
|
|||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>storagehub-client-library</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>social-networking-library</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
|
|
@ -22,12 +22,11 @@ import org.gcube.common.portal.PortalContext;
|
|||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
||||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.socialmail.EmailPopAccount;
|
||||
import org.gcube.portal.socialmail.PeriodicTask;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.social_networking.social_networking_client_library.LibClient;
|
||||
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys;
|
||||
|
@ -51,10 +50,14 @@ public class PortalSchedulerService extends HttpServlet {
|
|||
private static final String POP3_SERVER_NAME = "Pop3MailServer";
|
||||
|
||||
|
||||
private static DatabookStore store;
|
||||
private static LibClient libClient;
|
||||
|
||||
public void init() {
|
||||
store = new DBCassandraAstyanaxImpl();
|
||||
try {
|
||||
libClient = new LibClient();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,7 +77,7 @@ public class PortalSchedulerService extends HttpServlet {
|
|||
int pollingInterval = getPollingInterval();
|
||||
|
||||
ScheduledExecutorService pop3Scheduler = Executors.newScheduledThreadPool(1);
|
||||
pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(store, popAccount, request), 0, pollingInterval, TimeUnit.MINUTES);
|
||||
pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(libClient, popAccount, request), 0, pollingInterval, TimeUnit.MINUTES);
|
||||
String portalName = "unknown";
|
||||
try {
|
||||
popAccount.getPortalName() ;
|
||||
|
|
|
@ -42,18 +42,18 @@ import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|||
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.portal.databook.server.DatabookStore;
|
||||
import org.gcube.portal.databook.shared.Comment;
|
||||
import org.gcube.portal.databook.shared.Feed;
|
||||
import org.gcube.portal.databook.shared.Like;
|
||||
import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
|
||||
import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
|
||||
import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
|
||||
import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
|
||||
import org.gcube.social_networking.socialnetworking.model.shared.Comment;
|
||||
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
||||
import org.gcube.social_networking.socialnetworking.model.shared.Like;
|
||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.ColumnNameNotFoundException;
|
||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostIDNotFoundException;
|
||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PostTypeNotFoundException;
|
||||
import org.gcube.social_networking.socialnetworking.model.shared.exceptions.PrivacyLevelTypeNotFoundException;
|
||||
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||
import org.gcube.portal.notifications.thread.CommentNotificationsThread;
|
||||
import org.gcube.portal.notifications.thread.LikeNotificationsThread;
|
||||
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
|
||||
import org.gcube.social_networking.social_networking_client_library.LibClient;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
@ -71,13 +71,13 @@ public class PeriodicTask implements Runnable {
|
|||
private static final Log _log = LogFactoryUtil.getLog(PeriodicTask.class);
|
||||
private static final String APP_ID_NEWSFEED = "org.gcube.portlets.user.newsfeed.server.NewsServiceImpl";
|
||||
|
||||
private DatabookStore socialStore;
|
||||
private LibClient libClient;
|
||||
private EmailPopAccount popAccount;
|
||||
private SocialNetworkingSite site;
|
||||
|
||||
public PeriodicTask(DatabookStore store, EmailPopAccount popAccount, HttpServletRequest request) {
|
||||
public PeriodicTask(LibClient libClient, EmailPopAccount popAccount, HttpServletRequest request) {
|
||||
super();
|
||||
this.socialStore = store;
|
||||
this.libClient = libClient;
|
||||
this.popAccount = popAccount;
|
||||
this.site = new SocialNetworkingSite(request);
|
||||
String serverName = request.getServerName();
|
||||
|
@ -204,8 +204,8 @@ public class PeriodicTask implements Runnable {
|
|||
if (fakeSession != null && subAddressField != null) {
|
||||
if (subAddressField.endsWith(AppType.POST.toString()) || subAddressField.endsWith(AppType.POST.toString().toLowerCase())) { //it is a post, a comment on a post or a mention
|
||||
_log.debug("Looks like a post, a comment on a post or a mention to me");
|
||||
String feedId = extractIdentifier(subAddressField);
|
||||
handlePostReply(portalName, feedId, message, fakeSession);
|
||||
String postId = extractIdentifier(subAddressField);
|
||||
handlePostReply(portalName, postId, message, fakeSession);
|
||||
}
|
||||
else if (subAddressField.endsWith(AppType.MSG.toString()) || subAddressField.endsWith(AppType.MSG.toString().toLowerCase())) { //it is a message
|
||||
_log.debug("Looks like a message reply to me");
|
||||
|
@ -370,7 +370,7 @@ public class PeriodicTask implements Runnable {
|
|||
/**
|
||||
* this method manages the replies coming from post notifications
|
||||
* @param portalName
|
||||
* @param postId the identifier in the System managing the feeds
|
||||
* @param postId the identifier in the System managing the posts
|
||||
* @param message the javax mail Message instance
|
||||
* @param fakeSession
|
||||
* @throws Exception
|
||||
|
@ -391,13 +391,8 @@ public class PeriodicTask implements Runnable {
|
|||
|
||||
_log.debug("The EscapedCommentText =>" + escapedCommentText);
|
||||
boolean commentCommitResult = false;
|
||||
try {
|
||||
if (socialStore.addComment(comment))
|
||||
commentCommitResult = true;
|
||||
} catch (FeedIDNotFoundException e) {
|
||||
_log.error("Related post not found for this comment " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (libClient.addCommentLib(comment))
|
||||
commentCommitResult = true;
|
||||
if (commentCommitResult) { //the notifications should start
|
||||
notifyUsersInvolved(comment, escapedCommentText, postId, fakeSession);
|
||||
}
|
||||
|
@ -412,7 +407,7 @@ public class PeriodicTask implements Runnable {
|
|||
*/
|
||||
private void likePost(String postId, ASLSession fakeSession) {
|
||||
if (postId == null || postId.compareTo("") == 0) {
|
||||
_log.warn("Found email with no feedId from " + fakeSession.getUserEmailAddress() + ". Going to trash it");
|
||||
_log.warn("Found email with no postId from " + fakeSession.getUserEmailAddress() + ". Going to trash it");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -421,18 +416,13 @@ public class PeriodicTask implements Runnable {
|
|||
new Date(), postId, fakeSession.getUserFullName(), fakeSession.getUserAvatarId());
|
||||
|
||||
boolean likeCommitResult = false;
|
||||
try {
|
||||
if (socialStore.like(like));
|
||||
likeCommitResult = true;
|
||||
} catch (FeedIDNotFoundException e) {
|
||||
_log.error("Related post not found for this like " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (libClient.likeLib(like));
|
||||
likeCommitResult = true;
|
||||
if (likeCommitResult) { //the notification should be delivered to the post owner
|
||||
try {
|
||||
Feed post = socialStore.readFeed(postId);
|
||||
String feedOwnerId = post.getEntityId();
|
||||
boolean isAppFeed = post.isApplicationFeed();
|
||||
Post post = libClient.readPostLib(postId);
|
||||
String postOwnerId = post.getEntityId();
|
||||
boolean isApppost = post.isApplicationPost();
|
||||
|
||||
NotificationsManager nm = new ApplicationNotificationsManager(
|
||||
site,
|
||||
|
@ -440,8 +430,8 @@ public class PeriodicTask implements Runnable {
|
|||
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId()),
|
||||
APP_ID_NEWSFEED
|
||||
);
|
||||
if (! fakeSession.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
||||
boolean result = nm.notifyLikedFeed(feedOwnerId, postId, "");
|
||||
if (! fakeSession.getUsername().equals(postOwnerId) && (!isApppost)) {
|
||||
boolean result = nm.notifyLikedPost(postOwnerId, postId, "");
|
||||
_log.trace("Like Notification to post owner added? " + result);
|
||||
}
|
||||
}
|
||||
|
@ -453,48 +443,48 @@ public class PeriodicTask implements Runnable {
|
|||
/**
|
||||
* this method take care of notify all the users that need to be notified when someone comment
|
||||
* @param comment
|
||||
* @param feedId
|
||||
* @param postId
|
||||
* @param fakeSession
|
||||
* @throws PrivacyLevelTypeNotFoundException
|
||||
* @throws FeedTypeNotFoundException
|
||||
* @throws FeedIDNotFoundException
|
||||
* @throws PostTypeNotFoundException
|
||||
* @throws PostIDNotFoundException
|
||||
* @throws ColumnNameNotFoundException
|
||||
*/
|
||||
private void notifyUsersInvolved(Comment comment, String commentText, String feedId, ASLSession fakeSession) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException {
|
||||
Feed post = socialStore.readFeed(feedId);
|
||||
String feedOwnerId = post.getEntityId();
|
||||
boolean isAppFeed = post.isApplicationFeed();
|
||||
private void notifyUsersInvolved(Comment comment, String commentText, String postId, ASLSession fakeSession) throws PrivacyLevelTypeNotFoundException, PostTypeNotFoundException, PostIDNotFoundException, ColumnNameNotFoundException {
|
||||
Post post = libClient.readPostLib(postId);
|
||||
String postOwnerId = post.getEntityId();
|
||||
boolean isApppost = post.isApplicationPost();
|
||||
|
||||
//if the user who commented this post is not the user who posted it notifies the poster user (Feed owner)
|
||||
//if the user who commented this post is not the user who posted it notifies the poster user (post owner)
|
||||
NotificationsManager nm = new ApplicationNotificationsManager(
|
||||
site,
|
||||
post.getVreid(),
|
||||
new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId()),
|
||||
APP_ID_NEWSFEED
|
||||
);
|
||||
if (! fakeSession.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
|
||||
boolean result = nm.notifyOwnCommentReply(feedOwnerId, feedId, commentText, comment.getKey());
|
||||
if (! fakeSession.getUsername().equals(postOwnerId) && (!isApppost)) {
|
||||
boolean result = nm.notifyOwnCommentReply(postOwnerId, postId, commentText, comment.getKey());
|
||||
_log.trace("Comment Notification to post owner added? " + result);
|
||||
}
|
||||
|
||||
//if there are users who liked this post they get notified, asynchronously with this thread
|
||||
ArrayList<Like> likes = getAllLikesByFeed(feedId);
|
||||
Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, likes, feedOwnerId, comment.getKey()));
|
||||
ArrayList<Like> likes = getAllLikesByPost(postId);
|
||||
Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, likes, postOwnerId, comment.getKey()));
|
||||
likesThread.start();
|
||||
|
||||
UserManager userManager = new LiferayUserManager();
|
||||
//notify the other users who commented this post (excluding the ones above)
|
||||
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(socialStore, userManager, fakeSession.getUsername(), comment.getFeedid(), commentText, nm, feedOwnerId, comment.getKey(), likes));
|
||||
Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(userManager, fakeSession.getUsername(), comment.getPostid(), commentText, nm, postOwnerId, comment.getKey(), likes));
|
||||
commentsNotificationthread.start();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param feedid
|
||||
* @param postid
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<Like> getAllLikesByFeed(String feedid) {
|
||||
_log.trace("Asking likes for " + feedid);
|
||||
ArrayList<Like> toReturn = (ArrayList<Like>) socialStore.getAllLikesByFeed(feedid);
|
||||
public ArrayList<Like> getAllLikesByPost(String postid) {
|
||||
_log.trace("Asking likes for " + postid);
|
||||
ArrayList<Like> toReturn = (ArrayList<Like>) libClient.getAllLikesByPostLib(postid);
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue