diff --git a/pom.xml b/pom.xml index a45eb49..63919a3 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.applicationsupportlayer aslsocial - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT jar Social Portal ASL Extension diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index 814f93e..37484b6 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -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; /** + *

* Use this constructor if you do not need notifications to point back to your applications + *

* @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)"); } /** - * + *

+ * Use this constructor if your artifact is not deployed on the portal and do not need notifications to point back to your applications + *

+ * @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)"); + } + /** + *

* Use this constructor if you do need notifications to point back to your applications, * make sure you create your application profile on the infrastructure. - * + *

* @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(); + } + /** + *

+ * 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. + *

+ * @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()); diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java index 1111144..492e5eb 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java @@ -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. diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java index a13e4a2..a93d9c4 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/EmailPlugin.java @@ -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"); } diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java index b33ff58..d92379f 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/mailing/NotificationMail.java @@ -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());