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
This commit is contained in:
Costantino Perciante 2016-07-04 14:15:19 +00:00
parent 4c1734bd50
commit 38c73da8e8
2 changed files with 23 additions and 19 deletions

View File

@ -4,9 +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="ckan-util-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<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

@ -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)