From 580cf15c6c1dc9520d05dce6d0af168569c26e07 Mon Sep 17 00:00:00 2001 From: "massimiliano.assante" Date: Thu, 25 Feb 2016 17:57:25 +0000 Subject: [PATCH] Fix for Bug #1303 notification of posts do not handle multi tabs git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerSocial@124602 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../social/ApplicationNewsManager.java | 17 +- .../ApplicationNotificationsManager.java | 252 ++++++++++-------- .../social/SocialPortalBridge.java | 62 ++++- .../social/shared/SocialNetworkingUser.java | 66 +++++ 4 files changed, 272 insertions(+), 125 deletions(-) create mode 100644 src/main/java/org/gcube/applicationsupportlayer/social/shared/SocialNetworkingUser.java diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java index 136200d..0ed39d8 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNewsManager.java @@ -14,6 +14,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.common.encryption.StringEncrypter; import org.gcube.common.portal.PortalContext; import org.gcube.common.resources.gcore.ServiceEndpoint; @@ -45,13 +46,23 @@ public class ApplicationNewsManager extends SocialPortalBridge implements NewsMa private static String RUNTIME_RESOURCE_NAME = "SocialPortalStorage"; private static String CATEGORY_NAME = "FTPServer"; /** - * + * deprecated * @param aslSession the ASLSession instance * @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile */ + @Deprecated public ApplicationNewsManager(ASLSession session, String portletClassName) { super(session, portletClassName); } + /** + * + * @param scope the current scope + * @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data + * @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile + */ + public ApplicationNewsManager(String scope, SocialNetworkingUser currUser, String portletClassName) { + super(scope, currUser, portletClassName); + } /** * {@inheritDoc} */ @@ -98,9 +109,7 @@ public class ApplicationNewsManager extends SocialPortalBridge implements NewsMa //add the GET params if necessary if (uriParams != null && uriParams.compareTo("") != 0) uri += "?"+uriParams; - //String scope = getScopeByOrganizationId(""+aslSession.getGroupId()); - String scope = aslSession.getScopeName(); - System.out.println("scope: " + aslSession.getScopeName()); + String scope = currScope; Feed toReturn = new Feed( UUID.randomUUID().toString(), FeedType.PUBLISH, diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java index 60ebacb..cb2ba42 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/ApplicationNotificationsManager.java @@ -7,6 +7,7 @@ import java.util.UUID; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.applicationsupportlayer.social.mailing.EmailPlugin; +import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; @@ -37,27 +38,58 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen private String portalName; private String senderEmail; /** + * deprecated method:please use ApplicationNotificationsManager(String scope, {@link SocialNetworkingUser} currUser, String portletClassName) * Use this constructor if you do not need notifications to point back to your applications - * @param aslSession the ASLSession instance + * @param ASLSession the ASLSession instance */ + @Deprecated public ApplicationNotificationsManager(ASLSession session) { super(session); - portalName = PortalContext.getPortalInstanceName(); + portalName = PortalContext.getConfiguration().getGatewayName(); senderEmail = PortalContext.getConfiguration().getSenderEmail(); _log.warn("Asked for Simple Notification (without redirect to creator)"); } /** + * deprecated method: please use ApplicationNotificationsManager(String scope, {@link SocialNetworkingUser} currUser, String portletClassName) * 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://gcube.wiki.gcube-system.org/gcube/index.php/Social_Networking_Library#Create_Your_Application_Profile + * @see http://wiki.gcube-system.org/gcube/index.php/Social_Networking_Library#Create_Your_Application_Profile * - * @param aslSession the ASLSession instance + * @param ASLSession the ASLSession instance * @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile */ + @Deprecated public ApplicationNotificationsManager(ASLSession session, String portletClassName) { super(session, portletClassName); - portalName = PortalContext.getPortalInstanceName(); + portalName = PortalContext.getConfiguration().getGatewayName(); + senderEmail = PortalContext.getConfiguration().getSenderEmail(); + } + /** + * 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 + */ + public ApplicationNotificationsManager(String scope, SocialNetworkingUser currUser) { + super(scope, currUser); + portalName = PortalContext.getConfiguration().getGatewayName(); + senderEmail = PortalContext.getConfiguration().getSenderEmail(); + _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 + * @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data + * @param portletClassName your portlet class name will be used ad unique identifier for your applicationProfile + */ + public ApplicationNotificationsManager(String scope, SocialNetworkingUser currUser, String portletClassName) { + super(scope, currUser, portletClassName); + portalName = PortalContext.getConfiguration().getGatewayName(); senderEmail = PortalContext.getConfiguration().getSenderEmail(); } /** @@ -85,9 +117,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen else _log.error("Error While trying to save Notification"); } - if (channels.contains(NotificationChannelType.EMAIL)) - EmailPlugin.getInstance().sendNotification(notification2Save, aslSession.getGroupName(), portalName, senderEmail, hashtags); - + if (channels.contains(NotificationChannelType.EMAIL)) + EmailPlugin.getInstance().sendNotification(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()); result = true; @@ -130,9 +162,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), "shared the workspace folder \""+ sharedFolderName +"\" with you", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -151,9 +183,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+unsharedFolderId, "unshared the workspace folder \""+ unsharedFolderName+"\"", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -173,9 +205,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), "upgraded you to Administrator of the workspace folder \""+ sharedFolderName+"\"", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -195,9 +227,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), "downgraded you from Administrator of the workspace folder \""+ sharedFolderName+"\"", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -217,9 +249,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+renamedFolderId, "renamed your shared folder \""+ previousName +"\" as \"" + newName+"\"", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -242,9 +274,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), "added "+ user.getFullname() +" to your workspace shared folder \""+ sharedFolder.getName()+"\"", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -273,9 +305,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), "added "+ addedUsersFullNames +" to your workspace shared folder \""+ sharedFolder.getName()+"\"", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -296,9 +328,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), "unshared his shared folder \""+ sharedFolder.getName() + "\" from your workspace", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -321,9 +353,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+item.getParent().getId(), notifyText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -345,9 +377,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), notifyText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -369,9 +401,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+sharedFolder.getId(), notifyText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -393,9 +425,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+item.getParent().getId(), notifyText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -417,9 +449,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?itemid="+renamedItem.getParent().getId(), notifyText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -451,9 +483,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen + messageText +"" + otherRecipientNames + attachmentsNotice, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not, optionalParams); } @@ -462,9 +494,8 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ @Override public boolean notifyPost(String userIdToNotify, String feedid, String feedText, String ... hashtags) { - StringBuilder notificationText = new StringBuilder(); - notificationText.append("posted a news on ").append(aslSession.getGroupName()).append(":") // has done something + notificationText.append("posted a news on ").append(currGroupName).append(":") // has done something .append("

