From 40b4ae8f507f4736c3d114ead5df790deb19b9eb Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 4 Jul 2016 14:27:03 +0000 Subject: [PATCH] fixed getCkanUtilsObj() method git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@129876 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/GWTWorkspaceServiceImpl.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index c588dc7..7ad5758 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -41,6 +41,7 @@ import org.gcube.common.homelibrary.home.workspace.search.SearchItem; import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder; import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datacatalogue.ckanutillibrary.CKanUtils; import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsImpl; import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; @@ -119,27 +120,23 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT 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(); - /** - * Retrieve the ckan utils object + * Since it needs the scope, we need to check if it is null or not * @return */ - private CKanUtilsImpl getCkanUtils(){ + private CKanUtils getCkanUtilsObj(){ - if(instance == null){ - synchronized (LOCK) { - if(instance == null){ - try{ - String currentScope = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()).getScope(); - instance = new CKanUtilsImpl(currentScope); - }catch(Exception e){ - workspaceLogger.error("Unable to retrieve ckan information"); - } - } - } + // check into session + HttpSession httpSession = getThreadLocalRequest().getSession(); + String currentScope = WsUtil.getAslSession(httpSession).getScope(); + + CKanUtils instance = null; + + try{ + workspaceLogger.debug("The ckan util object was null"); + instance = new CKanUtilsImpl(currentScope); + }catch(Exception e){ + workspaceLogger.error("Unable to retrieve ckan utils", e); } return instance; } @@ -3461,7 +3458,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT return role; else{ - CKanUtilsImpl ckanUtils = getCkanUtils(); + CKanUtils ckanUtils = getCkanUtilsObj(); boolean result = false; try{ @@ -3591,7 +3588,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT if(httpSession.getAttribute(keyPerScope) != null) token = (String)httpSession.getAttribute(keyPerScope); else{ - token = getCkanUtils().getApiKeyFromUsername(username); + token = getCkanUtilsObj().getApiKeyFromUsername(username); httpSession.setAttribute(keyPerScope, token); workspaceLogger.debug("Ckan token has been set for user " + username); }