From 430c5f36ffb102942dad16bacc8155e86dfe0413 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Fri, 25 Nov 2016 09:32:50 +0000 Subject: [PATCH] removed asl session git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@134751 82a268e6-3cf1-43bd-a215-b396298e98cf --- distro/changelog.xml | 1 + pom.xml | 12 - .../server/CKANPublisherServicesImpl.java | 238 +++++++----------- .../server/utils/Utils.java | 112 ++++++++- .../client/TestClass.java | 17 -- 5 files changed, 192 insertions(+), 188 deletions(-) delete mode 100644 src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java diff --git a/distro/changelog.xml b/distro/changelog.xml index f2746d0..8bf572a 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -3,6 +3,7 @@ A post is automatically created by the Product Catalogue user every time someone publishes The user now can select all files in the hierarchy and publish them The user can now associate the product to the available groups + Removed ASL session dependency Creation of a group is now supported diff --git a/pom.xml b/pom.xml index 2c17480..b507ff5 100644 --- a/pom.xml +++ b/pom.xml @@ -55,13 +55,6 @@ - - xerces - xercesImpl - 2.9.1 - provided - - com.google.gwt gwt-servlet @@ -116,11 +109,6 @@ portal-service provided - - org.gcube.applicationsupportlayer - aslcore - provided - org.gcube.portal social-networking-library diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 10429ad..fdaab7c 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -10,14 +10,11 @@ import java.util.concurrent.ConcurrentHashMap; import javax.servlet.http.HttpSession; -import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.application.framework.core.session.SessionManager; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean; import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes; import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods; -import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.AssociationToGroupAndNotifyThread; import org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads.WritePostCatalogueManagerThread; @@ -30,6 +27,8 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfile import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.vomanagement.usermanagement.UserManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.LoggerFactory; @@ -44,15 +43,13 @@ import eu.trentorise.opendata.jackan.model.CkanLicense; * Server side of the data publisher. * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) */ -@SuppressWarnings({"serial","deprecation"}) public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{ + + private static final long serialVersionUID = 7252248774050361697L; // Logger private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); - public static final String TEST_SCOPE = "/gcube"; - public static final String TEST_USER = "test.user"; - // map private ConcurrentHashMap mapOrganizationScope = new ConcurrentHashMap(); @@ -66,7 +63,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C DataCatalogue instance = null; String scopeInWhichDiscover = null; try{ - scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope(); + scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : Utils.getCurrentContext(getThreadLocalRequest(), false); logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover); instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover); }catch(Exception e){ @@ -75,38 +72,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return instance; } - /** - * the current ASLSession - * @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) { - logger.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL"); - user = getDevelopmentUser(); - SessionManager.getInstance().getASLSession(sessionID, user).setScope(TEST_SCOPE); - } - return SessionManager.getInstance().getASLSession(sessionID, user); - } - - /** - * when packaging test will fail if the user is not set to test.user - * @return . - */ - public String getDevelopmentUser() { - String user = TEST_USER; - // user = "costantino.perciante"; - return user; - } - /** * Retrieve the list of organizations in which the user can publish (roles ADMIN) * @param username * @return the list of organizations + * @throws GroupRetrievalFault + * @throws UserManagementSystemException */ - private List getUserOrganizationsListAdmin(String username, String scope) { + private List getUserOrganizationsListAdmin(String username, String scope) throws UserManagementSystemException, GroupRetrievalFault { logger.debug("Request for user " + username + " organizations list"); List orgsName = new ArrayList(); @@ -119,7 +92,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.info("List of organizations was into session " + orgsName); } else{ - orgsName = Utils.getUserOrganizationsListAdminEditor(scope, username, getASLSession().getGroupName(), this); + orgsName = Utils.getUserOrganizationsListAdminEditor(scope, username, Utils.getGroupFromScope(scope).getGroupName(), this); httpSession.setAttribute(keyPerScope, orgsName); logger.info("Organizations name for user " + username + " has been saved into session " + orgsName); } @@ -149,7 +122,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C */ private String findLicenseIdByLicense(String chosenLicense) { - String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + // get scope from client url + String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest()); return getCatalogue(scope).findLicenseIdByLicenseTitle(chosenLicense); } @@ -157,66 +131,47 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C @Override public LicensesBean getLicenses() { - ASLSession session = getASLSession(); - String username = session.getUsername(); + // get http session + HttpSession httpSession = getThreadLocalRequest().getSession(); + String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest()); + logger.info("Request for CKAN licenses for scope " + scope); + String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope); - if(username.equals(TEST_USER)){ - - logger.warn("Session expired, returning null token"); - return null; - - }else{ - - // get http session - HttpSession httpSession = getThreadLocalRequest().getSession(); - String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); - logger.info("Request for CKAN licenses for scope " + scope); - String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope); - - LicensesBean licensesBean = null; - if(httpSession.getAttribute(keyPerScope) != null){ - licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope); - logger.info("List of licenses was into session"); - } - else{ - List titlesLicenses = getCatalogue(scope).getLicenses(); - List titles = new ArrayList(); - List urls = new ArrayList(); - for (CkanLicense license : titlesLicenses) { - titles.add(license.getTitle()); - String url = (license.getUrl() != null && !license.getUrl().isEmpty()) ? license.getUrl() : ""; - urls.add(url); - } - licensesBean = new LicensesBean(titles, urls); - httpSession.setAttribute(keyPerScope, licensesBean); - logger.info("List of licenses has been saved into session"); - } - - return licensesBean; + LicensesBean licensesBean = null; + if(httpSession.getAttribute(keyPerScope) != null){ + licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope); + logger.info("List of licenses was into session"); } + else{ + List titlesLicenses = getCatalogue(scope).getLicenses(); + List titles = new ArrayList(); + List urls = new ArrayList(); + for (CkanLicense license : titlesLicenses) { + titles.add(license.getTitle()); + String url = (license.getUrl() != null && !license.getUrl().isEmpty()) ? license.getUrl() : ""; + urls.add(url); + } + licensesBean = new LicensesBean(titles, urls); + httpSession.setAttribute(keyPerScope, licensesBean); + logger.info("List of licenses has been saved into session"); + } + + return licensesBean; + } @Override public DatasetMetadataBean getDatasetBean(String folderId){ DatasetMetadataBean bean = null; - - ASLSession aslSession = getASLSession(); - String userName = aslSession.getUsername(); + String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); logger.info("DatasetBean request for " + folderId + " and " + userName); if(isWithinPortal()){ try{ - // check if session expired - if(userName.equals(TEST_USER)){ - logger.debug("SESSION EXPIRED"); - return null; - } - - HttpSession httpSession = this.getThreadLocalRequest().getSession(); - String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest()); logger.debug("Scope recovered from session is " + scope); @@ -262,7 +217,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C bean.setAuthorEmail("costantino.perciante@isti.cnr.it"); bean.setMaintainer("Costantino Perciante"); bean.setMaintainerEmail("costantino.perciante@isti.cnr.it"); - bean.setOrganizationList(getUserOrganizationsListAdmin(userName, TEST_SCOPE)); + bean.setOrganizationList(getUserOrganizationsListAdmin(userName, Utils.getCurrentContext(getThreadLocalRequest(), true))); bean.setOwnerIdentifier(userName); if(folderId != null && !folderId.isEmpty()){ @@ -281,17 +236,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.debug("Request for creating a dataset with these information " + toCreate); - ASLSession aslSession = getASLSession(); - String userName = aslSession.getUsername(); + String userName = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); try{ - // check if session expired - if(userName.equals(TEST_USER)){ - logger.warn("SESSION EXPIRED"); - return null; - } - String title = toCreate.getTitle(); String organizationNameOrId = toCreate.getSelectedOrganization(); String author = toCreate.getAuthorFullName(); @@ -343,7 +291,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C datasetUrl, datasetId, toCreate.getTitle(), - aslSession.getUserFullName(), + Utils.getCurrentUser(getThreadLocalRequest()).getFullname(), userName, utils, organizationNameOrId, @@ -362,7 +310,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C datasetUrl, false, // send notification to other people toCreate.getTags(), - aslSession.getUserFullName() + Utils.getCurrentUser(getThreadLocalRequest()).getFullname() ); threadWritePost.start(); @@ -378,9 +326,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C @Override public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) { - - ASLSession session = getASLSession(); - String username = session.getUsername(); + String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); logger.debug("Incoming request for creating new resource for dataset with id " + datasetId + " and organization name of the dataset is " + resource.getOrganizationNameDatasetParent()); logger.debug("Owner is " + username + " and resource is " + resource); @@ -392,35 +338,31 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C }else{ - if(username.equals(TEST_USER)){ - logger.warn("SESSION EXPIRED!"); - return null; - }else{ - try{ - ResourceBean resourceBean = new ResourceBean( - resource.getUrl(), - resource.getName(), - resource.getDescription(), - null, - username, - datasetId, - null); + try{ + ResourceBean resourceBean = new ResourceBean( + resource.getUrl(), + resource.getName(), + resource.getDescription(), + null, + username, + datasetId, + null); - // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created - String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); - DataCatalogue catalogue = getCatalogue(scope); - String resourceId = catalogue.addResourceToDataset(resourceBean, catalogue.getApiKeyFromUsername(username)); + // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created + String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); + DataCatalogue catalogue = getCatalogue(scope); + String resourceId = catalogue.addResourceToDataset(resourceBean, catalogue.getApiKeyFromUsername(username)); - if(resourceId != null){ - logger.debug("Resource " + resource.getName() + " is now available"); - // set its id and turn it to the client - resource.setOriginalIdInWorkspace(resourceId); - return resource; - } - }catch(Exception e){ - logger.error("Unable to create new resource", e); + if(resourceId != null){ + logger.debug("Resource " + resource.getName() + " is now available"); + // set its id and turn it to the client + resource.setOriginalIdInWorkspace(resourceId); + return resource; } + }catch(Exception e){ + logger.error("Unable to create new resource", e); } + logger.debug("No resource created"); return null; } @@ -437,28 +379,22 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return deleted; }else{ - ASLSession session = getASLSession(); - String username = session.getUsername(); - - if(username.equals(TEST_USER)){ - logger.warn("SESSION EXPIRED!"); - return deleted; - }else{ - try{ - // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created - String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); - DataCatalogue catalogue = getCatalogue(scope); - deleted = catalogue. - deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), catalogue.getApiKeyFromUsername(username)); - if(deleted){ - logger.info("Resource described by " + resource + " deleted"); - }else - logger.error("Resource described by " + resource + " NOT deleted"); - }catch(Exception e){ - logger.error("Error while trying to delete resource described by " + resource, e); - } - return deleted; + String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); + try{ + // get the scope in which we should discover the ckan instance given the organization name in which the dataset was created + String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent()); + DataCatalogue catalogue = getCatalogue(scope); + deleted = catalogue. + deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), catalogue.getApiKeyFromUsername(username)); + if(deleted){ + logger.info("Resource described by " + resource + " deleted"); + }else + logger.error("Resource described by " + resource + " NOT deleted"); + }catch(Exception e){ + logger.error("Error while trying to delete resource described by " + resource, e); } + return deleted; + } } @@ -470,7 +406,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C try{ String evaluatedScope = getScopeFromOrgName(orgName); logger.debug("Evaluated scope is " + evaluatedScope); - toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest().getSession(), getASLSession()); + toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest()); }catch(Exception e){ logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e); } @@ -484,7 +420,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C if(title == null || title.isEmpty()) return true; // it's an error somehow try{ - String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest()); String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(title); return getCatalogue(scope).existProductWithNameOrId(idFromTitle); }catch(Exception e){ @@ -564,22 +500,16 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C @Override public List getUserGroups() { - ASLSession session = getASLSession(); List toReturn = new ArrayList(); if(isWithinPortal()){ - String username = session.getUsername(); - - if(username.equals(TEST_USER)){ - logger.warn("Session expired"); - return null; - } + String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); logger.debug("Request for user " + username + " groups"); // get http session HttpSession httpSession = getThreadLocalRequest().getSession(); - String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + String scope = Utils.getScopeFromClientUrl(getThreadLocalRequest()); // check if they are in session String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scope); @@ -602,7 +532,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C toReturn.add(new GroupBean(ckanGroup.getTitle(), ckanGroup.getName())); } - + httpSession.setAttribute(keyPerScopeGroups, toReturn); } }else{ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java index 7347953..94b2950 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java @@ -10,16 +10,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.UserInfo; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem; +import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg; import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes; @@ -46,6 +48,7 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeRole; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; import org.slf4j.LoggerFactory; @@ -72,6 +75,7 @@ public class Utils { private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token/"; private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app/"; private static final String MEDIATYPE_JSON = "application/json"; + public static final String GCUBE_REQUEST_URL = "gcube-request-url"; /** Gets the gcube item properties. * @@ -282,20 +286,22 @@ public class Utils { * Retrieve the list of metadata beans * @return */ - public static List getMetadataProfilesList(String scope, HttpSession httpSession, ASLSession aslSession) { + public static List getMetadataProfilesList(String scope, HttpServletRequest request) { List beans = new ArrayList(); - String username = aslSession.getUsername(); + String username = getCurrentUser(request).getUsername(); logger.debug("User in session is " + username); // check the scope we need to discover - String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : aslSession.getScope(); + String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getCurrentContext(request, false); logger.debug("Discovering into scope " + scopeInWhichDiscover); // scope in which we need to discover String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PROFILES_KEY, scopeInWhichDiscover); + HttpSession httpSession = request.getSession(); + if(httpSession.getAttribute(keyPerScope) != null){ beans = (List)httpSession.getAttribute(keyPerScope); logger.info("List of profiles was into session"); @@ -483,7 +489,7 @@ public class Utils { return toReturn; } - + /** * First check to retrieve the token, else create it * @param username @@ -507,4 +513,100 @@ public class Utils { } return token; } + + /** + * Get the scope in which ckan information needs to be discovered from the url + * @param httpServletRequest + * @return + */ + public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest){ + + if(httpServletRequest == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + String scopeToReturn = null; + try{ + String clientUrl = getCurrentClientUrl(httpServletRequest).split("\\?")[0]; + logger.debug("Client url is " + clientUrl); + + // check if this information is in session, otherwise set it and return + HttpSession session = httpServletRequest.getSession(); + + if((scopeToReturn = (String) session.getAttribute(clientUrl)) != null){ + logger.debug("Scope to return is " + scopeToReturn); + }else{ + // ask to the ckan library and set it + scopeToReturn = ApplicationProfileScopePerUrlReader.getScopePerUrl(clientUrl); + logger.debug("Scope to return is " + scopeToReturn); + session.setAttribute(clientUrl, scopeToReturn); + } + }catch(Exception e){ + scopeToReturn = getCurrentContext(httpServletRequest, false); + logger.warn("Failed to determine the scope from the client url, returning the current one: " + scopeToReturn); + } + return scopeToReturn; + } + + /** + * Needed to get the url of the client + * @param httpServletRequest the httpServletRequest object + * @return the instance of the user + * @see the url at client side + */ + public static String getCurrentClientUrl(HttpServletRequest httpServletRequest) { + return httpServletRequest.getHeader(GCUBE_REQUEST_URL); + } + + /** + * Retrieve the current user by using the portal manager + * @return a GcubeUser object + */ + public static GCubeUser getCurrentUser(HttpServletRequest request){ + + if(request == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + PortalContext pContext = PortalContext.getConfiguration(); + GCubeUser user = pContext.getCurrentUser(request); + logger.debug("Returning user " + user); + return user; + } + + /** + * Retrieve the current scope by using the portal manager + * @param b + * @return a GcubeUser object + */ + public static String getCurrentContext(HttpServletRequest request, boolean setInThread){ + + if(request == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + PortalContext pContext = PortalContext.getConfiguration(); + String context = pContext.getCurrentScope(request); + logger.debug("Returning context " + context); + + if(context != null && setInThread) + ScopeProvider.instance.set(context); + + return context; + } + + /** + * Retrieve the group given the scope + * @param scope + * @return + * @throws UserManagementSystemException + * @throws GroupRetrievalFault + */ + public static GCubeGroup getGroupFromScope(String scope) throws UserManagementSystemException, GroupRetrievalFault{ + + if(scope == null || scope.isEmpty()) + throw new IllegalArgumentException("Scope is missing here!!"); + + GroupManager gm = new LiferayGroupManager(); + long groupId = gm.getGroupIdFromInfrastructureScope(scope); + return gm.getGroup(groupId); + + } } \ No newline at end of file diff --git a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java b/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java deleted file mode 100644 index 86b4b81..0000000 --- a/src/test/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/TestClass.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.client; - -import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl; -import org.junit.Test; - -/** - * Junit tests class - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) - */ -public class TestClass { - - @Test - public void testUser() { - assert(new CKANPublisherServicesImpl().getDevelopmentUser().equals(CKANPublisherServicesImpl.TEST_USER)); - } - -}