").append(feedText).append(" ") .append("

"); @@ -477,9 +508,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+feedid, notificationText.toString(), false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not, hashtags); } /** @@ -499,9 +530,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen + "border-left: 3px solid #ccc; font-style: italic;\">\"" + feedText +"\"", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId(), + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId(), commentKey); return saveNotification(not); } @@ -510,7 +541,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ @Override public boolean notifyCommentReply(String userIdToNotify, String feedid, String commentText, String feedOwnerFullName, String feedOwnerId, String commentKey) { - String notificationText = (aslSession.getUsername().compareTo(feedOwnerId) == 0) ? + String notificationText = (currUser.getUsername().compareTo(feedOwnerId) == 0) ? "also commented on his post: " + "
\"" + commentText +"\"
" @@ -527,9 +558,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+feedid, notificationText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId(), + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId(), commentKey); return saveNotification(not); } @@ -549,9 +580,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen + "
\"" + commentText +"\"
", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId(), + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId(), commentKey); return saveNotification(not); } @@ -570,9 +601,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen "mentioned you: " + "
\"" + feedText +"\"
", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId(), + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId(), commentKey); return saveNotification(not); } @@ -591,9 +622,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+feedid, "favorited/subscribed to one of your post", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } /** @@ -618,9 +649,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+documentWorkflowId, "viewed document workflow " + escapeHtml(documentName), false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } /** @@ -638,9 +669,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+documentWorkflowId, "updated document workflow " + escapeHtml(documentName), false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } /** @@ -648,8 +679,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen */ @Override public boolean notifyDocumentWorkflowTaskRequest(String userIdToNotify, String documentWorkflowId, String documentName, String assignedRoleName) { - - String notificationText = "in " + aslSession.getGroupName() + " you are requested to perform a new task in the Document Workflow titled: " + String notificationText = "in " + currGroupName + " you are requested to perform a new task in the Document Workflow titled: " + escapeHtml(documentName) + ". Your role is: " + assignedRoleName; Notification not = new Notification( @@ -661,9 +691,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+documentWorkflowId, notificationText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); @@ -682,11 +712,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+documentWorkflowId, "forwarded the Document Workflow titled: " + escapeHtml(documentName) + - " from status \"" + fromStepName + "\" to status \"" + toStepName +"\". In " + aslSession.getGroupName(), + " from status \"" + fromStepName + "\" to status \"" + toStepName +"\". In " + currGroupName, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -703,11 +733,11 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen new Date(), getApplicationUrl()+"?oid="+documentWorkflowId, "has performed the last needed forward on a Document Workflow titled: " + escapeHtml(documentName) + ". " + - "Step \"" + fromStepName + "\" is now complete. The next step is \"" + toStepName +"\". In " + aslSession.getGroupName(), + "Step \"" + fromStepName + "\" is now complete. The next step is \"" + toStepName +"\". In " + currGroupName, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -727,9 +757,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?oid="+documentWorkflowId, notificationText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -746,7 +776,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen } StringBuilder notificationText = new StringBuilder(); - notificationText.append("added the following event in the ").append(aslSession.getGroupName()).append(" shared calendar: ") // has done something + notificationText.append("added the following event in the ").append(currGroupName).append(" shared calendar: ") // has done something .append("").append(eventTitle).append("
") .append("
Time: ").append(spf.format(startDate)).append(endDateToDisplay).append("
") .append("
Category: ").append(eventType); @@ -760,9 +790,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl(), notificationText.toString(), false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -780,7 +810,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen } StringBuilder notificationText = new StringBuilder(); - notificationText.append("edited the following event in the ").append(aslSession.getGroupName()).append(" shared calendar: ") // has done something + notificationText.append("edited the following event in the ").append(currGroupName).append(" shared calendar: ") // has done something .append("").append(eventTitle).append("
") .append("
Time: ").append(spf.format(startDate)).append(endDateToDisplay).append("
") .append("
Category: ").append(eventType); @@ -794,9 +824,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl(), notificationText.toString(), false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -813,7 +843,7 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen } StringBuilder notificationText = new StringBuilder(); - notificationText.append("deleted the following event in the ").append(aslSession.getGroupName()).append(" shared calendar: ") // has done something + notificationText.append("deleted the following event in the ").append(currGroupName).append(" shared calendar: ") // has done something .append("").append(eventTitle).append("
") .append("
Was planned: ").append(spf.format(startDate)).append(endDateToDisplay).append("
") .append("
Category: ").append(eventType); @@ -827,9 +857,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl(), notificationText.toString(), false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -847,9 +877,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen getApplicationUrl()+"?"+encodedTabularResourceParams, "shared the Tabular Resource \""+ tabularResourceName +"\" with you", false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } @@ -878,9 +908,9 @@ public class ApplicationNotificationsManager extends SocialPortalBridge implemen url, notificationText, false, - aslSession.getUsername(), - aslSession.getUserFullName(), - aslSession.getUserAvatarId()); + currUser.getUsername(), + currUser.getFullname(), + currUser.getUserAvatarId()); return saveNotification(not); } diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java index a9ad2f5..99a354b 100644 --- a/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java +++ b/src/main/java/org/gcube/applicationsupportlayer/social/SocialPortalBridge.java @@ -10,6 +10,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.applicationsupportlayer.social.ex.ApplicationProfileNotFoundException; +import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.common.portal.PortalContext; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; @@ -36,28 +37,58 @@ public class SocialPortalBridge { private static final Logger _log = LoggerFactory.getLogger(SocialPortalBridge.class); - protected ASLSession aslSession; + protected String currScope; + protected String currGroupName; + protected SocialNetworkingUser currUser; protected ApplicationProfile applicationProfile; //unique instance private static DatabookStore store; - /** - * - * @param session + * deprecated: please use SocialPortalBridge(String scope, {@link SocialNetworkingUser} currUser) + * @param session the ASL Session */ - public SocialPortalBridge(ASLSession session, String portletClassName) { - this.aslSession = session; + @Deprecated + protected SocialPortalBridge(ASLSession session) { + this.currScope = session.getScope(); + this.currGroupName = extractGroupNameFromScope(currScope); + this.currUser = new SocialNetworkingUser(session.getUsername(), session.getUserEmailAddress(), session.getUserFullName(), session.getUserAvatarId()); + this.applicationProfile = null; + _log.warn("Using deprecated method of ASLSocial, please consider to upgrade your code. Current scope=" + currScope + " currentGroup name="+currGroupName); + } + /** + * deprecated: please use SocialPortalBridge(String scope, {@link SocialNetworkingUser} currUser, String portletClassName) + * @param session the ASL Session + * @param portletClassName your application unique identifier registered in the infrastructure + */ + @Deprecated + protected SocialPortalBridge(ASLSession session, String portletClassName) { + this(session); this.applicationProfile = getProfileFromInfrastrucure(portletClassName); } /** * - * @param session + * @param scope the current scope + * @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data */ - public SocialPortalBridge(ASLSession session) { - this.aslSession = session; + public SocialPortalBridge(String scope, SocialNetworkingUser currUser) { + this.currScope = scope; + this.currGroupName = extractGroupNameFromScope(currScope); + this.currUser = currUser; this.applicationProfile = null; + _log.debug("ASLSocial instanciated with current scope=" + currScope + " currentGroup name="+currGroupName); } + /** + * + * @param scope the current scope + * @param currUser an instance of {@link SocialNetworkingUser} filled with the required user data + * @param portletClassName your application unique identifier registered in the infrastructure + */ + public SocialPortalBridge(String scope, SocialNetworkingUser currUser, String portletClassName) { + this(scope, currUser); + this.applicationProfile = getProfileFromInfrastrucure(portletClassName); + } + /** * * @return the unique instance of the store @@ -104,7 +135,7 @@ public class SocialPortalBridge { * @return the applicationProfile profile */ private ApplicationProfile getProfileFromInfrastrucure(String portletClassName) { - ScopeBean scope = new ScopeBean(aslSession.getScope()); + ScopeBean scope = new ScopeBean(currScope); _log.debug("Trying to fetch applicationProfile profile from the infrastructure for " + portletClassName + " scope: " + scope); try { ApplicationProfile toReturn = new ApplicationProfile(); @@ -182,4 +213,15 @@ public class SocialPortalBridge { } } + + private String extractGroupNameFromScope(String scope) throws IllegalArgumentException { + if (scope.indexOf('/') > -1) { + String[] splits = scope.split("/"); + String groupName = splits[splits.length-1]; + return groupName; + } + else { + throw new IllegalArgumentException("Scope " + scope + " is not a vaild scope, it should start with '/' "); + } + } } diff --git a/src/main/java/org/gcube/applicationsupportlayer/social/shared/SocialNetworkingUser.java b/src/main/java/org/gcube/applicationsupportlayer/social/shared/SocialNetworkingUser.java new file mode 100644 index 0000000..19ffe7e --- /dev/null +++ b/src/main/java/org/gcube/applicationsupportlayer/social/shared/SocialNetworkingUser.java @@ -0,0 +1,66 @@ +package org.gcube.applicationsupportlayer.social.shared; + +import java.io.Serializable; + +@SuppressWarnings("serial") +public class SocialNetworkingUser implements Serializable{ + + private String username; + private String email; + private String fullname; + private String userAvatarId; + + public SocialNetworkingUser() { + super(); + } + + public SocialNetworkingUser(String username, String email, String fullname, + String userAvatarId) { + super(); + this.username = username; + this.email = email; + this.fullname = fullname; + this.userAvatarId = userAvatarId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getFullname() { + return fullname; + } + + public void setFullname(String fullname) { + this.fullname = fullname; + } + + public String getUserAvatarId() { + return userAvatarId; + } + + public void setUserAvatarId(String userAvatarId) { + this.userAvatarId = userAvatarId; + } + + @Override + public String toString() { + return "SocialNetworkingUser [username=" + username + ", email=" + email + + ", fullname=" + fullname + ", userAvatarId=" + userAvatarId + + "]"; + } + + +}