Integrating the map with access URLs to catalogue added to

ckan-util-library
This commit is contained in:
Francesco Mangiacrapa 2019-11-12 18:18:22 +01:00
parent f159e1b855
commit 7214f2e188
8 changed files with 67 additions and 137 deletions

View File

@ -4,6 +4,9 @@
<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-2.12.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="uri-resolver"/>
<property name="java-output-path" value="/uri-resolver/target/classes"/>
</wb-module>

View File

@ -1,4 +1,8 @@
<ReleaseNotes>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-2-0" date="2019-11-12">
<Change>[Feature #18038] Catalogue Resolver: resolve a public ITEM URL to the public VRE Catalogue (if available)
</Change>
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-2-0" date="2019-10-04">
<Change>[Feature #17630] Support parametric Content-Disposition
</Change>

View File

@ -9,7 +9,7 @@
</parent>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>uri-resolver</artifactId>
<version>2.2.0</version>
<version>2.3.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description>

View File

@ -8,20 +8,22 @@ import lombok.Getter;
import lombok.Setter;
/**
* The Class ItemCatalogueURLs.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 26, 2018
*
* Nov 12, 2019
*/
@AllArgsConstructor
@Getter
@Setter
public class ItemCatalogueURLs {
private String itemName;
private boolean isPublicItem;
private String privateCataloguePortletURL;
private String publicCataloguePortletURL;
private String privateVRECataloguePortletURL;
private String publicGatewayCataloguePortletURL;
private String publicVRECataloguePortletURL;
}

View File

@ -13,6 +13,7 @@ import java.io.InputStream;
import java.io.StringReader;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
@ -21,6 +22,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueImpl;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
import org.gcube.datatransfer.resolver.catalogue.endpoint.CatalogueServiceEndpointReader;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -62,8 +64,13 @@ public class CkanCatalogueConfigurationsReader {
DataCatalogueImpl catalogueImpl = CatalogueServiceEndpointReader.getDataCatalogueImpl();
String privatePortletURL = catalogueImpl.getPortletUrl();
links.setPrivatePortletURL(privatePortletURL);
//String privatePortletURL = catalogueImpl.getPortletUrl();
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> accessLevelMap = catalogueImpl.getMapAccessURLToCatalogue();
String privatePortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE);
links.setPrivateVREPortletURL(privatePortletURL);
String publicVREPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
links.setPublicVREPortletURL(publicVREPortletURL);
//Building public URL from private portlet URL
try{
@ -73,7 +80,7 @@ public class CkanCatalogueConfigurationsReader {
String prefixToPublicCtlg = getRelativeURLToCatalogue();
//Replacing for example "ckan-bb" with "catalogue-bb"
String publicCatalogueName = extractCatalogueName(catalogueImpl.getCatalogueUrl(), prefixToPublicCtlg);
links.setPublicPortletURL(publicURL+"/"+publicCatalogueName);
links.setPublicGatewayPortletURL(publicURL+"/"+publicCatalogueName);
}catch(Exception e){
logger.warn("Erron on generating public catalogue URL from private URL: "+privatePortletURL, e);
}

View File

@ -4,137 +4,44 @@
package org.gcube.datatransfer.resolver.catalogue.resource;
import java.io.Serializable;
import java.util.Map;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* The Class GatewayCKANCatalogueReference.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 23, 2017
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 12, 2019
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class GatewayCKANCatalogueReference implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String privatePortletURL;
private String publicPortletURL;
private String scope;
private String privateVREPortletURL;
private String publicVREPortletURL;
private String publicGatewayPortletURL;
private String ckanURL;
/**
*
*/
public GatewayCKANCatalogueReference() {
}
/**
* @param privatePortletURL
* @param publicPortletURL
* @param ckanURL
* @param scope
*/
public GatewayCKANCatalogueReference(String scope,
String privatePortletURL, String publicPortletURL, String ckanURL) {
this.scope = scope;
this.privatePortletURL = privatePortletURL;
this.publicPortletURL = publicPortletURL;
this.ckanURL = ckanURL;
}
/**
* @return the ckanURL
*/
public String getCkanURL() {
return ckanURL;
}
/**
* @param ckanURL the ckanURL to set
*/
public void setCkanURL(String ckanURL) {
this.ckanURL = ckanURL;
}
/**
* @return the privatePortletURL
*/
public String getPrivatePortletURL() {
return privatePortletURL;
}
/**
* @return the publicPortletURL
*/
public String getPublicPortletURL() {
return publicPortletURL;
}
/**
* @return the scope
*/
public String getScope() {
return scope;
}
/**
* @param privatePortletURL the privatePortletURL to set
*/
public void setPrivatePortletURL(String privatePortletURL) {
this.privatePortletURL = privatePortletURL;
}
/**
* @param publicPortletURL the publicPortletURL to set
*/
public void setPublicPortletURL(String publicPortletURL) {
this.publicPortletURL = publicPortletURL;
}
/**
* @param scope the scope to set
*/
public void setScope(String scope) {
this.scope = scope;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GatewayCatalogueReference [privatePortletURL=");
builder.append(privatePortletURL);
builder.append(", publicPortletURL=");
builder.append(publicPortletURL);
builder.append(", scope=");
builder.append(scope);
builder.append(", ckanURL=");
builder.append(ckanURL);
builder.append("]");
return builder.toString();
}
public Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue;
}

View File

@ -74,10 +74,16 @@ public class CatalogueResolver {
String itemCatalogueURL;
if(itemCatalogueURLs.isPublicItem()){
itemCatalogueURL = itemCatalogueURLs.getPublicCataloguePortletURL();
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a public item so using public access to CKAN portlet: "+itemCatalogueURL);
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a public");
if(itemCatalogueURLs.getPublicVRECataloguePortletURL()!=null && !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL();
logger.info("I found the public VRE catalogue URL "+itemCatalogueURL+" so using public access to it");
}else {
itemCatalogueURL = itemCatalogueURLs.getPublicGatewayCataloguePortletURL();
logger.info("No public VRE catalogue URL found, so using public access to gateway CKAN portlet: "+itemCatalogueURL);
}
}else{
itemCatalogueURL = itemCatalogueURLs.getPrivateCataloguePortletURL();
itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL();
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a private item so using protected access to CKAN portlet: "+itemCatalogueURL);
}
@ -156,7 +162,7 @@ public class CatalogueResolver {
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
}
//ALREADY MANAGED AS WebApplicationException
//ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
logger.error("Exception:", e);
throw (WebApplicationException) e;
}
@ -217,9 +223,10 @@ public class CatalogueResolver {
}
}
String publicPorltetURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicPortletURL(),entityContextValue, entityName);
String privatePortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPrivatePortletURL(),entityContextValue, entityName);
return new ItemCatalogueURLs(entityName, isPublicItem, privatePortletURL, publicPorltetURL);
String publicGatewayPorltetURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicGatewayPortletURL(),entityContextValue, entityName);
String privateVREPortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPrivateVREPortletURL(),entityContextValue, entityName);
String publicVREPortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicVREPortletURL(),entityContextValue, entityName);
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicGatewayPorltetURL, publicVREPortletURL);
}catch (Exception e) {
logger.error("Error when resolving CatalogueURL:", e);
throw e;

View File

@ -79,7 +79,7 @@ public class PartheosRegistryResolver {
String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL);
logger.info("Trying to resolve with Catalogue EntityName: "+normalizedEntityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateCataloguePortletURL()).toURI()).build();
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateVRECataloguePortletURL()).toURI()).build();
}catch (Exception e) {
@ -127,8 +127,8 @@ public class PartheosRegistryResolver {
//APPLYING NAME TRANSFORMATION
String normalizedEntityName = toNameForCatalogue(entityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
logger.info("Returining Catalogue URL: "+itemCatalogueURLs.getPrivateCataloguePortletURL());
return Response.ok(normalizedEntityName).header("Location", itemCatalogueURLs.getPrivateCataloguePortletURL()).build();
logger.info("Returining Catalogue URL: "+itemCatalogueURLs.getPrivateVRECataloguePortletURL());
return Response.ok(normalizedEntityName).header("Location", itemCatalogueURLs.getPrivateVRECataloguePortletURL()).build();
}catch (Exception e) {