Updated isViewePerVreEnable. Now it depends on BrowserLocationURL

This commit is contained in:
Francesco Mangiacrapa 2020-07-03 12:01:22 +02:00
parent 3dfa8671b5
commit f77edbfa1d
6 changed files with 65 additions and 17 deletions

View File

@ -4,6 +4,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.9.0] [r4.25.0] - 2020-07-01
** Enhancements **
[#19559] Check and try to avoid the view per VRE configuration for Public and Gateway Catalogue
## [v1.8.1] [r4.24.0] - 2020-06-18
Just to include the dependencies [#18700] and [#19479]

View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.gcubeckan</groupId>
<artifactId>gcube-ckan-datacatalog</artifactId>
<packaging>war</packaging>
<version>1.8.1</version>
<version>1.9.0-SNAPSHOT</version>
<name>gCube CKAN Data Catalog</name>
<description>The gCube CKAN Data Catalog portlet</description>

View File

@ -23,13 +23,14 @@ public interface GcubeCkanDataCatalogService extends RemoteService {
/**
* Get the ckan connector access point.
*
* @param browserLocationURL the browser location URL
* @param pathInfoParameters the path info parameters
* @param queryStringParameters the query string parameters
* @return the c kan connector
* @throws Exception the exception
*/
CkanConnectorAccessPoint getCKanConnector(
String pathInfoParameters, String queryStringParameters) throws Exception;
String browserLocationURL, String pathInfoParameters, String queryStringParameters) throws Exception;
/**
* Get the current role in CKAN for this user.
@ -75,9 +76,11 @@ public interface GcubeCkanDataCatalogService extends RemoteService {
boolean isManageProductEnabled();
/**
* Check if the management panels but publish/share link must be removed
* Check if the view per VRE is enabled, so the management panels but publish/share link must be removed.
* @param browserLocationURL the browser location URL
* @return the string
*/
String isViewPerVREEnabled();
String isViewPerVREEnabled(String browserLocationURL);
/**

View File

@ -30,15 +30,16 @@ public interface GcubeCkanDataCatalogServiceAsync {
void getMyRole(AsyncCallback<RolesCkanGroupOrOrg> callback);
/**
* Gets the c kan connector.
* Gets the CKAN connector.
*
* @param browserLocationURL the browser location URL that performs the call
* @param pathInfoParameters the path info parameters
* @param queryStringParameters the query string parameters
* @param callback the callback
* @return the c kan connector
*/
void getCKanConnector(
String pathInfoParameters, String queryStringParameters,
String browserLocationURL, String pathInfoParameters, String queryStringParameters,
AsyncCallback<CkanConnectorAccessPoint> callback);
/**
@ -73,12 +74,14 @@ public interface GcubeCkanDataCatalogServiceAsync {
*/
void isManageProductEnabled(AsyncCallback<Boolean> callback);
/**
* check if the view per vre is enabled.
* Checks if is view per VRE enabled.
*
* @param browserLocationURL the browser location URL
* @param callback the callback
*/
void isViewPerVREEnabled(AsyncCallback<String> callback);
void isViewPerVREEnabled(String browserLocationURL, AsyncCallback<String> callback);
/**

View File

@ -99,7 +99,9 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
String pathParameter = paramsMap.get(GCubeCkanDataCatalog.GET_PATH_PARAMETER); //Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
String queryParameter = paramsMap.get(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);// Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);
GCubeCkanDataCatalog.service.getCKanConnector(
String browserLocationURL = getBrowserLocationURL();
GCubeCkanDataCatalog.service.getCKanConnector(browserLocationURL,
pathParameter, queryParameter,
new AsyncCallback<CkanConnectorAccessPoint>() {
@ -122,10 +124,11 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
instanceCkanFrame(ckan.buildURI());
GCubeCkanDataCatalogPanel.this.rootPanel.remove(loading);
String browserLocationURL = getBrowserLocationURL();
// check if view per organisation is enabled
//and performing some actions in this case (e.g. removed the management buttons, etc.)
GCubeCkanDataCatalog.service.isViewPerVREEnabled(new AsyncCallback<String>() {
GCubeCkanDataCatalog.service.isViewPerVREEnabled(browserLocationURL, new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
@ -267,6 +270,26 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
listenForPostMessage();
}
/**
* Gets the browser location URL.
*
* @return the browser location URL
*/
public String getBrowserLocationURL() {
String browserLocationURL = null;
try {
browserLocationURL = Window.Location.getHref();
}catch (Exception e) {
// silent
}
GWT.log("Returning browserLocationURL: "+browserLocationURL);
return browserLocationURL;
}
public static String getLatestSelectedProductIdentifier(){
return latestSelectedProductIdentifier;

View File

@ -81,7 +81,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector(java.lang.String, java.lang.String)
*/
@Override
public CkanConnectorAccessPoint getCKanConnector(String pathInfoParameter, String queryStringParameters) throws Exception {
public CkanConnectorAccessPoint getCKanConnector(String browserLocationURL, String pathInfoParameter, String queryStringParameters) throws Exception {
logger.info("getCKanConnector [browserLocationURL: "+browserLocationURL+ " ]");
logger.info("getCKanConnector [pathInfo: "+pathInfoParameter + ", query: "+queryStringParameters+"]");
try{
@ -106,10 +107,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
if(pathInfoParameter == null || pathInfoParameter.isEmpty()){
pathInfoParameter = isViewPerVREEnabled();
//pathInfoParameter is null or empty, in this case we are pointing to the Catalogue Home
pathInfoParameter = isViewPerVREEnabled(browserLocationURL);
}
CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(pathInfoParameter, queryStringParameters, scopePerCurrentUrl);
CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(browserLocationURL, pathInfoParameter, queryStringParameters, scopePerCurrentUrl);
SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl, ckAP);
logger.info("Built the URI to CKAN (connector in case of user logged): "+ckAP.buildURI());
logger.debug("returning ckanConnectorUri: "+ckAP);
@ -125,13 +127,14 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
/**
* Gets the ckan connector access point.
*
* @param browserLocationURL the browser location URL
* @param pathInfoParameter the path info parameter
* @param queryStringParameters the query string parameters
* @param scopePerCurrentUrl the scope per current url
* @return the ckan connector access point
* @throws Exception the exception
*/
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String pathInfoParameter, String queryStringParameters, String scopePerCurrentUrl) throws Exception {
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String browserLocationURL, String pathInfoParameter, String queryStringParameters, String scopePerCurrentUrl) throws Exception {
if(outsideLoginPortal()){
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(getCatalogue(scopePerCurrentUrl).getCatalogueUrl(),"");
@ -186,7 +189,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
getThreadLocalRequest()).getEmail(),
scopePerCurrentUrl,
getCatalogue(scopePerCurrentUrl),
isViewPerVREEnabled() != null,
isViewPerVREEnabled(browserLocationURL) != null,
getThreadLocalRequest().getSession());
ckan.addListOfVREs(roleForVre);
@ -529,10 +532,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
/**
* Ask to liferay.
*
* @param browserLocationURL the browser location URL
* @return the string
*/
@Override
public String isViewPerVREEnabled(){
public String isViewPerVREEnabled(String browserLocationURL){
String toReturn = null;
String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());// the view per vre can be managed independently for each context SessionUtil.getScopeFromClientUrl(getThreadLocalRequest());
@ -552,11 +556,20 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
GroupManager gm = new LiferayGroupManager();
enabled = (boolean) gm.readCustomAttr(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl), VIEW_PER_ORGANIZATION_LIFERAY_CUSTOM_FIELD);
if(enabled){
String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName().toLowerCase();
toReturn = "/organization_vre/" + groupName;
//this should mean the caller (the location URL) is from VRE environment
if(browserLocationURL.toLowerCase().contains(groupName)){
logger.info("The browserLocationURL: "+browserLocationURL+ " contains the OrgName '"+groupName+"' read by LF GroupManager. The Catalogue Portlet should be at VRE level, reading configuration isViewPerVREEnabled");
toReturn = "/organization_vre/" + groupName;
}else {
//this should mean the caller is out from VRE environment,so should be a public or gateway catalogue
logger.info("The browserLocationURL: "+browserLocationURL+ " DOES NOT contain the OrgName '"+groupName+"' read by LF GroupManager. Ignoring configuration isViewPerVREEnabled");
}
}
logger.debug("Read value for " + VIEW_PER_ORGANIZATION_LIFERAY_CUSTOM_FIELD + " is " + enabled + " and path is " + toReturn);
}catch(Exception e){
logger.error("Failed to parse custom field value", e);
}