Fixed invalid scope bug when creating the ckanutils library

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129452 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-27 09:10:47 +00:00
parent 5405ca56c1
commit 0ae2fe5236
2 changed files with 36 additions and 31 deletions

View File

@ -4,12 +4,6 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="workspace-sharing-widget-1.7.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-sharing-widget-TRUNK/workspace-sharing-widget-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="workspace-uploader-1.4.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-uploader-TRUNK/workspace-uploader-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="gcube-ckan-datacatalog"/>
<property name="java-output-path" value="/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>

View File

@ -63,21 +63,25 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
// ckan utils methods
private CKanUtilsImpl instance;
/* (non-Javadoc)
* @see javax.servlet.GenericServlet#init()
/**
* Since it needs the scope, we need to check if it is null or not
* @return
*/
@Override
public void init(){
private CKanUtilsImpl getCkanUtilsObj(){
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");
logger.error("Unable to retrieve ckan information", e);
}
}
return instance;
}
/* (non-Javadoc)
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector(java.lang.String, java.lang.String)
@ -250,7 +254,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
return CkanRole.ADMIN;
}
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
boolean isSysAdmin = instance.isSysAdmin(username, getUserCKanTokenFromSession());
boolean isSysAdmin = getCkanUtilsObj().isSysAdmin(username, getUserCKanTokenFromSession());
if(isSysAdmin){
@ -287,7 +291,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
// with this invocation, we check if the role is present in ckan and if it is not it will be added
boolean res = instance.checkRole(username, groupName, correspondentRoleToCheck);
boolean res = getCkanUtilsObj().checkRole(username, groupName, correspondentRoleToCheck);
if(res)
return reMapRole(mainRole);
@ -342,12 +346,14 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
String username = session.getUsername();
logger.debug("User in session is " + username);
try{
String token = null;
if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null)
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
else{
token = instance.getApiKeyFromUsername(username);
token = getCkanUtilsObj().getApiKeyFromUsername(username);
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
logger.debug("Ckan token has been set for user " + username);
}
@ -355,6 +361,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
logger.debug("Found ckan token " + token + " for user " + username);
return token;
}catch(Exception e){
logger.error("Error while retrieving the key" , e);
}
return null;
}