From d0222dc355f87a4d3921f7a800aa0c5e3204ec93 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Mon, 14 Nov 2016 17:03:55 +0000 Subject: [PATCH] removed ASL Session, ported to gCube Client Context git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@134138 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 6 +- .settings/org.eclipse.wst.common.component | 2 +- pom.xml | 19 +- .../shareupdates/client/ShareUpdates.java | 14 +- .../server/ShareUpdateServiceImpl.java | 176 +++++++----------- .../server/portlet/ShareUpdatesPortlet.java | 18 +- .../user/shareupdates/test/TestForDeploy.java | 19 -- 7 files changed, 78 insertions(+), 176 deletions(-) delete mode 100644 src/test/java/org/gcube/portlets/user/shareupdates/test/TestForDeploy.java diff --git a/.classpath b/.classpath index a463a53..0c9cd5a 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -39,5 +39,5 @@ - + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 0c6f3eb..8907d91 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -5,7 +5,7 @@ - + uses diff --git a/pom.xml b/pom.xml index ad3f4df..d50a4b8 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user share-updates war - 2.1.0-SNAPSHOT + 2.2.0-SNAPSHOT gCube Share Updates Portlet gCube Share Updates for exchanging updates with other users of VREs. @@ -72,6 +72,7 @@ org.gcube.common.portal portal-manager + provided org.gcube.portal @@ -83,11 +84,6 @@ notifications-common-library provided - - org.gcube.applicationsupportlayer - aslcore - provided - org.gcube.applicationsupportlayer aslsocial @@ -130,10 +126,6 @@ storage-manager-wrapper provided - - org.gcube.applicationsupportlayer - accesslogger - org.swinglabs pdf-renderer @@ -173,16 +165,9 @@ home-library-jcr provided - - org.gcube.portal - custom-portal-handler - [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) - provided - org.gcube.dvos usermanagement-core - [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) provided diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdates.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdates.java index 308d16a..428d9db 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdates.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/ShareUpdates.java @@ -1,11 +1,8 @@ package org.gcube.portlets.user.shareupdates.client; -import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper; import org.gcube.portlets.user.shareupdates.client.view.ShareUpdateForm; import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.user.client.Window.Location; -import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.RootPanel; /** @@ -16,15 +13,6 @@ import com.google.gwt.user.client.ui.RootPanel; public class ShareUpdates implements EntryPoint { public void onModuleLoad() { - // start UI and related stuff - ClientScopeHelper.getService().setScope(Location.getHref(), new AsyncCallback() { - @Override - public void onSuccess(Boolean result) { - RootPanel.get("shareUpdateDiv").add(new ShareUpdateForm()); - } - @Override - public void onFailure(Throwable caught) { - } - }); + RootPanel.get("shareUpdateDiv").add(new ShareUpdateForm()); } } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index d224f13..2456a7f 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -19,8 +19,6 @@ import java.util.UUID; import javax.net.ssl.HttpsURLConnection; import org.apache.commons.validator.routines.UrlValidator; -import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.application.framework.core.session.SessionManager; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; @@ -34,7 +32,6 @@ 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; -import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.Attachment; @@ -105,26 +102,6 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar store.closeConnection(); } - - /** - * the current ASsLSession - * @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"); - user = getDevelopmentUser(); - SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube/devsec/devVRE"); - } - return SessionManager.getInstance().getASLSession(sessionID, user); - } - public String getDevelopmentUser() { - String user = TEST_USER; - // user = "costantino.perciante"; - return user; - } /** * * @return true if you're running into the portal, false if in development @@ -134,12 +111,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar UserLocalServiceUtil.getService(); return true; } - catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) { + catch (Exception ex) { _log.trace("Development Mode ON"); return false; } } - /** * Share post that could contain a link preview. */ @@ -162,26 +138,14 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar escapedFeedText = Utils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers, getThreadLocalRequest()); } - // get session - 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(); - } - } + PortalContext context = PortalContext.getConfiguration(); + GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest()); + String username = currUser.getUsername(); + String email = currUser.getEmail(); + String fullName = currUser.getFullname(); + String thumbnailAvatarURL = currUser.getUserAvatarId(); + // get data from the preview of the link String linkTitle = preview.getTitle(); String linkDesc = preview.getDescription(); @@ -195,7 +159,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar //get the VRE scope if single channel post String vreScope2Set = ""; if (pLevel == PrivacyLevel.SINGLE_VRE && vreOrgId != null) { - vreScope2Set = (withinPortal) ? getScopeByGroupId(vreOrgId) : session.getScope(); + vreScope2Set = context.getCurrentScope(getThreadLocalRequest()); } // build the feed to share (and save on cassandra) @@ -283,24 +247,13 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar escapedFeedText = Utils.convertMentionPeopleAnchorHTML(escapedFeedText, mentionedUsers, getThreadLocalRequest()); } - ASLSession session = getASLSession(); - String username = session.getUsername(); - String email = username+"@isti.cnr.it"; - String fullName = username+" FULL"; - String thumbnailAvatarURL = "images/Avatar_default.png"; + PortalContext context = PortalContext.getConfiguration(); + GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest()); - 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(); - } - } + String username = currUser.getUsername(); + String email = currUser.getEmail(); + String fullName = currUser.getFullname(); + String thumbnailAvatarURL = currUser.getUserAvatarId(); // Managing attachments: the first one will use the same fields of a link preview. // If more than one attachments are present, they will be saved as Attachment objects. @@ -366,7 +319,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar //get the VRE scope if single channel post String vreScope2Set = ""; if (pLevel == PrivacyLevel.SINGLE_VRE && vreOrgId != null ) { - vreScope2Set = (withinPortal) ? getScopeByGroupId(vreOrgId) : session.getScope(); + vreScope2Set = context.getCurrentScope(getThreadLocalRequest()); } Feed toShare = null; @@ -568,46 +521,31 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar @Override public UserSettings getUserSettings() { try { - ASLSession session = getASLSession(); - String username = session.getUsername(); + PortalContext context = PortalContext.getConfiguration(); + GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest()); + String username = currUser.getUsername(); _log.debug("getUserSettings() for " + username); - String email = username+"@isti.cnr.it"; - String fullName = username+" FULL"; - String thumbnailURL = "images/Avatar_default.png"; - - if (isWithinPortal() && username.compareTo(TEST_USER) != 0) { - UserManager um = new LiferayUserManager(); - GCubeUser user = um.getUserByUsername(username); - - thumbnailURL = user.getUserAvatarURL(); - fullName = user.getFullname(); - email = user.getEmail(); - final String profilePageURL = - GCubePortalConstants.PREFIX_GROUP_URL + - PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest())+ - GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; - String accountURL = profilePageURL; - try { - accountURL = ""; - }catch (NullPointerException e) { - e.printStackTrace(); - } - HashMap vreNames = getUserVreNames(username); - UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmail(), accountURL, true, isAdmin(), vreNames); - UserSettings toReturn = new UserSettings(userInfo, 0, session.getScopeName(), isInfrastructureScope(), isNotificationViaEmailEnabled(session)); - _log.debug("getUserSettings() return " + toReturn); - return toReturn; + String thumbnailURL = currUser.getUserAvatarURL(); + String fullName = currUser.getFullname(); + String email = currUser.getEmail(); + final String profilePageURL = + GCubePortalConstants.PREFIX_GROUP_URL + + PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest())+ + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL; + String accountURL = profilePageURL; + try { + accountURL = ""; + }catch (NullPointerException e) { + e.printStackTrace(); } - else { - _log.info("Returning test USER = " + session.getUsername()); - HashMap fakeVreNames = new HashMap(); - fakeVreNames.put("/gcube/devsec/devVRE","devVRE"); - //fakeVreNames.put("/gcube/devNext/NexNext","NexNext"); + HashMap vreNames = getUserVreNames(username); + UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, email, accountURL, true, isAdmin(), vreNames); + UserSettings toReturn = new UserSettings(userInfo, 0, context.getCurrentScope(getThreadLocalRequest()), isInfrastructureScope(), isNotificationViaEmailEnabled()); + _log.debug("getUserSettings() return " + toReturn); + return toReturn; + - UserInfo user = new UserInfo(session.getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames); - return new UserSettings(user, 0, session.getScopeName(), false, true); - } } catch (Exception e) { e.printStackTrace(); @@ -615,10 +553,12 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar return new UserSettings(); } - private boolean isNotificationViaEmailEnabled(ASLSession session) throws UserManagementSystemException, GroupRetrievalFault { + private boolean isNotificationViaEmailEnabled() throws UserManagementSystemException, GroupRetrievalFault { + if (! isWithinPortal()) + return false; + PortalContext context = PortalContext.getConfiguration(); GroupManager gm = new LiferayGroupManager(); - GCubeGroup group = gm.getGroup(session.getGroupId()); - return (Boolean) gm.readCustomAttr(group.getGroupId(), CustomAttributeKeys.POST_NOTIFICATION.getKeyName()); + return (Boolean) gm.readCustomAttr(context.getCurrentGroupId(getThreadLocalRequest()), CustomAttributeKeys.POST_NOTIFICATION.getKeyName()); } /** * tell if the user is a portal administrator or not @@ -631,8 +571,9 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar if (! isWithinPortal()) return false; try { - GCubeUser curUser = new LiferayUserManager().getUserByUsername(getASLSession().getUsername()); - return new LiferayRoleManager().isAdmin(curUser.getUserId()); + PortalContext context = PortalContext.getConfiguration(); + GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest()); + return new LiferayRoleManager().isAdmin(currUser.getUserId()); } catch (Exception e) { _log.error("Could not check if the user is an Administrator, returning false"); @@ -644,13 +585,16 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar */ @Override public LinkPreview checkUploadedFile(String fileName, String fileabsolutePathOnServer) { + + PortalContext context = PortalContext.getConfiguration(); + LinkPreview toReturn = null; String randomUploadFolderName = UUID.randomUUID().toString(); String remoteFilePath = UPLOAD_DIR + "/" + randomUploadFolderName + "/" + fileName; //get the Storage Client String currScope = ScopeProvider.instance.get(); - ScopeProvider.instance.set(getASLSession().getScope()); + ScopeProvider.instance.set(context.getCurrentScope(getThreadLocalRequest())); IClient storageClient = new StorageClient(STORAGE_OWNER, AccessType.SHARED, MemoryType.PERSISTENT).getClient(); ScopeProvider.instance.set(currScope); @@ -814,9 +758,11 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar * @return the id as key and the names as value of the vre a user is subscribed to */ private HashMap getUserVreNames(String username) { + PortalContext context = PortalContext.getConfiguration(); + String groupName = context.getCurrentGroupName(getThreadLocalRequest()); HashMap toReturn = new HashMap(); for (GCubeGroup vre : getUserVREs(username)) { - if (vre.getGroupName().compareTo(getASLSession().getGroupName())==0) + if (vre.getGroupName().compareTo(groupName)==0) toReturn.put(vre.getGroupId()+"", vre.getGroupName()); } return toReturn; @@ -859,7 +805,8 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar * @return true if it is, false otherwise. */ private boolean isInfrastructureScope() { - ScopeBean scope = new ScopeBean(getASLSession().getScope()); + PortalContext context = PortalContext.getConfiguration(); + ScopeBean scope = new ScopeBean(context.getCurrentScope(getThreadLocalRequest())); return scope.is(Type.INFRASTRUCTURE); } @@ -886,19 +833,24 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar @Override public ArrayList getPortalItemBeans() { - ASLSession session = getASLSession(); + PortalContext context = PortalContext.getConfiguration(); + context.getCurrentScope(getThreadLocalRequest()); + String scope = context.getCurrentScope(getThreadLocalRequest()); + String username = context.getCurrentUser(getThreadLocalRequest()).getUsername(); boolean withinPortal = false; - if (isWithinPortal() && session.getUsername().compareTo(TEST_USER) != 0) { + if (isWithinPortal() && username.compareTo(TEST_USER) != 0) { withinPortal = true; } // retrieve user and group beans - return Utils.getDisplayableItemBeans(session.getScope(), session.getUsername(), withinPortal); + return Utils.getDisplayableItemBeans(scope, username, withinPortal); } @Override public ArrayList getHashtags() { - ASLSession session = getASLSession(); - String scope = session.getScope(); + PortalContext context = PortalContext.getConfiguration(); + context.getCurrentScope(getThreadLocalRequest()); + String scope = context.getCurrentScope(getThreadLocalRequest()); + _log.error("getting hashtags for " + scope); Map map = store.getVREHashtagsWithOccurrence(scope); ArrayList toSort = new ArrayList(); diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/portlet/ShareUpdatesPortlet.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/portlet/ShareUpdatesPortlet.java index 3bb4b2c..9d1e5d2 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/portlet/ShareUpdatesPortlet.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/portlet/ShareUpdatesPortlet.java @@ -1,27 +1,23 @@ package org.gcube.portlets.user.shareupdates.server.portlet; -import javax.portlet.GenericPortlet; -import javax.portlet.ActionRequest; -import javax.portlet.RenderRequest; -import javax.portlet.ActionResponse; -import javax.portlet.RenderResponse; -import javax.portlet.PortletException; import java.io.IOException; -import javax.portlet.PortletRequestDispatcher; -import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.GenericPortlet; +import javax.portlet.PortletException; +import javax.portlet.PortletRequestDispatcher; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; /** - * WfTemplatesPortlet Portlet Class * * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it - * @version May 2011 (0.1) */ public class ShareUpdatesPortlet extends GenericPortlet { public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); - ScopeHelper.setContext(request); PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/ShareUpdates_view.jsp"); dispatcher.include(request, response); } diff --git a/src/test/java/org/gcube/portlets/user/shareupdates/test/TestForDeploy.java b/src/test/java/org/gcube/portlets/user/shareupdates/test/TestForDeploy.java deleted file mode 100644 index b2aaff0..0000000 --- a/src/test/java/org/gcube/portlets/user/shareupdates/test/TestForDeploy.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.gcube.portlets.user.shareupdates.test; - -import static org.junit.Assert.*; - -import org.gcube.portlets.user.shareupdates.server.ShareUpdateServiceImpl; -import org.junit.Test; - -public class TestForDeploy { - - @Test - public void testUserIsTestUser() { - ShareUpdateServiceImpl serviceImpl = new ShareUpdateServiceImpl(); - String username = serviceImpl.getDevelopmentUser(); - System.out.println("username for deploy is: " + username); - assertTrue(username.compareTo(ShareUpdateServiceImpl.TEST_USER) == 0); - System.out.println("Test OK!"); - } - -}