From 6f355ecc462ad69d64f91e9e99174aeee8b8b5e6 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 4 Jul 2016 14:13:00 +0000 Subject: [PATCH] fixed getCkanUtilsObj() method git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@129870 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/CKANPublisherServicesImpl.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) 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 3d041c7..1791565 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 @@ -60,37 +60,40 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // 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_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 - private Object LOCK = new Object(); - - // library util instance - private CKanUtilsImpl instance; - /** * 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 = getASLSession().getScope(); - logger.debug("Scope from asl is " + currentScope); - instance = new CKanUtilsImpl(currentScope); - }catch(Exception e){ - logger.error("Unable to retrieve ckan information", e); - } - } + // check into session + String currentScope = getASLSession().getScope(); + HttpSession httpSession = getThreadLocalRequest().getSession(); + 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); return instance; + } /** @@ -179,13 +182,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.debug("Request for user " + username + " organizations list"); List orgsName = new ArrayList(); CKanUtils ckanUtils = getCkanUtilsObj(); - + // get http session HttpSession httpSession = getThreadLocalRequest().getSession(); - + // get key String keyPerScope = concatenateSessionKeyScope(CKAN_ORGANIZATIONS_PUBLISH_KEY, scope); - + if(httpSession.getAttribute(keyPerScope) != null){ orgsName = (List)httpSession.getAttribute(keyPerScope); logger.info("List of organizations was into session"); @@ -257,10 +260,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C ASLSession session = getASLSession(); String username = session.getUsername(); logger.debug("User in session is " + username); - + // get http session HttpSession httpSession = getThreadLocalRequest().getSession(); - + // get key per scope String keyPerScope = concatenateSessionKeyScope(CKAN_PROFILES_KEY, session.getScope()); @@ -331,10 +334,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C ASLSession session = getASLSession(); String username = session.getUsername(); logger.debug("User in session is " + username); - + // get http session HttpSession httpSession = getThreadLocalRequest().getSession(); - + // get key per scope String keyPerScope = concatenateSessionKeyScope(CKAN_LICENSES_KEY, session.getScope());