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());