From 38c73da8e85da0cea988a5354945d3b317a03198 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 4 Jul 2016 14:15:19 +0000 Subject: [PATCH] fixed getCkanUtilsObj() method git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129873 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/org.eclipse.wst.common.component | 3 -- .../GcubeCkanDataCatalogServiceImpl.java | 39 +++++++++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 52c9d95..5fe3680 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,9 +4,6 @@ - - uses - diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index cc340d8..ea00089 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -60,38 +60,45 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem // ckan keys for ASL private static final String CKAN_TOKEN_KEY = "ckanToken"; + private static final String CKAN_OBJ_KEY = "ckanObj"; private static final String CKAN_ORGS_USER_KEY = "ckanOrgs"; // organizations to whom he belongs private static final String CKAN_HIGHEST_ROLE = "ckanHighestRole"; // editor, member, admin, sysadmin private static final String CKAN_LICENSES_KEY = "ckanLicenses"; // licenses private static final String CKAN_ORGANIZATIONS_PUBLISH_KEY = "ckanOrganizationsPublish"; // here he can publish private static final String CKAN_PROFILES_KEY = "ckanProfiles"; // product profiles - // ckan utils methods - private CKanUtilsImpl instance; - private Object LOCK = new Object(); - + /** * Since it needs the scope, we need to check if it is null or not * @return */ private CKanUtils getCkanUtilsObj(){ - if(instance == null){ - synchronized(LOCK){ - if(instance == null){ - // retrieve ckan information - try{ - String currentScope = ScopeProvider.instance.get(); - logger.debug("Scope is " + currentScope); - instance = new CKanUtilsImpl(currentScope); - }catch(Exception e){ - logger.error("Unable to retrieve ckan information", e); - } - } + // check into session + HttpSession httpSession = getThreadLocalRequest().getSession(); + String currentScope = getASLSession(httpSession).getScope(); + String keyForScope = concatenateSessionKeyScope(CKAN_OBJ_KEY, currentScope); + + CKanUtils instance = null; + + if(httpSession.getAttribute(keyForScope) == null){ + try{ + logger.debug("The ckan util object was null"); + instance = new CKanUtilsImpl(currentScope); + + // put it into session + logger.debug("Putting object into session "); + httpSession.setAttribute(keyForScope, instance); + }catch(Exception e){ + logger.error("Unable to retrieve ckan utils", e); } + }else{ + instance = (CKanUtils)httpSession.getAttribute(keyForScope); + logger.debug("Ckan utils object was into session"); } return instance; + } /* (non-Javadoc)