diff --git a/changelog.xml b/changelog.xml index e197d17..5a3dbe1 100644 --- a/changelog.xml +++ b/changelog.xml @@ -1,4 +1,8 @@ + + [Feature #18038] Catalogue Resolver: resolve a public ITEM URL to the public VRE Catalogue (if available) + + [Feature #17630] Support parametric Content-Disposition diff --git a/pom.xml b/pom.xml index 63b0a65..1e42a97 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.2.0 + 2.3.0-SNAPSHOT war 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. diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/ItemCatalogueURLs.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/ItemCatalogueURLs.java index 1d06bd5..d6b74f0 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/ItemCatalogueURLs.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/ItemCatalogueURLs.java @@ -8,20 +8,23 @@ 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 publicVRECataloguePortletURL; + private String publicGatewayCataloguePortletURL; + } diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CkanCatalogueConfigurationsReader.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CkanCatalogueConfigurationsReader.java index 090329f..424ec14 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CkanCatalogueConfigurationsReader.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/CkanCatalogueConfigurationsReader.java @@ -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; @@ -48,8 +50,7 @@ public class CkanCatalogueConfigurationsReader { public final static String APPLICATION_PROFILE_NAME = "CkanPortlet"; private static final String DATACATALOGUECONFIGURATION_PROPERTIES = "datacatalogueconfiguration.properties"; - - + /** * Load catalogue end points. * @@ -62,18 +63,27 @@ public class CkanCatalogueConfigurationsReader { DataCatalogueImpl catalogueImpl = CatalogueServiceEndpointReader.getDataCatalogueImpl(); - String privatePortletURL = catalogueImpl.getPortletUrl(); - links.setPrivatePortletURL(privatePortletURL); - - //Building public URL from private portlet URL + Map accessLevelMap = catalogueImpl.getMapAccessURLToCatalogue(); + links.setMapAccessURLToCatalogue(accessLevelMap); + 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); + String publicGatewayPortletURL = accessLevelMap.get(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY); + links.setPublicGatewayPortletURL(publicGatewayPortletURL); + try{ - URI toURL = new URI(privatePortletURL); - String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost(); - //It returns the string "catalogue" - String prefixToPublicCtlg = getRelativeURLToCatalogue(); - //Replacing for example "ckan-bb" with "catalogue-bb" - String publicCatalogueName = extractCatalogueName(catalogueImpl.getCatalogueUrl(), prefixToPublicCtlg); - links.setPublicPortletURL(publicURL+"/"+publicCatalogueName); + + if(publicGatewayPortletURL==null || publicGatewayPortletURL.isEmpty()) { + //Building the gateway catalogue public URL from private VRE Portlet URL + URI toURL = new URI(privatePortletURL); + String publicURL = privatePortletURL.startsWith("https://")?"https://"+toURL.getHost():"http://"+toURL.getHost(); + //It returns the string "catalogue" + String prefixToPublicCtlg = getRelativeURLToCatalogue(); + //Replacing for example "ckan-bb" with "catalogue-bb" + String publicCatalogueName = extractCatalogueName(catalogueImpl.getCatalogueUrl(), prefixToPublicCtlg); + links.setPublicGatewayPortletURL(publicURL+"/"+publicCatalogueName); + } }catch(Exception e){ logger.warn("Erron on generating public catalogue URL from private URL: "+privatePortletURL, e); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GatewayCKANCatalogueReference.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GatewayCKANCatalogueReference.java index fe05f97..6d64c53 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GatewayCKANCatalogueReference.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GatewayCKANCatalogueReference.java @@ -4,137 +4,46 @@ 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; +import lombok.ToString; /** + * 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 +@ToString 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 mapAccessURLToCatalogue; + } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java index 4a06ffe..fa5ee7d 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -74,11 +74,17 @@ 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()+" should be a public item (not private to VRE)."); + if(itemCatalogueURLs.getPublicVRECataloguePortletURL()!=null && !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) { + itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL(); + logger.info("I found the public VRE catalogue URL, so using public access to it: "+itemCatalogueURL); + }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(); - logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a private item so using protected access to CKAN portlet: "+itemCatalogueURL); + itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL(); + logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a private item (to VRE) so using protected access to CKAN portlet: "+itemCatalogueURL); } return Response.seeOther(new URL(itemCatalogueURL).toURI()).build(); @@ -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, publicVREPortletURL, publicGatewayPorltetURL); }catch (Exception e) { logger.error("Error when resolving CatalogueURL:", e); throw e; diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java index 96d0dda..1062a2b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/PartheosRegistryResolver.java @@ -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) { diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore index dd9b900..5513774 100644 --- a/src/test/resources/.gitignore +++ b/src/test/resources/.gitignore @@ -1,4 +1,5 @@ /CNR.it.gcubekey +/EUBrazilOpenBio.gcubekey /Ecosystem.gcubekey /FARM.gcubekey /ISTI.gcubekey