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
This commit is contained in:
Costantino Perciante 2016-07-04 14:13:00 +00:00
parent 7d768461e2
commit 6f355ecc46
1 changed files with 28 additions and 25 deletions

View File

@ -60,37 +60,40 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// ckan keys for ASL // ckan keys for ASL
private static final String CKAN_TOKEN_KEY = "ckanToken"; 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_LICENSES_KEY = "ckanLicenses"; // licenses
private static final String CKAN_ORGANIZATIONS_PUBLISH_KEY = "ckanOrganizationsPublish"; // here he can publish private static final String CKAN_ORGANIZATIONS_PUBLISH_KEY = "ckanOrganizationsPublish"; // here he can publish
private static final String CKAN_PROFILES_KEY = "ckanProfiles"; // product profiles 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 * Since it needs the scope, we need to check if it is null or not
* @return * @return
*/ */
private CKanUtils getCkanUtilsObj(){ private CKanUtils getCkanUtilsObj(){
if(instance == null){ // check into session
synchronized(LOCK){ String currentScope = getASLSession().getScope();
if(instance == null){ HttpSession httpSession = getThreadLocalRequest().getSession();
// retrieve ckan information String keyForScope = concatenateSessionKeyScope(CKAN_OBJ_KEY, currentScope);
try{
String currentScope = getASLSession().getScope(); CKanUtils instance = null;
logger.debug("Scope from asl is " + currentScope);
instance = new CKanUtilsImpl(currentScope); if(httpSession.getAttribute(keyForScope) == null){
}catch(Exception e){ try{
logger.error("Unable to retrieve ckan information", e); 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; return instance;
} }
/** /**