modified some methods to support usage from remote service and remove the local impl.

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@141613 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-01-18 11:37:27 +00:00
parent 5bf6b8d078
commit 1abe50026c
5 changed files with 55 additions and 23 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Social Portal ASL Extension</name>
<description>

View File

@ -21,6 +21,7 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalExcep
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.impl.ws.LiferayWSUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,8 +45,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
private String senderEmail;
private String portalURL;
private String siteLandingPagePath;
private UserManager userManager;
/**
* <p>
* Use this constructor if you do not need notifications to point back to your applications
* </p>
* @param scope the current scope
* @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data
* @param site an instance of {@link SocialNetworkingSite} filled with the required data
@ -53,14 +57,30 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
public ApplicationNotificationsManager(SocialNetworkingSite site, String scope, SocialNetworkingUser currUser) {
super(scope, currUser);
setContext(site);
userManager = new LiferayUserManager();
_log.warn("Asked for Simple Notification (without redirect to creator)");
}
/**
*
* <p>
* Use this constructor if your artifact is not deployed on the portal and do not need notifications to point back to your applications
* </p>
* @param userManager a remote implementation of {@link UserManager},see {@link LiferayWSUserManager}
* @param site an instance of {@link SocialNetworkingSite} filled with the required data
* @param scope the current scope
* @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data
*/
public ApplicationNotificationsManager(UserManager userManager, SocialNetworkingSite site, String scope, SocialNetworkingUser currUser) {
super(scope, currUser);
setContext(site);
this.userManager = userManager;
_log.warn("Asked for Simple Notification (without redirect to creator)");
}
/**
* <p>
* Use this constructor if you do need notifications to point back to your applications,
* make sure you create your application profile on the infrastructure.
*
* </p>
* @see http://wiki.gcube-system.org/gcube/index.php/Social_Networking_Library#Create_Your_Application_Profile
*
* @param scope the current scope
@ -71,6 +91,25 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
public ApplicationNotificationsManager(SocialNetworkingSite site, String scope, SocialNetworkingUser currUser, String portletClassName) {
super(scope, currUser, portletClassName);
setContext(site);
userManager = new LiferayUserManager();
}
/**
* <p>
* Use this constructor if your artifact is not deployed on the portal and you do need notifications to point back to your applications,
* make sure you create your application profile on the infrastructure.
* </p>
* @see http://wiki.gcube-system.org/gcube/index.php/Social_Networking_Library#Create_Your_Application_Profile
*
* @param userManager a remote implementation of {@link UserManager},see {@link LiferayWSUserManager}
* @param scope the current scope
* @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data
* @param site an instance of {@link SocialNetworkingSite} filled with the required data
* @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile
*/
public ApplicationNotificationsManager(UserManager userManager, SocialNetworkingSite site, String scope, SocialNetworkingUser currUser, String portletClassName) {
super(scope, currUser, portletClassName);
setContext(site);
this.userManager = userManager;
}
/**
* set the current portal context (name, emal, url)
@ -114,7 +153,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen
_log.error("Error While trying to save Notification");
}
if (channels.contains(NotificationChannelType.EMAIL)) {
EmailPlugin.getInstance(currScope).sendNotification(portalURL, siteLandingPagePath, notification2Save, currGroupName, portalName, senderEmail, hashtags);
EmailPlugin.getInstance(userManager, currScope).sendNotification(portalURL, siteLandingPagePath, notification2Save, currGroupName, portalName, senderEmail, hashtags);
}
if (channels.isEmpty()) {
_log.info("Notification was not needed as "+ notification2Save.getUserid() +" decided not to be notified for " + notification2Save.getType());

View File

@ -19,8 +19,6 @@ import org.gcube.portal.databook.shared.ApplicationProfile;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
@ -75,16 +73,6 @@ public class SocialPortalBridge {
}
return store;
}
protected String getScopeByVREId(long vreid) {
GroupManager gm = new LiferayGroupManager();
try {
return gm.getInfrastructureScope(vreid);
} catch (Exception e) {
_log.error("Could not find a scope for this VREid: " + vreid);
return null;
}
}
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.

View File

@ -3,6 +3,7 @@ package org.gcube.applicationsupportlayer.social.mailing;
import java.util.ArrayList;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -17,19 +18,21 @@ public class EmailPlugin {
private static final Logger _log = LoggerFactory.getLogger(EmailPlugin.class);
protected static final int SECONDS2WAIT = 60;
private static EmailPlugin singleton;
private UserManager userManager;
/**
*
* @param context the infrastucture context (scope)
* @return
*/
public static EmailPlugin getInstance(String context) {
public static EmailPlugin getInstance(UserManager userManager, String context) {
if (singleton == null) {
singleton = new EmailPlugin(context);
singleton = new EmailPlugin(userManager, context);
}
return singleton;
}
private EmailPlugin(String context) {
private EmailPlugin(UserManager userManager, String context) {
this.userManager = userManager;
new EmailNotificationsConsumer(context).start();
}
@ -42,7 +45,7 @@ public class EmailPlugin {
* @param senderEmail
*/
public void sendNotification(String portalURL, String siteLandingPagePath, Notification notification2Save, String vreName, String portalName, String senderEmail, String ... hashtags) {
EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(portalURL, siteLandingPagePath, notification2Save, vreName, portalName, senderEmail, hashtags));
EmailNotificationProducer thread = new EmailNotificationProducer(new NotificationMail(userManager, portalURL, siteLandingPagePath, notification2Save, vreName, portalName, senderEmail, hashtags));
thread.start();
_log.trace("Thread notification Mail started OK");
}

View File

@ -18,7 +18,7 @@ import org.gcube.portal.databook.shared.Comment;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,6 +31,7 @@ public class NotificationMail {
private static final Logger _log = LoggerFactory.getLogger(NotificationMail.class);
private Notification notification2Send;
private UserManager userManager;
private String vreName;
private String portalName;
private String senderEmail;
@ -40,8 +41,9 @@ public class NotificationMail {
private static DatabookStore store = new DBCassandraAstyanaxImpl();
public NotificationMail(String portalURL, String siteLandingPagePath, Notification notification2Send, String vreName, String portalName, String senderEmail, String ... hashtags) {
public NotificationMail(UserManager userManager, String portalURL, String siteLandingPagePath, Notification notification2Send, String vreName, String portalName, String senderEmail, String ... hashtags) {
super();
this.userManager = userManager;
this.portalURL = portalURL;
this.siteLandingPagePath = siteLandingPagePath;
this.notification2Send = notification2Send;
@ -55,7 +57,7 @@ public class NotificationMail {
GCubeUser user = null;
try {
user = new LiferayUserManager().getUserByUsername(notification2Send.getUserid());
user = userManager.getUserByUsername(notification2Send.getUserid());
} catch (Exception e1) {
e1.printStackTrace();
_log.warn("While trying to get email for user/group: " + notification2Send.getUserid());