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
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<String> orgsName = new ArrayList<String>();
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<String>)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());