minor fix due to http session attributes moved into the ckan library

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@131394 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-15 14:29:27 +00:00
parent 5ed0eeb3b0
commit 7231aa455b
2 changed files with 12 additions and 17 deletions

View File

@ -17,6 +17,7 @@ import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.datacatalogue.ckanutillibrary.CKanUtils; import org.gcube.datacatalogue.ckanutillibrary.CKanUtils;
import org.gcube.datacatalogue.ckanutillibrary.CkanUtilsFactory; import org.gcube.datacatalogue.ckanutillibrary.CkanUtilsFactory;
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean; import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods; import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
@ -49,14 +50,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
public static final String TEST_SCOPE = "/gcube/devsec/devVRE"; public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
public static final String TEST_USER = "test.user"; public static final String TEST_USER = "test.user";
private final static String TEST_SEC_TOKEN = "a1e19695-467f-42b8-966d-bf83dd2382ef"; private final static String TEST_SEC_TOKEN = "a1e19695-467f-42b8-966d-bf83dd2382ef";
// ckan keys for ASL
private static final String CKAN_TOKEN_KEY = "ckanToken";
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 final static String SCOPE_CLIENT_PORTLET_URL = "currentClientUrlPortletScope"; // set by the ckan portlet in session according the user's current url location
/** /**
* Retrieve an instance of the library for the scope * Retrieve an instance of the library for the scope
* @param scope if it is null it is evaluated from the session * @param scope if it is null it is evaluated from the session
@ -125,7 +119,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope(); String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope();
// get the key per scope // get the key per scope
String keyPerScope = UtilMethods.concatenateSessionKeyScope(CKAN_TOKEN_KEY, scopeInWhichDiscover); String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_TOKEN_KEY, scopeInWhichDiscover);
// check if session expired // check if session expired
if(username.equals(TEST_USER)){ if(username.equals(TEST_USER)){
@ -169,7 +163,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
HttpSession httpSession = getThreadLocalRequest().getSession(); HttpSession httpSession = getThreadLocalRequest().getSession();
// get key // get key
String keyPerScope = UtilMethods.concatenateSessionKeyScope(CKAN_ORGANIZATIONS_PUBLISH_KEY, scope); String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scope);
if(httpSession.getAttribute(keyPerScope) != null){ if(httpSession.getAttribute(keyPerScope) != null){
orgsName = (List<OrganizationBean>)httpSession.getAttribute(keyPerScope); orgsName = (List<OrganizationBean>)httpSession.getAttribute(keyPerScope);
@ -205,7 +199,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
* @return * @return
*/ */
private String findLicenseIdByLicense(String chosenLicense) { private String findLicenseIdByLicense(String chosenLicense) {
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SCOPE_CLIENT_PORTLET_URL); String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
return getCkanUtilsObj(scope).findLicenseIdByLicenseTitle(chosenLicense); return getCkanUtilsObj(scope).findLicenseIdByLicenseTitle(chosenLicense);
} }
@ -217,12 +211,12 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// get http session // get http session
HttpSession httpSession = getThreadLocalRequest().getSession(); HttpSession httpSession = getThreadLocalRequest().getSession();
String scope = (String)httpSession.getAttribute(SCOPE_CLIENT_PORTLET_URL); String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
logger.info("Request for CKAN licenses for scope " + scope); logger.info("Request for CKAN licenses for scope " + scope);
// get key per scope // get key per scope
String keyPerScope = UtilMethods.concatenateSessionKeyScope(CKAN_LICENSES_KEY, scope); String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
LicensesBean licensesBean = null; LicensesBean licensesBean = null;
if(httpSession.getAttribute(keyPerScope) != null){ if(httpSession.getAttribute(keyPerScope) != null){
@ -257,7 +251,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("DatasetBean request for " + folderId + " and " + userName); logger.info("DatasetBean request for " + folderId + " and " + userName);
HttpSession httpSession = this.getThreadLocalRequest().getSession(); HttpSession httpSession = this.getThreadLocalRequest().getSession();
String scope = (String)httpSession.getAttribute(SCOPE_CLIENT_PORTLET_URL); String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
logger.debug("Scope recovered from session is " + scope); logger.debug("Scope recovered from session is " + scope);
@ -593,7 +587,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
try{ try{
String evaluatedScope = Utils.retrieveScopeFromOrganizationName(orgName); String evaluatedScope = Utils.retrieveScopeFromOrganizationName(orgName);
logger.debug("Evaluated scope is " + evaluatedScope); logger.debug("Evaluated scope is " + evaluatedScope);
toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest().getSession(), getASLSession(), CKAN_PROFILES_KEY); toReturn = Utils.getMetadataProfilesList(evaluatedScope, getThreadLocalRequest().getSession(), getASLSession());
}catch(Exception e){ }catch(Exception e){
logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e); logger.error("Failed to retrieve profiles for scope coming from organization name " + orgName, e);
} }

View File

@ -16,6 +16,7 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.ckanutillibrary.CKanUtils; import org.gcube.datacatalogue.ckanutillibrary.CKanUtils;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization; import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods; import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType; import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
@ -310,7 +311,7 @@ public class Utils {
* Retrieve the list of metadata beans * Retrieve the list of metadata beans
* @return * @return
*/ */
public static List<MetaDataProfileBean> getMetadataProfilesList(String scope, HttpSession httpSession, ASLSession aslSession, String profilesKey) { public static List<MetaDataProfileBean> getMetadataProfilesList(String scope, HttpSession httpSession, ASLSession aslSession) {
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>(); List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
String username = aslSession.getUsername(); String username = aslSession.getUsername();
@ -320,7 +321,7 @@ public class Utils {
String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : aslSession.getScope(); String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : aslSession.getScope();
// scope in which we need to discover // scope in which we need to discover
String keyPerScope = UtilMethods.concatenateSessionKeyScope(profilesKey, scopeInWhichDiscover); String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PROFILES_KEY, scopeInWhichDiscover);
if(httpSession.getAttribute(keyPerScope) != null){ if(httpSession.getAttribute(keyPerScope) != null){
beans = (List<MetaDataProfileBean>)httpSession.getAttribute(keyPerScope); beans = (List<MetaDataProfileBean>)httpSession.getAttribute(keyPerScope);