From fc72fe1029075993196528f037671e26615670a4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 23 Mar 2023 15:54:00 +0100 Subject: [PATCH 01/35] First version of Geoportal Resolver --- .classpath | 10 +- CHANGELOG.md | 4 + pom.xml | 12 +- .../catalogue/ResourceCatalogueCodes.java | 77 +++-- .../geoportal/GeoportalCommonConstants.java | 17 + .../GeoportalDataViewerConfigProfile.java | 75 +++++ ...eoportalDataViewerConfigProfileReader.java | 170 ++++++++++ .../resolver/geoportal/GeoportalRequest.java | 43 +++ .../geoportal/ResourceGeoportalCodes.java | 118 +++++++ .../resolver/services/CatalogueResolver.java | 2 +- .../resolver/services/GeoportalResolver.java | 291 ++++++++++++++++++ 11 files changed, 771 insertions(+), 48 deletions(-) create mode 100644 src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalCommonConstants.java create mode 100644 src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfile.java create mode 100644 src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfileReader.java create mode 100644 src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java create mode 100644 src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java create mode 100644 src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java diff --git a/.classpath b/.classpath index 06c0510..2ae7ba7 100644 --- a/.classpath +++ b/.classpath @@ -24,16 +24,16 @@ + + + + + - - - - - diff --git a/CHANGELOG.md b/CHANGELOG.md index 79b0ac6..1b28d88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ 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). +## [v2.9.0-SNAPSHOT] + +- GeoPortalResolver implemented [#24792] + ## [v2.8.1] - 2022-06-13 **New** diff --git a/pom.xml b/pom.xml index 24dc8d2..913452e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.8.1 + 2.9.0-SNAPSHOT war The URI Resolver is an HTTP URI resolver implemented as a REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications. @@ -202,6 +202,14 @@ compile + + + org.opengis + geoapi + 3.0.1 + + commons-lang commons-lang @@ -249,7 +257,7 @@ 4.8.2 test - + diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/ResourceCatalogueCodes.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/ResourceCatalogueCodes.java index 57fb069..ce3051c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/ResourceCatalogueCodes.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/ResourceCatalogueCodes.java @@ -3,35 +3,34 @@ */ package org.gcube.datatransfer.resolver.catalogue; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; - +import java.util.stream.Collectors; /** * The Enum ResourceCatalogueCodes. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jan 31, 2017 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 31, 2017 * - * see wiki page: https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver + * see wiki page: + * https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver */ public enum ResourceCatalogueCodes { - CTLG("ctlg","dataset", "Catalogue Product/Dataset"), - //CTLGP("ctlg-p","product", "Catalogue Product"), - CTLGD("ctlg-d","dataset", "Catalogue Dataset"), - CTLGO("ctlg-o","organization", "Catalogue Organization"), - CTLGG("ctlg-g","group", "Catalogue Group"); + CTLG("ctlg", "dataset", "Catalogue Product/Dataset"), + // CTLGP("ctlg-p","product", "Catalogue Product"), + CTLGD("ctlg-d", "dataset", "Catalogue Dataset"), CTLGO("ctlg-o", "organization", "Catalogue Organization"), + CTLGG("ctlg-g", "group", "Catalogue Group"); - private String id; //the code id - private String value; //the code value + private String id; // the code id + private String value; // the code value private String description; /** * Instantiates a new resource catalogue codes. * - * @param id the id - * @param value the value + * @param id the id + * @param value the value * @param description the description */ private ResourceCatalogueCodes(String id, String value, String description) { @@ -50,7 +49,6 @@ public enum ResourceCatalogueCodes { return id; } - /** * Gets the value. * @@ -61,7 +59,6 @@ public enum ResourceCatalogueCodes { return value; } - /** * Gets the description. * @@ -72,40 +69,37 @@ public enum ResourceCatalogueCodes { return description; } - /** * Codes. * * @return the list */ - public static List codes(){ + public static List codes() { - List codes = new ArrayList(ResourceCatalogueCodes.values().length); - for (ResourceCatalogueCodes value : ResourceCatalogueCodes.values()) { - codes.add(value.getId()); - } - - return codes; + return Arrays.asList(ResourceCatalogueCodes.values()).stream().map(ResourceCatalogueCodes::getId) + .collect(Collectors.toList()); } - /** * Value of code id. * * @param id the id * @return the resource catalogue codes */ - public static ResourceCatalogueCodes valueOfCodeId(String id){ - if(id==null || id.isEmpty()) + public static ResourceCatalogueCodes valueOfCodeId(String id) { + if (id == null || id.isEmpty()) return null; - for (ResourceCatalogueCodes value : ResourceCatalogueCodes.values()) { - if(value.id.compareTo(id)==0) - return value; - } - return null; - } + List codes = Arrays.asList(ResourceCatalogueCodes.values()).stream() + .filter(r -> r.getId().compareTo(id) == 0) + .collect(Collectors.toList()); + if (codes == null || codes.isEmpty()) + return null; + + return codes.get(0); + + } /** * Value of code value. @@ -113,14 +107,17 @@ public enum ResourceCatalogueCodes { * @param codeValue the code value * @return the resource catalogue codes */ - public static ResourceCatalogueCodes valueOfCodeValue(String codeValue){ - if(codeValue==null || codeValue.isEmpty()) + public static ResourceCatalogueCodes valueOfCodeValue(String codeValue) { + if (codeValue == null || codeValue.isEmpty()) return null; - for (ResourceCatalogueCodes rcc : ResourceCatalogueCodes.values()) { - if(rcc.value.compareTo(codeValue)==0) - return rcc; - } - return null; + List codes = Arrays.asList(ResourceCatalogueCodes.values()).stream() + .filter(r -> r.getValue().compareTo(codeValue) == 0) + .collect(Collectors.toList()); + + if (codes == null || codes.isEmpty()) + return null; + + return codes.get(0); } } diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalCommonConstants.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalCommonConstants.java new file mode 100644 index 0000000..b2ff4d5 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalCommonConstants.java @@ -0,0 +1,17 @@ +package org.gcube.datatransfer.resolver.geoportal; + +/** + * The Class GeoportalCommonConstants. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Dec 1, 2020 + */ +public class GeoportalCommonConstants { + + public static final String GET_GEONA_ITEM_TYPE = "git"; + public static final String GET_GEONA_ITEM_ID = "gid"; + + public static final String GEOPORTAL_DATA_VIEWER_APP = "geoportal-data-viewer-app"; + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfile.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfile.java new file mode 100644 index 0000000..b3c0c73 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfile.java @@ -0,0 +1,75 @@ +package org.gcube.datatransfer.resolver.geoportal; + +import java.io.Serializable; + +/** + * The Class GeoportalDataViewerConfigProfile. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 21, 2021 + */ +public class GeoportalDataViewerConfigProfile implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 2968334957258327191L; + private String restrictedPortletURL; + private String openPortletURL; + + /** + * Instantiates a new geo na data viewer profile. + */ + public GeoportalDataViewerConfigProfile() { + + } + + /** + * Gets the restricted portlet URL. + * + * @return the restricted portlet URL + */ + public String getRestrictedPortletURL() { + return restrictedPortletURL; + } + + /** + * Sets the restricted portlet URL. + * + * @param restrictedPortletURL the new restricted portlet URL + */ + public void setRestrictedPortletURL(String restrictedPortletURL) { + this.restrictedPortletURL = restrictedPortletURL; + } + + /** + * Gets the open portlet URL. + * + * @return the open portlet URL + */ + public String getOpenPortletURL() { + return openPortletURL; + } + + /** + * Sets the open portlet URL. + * + * @param openPortletURL the new open portlet URL + */ + public void setOpenPortletURL(String openPortletURL) { + this.openPortletURL = openPortletURL; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeoportalDataViewerConfigProfile [restrictedPortletURL="); + builder.append(restrictedPortletURL); + builder.append(", openPortletURL="); + builder.append(openPortletURL); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfileReader.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfileReader.java new file mode 100644 index 0000000..5b8fb8b --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalDataViewerConfigProfileReader.java @@ -0,0 +1,170 @@ +package org.gcube.datatransfer.resolver.geoportal; + +import static org.gcube.resources.discovery.icclient.ICFactory.client; + +import java.io.StringReader; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.gcube.common.resources.gcore.utils.XPathHelper; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.Query; +import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +/** + * The Class GeoportalDataViewerConfigProfileReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 23, 2023 + */ +public class GeoportalDataViewerConfigProfileReader { + + private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; + public static final String SECONDARY_TYPE = "ApplicationProfile"; + public static final String GENERIC_RESOURCE_NAME = "Geoportal-DataViewer-Configs"; + + private static Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerConfigProfileReader.class); + private String secondaryType; + private String scope; + private String appID; + private GeoportalDataViewerConfigProfile geoportalDataViewerConfigProfile; + + /** + * Instantiates a new geoportal data viewer config profile reader. + * + * @param appID the app ID + * @throws Exception the exception + */ + public GeoportalDataViewerConfigProfileReader(String appID) throws Exception { + + this.appID = appID; + this.secondaryType = SECONDARY_TYPE; + this.scope = ScopeProvider.instance.get(); + this.geoportalDataViewerConfigProfile = readProfileFromInfrastructure(); + } + + /** + * Read profile from infrastrucure. + * + * @return the map + * @throws Exception the exception + */ + private GeoportalDataViewerConfigProfile readProfileFromInfrastructure() throws Exception { + + String queryString = getGcubeGenericQueryString(secondaryType, appID); + LOG.info("Scope " + scope + ", trying to perform query: " + queryString); + + try { + + if (scope == null) + throw new Exception("Scope is null, set scope into ScopeProvider"); + + GeoportalDataViewerConfigProfile profile = new GeoportalDataViewerConfigProfile(); + + LOG.info("Trying to fetch ApplicationProfile in the scope: " + scope + ", SecondaryType: " + secondaryType + + ", AppId: " + appID); + Query q = new QueryBox(queryString); + DiscoveryClient client = client(); + List appProfile = client.submit(q); +// String item_fields = ""; + + if (appProfile == null || appProfile.size() == 0) + throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + + ", AppId: " + appID + " is not registered in the scope: " + scope); + else { + String elem = appProfile.get(0); + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = docBuilder.parse(new InputSource(new StringReader(elem))); + + XPathHelper helper = new XPathHelper(doc.getDocumentElement()); + + List currValue = null; + String xPathExp = RESOURCE_PROFILE_BODY + "/RestrictedPortletURL/text()"; + currValue = helper.evaluate(xPathExp); + if (currValue != null && currValue.size() > 0) { + profile.setRestrictedPortletURL(currValue.get(0)); + } else + throw new Exception("I'm not able to read the path: " + xPathExp); + + xPathExp = RESOURCE_PROFILE_BODY + "/OpenPortletURL/text()"; + currValue = helper.evaluate(xPathExp); + if (currValue != null && currValue.size() > 0) { + profile.setOpenPortletURL(currValue.get(0)); + } else + throw new Exception("I'm not able to read the path: " + xPathExp); + + LOG.info("returning: " + profile); + return profile; + } + + } catch (Exception e) { + LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " + + GENERIC_RESOURCE_NAME + " from scope " + scope, e); + return null; + } finally { + + } + + } + + public GeoportalDataViewerConfigProfile getGeoportalDataViewerConfigProfile() { + return geoportalDataViewerConfigProfile; + } + + /** + * Gets the gcube generic query string. + * + * @param secondaryType the secondary type + * @param appId the app id + * @return the gcube generic query string + */ + public static String getGcubeGenericQueryString(String secondaryType, String appId) { + + return "for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq '" + secondaryType + + "' and $profile/Profile/Body/AppId/string() " + " eq '" + appId + "'" + "return $profile"; + } + + /** + * Gets the secondary type. + * + * @return the secondary type + */ + public String getSecondaryType() { + return secondaryType; + } + + /** + * Gets the scope. + * + * @return the scope + */ + public String getScope() { + return scope; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeoportalDataViewerConfigProfileReader [secondaryType="); + builder.append(secondaryType); + builder.append(", scope="); + builder.append(scope); + builder.append(", appID="); + builder.append(appID); + builder.append(", geoportalDataViewerConfigProfile="); + builder.append(geoportalDataViewerConfigProfile); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java new file mode 100644 index 0000000..0a7a5ba --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java @@ -0,0 +1,43 @@ +package org.gcube.datatransfer.resolver.geoportal; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + + +/** + * The Class GeoportalRequest. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 23, 2023 + */ +@Slf4j +@Data +public class GeoportalRequest { + + public static final String P_GCUBE_SCOPE = "gcube_scope"; + public static final String P_TARGET_APP = "target_app"; + public static final String P_ITEM_TYPE = "item_type"; + public static final String P_ITEM_ID = "item_id"; + public static final String P_QUERY_STRING = "query_string"; + + @JsonProperty(P_GCUBE_SCOPE) + private String gcubeScope; + @JsonProperty(P_TARGET_APP) + private String targetApp; + /** + * It is the UCD ID {usecase_id} + */ + @JsonProperty(P_ITEM_TYPE) + private String itemType; + /** + * It is the Project ID {project_id} + */ + @JsonProperty(P_ITEM_ID) + private String itemID; + @JsonProperty(P_QUERY_STRING) + private String queryString; + +} diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java new file mode 100644 index 0000000..91fa566 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java @@ -0,0 +1,118 @@ +/** + * + */ +package org.gcube.datatransfer.resolver.geoportal; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * The Enum ResourceGeoportalCodes. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 23, 2023 + */ +public enum ResourceGeoportalCodes { + + GEO("geo", "data-viewer", "Geoportal Viewer"), GEOV("geo-v", "data-viewer", "Geoportal Viewer"); + + private String id; // the code id + private String target_app; // the code value + private String description; + + /** + * Instantiates a new resource catalogue codes. + * + * @param id the id + * @param target_app the target app + * @param description the description + */ + private ResourceGeoportalCodes(String id, String target_app, String description) { + this.id = id; + this.target_app = target_app; + this.description = description; + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + + return id; + } + + /** + * Gets the target app. + * + * @return the target app + */ + public String getTarget_app() { + return target_app; + } + + /** + * Gets the description. + * + * @return the description + */ + public String getDescription() { + + return description; + } + + /** + * Codes. + * + * @return the list + */ + public static List codes() { + + return Arrays.asList(ResourceGeoportalCodes.values()).stream().map(ResourceGeoportalCodes::getId) + .collect(Collectors.toList()); + } + + /** + * Value of code id. + * + * @param id the id + * @return the resource geoportal codes + */ + public static ResourceGeoportalCodes valueOfCodeId(String id) { + if (id == null || id.isEmpty()) + return null; + + List codes = Arrays.asList(ResourceGeoportalCodes.values()).stream() + .filter(value -> value.getId().compareTo(id) == 0).collect(Collectors.toList()); + + if (codes == null || codes.isEmpty()) + return null; + + return codes.get(0); + + } + + /** + * Value of target app. + * + * @param targetApp the target app + * @return the resource geoportal codes + */ + public static ResourceGeoportalCodes valueOfTargetApp(String targetApp) { + if (targetApp == null || targetApp.isEmpty()) + return null; + + List codes = Arrays.asList(ResourceGeoportalCodes.values()).stream() + .filter(value -> value.getTarget_app().compareTo(targetApp) == 0).collect(Collectors.toList()); + + if (codes == null || codes.isEmpty()) + return null; + + return codes.get(0); + + } + +} 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 05bb132..0dbd969 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -207,7 +207,7 @@ public class CatalogueResolver { linkURL += "?" + jsonRequest.getQuery_string(); } - logger.info("Returining Catalogue URL: " + linkURL); + logger.info("Returning "+CatalogueResolver.class.getSimpleName()+" URL: " + linkURL); return Response.ok(linkURL).header("Location", linkURL).build(); } catch (Exception e) { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java new file mode 100644 index 0000000..8f7dae8 --- /dev/null +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -0,0 +1,291 @@ +package org.gcube.datatransfer.resolver.services; + +import java.net.URL; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.datatransfer.resolver.ConstantsResolver; +import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache; +import org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants; +import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfile; +import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfileReader; +import org.gcube.datatransfer.resolver.geoportal.GeoportalRequest; +import org.gcube.datatransfer.resolver.geoportal.ResourceGeoportalCodes; +import org.gcube.datatransfer.resolver.services.error.ExceptionManager; +import org.gcube.datatransfer.resolver.util.Util; +import org.gcube.smartgears.utils.InnerMethodName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.cache.CacheLoader.InvalidCacheLoadException; + +/** + * The GeoportalResolver is able to get/resolve a link to a "Geoportal Viewer" + * + * See more at + * https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 23, 2023 + */ +@Path("{targetApp:geo(-(v))?}") +public class GeoportalResolver { + + private static final String PROJECT_ID = "project_id"; + private static final String USECASE_ID = "usecase_id"; + private static final String VRE_NAME = "vreName"; + private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class); + private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; + + private static enum RESOLVE_AS { + PUBLIC, PRIVATE + } + + /** + * The Enum SCOPE_STATUS. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 24, 2022 + */ + private static enum SCOPE_STATUS { + ACTIVE, DETACHED + } + + @GET + @Path("/{vreName}/{usecase_id}/{project_id}") + public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(VRE_NAME) String vreName, + @PathParam(USECASE_ID) String ucdID, @PathParam(PROJECT_ID) String projectID, + @QueryParam("r") String resolve) throws WebApplicationException { + + LOG.info(this.getClass().getSimpleName() + " GET starts..."); + + try { + InnerMethodName.instance.set("resolveGeoportalPublicLink"); + + if (vreName == null || vreName.isEmpty()) { + LOG.error("The path parameter '" + VRE_NAME + "' not found or empty in the path"); + throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", + this.getClass(), helpURI); + } + + if (ucdID == null) { + LOG.error("The path parameter '" + USECASE_ID + "' not found or empty in the path"); + throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", + this.getClass(), helpURI); + } + + if (projectID == null) { + LOG.error("The path parameter '" + PROJECT_ID + "' not found or empty in the path"); + throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", + this.getClass(), helpURI); + } + + ScopeBean fullScopeBean = null; + + // CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE... + try { + fullScopeBean = LoadingMapOfScopeCache.get(vreName); + } catch (ExecutionException | InvalidCacheLoadException e) { + LOG.error("Error on getting the fullscope from cache for vreName " + vreName, e); + throw ExceptionManager.wrongParameterException(req, + "Error on getting full scope for the VRE name " + vreName + + ". Is it registered as VRE in the D4Science Infrastructure System?", + this.getClass(), helpURI); + } + + RESOLVE_AS resolveTO = RESOLVE_AS.PUBLIC; + if (resolve != null) { + switch (resolve.toLowerCase()) { + case "public": + resolveTO = RESOLVE_AS.PUBLIC; + break; + case "private": + resolveTO = RESOLVE_AS.PRIVATE; + break; + } + } + + String originalScope = ScopeProvider.instance.get(); + GeoportalDataViewerConfigProfileReader reader; + try { + + ScopeProvider.instance.set(fullScopeBean.toString()); + reader = new GeoportalDataViewerConfigProfileReader( + org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); + } catch (Exception e) { + LOG.error("Error on reading the " + GeoportalDataViewerConfigProfileReader.SECONDARY_TYPE + + " with generic resource name: " + + GeoportalDataViewerConfigProfileReader.GENERIC_RESOURCE_NAME, e); + throw ExceptionManager.internalErrorException(req, + "Error on reading the " + GeoportalDataViewerConfigProfileReader.SECONDARY_TYPE + " for name " + + GeoportalDataViewerConfigProfileReader.GENERIC_RESOURCE_NAME + + ". Please contact the support", + this.getClass(), helpURI); + } finally { + if (originalScope != null && !originalScope.isEmpty()) { + ScopeProvider.instance.set(originalScope); + LOG.info("scope provider set to orginal scope: " + originalScope); + } else { + ScopeProvider.instance.reset(); + LOG.info("scope provider reset"); + } + } + + GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile(); + String itemLink = null; + switch (resolveTO) { + case PUBLIC: + // Open Link + itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(), + GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID, + GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID); + break; + case PRIVATE: + + // Restricted Link + String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(), + GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID, + GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID); + + break; + + default: + break; + } + + return Response.seeOther(new URL(itemLink).toURI()).build(); + } catch (Exception e) { + + if (!(e instanceof WebApplicationException)) { + // UNEXPECTED EXCEPTION managing it as WebApplicationException + String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!"; + if (e.getCause() != null) + error += "\n\nCaused: " + e.getCause().getMessage(); + throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); + } + // ALREADY MANAGED AS WebApplicationException + LOG.error("Exception:", e); + throw (WebApplicationException) e; + } + } + + /** + * Create a Catalogue Link. + * + * @param req the req + * @param jsonRequest the json request + * @return the response + * @throws WebApplicationException the web application exception + */ + @POST + @Path("") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) + throws WebApplicationException { + LOG.info(this.getClass().getSimpleName() + " POST starts..."); + + try { + + InnerMethodName.instance.set("postGeoportalPublicLink"); + LOG.info("The body contains the request: " + jsonRequest.toString()); + + if (jsonRequest.getGcubeScope() == null) { + throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_GCUBE_SCOPE, + this.getClass(), helpURI); + } + + if (jsonRequest.getItemID() == null) { + throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_ITEM_ID, + this.getClass(), helpURI); + } + + if (jsonRequest.getItemType() == null) { + throw ExceptionManager.badRequestException(req, "Missing parameter " + GeoportalRequest.P_ITEM_TYPE, + this.getClass(), helpURI); + } + + // CHECK IF INPUT SCOPE IS VALID + String scope = jsonRequest.getGcubeScope(); + if (!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)) { + LOG.info("Scope not start with char '{}' adding it", ConstantsResolver.SCOPE_SEPARATOR); + scope += ConstantsResolver.SCOPE_SEPARATOR + scope; + } + + String serverUrl = Util.getServerURL(req); + final String vreName = scope.substring(scope.lastIndexOf(ConstantsResolver.SCOPE_SEPARATOR) + 1, + scope.length()); + ScopeBean fullScope = null; + + // CHECK IF THE vreName has a valid scope, so it is a valid VRE + try { + fullScope = LoadingMapOfScopeCache.get(vreName); + } catch (ExecutionException e) { + LOG.error("Error on getting the fullscope from cache for vreName " + vreName, e); + throw ExceptionManager.wrongParameterException(req, + "Error on getting full scope for the VRE name " + vreName + + ". Is it registered as VRE in the D4Science Infrastructure System?", + this.getClass(), helpURI); + } + + if (fullScope == null) + throw ExceptionManager.notFoundException(req, + "The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?", + this.getClass(), helpURI); + + ResourceGeoportalCodes resoruceGeoportalCodes = ResourceGeoportalCodes + .valueOfTargetApp(jsonRequest.getTargetApp()); + + if (resoruceGeoportalCodes == null) { + LOG.error("Target application is null/malformed"); + + List targetApps = Arrays.asList(ResourceGeoportalCodes.values()).stream() + .map(ResourceGeoportalCodes::getTarget_app).collect(Collectors.toList()); + + throw ExceptionManager.badRequestException(req, + "Target application is null/malformed. It must be: " + targetApps, this.getClass(), helpURI); + } + + String linkURL = String.format("%s/%s/%s/%s%s", serverUrl, resoruceGeoportalCodes.getId(), vreName, + jsonRequest.getItemType(), jsonRequest.getItemID()); + + if (jsonRequest.getQueryString() != null) { + linkURL += "?" + jsonRequest.getQueryString(); + } + + LOG.info("Returning " + CatalogueResolver.class.getSimpleName() + " URL: " + linkURL); + return Response.ok(linkURL).header("Location", linkURL).build(); + + } catch (Exception e) { + + if (!(e instanceof WebApplicationException)) { + // UNEXPECTED EXCEPTION managing it as WebApplicationException + String error = "Error occurred on resolving the Analytics URL. Please, contact the support!"; + throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); + } + // ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs + LOG.error("Exception:", e); + throw (WebApplicationException) e; + } + } + +} From 55a8e4001e9e380fa27b8b6105d033a3efce3603 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 23 Mar 2023 16:01:17 +0100 Subject: [PATCH 02/35] added `jaxb-api` for building towards JDK_11 --- pom.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 913452e..42aaf28 100644 --- a/pom.xml +++ b/pom.xml @@ -192,7 +192,15 @@ lombok 1.14.8 - + + + + javax.xml.bind + jaxb-api + 2.3.0 + provided + + @@ -208,6 +216,7 @@ org.opengis geoapi 3.0.1 + provided From 59f97bc752940dc0021af5016f8ca478fbe54f9d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 23 Mar 2023 16:04:23 +0100 Subject: [PATCH 03/35] added `lombok` 1.18.4 FOR BUILDING towards JDK_11 --- pom.xml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 42aaf28..6341e37 100644 --- a/pom.xml +++ b/pom.xml @@ -192,15 +192,23 @@ lombok 1.14.8 - + - - javax.xml.bind - jaxb-api - 2.3.0 - provided - - + + javax.xml.bind + jaxb-api + 2.3.0 + provided + + + + + org.projectlombok + lombok + 1.18.4 + provided + + From be8f8755ac69f2c04b2004cfd8821de5bfa45187 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 23 Mar 2023 16:32:45 +0100 Subject: [PATCH 04/35] Moved Builder to lombok 1.18.4 --- .../gcube/datatransfer/resolver/services/error/ErrorReport.java | 2 +- .../datatransfer/resolver/services/error/ExceptionReport.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java b/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java index 280a96b..ce509c3 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/error/ErrorReport.java @@ -9,10 +9,10 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.experimental.Builder; @XmlRootElement(name="error") diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java b/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java index 0f4088d..45cb9a0 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/error/ExceptionReport.java @@ -10,10 +10,10 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.experimental.Builder; /** From b1e3dc5dbc40ece246f7d2c387f3ade94e875c93 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 23 Mar 2023 16:52:08 +0100 Subject: [PATCH 05/35] Fixed Geoportal Get Request. --- .../gcube/datatransfer/resolver/services/GeoportalResolver.java | 2 +- .../resolver/services/exceptions/BadRequestException.java | 2 +- .../resolver/services/exceptions/ForbiddenRequestException.java | 2 +- .../resolver/services/exceptions/InternalServerException.java | 2 +- .../services/exceptions/NotAuthorizedRequestException.java | 2 +- .../resolver/services/exceptions/NotFoundException.java | 2 +- .../resolver/services/exceptions/WrongParameterException.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 8f7dae8..af051c7 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -265,7 +265,7 @@ public class GeoportalResolver { "Target application is null/malformed. It must be: " + targetApps, this.getClass(), helpURI); } - String linkURL = String.format("%s/%s/%s/%s%s", serverUrl, resoruceGeoportalCodes.getId(), vreName, + String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, resoruceGeoportalCodes.getId(), vreName, jsonRequest.getItemType(), jsonRequest.getItemID()); if (jsonRequest.getQueryString() != null) { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java index 22412e1..15c039c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java @@ -55,7 +55,7 @@ public class BadRequestException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XML).build()); + .type(MediaType.APPLICATION_XHTML_XML).build()); } } \ No newline at end of file diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java index 0fd49f1..6c24ccb 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java @@ -58,7 +58,7 @@ public class ForbiddenRequestException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XML).build()); + .type(MediaType.APPLICATION_XHTML_XML).build()); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java index d50c73a..cb2e1be 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java @@ -53,7 +53,7 @@ public class InternalServerException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XML).build()); + .type(MediaType.APPLICATION_XHTML_XML).build()); } } \ No newline at end of file diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java index 76e2772..a65df92 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java @@ -56,7 +56,7 @@ public class NotAuthorizedRequestException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XML).build()); + .type(MediaType.APPLICATION_XHTML_XML).build()); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java index 489ca8b..b0c12b4 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java @@ -56,7 +56,7 @@ public class NotFoundException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XML).build()); + .type(MediaType.APPLICATION_XHTML_XML).build()); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java index cf456c3..28088c9 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java @@ -55,7 +55,7 @@ public class WrongParameterException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XML).build()); + .type(MediaType.APPLICATION_XHTML_XML).build()); } } \ No newline at end of file From 28ce7ae5898852067387c3646e5b8957df258805 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 23 Mar 2023 17:15:18 +0100 Subject: [PATCH 06/35] Updated Get resolve --- .../resolver/geoportal/ResourceGeoportalCodes.java | 2 +- .../datatransfer/resolver/services/GeoportalResolver.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java index 91fa566..83350e0 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; */ public enum ResourceGeoportalCodes { - GEO("geo", "data-viewer", "Geoportal Viewer"), GEOV("geo-v", "data-viewer", "Geoportal Viewer"); + GEO("geo", "geoportal-viewer", "Geoportal Viewer"), GEO_V("geo-v", "data-viewer", "Geoportal Viewer"); private String id; // the code id private String target_app; // the code value diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index af051c7..49acb0a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -257,7 +257,9 @@ public class GeoportalResolver { if (resoruceGeoportalCodes == null) { LOG.error("Target application is null/malformed"); - + resoruceGeoportalCodes = ResourceGeoportalCodes.GEO; + LOG.info("Target application using default: "+resoruceGeoportalCodes); + }else { List targetApps = Arrays.asList(ResourceGeoportalCodes.values()).stream() .map(ResourceGeoportalCodes::getTarget_app).collect(Collectors.toList()); From 1107c69b479d85d7db41f4903fac42a112de9f8d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 23 Mar 2023 17:24:09 +0100 Subject: [PATCH 07/35] Fixed logs --- .../datatransfer/resolver/services/CatalogueResolver.java | 8 +++++--- .../datatransfer/resolver/services/GeoportalResolver.java | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) 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 0dbd969..06baae6 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java @@ -132,7 +132,8 @@ public class CatalogueResolver { if (!(e instanceof WebApplicationException)) { // UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!"; + String error = "Error occurred on resolving the " + CatalogueResolver.class.getSimpleName() + + " URL. Please, contact the support!"; if (e.getCause() != null) error += "\n\nCaused: " + e.getCause().getMessage(); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); @@ -207,14 +208,15 @@ public class CatalogueResolver { linkURL += "?" + jsonRequest.getQuery_string(); } - logger.info("Returning "+CatalogueResolver.class.getSimpleName()+" URL: " + linkURL); + logger.info("Returning " + CatalogueResolver.class.getSimpleName() + " URL: " + linkURL); return Response.ok(linkURL).header("Location", linkURL).build(); } catch (Exception e) { if (!(e instanceof WebApplicationException)) { // UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = "Error occurred on resolving the Analytics URL. Please, contact the support!"; + String error = "Error occurred on creating the " + CatalogueResolver.class.getSimpleName() + + " URL. Please, contact the support!"; throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); } // ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 49acb0a..073ae76 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -177,7 +177,7 @@ public class GeoportalResolver { if (!(e instanceof WebApplicationException)) { // UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!"; + String error = "Error occurred on resolving the "+GeoportalResolver.class.getSimpleName()+" URL. Please, contact the support!"; if (e.getCause() != null) error += "\n\nCaused: " + e.getCause().getMessage(); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); @@ -281,7 +281,7 @@ public class GeoportalResolver { if (!(e instanceof WebApplicationException)) { // UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = "Error occurred on resolving the Analytics URL. Please, contact the support!"; + String error = "Error occurred on creating the "+GeoportalResolver.class.getSimpleName()+" URL. Please, contact the support!"; throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); } // ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs From c6694cd856537be0f7cfbeb37e77c188163f327c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 09:49:57 +0100 Subject: [PATCH 08/35] Updated Geoportal Resolver --- .../resolver/geoportal/GeoportalRequest.java | 2 +- ...odes.java => TargetAppGeoportalCodes.java} | 43 +++--- .../resolver/services/GeoportalResolver.java | 146 +++++++++++------- 3 files changed, 113 insertions(+), 78 deletions(-) rename src/main/java/org/gcube/datatransfer/resolver/geoportal/{ResourceGeoportalCodes.java => TargetAppGeoportalCodes.java} (53%) diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java index 0a7a5ba..8ca093f 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java @@ -18,7 +18,7 @@ import lombok.extern.slf4j.Slf4j; public class GeoportalRequest { public static final String P_GCUBE_SCOPE = "gcube_scope"; - public static final String P_TARGET_APP = "target_app"; + public static final String P_TARGET_APP = "target_app_name"; public static final String P_ITEM_TYPE = "item_type"; public static final String P_ITEM_ID = "item_id"; public static final String P_QUERY_STRING = "query_string"; diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java similarity index 53% rename from src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java rename to src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java index 83350e0..00388cd 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/geoportal/ResourceGeoportalCodes.java +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java @@ -8,30 +8,31 @@ import java.util.List; import java.util.stream.Collectors; /** - * The Enum ResourceGeoportalCodes. + * The Enum TargetAppGeoportalCodes. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Mar 23, 2023 + * Mar 24, 2023 */ -public enum ResourceGeoportalCodes { +public enum TargetAppGeoportalCodes { - GEO("geo", "geoportal-viewer", "Geoportal Viewer"), GEO_V("geo-v", "data-viewer", "Geoportal Viewer"); + GEO("geo", "geoportal", "Geoportal"), GEO_DV("geo-dv", "data-viewer", "Geoportal Viewer"), + GEO_DE("geo-de", "data-entry", "Geoportal Entry"); private String id; // the code id - private String target_app; // the code value + private String name; // the code value private String description; /** * Instantiates a new resource catalogue codes. * * @param id the id - * @param target_app the target app + * @param name the target app * @param description the description */ - private ResourceGeoportalCodes(String id, String target_app, String description) { + private TargetAppGeoportalCodes(String id, String name, String description) { this.id = id; - this.target_app = target_app; + this.name = name; this.description = description; } @@ -51,7 +52,7 @@ public enum ResourceGeoportalCodes { * @return the target app */ public String getTarget_app() { - return target_app; + return name; } /** @@ -71,21 +72,21 @@ public enum ResourceGeoportalCodes { */ public static List codes() { - return Arrays.asList(ResourceGeoportalCodes.values()).stream().map(ResourceGeoportalCodes::getId) + return Arrays.asList(TargetAppGeoportalCodes.values()).stream().map(TargetAppGeoportalCodes::getId) .collect(Collectors.toList()); } /** - * Value of code id. + * Value of id. * * @param id the id - * @return the resource geoportal codes + * @return the target app geoportal codes */ - public static ResourceGeoportalCodes valueOfCodeId(String id) { + public static TargetAppGeoportalCodes valueOfId(String id) { if (id == null || id.isEmpty()) return null; - List codes = Arrays.asList(ResourceGeoportalCodes.values()).stream() + List codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream() .filter(value -> value.getId().compareTo(id) == 0).collect(Collectors.toList()); if (codes == null || codes.isEmpty()) @@ -96,17 +97,17 @@ public enum ResourceGeoportalCodes { } /** - * Value of target app. + * Value of name. * - * @param targetApp the target app - * @return the resource geoportal codes + * @param name the name + * @return the target app geoportal codes */ - public static ResourceGeoportalCodes valueOfTargetApp(String targetApp) { - if (targetApp == null || targetApp.isEmpty()) + public static TargetAppGeoportalCodes valueOfName(String name) { + if (name == null || name.isEmpty()) return null; - List codes = Arrays.asList(ResourceGeoportalCodes.values()).stream() - .filter(value -> value.getTarget_app().compareTo(targetApp) == 0).collect(Collectors.toList()); + List codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream() + .filter(value -> value.getTarget_app().compareTo(name) == 0).collect(Collectors.toList()); if (codes == null || codes.isEmpty()) return null; diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 073ae76..79b367a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -27,7 +27,7 @@ import org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants; import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfile; import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfileReader; import org.gcube.datatransfer.resolver.geoportal.GeoportalRequest; -import org.gcube.datatransfer.resolver.geoportal.ResourceGeoportalCodes; +import org.gcube.datatransfer.resolver.geoportal.TargetAppGeoportalCodes; import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.util.Util; import org.gcube.smartgears.utils.InnerMethodName; @@ -46,12 +46,14 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("{targetApp:geo(-(v))?}") +@Path("{targetAppId:geo(-(dv|-de))?}") public class GeoportalResolver { - private static final String PROJECT_ID = "project_id"; - private static final String USECASE_ID = "usecase_id"; - private static final String VRE_NAME = "vreName"; + private static final String QP_RESOLVE_AS = "res"; + private static final String PATH_PROJECT_ID = "project_id"; + private static final String PATH_USECASE_ID = "usecase_id"; + private static final String PATH_VRE_NAME = "vre_name"; + private static final String PATH_TARGET_APP = "targetAppId"; private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class); private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; @@ -59,44 +61,48 @@ public class GeoportalResolver { PUBLIC, PRIVATE } - /** - * The Enum SCOPE_STATUS. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Mar 24, 2022 - */ - private static enum SCOPE_STATUS { - ACTIVE, DETACHED - } - @GET - @Path("/{vreName}/{usecase_id}/{project_id}") - public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(VRE_NAME) String vreName, - @PathParam(USECASE_ID) String ucdID, @PathParam(PROJECT_ID) String projectID, - @QueryParam("r") String resolve) throws WebApplicationException { + @Path("/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, + @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, + @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) + throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " GET starts..."); try { InnerMethodName.instance.set("resolveGeoportalPublicLink"); + TargetAppGeoportalCodes resoruceGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId); + + LOG.info("Found target app: " + resoruceGeoportalCodes); + + if (resoruceGeoportalCodes == null) { + LOG.error("The path parameter '" + PATH_TARGET_APP + "' not found or empty in the path"); + throw ExceptionManager.badRequestException(req, + "Mandatory path parameter '" + PATH_TARGET_APP + "' not found or empty", this.getClass(), + helpURI); + } + if (vreName == null || vreName.isEmpty()) { - LOG.error("The path parameter '" + VRE_NAME + "' not found or empty in the path"); - throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", - this.getClass(), helpURI); + LOG.error("The path parameter '" + PATH_VRE_NAME + "' not found or empty in the path"); + throw ExceptionManager.badRequestException(req, + "Mandatory path parameter '" + PATH_VRE_NAME + "' not found or empty", this.getClass(), + helpURI); } if (ucdID == null) { - LOG.error("The path parameter '" + USECASE_ID + "' not found or empty in the path"); - throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", - this.getClass(), helpURI); + LOG.error("The path parameter '" + PATH_USECASE_ID + "' not found or empty in the path"); + throw ExceptionManager.badRequestException(req, + "Mandatory path parameter '" + PATH_USECASE_ID + "' not found or empty", this.getClass(), + helpURI); } if (projectID == null) { - LOG.error("The path parameter '" + PROJECT_ID + "' not found or empty in the path"); - throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", - this.getClass(), helpURI); + LOG.error("The path parameter '" + PATH_PROJECT_ID + "' not found or empty in the path"); + throw ExceptionManager.badRequestException(req, + "Mandatory path parameter '" + PATH_PROJECT_ID + "' not found or empty", this.getClass(), + helpURI); } ScopeBean fullScopeBean = null; @@ -113,8 +119,8 @@ public class GeoportalResolver { } RESOLVE_AS resolveTO = RESOLVE_AS.PUBLIC; - if (resolve != null) { - switch (resolve.toLowerCase()) { + if (resolveAs != null) { + switch (resolveAs.toLowerCase()) { case "public": resolveTO = RESOLVE_AS.PUBLIC; break; @@ -124,11 +130,14 @@ public class GeoportalResolver { } } + LOG.info("Found RESOLVE_AS: " + resolveAs); + String originalScope = ScopeProvider.instance.get(); GeoportalDataViewerConfigProfileReader reader; try { - - ScopeProvider.instance.set(fullScopeBean.toString()); + String theScope = fullScopeBean.toString(); + LOG.info("Full scope is: " + theScope); + ScopeProvider.instance.set(theScope); reader = new GeoportalDataViewerConfigProfileReader( org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP); } catch (Exception e) { @@ -150,34 +159,58 @@ public class GeoportalResolver { } } - GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile(); + // Resolving towards Data-Viewer or Data-Entry Application String itemLink = null; - switch (resolveTO) { - case PUBLIC: - // Open Link - itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(), - GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID, - GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID); - break; - case PRIVATE: - // Restricted Link - String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(), - GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID, - GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID); + switch (resoruceGeoportalCodes) { + case GEO: + case GEO_DV: { + + GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile(); + + switch (resolveTO) { + case PUBLIC: + // Open Link + itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(), + GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID, + GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID); + break; + case PRIVATE: + + // Restricted Link + itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(), + GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID, + GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID); + + break; + + default: + break; + } break; + } + case GEO_DE: { + + LOG.error("The Resolver towards '" + resoruceGeoportalCodes + "' not implemented yet"); + throw ExceptionManager.internalErrorException(req, + "The Resolver towards '" + resoruceGeoportalCodes + "' not implemented yet", this.getClass(), + helpURI); + + } default: break; } + LOG.info("Returning link: " + itemLink); return Response.seeOther(new URL(itemLink).toURI()).build(); } catch (Exception e) { if (!(e instanceof WebApplicationException)) { // UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = "Error occurred on resolving the "+GeoportalResolver.class.getSimpleName()+" URL. Please, contact the support!"; + String error = "Error occurred on resolving the " + GeoportalResolver.class.getSimpleName() + + " URL. Please, contact the support!"; if (e.getCause() != null) error += "\n\nCaused: " + e.getCause().getMessage(); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); @@ -252,16 +285,16 @@ public class GeoportalResolver { "The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI); - ResourceGeoportalCodes resoruceGeoportalCodes = ResourceGeoportalCodes - .valueOfTargetApp(jsonRequest.getTargetApp()); + TargetAppGeoportalCodes resoruceGeoportalCodes = TargetAppGeoportalCodes + .valueOfName(jsonRequest.getTargetApp()); if (resoruceGeoportalCodes == null) { - LOG.error("Target application is null/malformed"); - resoruceGeoportalCodes = ResourceGeoportalCodes.GEO; - LOG.info("Target application using default: "+resoruceGeoportalCodes); - }else { - List targetApps = Arrays.asList(ResourceGeoportalCodes.values()).stream() - .map(ResourceGeoportalCodes::getTarget_app).collect(Collectors.toList()); + LOG.error("Target application parameter is null/malformed"); + resoruceGeoportalCodes = TargetAppGeoportalCodes.GEO; + LOG.info("Target application using default: " + resoruceGeoportalCodes); + } else { + List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() + .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); throw ExceptionManager.badRequestException(req, "Target application is null/malformed. It must be: " + targetApps, this.getClass(), helpURI); @@ -281,7 +314,8 @@ public class GeoportalResolver { if (!(e instanceof WebApplicationException)) { // UNEXPECTED EXCEPTION managing it as WebApplicationException - String error = "Error occurred on creating the "+GeoportalResolver.class.getSimpleName()+" URL. Please, contact the support!"; + String error = "Error occurred on creating the " + GeoportalResolver.class.getSimpleName() + + " URL. Please, contact the support!"; throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); } // ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs From 7c0928b1e984726b26f15b500a83b476a7e13606 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 10:35:59 +0100 Subject: [PATCH 09/35] Fixing post request --- .../resolver/geoportal/GeoportalRequest.java | 2 +- .../resolver/services/GeoportalResolver.java | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java index 8ca093f..21e3790 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java @@ -26,7 +26,7 @@ public class GeoportalRequest { @JsonProperty(P_GCUBE_SCOPE) private String gcubeScope; @JsonProperty(P_TARGET_APP) - private String targetApp; + private String targetAppName; /** * It is the UCD ID {usecase_id} */ diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 79b367a..d0cfcde 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -285,19 +285,25 @@ public class GeoportalResolver { "The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI); - TargetAppGeoportalCodes resoruceGeoportalCodes = TargetAppGeoportalCodes - .valueOfName(jsonRequest.getTargetApp()); + String targetAppName = jsonRequest.getTargetAppName(); - if (resoruceGeoportalCodes == null) { - LOG.error("Target application parameter is null/malformed"); + TargetAppGeoportalCodes resoruceGeoportalCodes = null; + + if (targetAppName == null) { resoruceGeoportalCodes = TargetAppGeoportalCodes.GEO; - LOG.info("Target application using default: " + resoruceGeoportalCodes); + LOG.error("Target application parameter is null, using default: " + resoruceGeoportalCodes); } else { - List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() - .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); - throw ExceptionManager.badRequestException(req, - "Target application is null/malformed. It must be: " + targetApps, this.getClass(), helpURI); + resoruceGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); + + if (resoruceGeoportalCodes == null) { + LOG.error("Target application parameter is malformed"); + List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() + .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); + throw ExceptionManager.badRequestException(req, + "Target application is wrong. It must be one value of: " + targetApps, this.getClass(), + helpURI); + } } String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, resoruceGeoportalCodes.getId(), vreName, From 49fc47eafa05c66da45f133dd80d679d17adecd6 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 10:46:52 +0100 Subject: [PATCH 10/35] Fixing Geoportal Path --- .../datatransfer/resolver/services/GeoportalResolver.java | 4 ++-- .../resolver/services/exceptions/BadRequestException.java | 2 +- .../services/exceptions/ForbiddenRequestException.java | 2 +- .../resolver/services/exceptions/InternalServerException.java | 2 +- .../services/exceptions/NotAuthorizedRequestException.java | 2 +- .../resolver/services/exceptions/NotFoundException.java | 2 +- .../resolver/services/exceptions/WrongParameterException.java | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index d0cfcde..f4c808e 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("{targetAppId:geo(-(dv|-de))?}") +@Path("{targetAppId:geo(-(dv|de))?}") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -313,7 +313,7 @@ public class GeoportalResolver { linkURL += "?" + jsonRequest.getQueryString(); } - LOG.info("Returning " + CatalogueResolver.class.getSimpleName() + " URL: " + linkURL); + LOG.info("Returning " + GeoportalResolver.class.getSimpleName() + " URL: " + linkURL); return Response.ok(linkURL).header("Location", linkURL).build(); } catch (Exception e) { diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java index 15c039c..22412e1 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/BadRequestException.java @@ -55,7 +55,7 @@ public class BadRequestException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XHTML_XML).build()); + .type(MediaType.APPLICATION_XML).build()); } } \ No newline at end of file diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java index 6c24ccb..0fd49f1 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/ForbiddenRequestException.java @@ -58,7 +58,7 @@ public class ForbiddenRequestException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XHTML_XML).build()); + .type(MediaType.APPLICATION_XML).build()); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java index cb2e1be..d50c73a 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/InternalServerException.java @@ -53,7 +53,7 @@ public class InternalServerException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XHTML_XML).build()); + .type(MediaType.APPLICATION_XML).build()); } } \ No newline at end of file diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java index a65df92..76e2772 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotAuthorizedRequestException.java @@ -56,7 +56,7 @@ public class NotAuthorizedRequestException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XHTML_XML).build()); + .type(MediaType.APPLICATION_XML).build()); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java index b0c12b4..489ca8b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/NotFoundException.java @@ -56,7 +56,7 @@ public class NotFoundException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XHTML_XML).build()); + .type(MediaType.APPLICATION_XML).build()); } diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java index 28088c9..cf456c3 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/exceptions/WrongParameterException.java @@ -55,7 +55,7 @@ public class WrongParameterException extends WebApplicationException { .message(message). thrownBy(thrownBySource.getName()).build()) .build()) - .type(MediaType.APPLICATION_XHTML_XML).build()); + .type(MediaType.APPLICATION_XML).build()); } } \ No newline at end of file From 011f57cb25251f6bc26a5f3256d0cafe1a7d9054 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 10:55:34 +0100 Subject: [PATCH 11/35] fixing GET request PATHs --- .../resolver/services/GeoportalResolver.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index f4c808e..23d0f1e 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("{targetAppId:geo(-(dv|de))?}") +@Path("{targetAppId:geo|geo-dv|geo-de}") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -287,16 +287,16 @@ public class GeoportalResolver { String targetAppName = jsonRequest.getTargetAppName(); - TargetAppGeoportalCodes resoruceGeoportalCodes = null; + TargetAppGeoportalCodes targetAppGeoportalCodes = null; if (targetAppName == null) { - resoruceGeoportalCodes = TargetAppGeoportalCodes.GEO; - LOG.error("Target application parameter is null, using default: " + resoruceGeoportalCodes); + targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO; + LOG.error("Target application parameter is null, using default: " + targetAppGeoportalCodes); } else { - resoruceGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); + targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); - if (resoruceGeoportalCodes == null) { + if (targetAppGeoportalCodes == null) { LOG.error("Target application parameter is malformed"); List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); @@ -305,8 +305,10 @@ public class GeoportalResolver { helpURI); } } + + LOG.info("The target app is: " + targetAppGeoportalCodes); - String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, resoruceGeoportalCodes.getId(), vreName, + String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName, jsonRequest.getItemType(), jsonRequest.getItemID()); if (jsonRequest.getQueryString() != null) { From ad9bd54412fa898fe5bca3701c064f46272dc1e7 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 11:31:22 +0100 Subject: [PATCH 12/35] Updated paths and behaviour --- .../resolver/services/GeoportalResolver.java | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 23d0f1e..f3c8969 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -233,8 +233,8 @@ public class GeoportalResolver { @Path("") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) - throws WebApplicationException { + public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest, + @PathParam(PATH_TARGET_APP) String targetAppId) throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " POST starts..."); try { @@ -285,29 +285,45 @@ public class GeoportalResolver { "The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI); - String targetAppName = jsonRequest.getTargetAppName(); - TargetAppGeoportalCodes targetAppGeoportalCodes = null; + TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId); + LOG.info("The target app is: " + targetAppGeoportalCodes); + + //Checking the application towards redirect according the PATH + switch (targetAppGeoportalCodes) { + case GEO: { + + //If the PATH is /geo going to check the target_app_name parameter in the request + String targetAppName = jsonRequest.getTargetAppName(); + + if (targetAppName == null) { + targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV; + LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes); + } else { + + //IF the target application passed in the request. It must be proper. + targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); - if (targetAppName == null) { - targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO; - LOG.error("Target application parameter is null, using default: " + targetAppGeoportalCodes); - } else { - - targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); - - if (targetAppGeoportalCodes == null) { - LOG.error("Target application parameter is malformed"); - List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() - .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); - throw ExceptionManager.badRequestException(req, - "Target application is wrong. It must be one value of: " + targetApps, this.getClass(), - helpURI); + if (targetAppGeoportalCodes == null) { + LOG.error("Target application parameter is malformed"); + List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() + .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); + throw ExceptionManager.badRequestException(req, + "Target application is wrong. It must be one value of: " + targetApps, this.getClass(), + helpURI); + } } + + } + case GEO_DV: + case GEO_DE: { + LOG.info("Do nothing"); + break; + } + default: + break; } - LOG.info("The target app is: " + targetAppGeoportalCodes); - String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName, jsonRequest.getItemType(), jsonRequest.getItemID()); From 5ca0406997c4d0b9198f4b410849f0cb96abedda Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 11:36:21 +0100 Subject: [PATCH 13/35] updated paths --- .../resolver/services/GeoportalResolver.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index f3c8969..2593701 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("{targetAppId:geo|geo-dv|geo-de}") +@Path("/") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -62,7 +62,7 @@ public class GeoportalResolver { } @GET - @Path("/{vre_name}/{usecase_id}/{project_id}") + @Path("{targetAppId:geo|geo-dv|geo-de}/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) @@ -230,7 +230,7 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @POST - @Path("") + @Path("{targetAppId:geo|geo-dv|geo-de}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest, @@ -292,7 +292,7 @@ public class GeoportalResolver { //Checking the application towards redirect according the PATH switch (targetAppGeoportalCodes) { case GEO: { - + LOG.debug("With "+targetAppId+" checking the JSON body passed in the request..."); //If the PATH is /geo going to check the target_app_name parameter in the request String targetAppName = jsonRequest.getTargetAppName(); @@ -317,7 +317,7 @@ public class GeoportalResolver { } case GEO_DV: case GEO_DE: { - LOG.info("Do nothing"); + LOG.debug("With "+targetAppId+" do nothing"); break; } default: From 7aa6c479a10b18e0703514d1c8435d14bb549cdc Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 11:43:30 +0100 Subject: [PATCH 14/35] Updated paths --- .../datatransfer/resolver/services/GeoportalResolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 2593701..63ff208 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("/") +@Path("{targetAppId:geo|geo-dv|geo-de}") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -62,7 +62,7 @@ public class GeoportalResolver { } @GET - @Path("{targetAppId:geo|geo-dv|geo-de}/{vre_name}/{usecase_id}/{project_id}") + @Path("/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) From 8a2fd1d67a13d4bc35bef76c53b4f8b934f28d2e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 11:47:27 +0100 Subject: [PATCH 15/35] Changed path --- .../datatransfer/resolver/services/GeoportalResolver.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 63ff208..3160bb0 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("{targetAppId:geo|geo-dv|geo-de}") +@Path("/{targetAppId:geo|geo-dv|geo-de}") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -220,7 +220,7 @@ public class GeoportalResolver { throw (WebApplicationException) e; } } - + /** * Create a Catalogue Link. * @@ -230,7 +230,7 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @POST - @Path("{targetAppId:geo|geo-dv|geo-de}") + @Path("") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest, From 0f57f7365fd36ad61a9e1329ff7e8a28e76a1394 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 11:52:21 +0100 Subject: [PATCH 16/35] Updated Paths --- .../datatransfer/resolver/services/GeoportalResolver.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 3160bb0..f2be317 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("/{targetAppId:geo|geo-dv|geo-de}") +@Path("/") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -62,7 +62,7 @@ public class GeoportalResolver { } @GET - @Path("/{vre_name}/{usecase_id}/{project_id}") + @Path("{targetAppId:geo|geo-dv|geo-de}/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) @@ -230,7 +230,7 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @POST - @Path("") + @Path("{targetAppId:geo|geo-dv|geo-de}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest, From 31fe39004452d2f15a91665b28ff2f3e142562f7 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 12:00:31 +0100 Subject: [PATCH 17/35] Updated paths --- .../datatransfer/resolver/services/GeoportalResolver.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index f2be317..5dae553 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("/") +@Path("{targetAppId:geo(-(dv|de))?}") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -62,7 +62,7 @@ public class GeoportalResolver { } @GET - @Path("{targetAppId:geo|geo-dv|geo-de}/{vre_name}/{usecase_id}/{project_id}") + @Path("/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) @@ -230,7 +230,7 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @POST - @Path("{targetAppId:geo|geo-dv|geo-de}") + @Path("") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest, From df02f4aa279d2b2558d50b4779295f5e2db984cc Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 12:15:06 +0100 Subject: [PATCH 18/35] updated paths --- .../gcube/datatransfer/resolver/services/GeoportalResolver.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 5dae553..3160bb0 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("{targetAppId:geo(-(dv|de))?}") +@Path("/{targetAppId:geo|geo-dv|geo-de}") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; From a70c7b5f10ba21b2301793208b240458e9a7af07 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 12:28:57 +0100 Subject: [PATCH 19/35] Static Paths --- .../resolver/services/GeoportalResolver.java | 176 +++++++++++++++--- 1 file changed, 153 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 3160bb0..6cd1626 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("/{targetAppId:geo|geo-dv|geo-de}") +@Path("") public class GeoportalResolver { private static final String QP_RESOLVE_AS = "res"; @@ -57,13 +57,145 @@ public class GeoportalResolver { private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class); private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; + /** + * The Enum RESOLVE_AS. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 24, 2023 + */ private static enum RESOLVE_AS { PUBLIC, PRIVATE } + /** + * Resolve geoportal. + * + * @param req the req + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ @GET - @Path("/{vre_name}/{usecase_id}/{project_id}") - public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, + @Path("geo/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, + @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { + String targetAppId = "geo"; + return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); + + } + + /** + * Resolve geoportal DV. + * + * @param req the req + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path("geo-dv/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, + @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { + String targetAppId = "geo-dv"; + return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); + + } + + /** + * Resolve geoportal DE. + * + * @param req the req + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path("geo-de/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportalDE(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, + @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { + String targetAppId = "geo-de"; + return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); + + } + + /** + * Create a Catalogue Link. + * + * @param req the req + * @param jsonRequest the json request + * @return the response + * @throws WebApplicationException the web application exception + */ + @POST + @Path("geo") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { + LOG.info(this.getClass().getSimpleName() + " POST starts..."); + String targetAppId = "geo"; + return genericPost(req, jsonRequest, targetAppId); + } + + /** + * Post geoportal DV. + * + * @param req the req + * @param jsonRequest the json request + * @return the response + * @throws WebApplicationException the web application exception + */ + @Path("geo-dv") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public Response postGeoportalDV(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { + LOG.info(this.getClass().getSimpleName() + " POST starts..."); + String targetAppId = "geo-dv"; + return genericPost(req, jsonRequest, targetAppId); + } + + /** + * Post geoportal DE. + * + * @param req the req + * @param jsonRequest the json request + * @return the response + * @throws WebApplicationException the web application exception + */ + @Path("geo-de") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public Response postGeoportalDE(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { + LOG.info(this.getClass().getSimpleName() + " POST starts..."); + String targetAppId = "geo-de"; + return genericPost(req, jsonRequest, targetAppId); + } + + /** + * Generic get. + * + * @param req the req + * @param targetAppId the target app id + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ + public Response genericGet(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { @@ -220,21 +352,18 @@ public class GeoportalResolver { throw (WebApplicationException) e; } } - + /** - * Create a Catalogue Link. + * Generic post. * * @param req the req * @param jsonRequest the json request + * @param targetAppId the target app id * @return the response - * @throws WebApplicationException the web application exception */ - @POST - @Path("") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.TEXT_PLAIN) - public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest, - @PathParam(PATH_TARGET_APP) String targetAppId) throws WebApplicationException { + protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest, + @PathParam(PATH_TARGET_APP) String targetAppId) { + LOG.info(this.getClass().getSimpleName() + " POST starts..."); try { @@ -285,23 +414,23 @@ public class GeoportalResolver { "The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI); - TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId); LOG.info("The target app is: " + targetAppGeoportalCodes); - - //Checking the application towards redirect according the PATH + + // Checking the application towards redirect according the PATH switch (targetAppGeoportalCodes) { case GEO: { - LOG.debug("With "+targetAppId+" checking the JSON body passed in the request..."); - //If the PATH is /geo going to check the target_app_name parameter in the request + LOG.debug("With " + targetAppId + " checking the JSON body passed in the request..."); + // If the PATH is /geo going to check the target_app_name parameter in the + // request String targetAppName = jsonRequest.getTargetAppName(); - + if (targetAppName == null) { targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV; LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes); } else { - - //IF the target application passed in the request. It must be proper. + + // IF the target application passed in the request. It must be proper. targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); if (targetAppGeoportalCodes == null) { @@ -313,17 +442,17 @@ public class GeoportalResolver { helpURI); } } - + } case GEO_DV: case GEO_DE: { - LOG.debug("With "+targetAppId+" do nothing"); + LOG.debug("With " + targetAppId + " do nothing"); break; } default: break; } - + String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName, jsonRequest.getItemType(), jsonRequest.getItemID()); @@ -346,6 +475,7 @@ public class GeoportalResolver { LOG.error("Exception:", e); throw (WebApplicationException) e; } + } } From f6004df3db08b45c05fb398620ba6ac7c02c15bb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 14:00:24 +0100 Subject: [PATCH 20/35] Updated Paths --- .../geoportal/TargetAppGeoportalCodes.java | 7 +++-- .../resolver/services/GeoportalResolver.java | 29 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java index 00388cd..d544e54 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java @@ -7,6 +7,8 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import org.gcube.datatransfer.resolver.services.GeoportalResolver; + /** * The Enum TargetAppGeoportalCodes. * @@ -16,8 +18,9 @@ import java.util.stream.Collectors; */ public enum TargetAppGeoportalCodes { - GEO("geo", "geoportal", "Geoportal"), GEO_DV("geo-dv", "data-viewer", "Geoportal Viewer"), - GEO_DE("geo-de", "data-entry", "Geoportal Entry"); + GEO(GeoportalResolver.GEO, "geoportal", "Geoportal"), + GEO_DV(GeoportalResolver.GEO_DV, "data-viewer", "Geoportal Viewer"), + GEO_DE(GeoportalResolver.GEO_DE, "data-entry", "Geoportal Entry"); private String id; // the code id private String name; // the code value diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 6cd1626..97057d8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -49,11 +49,16 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; @Path("") public class GeoportalResolver { + public static final String GEO_DE = "geo-de"; + public static final String GEO = "geo"; + public static final String GEO_DV = "geo-dv"; + private static final String QP_RESOLVE_AS = "res"; private static final String PATH_PROJECT_ID = "project_id"; private static final String PATH_USECASE_ID = "usecase_id"; private static final String PATH_VRE_NAME = "vre_name"; private static final String PATH_TARGET_APP = "targetAppId"; + private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class); private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; @@ -80,11 +85,11 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @GET - @Path("geo/{vre_name}/{usecase_id}/{project_id}") + @Path(GEO+"/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = "geo"; + String targetAppId = GEO; return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); } @@ -101,11 +106,11 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @GET - @Path("geo-dv/{vre_name}/{usecase_id}/{project_id}") + @Path(GEO_DV+"/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = "geo-dv"; + String targetAppId = GEO_DV; return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); } @@ -122,11 +127,11 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @GET - @Path("geo-de/{vre_name}/{usecase_id}/{project_id}") + @Path(GEO_DE+"/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportalDE(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = "geo-de"; + String targetAppId = GEO_DE; return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); } @@ -140,12 +145,12 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @POST - @Path("geo") + @Path(GEO) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " POST starts..."); - String targetAppId = "geo"; + String targetAppId = GEO; return genericPost(req, jsonRequest, targetAppId); } @@ -157,12 +162,12 @@ public class GeoportalResolver { * @return the response * @throws WebApplicationException the web application exception */ - @Path("geo-dv") + @Path(GEO_DV) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportalDV(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " POST starts..."); - String targetAppId = "geo-dv"; + String targetAppId = GEO_DV; return genericPost(req, jsonRequest, targetAppId); } @@ -174,12 +179,12 @@ public class GeoportalResolver { * @return the response * @throws WebApplicationException the web application exception */ - @Path("geo-de") + @Path(GEO_DE) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportalDE(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " POST starts..."); - String targetAppId = "geo-de"; + String targetAppId = GEO_DE; return genericPost(req, jsonRequest, targetAppId); } From b57bd038896d98f3386eeb255c413e2cab40a73a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 14:47:32 +0100 Subject: [PATCH 21/35] Updated paths --- .settings/org.eclipse.wst.common.component | 30 +++- .../resolver/services/GeoportalResolver.java | 161 +++++++++--------- 2 files changed, 103 insertions(+), 88 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 068f0a5..e322491 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -12,7 +13,8 @@ - + + @@ -25,7 +27,8 @@ - + + @@ -38,7 +41,8 @@ - + + @@ -51,7 +55,8 @@ - + + @@ -64,7 +69,11 @@ - + + uses + + + @@ -77,7 +86,8 @@ - + + @@ -90,7 +100,8 @@ - + + @@ -103,7 +114,8 @@ - + + diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 97057d8..1a01614 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,19 +46,19 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("") +@Path("/") public class GeoportalResolver { public static final String GEO_DE = "geo-de"; public static final String GEO = "geo"; public static final String GEO_DV = "geo-dv"; - + private static final String QP_RESOLVE_AS = "res"; private static final String PATH_PROJECT_ID = "project_id"; private static final String PATH_USECASE_ID = "usecase_id"; private static final String PATH_VRE_NAME = "vre_name"; private static final String PATH_TARGET_APP = "targetAppId"; - + private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class); private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; @@ -85,7 +85,7 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @GET - @Path(GEO+"/{vre_name}/{usecase_id}/{project_id}") + @Path(GEO + "/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { @@ -94,47 +94,47 @@ public class GeoportalResolver { } - /** - * Resolve geoportal DV. - * - * @param req the req - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as - * @return the response - * @throws WebApplicationException the web application exception - */ - @GET - @Path(GEO_DV+"/{vre_name}/{usecase_id}/{project_id}") - public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, - @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, - @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = GEO_DV; - return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); - - } - - /** - * Resolve geoportal DE. - * - * @param req the req - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as - * @return the response - * @throws WebApplicationException the web application exception - */ - @GET - @Path(GEO_DE+"/{vre_name}/{usecase_id}/{project_id}") - public Response resolveGeoportalDE(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, - @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, - @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = GEO_DE; - return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); - - } +// /** +// * Resolve geoportal DV. +// * +// * @param req the req +// * @param vreName the vre name +// * @param ucdID the ucd ID +// * @param projectID the project ID +// * @param resolveAs the resolve as +// * @return the response +// * @throws WebApplicationException the web application exception +// */ +// @GET +// @Path(GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") +// public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, +// @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, +// @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { +// String targetAppId = GEO_DV; +// return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); +// +// } +// +// /** +// * Resolve geoportal DE. +// * +// * @param req the req +// * @param vreName the vre name +// * @param ucdID the ucd ID +// * @param projectID the project ID +// * @param resolveAs the resolve as +// * @return the response +// * @throws WebApplicationException the web application exception +// */ +// @GET +// @Path(GEO_DE + "/{vre_name}/{usecase_id}/{project_id}") +// public Response resolveGeoportalDE(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, +// @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, +// @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { +// String targetAppId = GEO_DE; +// return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); +// +// } /** * Create a Catalogue Link. @@ -148,45 +148,48 @@ public class GeoportalResolver { @Path(GEO) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { + public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) + throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " POST starts..."); String targetAppId = GEO; return genericPost(req, jsonRequest, targetAppId); } - /** - * Post geoportal DV. - * - * @param req the req - * @param jsonRequest the json request - * @return the response - * @throws WebApplicationException the web application exception - */ - @Path(GEO_DV) - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.TEXT_PLAIN) - public Response postGeoportalDV(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { - LOG.info(this.getClass().getSimpleName() + " POST starts..."); - String targetAppId = GEO_DV; - return genericPost(req, jsonRequest, targetAppId); - } - - /** - * Post geoportal DE. - * - * @param req the req - * @param jsonRequest the json request - * @return the response - * @throws WebApplicationException the web application exception - */ - @Path(GEO_DE) - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.TEXT_PLAIN) - public Response postGeoportalDE(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { - LOG.info(this.getClass().getSimpleName() + " POST starts..."); - String targetAppId = GEO_DE; - return genericPost(req, jsonRequest, targetAppId); - } +// /** +// * Post geoportal DV. +// * +// * @param req the req +// * @param jsonRequest the json request +// * @return the response +// * @throws WebApplicationException the web application exception +// */ +// @Path(GEO_DV) +// @Consumes(MediaType.APPLICATION_JSON) +// @Produces(MediaType.TEXT_PLAIN) +// public Response postGeoportalDV(@Context HttpServletRequest req, GeoportalRequest jsonRequest) +// throws WebApplicationException { +// LOG.info(this.getClass().getSimpleName() + " POST starts..."); +// String targetAppId = GEO_DV; +// return genericPost(req, jsonRequest, targetAppId); +// } +// +// /** +// * Post geoportal DE. +// * +// * @param req the req +// * @param jsonRequest the json request +// * @return the response +// * @throws WebApplicationException the web application exception +// */ +// @Path(GEO_DE) +// @Consumes(MediaType.APPLICATION_JSON) +// @Produces(MediaType.TEXT_PLAIN) +// public Response postGeoportalDE(@Context HttpServletRequest req, GeoportalRequest jsonRequest) +// throws WebApplicationException { +// LOG.info(this.getClass().getSimpleName() + " POST starts..."); +// String targetAppId = GEO_DE; +// return genericPost(req, jsonRequest, targetAppId); +// } /** * Generic get. From 0b7ca3d03fe6a43332dc1f293a696eda678559dc Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 14:54:23 +0100 Subject: [PATCH 22/35] Updated paths --- .../resolver/services/GeoportalResolver.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 1a01614..c6e7192 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -85,35 +85,36 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @GET - @Path(GEO + "/{vre_name}/{usecase_id}/{project_id}") - public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, - @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, - @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = GEO; + @Path("{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}" + "/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, + @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, + @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) + throws WebApplicationException { + // String targetAppId = GEO; return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); } -// /** -// * Resolve geoportal DV. -// * -// * @param req the req -// * @param vreName the vre name -// * @param ucdID the ucd ID -// * @param projectID the project ID -// * @param resolveAs the resolve as -// * @return the response -// * @throws WebApplicationException the web application exception -// */ -// @GET -// @Path(GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") -// public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, -// @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, -// @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { -// String targetAppId = GEO_DV; -// return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); -// -// } + /** + * Resolve geoportal DV. + * + * @param req the req + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path(GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, + @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { + String targetAppId = GEO_DV; + return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); + + } // // /** // * Resolve geoportal DE. From 0b23748a3b9e85c2958eb6695a813910ce72483f Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 15:03:22 +0100 Subject: [PATCH 23/35] Updated Paths --- .../resolver/services/GeoportalResolver.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index c6e7192..abdefb8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -49,9 +49,9 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; @Path("/") public class GeoportalResolver { - public static final String GEO_DE = "geo-de"; + public static final String GEO_DE = "geode"; public static final String GEO = "geo"; - public static final String GEO_DV = "geo-dv"; + public static final String GEO_DV = "geodv"; private static final String QP_RESOLVE_AS = "res"; private static final String PATH_PROJECT_ID = "project_id"; @@ -77,6 +77,7 @@ public class GeoportalResolver { * Resolve geoportal. * * @param req the req + * @param targetAppId the target app id * @param vreName the vre name * @param ucdID the ucd ID * @param projectID the project ID @@ -95,26 +96,26 @@ public class GeoportalResolver { } - /** - * Resolve geoportal DV. - * - * @param req the req - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as - * @return the response - * @throws WebApplicationException the web application exception - */ - @GET - @Path(GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") - public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, - @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, - @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = GEO_DV; - return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); - - } +// /** +// * Resolve geoportal DV. +// * +// * @param req the req +// * @param vreName the vre name +// * @param ucdID the ucd ID +// * @param projectID the project ID +// * @param resolveAs the resolve as +// * @return the response +// * @throws WebApplicationException the web application exception +// */ +// @GET +// @Path(GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") +// public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, +// @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, +// @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { +// String targetAppId = GEO_DV; +// return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); +// +// } // // /** // * Resolve geoportal DE. @@ -146,13 +147,13 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @POST - @Path(GEO) + @Path("{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) + public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, GeoportalRequest jsonRequest) throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " POST starts..."); - String targetAppId = GEO; + //String targetAppId = GEO; return genericPost(req, jsonRequest, targetAppId); } From 526a877b264088350cb7f0294cbf31f74e0dd68e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 15:10:43 +0100 Subject: [PATCH 24/35] Updated path --- .../resolver/services/GeoportalResolver.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index abdefb8..ce75edf 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -86,7 +86,7 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @GET - @Path("{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}" + "/{vre_name}/{usecase_id}/{project_id}") + @Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}" + "/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) @@ -96,26 +96,26 @@ public class GeoportalResolver { } -// /** -// * Resolve geoportal DV. -// * -// * @param req the req -// * @param vreName the vre name -// * @param ucdID the ucd ID -// * @param projectID the project ID -// * @param resolveAs the resolve as -// * @return the response -// * @throws WebApplicationException the web application exception -// */ -// @GET -// @Path(GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") -// public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, -// @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, -// @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { -// String targetAppId = GEO_DV; -// return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); -// -// } + /** + * Resolve geoportal DV. + * + * @param req the req + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path("/"+GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, + @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { + String targetAppId = GEO_DV; + return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); + + } // // /** // * Resolve geoportal DE. From 9b1f34312e1fdaf8ddc1c767ea928121f956abfe Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 15:20:00 +0100 Subject: [PATCH 25/35] Updated paths --- .../resolver/services/GeoportalResolver.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index ce75edf..58ba53e 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -@Path("/") +//@Path("/") public class GeoportalResolver { public static final String GEO_DE = "geode"; @@ -84,9 +84,10 @@ public class GeoportalResolver { * @param resolveAs the resolve as * @return the response * @throws WebApplicationException the web application exception + * @Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}" + "/{vre_name}/{usecase_id}/{project_id}") */ @GET - @Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}" + "/{vre_name}/{usecase_id}/{project_id}") + @Path("/"+GEO_DE + "/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) @@ -95,6 +96,8 @@ public class GeoportalResolver { return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); } + + /** * Resolve geoportal DV. @@ -147,7 +150,7 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @POST - @Path("{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}") + @Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, GeoportalRequest jsonRequest) From de4b6080519e38d330d03fe95af9ba3d184d0b04 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 15:42:11 +0100 Subject: [PATCH 26/35] Updated the paths --- .../resolver/services/GeoportalResolver.java | 203 ++++++------------ 1 file changed, 71 insertions(+), 132 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 58ba53e..4b87303 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -46,12 +46,12 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; * * Mar 23, 2023 */ -//@Path("/") +@Path("/geo") public class GeoportalResolver { - public static final String GEO_DE = "geode"; + public static final String GEO_DE = "de"; public static final String GEO = "geo"; - public static final String GEO_DV = "geodv"; + public static final String GEO_DV = "dv"; private static final String QP_RESOLVE_AS = "res"; private static final String PATH_PROJECT_ID = "project_id"; @@ -76,28 +76,30 @@ public class GeoportalResolver { /** * Resolve geoportal. * - * @param req the req + * @param req the req * @param targetAppId the target app id - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as * @return the response - * @throws WebApplicationException the web application exception - * @Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}" + "/{vre_name}/{usecase_id}/{project_id}") + * @throws WebApplicationException the web application + * exception @Path("/{targetAppId:" + GEO + "|" + * + GEO_DV + "|" + GEO_DE + "}" + + * "/{vre_name}/{usecase_id}/{project_id}") */ @GET - @Path("/"+GEO_DE + "/{vre_name}/{usecase_id}/{project_id}") + @Path("/{targetAppId}/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { // String targetAppId = GEO; - return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); + TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId); + LOG.info("The target app is: " + targetAppGeoportalCodes); + return genericGet(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); } - - /** * Resolve geoportal DV. @@ -111,104 +113,83 @@ public class GeoportalResolver { * @throws WebApplicationException the web application exception */ @GET - @Path("/"+GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") + @Path("/" + GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - String targetAppId = GEO_DV; - return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); + TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV; + return genericGet(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); } -// -// /** -// * Resolve geoportal DE. -// * -// * @param req the req -// * @param vreName the vre name -// * @param ucdID the ucd ID -// * @param projectID the project ID -// * @param resolveAs the resolve as -// * @return the response -// * @throws WebApplicationException the web application exception -// */ -// @GET -// @Path(GEO_DE + "/{vre_name}/{usecase_id}/{project_id}") -// public Response resolveGeoportalDE(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, -// @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, -// @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { -// String targetAppId = GEO_DE; -// return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); -// -// } /** * Create a Catalogue Link. * * @param req the req + * @param targetAppId the target app id * @param jsonRequest the json request * @return the response * @throws WebApplicationException the web application exception */ @POST - @Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}") + @Path("/{targetAppId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) - public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, GeoportalRequest jsonRequest) - throws WebApplicationException { + public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, + GeoportalRequest jsonRequest) throws WebApplicationException { LOG.info(this.getClass().getSimpleName() + " POST starts..."); - //String targetAppId = GEO; - return genericPost(req, jsonRequest, targetAppId); + // String targetAppId = GEO; + TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId); + LOG.info("The target app is: " + targetAppGeoportalCodes); + return genericPost(req, jsonRequest, targetAppGeoportalCodes); } -// /** -// * Post geoportal DV. -// * -// * @param req the req -// * @param jsonRequest the json request -// * @return the response -// * @throws WebApplicationException the web application exception -// */ -// @Path(GEO_DV) -// @Consumes(MediaType.APPLICATION_JSON) -// @Produces(MediaType.TEXT_PLAIN) -// public Response postGeoportalDV(@Context HttpServletRequest req, GeoportalRequest jsonRequest) -// throws WebApplicationException { -// LOG.info(this.getClass().getSimpleName() + " POST starts..."); -// String targetAppId = GEO_DV; -// return genericPost(req, jsonRequest, targetAppId); -// } -// -// /** -// * Post geoportal DE. -// * -// * @param req the req -// * @param jsonRequest the json request -// * @return the response -// * @throws WebApplicationException the web application exception -// */ -// @Path(GEO_DE) -// @Consumes(MediaType.APPLICATION_JSON) -// @Produces(MediaType.TEXT_PLAIN) -// public Response postGeoportalDE(@Context HttpServletRequest req, GeoportalRequest jsonRequest) -// throws WebApplicationException { -// LOG.info(this.getClass().getSimpleName() + " POST starts..."); -// String targetAppId = GEO_DE; -// return genericPost(req, jsonRequest, targetAppId); -// } + /** + * Check target appliction ID. + * + * @param req the req + * @param targetAppId the target app id + * @return the target app geoportal codes + */ + private TargetAppGeoportalCodes checkTargetApplictionID(@Context HttpServletRequest req, String targetAppId) { + + TargetAppGeoportalCodes targetAppGeoportalCodes = null; + + if (targetAppId == null) { + targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV; + LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes); + } else { + + // IF the target application passed in the request. It must be proper. + targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId); + + if (targetAppGeoportalCodes == null) { + LOG.error("Target application parameter is malformed"); + List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() + .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); + throw ExceptionManager.badRequestException(req, + "Target application is wrong. It must be one value of: " + targetApps, this.getClass(), + helpURI); + } + } + + return targetAppGeoportalCodes; + + } /** * Generic get. * - * @param req the req - * @param targetAppId the target app id - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as + * @param req the req + * @param resoruceGeoportalCodes the resoruce geoportal codes + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as * @return the response * @throws WebApplicationException the web application exception */ - public Response genericGet(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, + public Response genericGet(@Context HttpServletRequest req, TargetAppGeoportalCodes resoruceGeoportalCodes, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { @@ -218,8 +199,6 @@ public class GeoportalResolver { try { InnerMethodName.instance.set("resolveGeoportalPublicLink"); - TargetAppGeoportalCodes resoruceGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId); - LOG.info("Found target app: " + resoruceGeoportalCodes); if (resoruceGeoportalCodes == null) { @@ -308,7 +287,6 @@ public class GeoportalResolver { String itemLink = null; switch (resoruceGeoportalCodes) { - case GEO: case GEO_DV: { GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile(); @@ -369,13 +347,13 @@ public class GeoportalResolver { /** * Generic post. * - * @param req the req - * @param jsonRequest the json request - * @param targetAppId the target app id + * @param req the req + * @param jsonRequest the json request + * @param targetAppGeoportalCodes the target app geoportal codes * @return the response */ protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest, - @PathParam(PATH_TARGET_APP) String targetAppId) { + TargetAppGeoportalCodes targetAppGeoportalCodes) { LOG.info(this.getClass().getSimpleName() + " POST starts..."); @@ -427,46 +405,7 @@ public class GeoportalResolver { "The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI); - TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId); - LOG.info("The target app is: " + targetAppGeoportalCodes); - - // Checking the application towards redirect according the PATH - switch (targetAppGeoportalCodes) { - case GEO: { - LOG.debug("With " + targetAppId + " checking the JSON body passed in the request..."); - // If the PATH is /geo going to check the target_app_name parameter in the - // request - String targetAppName = jsonRequest.getTargetAppName(); - - if (targetAppName == null) { - targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV; - LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes); - } else { - - // IF the target application passed in the request. It must be proper. - targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); - - if (targetAppGeoportalCodes == null) { - LOG.error("Target application parameter is malformed"); - List targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream() - .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList()); - throw ExceptionManager.badRequestException(req, - "Target application is wrong. It must be one value of: " + targetApps, this.getClass(), - helpURI); - } - } - - } - case GEO_DV: - case GEO_DE: { - LOG.debug("With " + targetAppId + " do nothing"); - break; - } - default: - break; - } - - String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName, + String linkURL = String.format("%s/%s%s/%s/%s/%s", serverUrl, GEO, targetAppGeoportalCodes.getId(), vreName, jsonRequest.getItemType(), jsonRequest.getItemID()); if (jsonRequest.getQueryString() != null) { From d4862b88d6eb88e48abca0579fbd6cefbb04a7bb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 15:54:40 +0100 Subject: [PATCH 27/35] Updated Paths --- .../resolver/geoportal/GeoportalRequest.java | 3 -- .../geoportal/TargetAppGeoportalCodes.java | 1 - .../resolver/services/GeoportalResolver.java | 50 +++++++------------ 3 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java index 21e3790..3bf4206 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/GeoportalRequest.java @@ -18,15 +18,12 @@ import lombok.extern.slf4j.Slf4j; public class GeoportalRequest { public static final String P_GCUBE_SCOPE = "gcube_scope"; - public static final String P_TARGET_APP = "target_app_name"; public static final String P_ITEM_TYPE = "item_type"; public static final String P_ITEM_ID = "item_id"; public static final String P_QUERY_STRING = "query_string"; @JsonProperty(P_GCUBE_SCOPE) private String gcubeScope; - @JsonProperty(P_TARGET_APP) - private String targetAppName; /** * It is the UCD ID {usecase_id} */ diff --git a/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java b/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java index d544e54..2e074ca 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java +++ b/src/main/java/org/gcube/datatransfer/resolver/geoportal/TargetAppGeoportalCodes.java @@ -18,7 +18,6 @@ import org.gcube.datatransfer.resolver.services.GeoportalResolver; */ public enum TargetAppGeoportalCodes { - GEO(GeoportalResolver.GEO, "geoportal", "Geoportal"), GEO_DV(GeoportalResolver.GEO_DV, "data-viewer", "Geoportal Viewer"), GEO_DE(GeoportalResolver.GEO_DE, "data-entry", "Geoportal Entry"); diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 4b87303..529191b 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -49,9 +49,9 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; @Path("/geo") public class GeoportalResolver { - public static final String GEO_DE = "de"; - public static final String GEO = "geo"; - public static final String GEO_DV = "dv"; + public static final String GEO_DE = "de"; //data-entry + public static final String GEO = "geo"; //geoportal + public static final String GEO_DV = "dv"; //data-viewer private static final String QP_RESOLVE_AS = "res"; private static final String PATH_PROJECT_ID = "project_id"; @@ -73,21 +73,6 @@ public class GeoportalResolver { PUBLIC, PRIVATE } - /** - * Resolve geoportal. - * - * @param req the req - * @param targetAppId the target app id - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as - * @return the response - * @throws WebApplicationException the web application - * exception @Path("/{targetAppId:" + GEO + "|" - * + GEO_DV + "|" + GEO_DE + "}" + - * "/{vre_name}/{usecase_id}/{project_id}") - */ @GET @Path("/{targetAppId}/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @@ -102,24 +87,25 @@ public class GeoportalResolver { } /** - * Resolve geoportal DV. + * Create a Catalogue Link. * - * @param req the req - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as + * @param req the req + * @param targetAppId the target app id + * @param jsonRequest the json request * @return the response * @throws WebApplicationException the web application exception */ - @GET - @Path("/" + GEO_DV + "/{vre_name}/{usecase_id}/{project_id}") - public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, - @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, - @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV; - return genericGet(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); - + @POST + @Path("") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + public Response postGeoportalNoAppDef(@Context HttpServletRequest req, GeoportalRequest jsonRequest) + throws WebApplicationException { + LOG.info(this.getClass().getSimpleName() + " POST starts..."); + // String targetAppId = GEO; + TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); + LOG.info("The target app is: " + targetAppGeoportalCodes); + return genericPost(req, jsonRequest, targetAppGeoportalCodes); } /** From 4ba61bf2320f942d739a58d3e81c68d6e5f4bed1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 16:05:02 +0100 Subject: [PATCH 28/35] Paths Updated --- .../resolver/services/GeoportalResolver.java | 63 ++++++++++++++----- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 529191b..011e9e5 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -49,9 +49,9 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException; @Path("/geo") public class GeoportalResolver { - public static final String GEO_DE = "de"; //data-entry - public static final String GEO = "geo"; //geoportal - public static final String GEO_DV = "dv"; //data-viewer + public static final String GEO_DE = "de"; // data-entry + public static final String GEO = "geo"; // geoportal + public static final String GEO_DV = "dv"; // data-viewer private static final String QP_RESOLVE_AS = "res"; private static final String PATH_PROJECT_ID = "project_id"; @@ -73,13 +73,51 @@ public class GeoportalResolver { PUBLIC, PRIVATE } + /** + * Resolve geoportal. + * + * @param req the req + * @param targetAppId the target app id + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path("/{vre_name}/{usecase_id}/{project_id}") + public Response resolveGeoportalNoAppDef(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName, + @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, + @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { + + LOG.info(this.getClass().getSimpleName() + " resolveGeoportalNoAppDef - GET starts..."); + TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); + LOG.info("The target app is: " + targetAppGeoportalCodes); + return genericGet(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); + + } + + /** + * Resolve geoportal. + * + * @param req the req + * @param targetAppId the target app id + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as + * @return the response + * @throws WebApplicationException the web application exception + */ @GET @Path("/{targetAppId}/{vre_name}/{usecase_id}/{project_id}") public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - // String targetAppId = GEO; + + LOG.info(this.getClass().getSimpleName() + " resolveGeoportal - GET starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId); LOG.info("The target app is: " + targetAppGeoportalCodes); return genericGet(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); @@ -87,10 +125,9 @@ public class GeoportalResolver { } /** - * Create a Catalogue Link. + * Post geoportal no app def. * * @param req the req - * @param targetAppId the target app id * @param jsonRequest the json request * @return the response * @throws WebApplicationException the web application exception @@ -101,8 +138,8 @@ public class GeoportalResolver { @Produces(MediaType.TEXT_PLAIN) public Response postGeoportalNoAppDef(@Context HttpServletRequest req, GeoportalRequest jsonRequest) throws WebApplicationException { - LOG.info(this.getClass().getSimpleName() + " POST starts..."); - // String targetAppId = GEO; + + LOG.info(this.getClass().getSimpleName() + " postGeoportalNoAppDef - POST starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); LOG.info("The target app is: " + targetAppGeoportalCodes); return genericPost(req, jsonRequest, targetAppGeoportalCodes); @@ -123,8 +160,8 @@ public class GeoportalResolver { @Produces(MediaType.TEXT_PLAIN) public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, GeoportalRequest jsonRequest) throws WebApplicationException { - LOG.info(this.getClass().getSimpleName() + " POST starts..."); - // String targetAppId = GEO; + + LOG.info(this.getClass().getSimpleName() + " postGeoportal - POST starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId); LOG.info("The target app is: " + targetAppGeoportalCodes); return genericPost(req, jsonRequest, targetAppGeoportalCodes); @@ -180,8 +217,6 @@ public class GeoportalResolver { @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - LOG.info(this.getClass().getSimpleName() + " GET starts..."); - try { InnerMethodName.instance.set("resolveGeoportalPublicLink"); @@ -391,8 +426,8 @@ public class GeoportalResolver { "The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI); - String linkURL = String.format("%s/%s%s/%s/%s/%s", serverUrl, GEO, targetAppGeoportalCodes.getId(), vreName, - jsonRequest.getItemType(), jsonRequest.getItemID()); + String linkURL = String.format("%s/%s/%s/%s/%s/%s", serverUrl, GEO, targetAppGeoportalCodes.getId(), + vreName, jsonRequest.getItemType(), jsonRequest.getItemID()); if (jsonRequest.getQueryString() != null) { linkURL += "?" + jsonRequest.getQueryString(); From 30d702a0736ddee1cb2e7723eacc1f6f1bbc53c4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 16:26:38 +0100 Subject: [PATCH 29/35] Updated Java Doc --- .../resolver/services/GeoportalResolver.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 011e9e5..449213c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -37,7 +37,8 @@ import org.slf4j.LoggerFactory; import com.google.common.cache.CacheLoader.InvalidCacheLoadException; /** - * The GeoportalResolver is able to get/resolve a link to a "Geoportal Viewer" + * The GeoportalResolver is able to get/resolve a link to "Geoportal Viewer" + * or "Geoportal Entry" Application. * * See more at * https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver @@ -74,14 +75,13 @@ public class GeoportalResolver { } /** - * Resolve geoportal. + * Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" App * - * @param req the req - * @param targetAppId the target app id - * @param vreName the vre name - * @param ucdID the ucd ID - * @param projectID the project ID - * @param resolveAs the resolve as + * @param req the req + * @param vreName the vre name + * @param ucdID the ucd ID + * @param projectID the project ID + * @param resolveAs the resolve as * @return the response * @throws WebApplicationException the web application exception */ @@ -99,7 +99,7 @@ public class GeoportalResolver { } /** - * Resolve geoportal. + * Resolve geoportal. Resolve a Geoportal Link to to "Data-Viewer" or "Data-Entry" App * * @param req the req * @param targetAppId the target app id @@ -125,7 +125,7 @@ public class GeoportalResolver { } /** - * Post geoportal no app def. + * Post geoportal. Create a Geoportal Link to Data-Viewer App * * @param req the req * @param jsonRequest the json request @@ -146,7 +146,7 @@ public class GeoportalResolver { } /** - * Create a Catalogue Link. + * Post geoportal. Create a Geoportal Link to "Data-Viewer" or "Data-Entry" App * * @param req the req * @param targetAppId the target app id From b2ec64c8284f8eadbc6f5203c3dc02fea316a536 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 16:30:56 +0100 Subject: [PATCH 30/35] Updated Java Doc --- .../datatransfer/resolver/services/GeoportalResolver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 449213c..b3319b8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -99,7 +99,7 @@ public class GeoportalResolver { } /** - * Resolve geoportal. Resolve a Geoportal Link to to "Data-Viewer" or "Data-Entry" App + * Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" or "Data-Entry" App * * @param req the req * @param targetAppId the target app id @@ -125,7 +125,7 @@ public class GeoportalResolver { } /** - * Post geoportal. Create a Geoportal Link to Data-Viewer App + * Post geoportal. Create a Geoportal Link to "Data-Viewer" App * * @param req the req * @param jsonRequest the json request From 4864094ed067074bf4b1e57615ec450cad13bb7e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 27 Mar 2023 10:55:08 +0200 Subject: [PATCH 31/35] Added new method `createDataViewerLink` --- .../resolver/services/GeoportalResolver.java | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index b3319b8..7ce7412 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -37,8 +37,8 @@ import org.slf4j.LoggerFactory; import com.google.common.cache.CacheLoader.InvalidCacheLoadException; /** - * The GeoportalResolver is able to get/resolve a link to "Geoportal Viewer" - * or "Geoportal Entry" Application. + * The GeoportalResolver is able to get/resolve a link to "Geoportal Viewer" or + * "Geoportal Entry" Application. * * See more at * https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver @@ -94,12 +94,13 @@ public class GeoportalResolver { LOG.info(this.getClass().getSimpleName() + " resolveGeoportalNoAppDef - GET starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); LOG.info("The target app is: " + targetAppGeoportalCodes); - return genericGet(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); + return genericResolveLink(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); } /** - * Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" or "Data-Entry" App + * Resolve geoportal. Resolve a Geoportal Link to "Data-Viewer" or "Data-Entry" + * App * * @param req the req * @param targetAppId the target app id @@ -120,7 +121,35 @@ public class GeoportalResolver { LOG.info(this.getClass().getSimpleName() + " resolveGeoportal - GET starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId); LOG.info("The target app is: " + targetAppGeoportalCodes); - return genericGet(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); + return genericResolveLink(req, targetAppGeoportalCodes, vreName, ucdID, projectID, resolveAs); + + } + + /** + * Creates the data viewer link. + * + * @param req the req + * @param gcubeScope the gcube scope + * @param itemId the item id + * @param itemType the item type + * @return the response + * @throws WebApplicationException the web application exception + */ + @GET + @Path("/") + public Response createDataViewerLink(@Context HttpServletRequest req, + @QueryParam(GeoportalRequest.P_GCUBE_SCOPE) String gcubeScope, + @QueryParam(GeoportalRequest.P_ITEM_ID) String itemId, + @QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType) throws WebApplicationException { + + LOG.info(this.getClass().getSimpleName() + " resolveGeoportalNoAppDef - GET starts..."); + TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); + LOG.info("The target app is: " + targetAppGeoportalCodes); + GeoportalRequest geoportalRequest = new GeoportalRequest(); + geoportalRequest.setGcubeScope(gcubeScope); + geoportalRequest.setItemID(itemId); + geoportalRequest.setItemType(itemType); + return genericCreateLink(req, geoportalRequest, targetAppGeoportalCodes); } @@ -142,7 +171,7 @@ public class GeoportalResolver { LOG.info(this.getClass().getSimpleName() + " postGeoportalNoAppDef - POST starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); LOG.info("The target app is: " + targetAppGeoportalCodes); - return genericPost(req, jsonRequest, targetAppGeoportalCodes); + return genericCreateLink(req, jsonRequest, targetAppGeoportalCodes); } /** @@ -164,7 +193,7 @@ public class GeoportalResolver { LOG.info(this.getClass().getSimpleName() + " postGeoportal - POST starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId); LOG.info("The target app is: " + targetAppGeoportalCodes); - return genericPost(req, jsonRequest, targetAppGeoportalCodes); + return genericCreateLink(req, jsonRequest, targetAppGeoportalCodes); } /** @@ -201,7 +230,7 @@ public class GeoportalResolver { } /** - * Generic get. + * Generic resolve link. * * @param req the req * @param resoruceGeoportalCodes the resoruce geoportal codes @@ -212,7 +241,7 @@ public class GeoportalResolver { * @return the response * @throws WebApplicationException the web application exception */ - public Response genericGet(@Context HttpServletRequest req, TargetAppGeoportalCodes resoruceGeoportalCodes, + public Response genericResolveLink(@Context HttpServletRequest req, TargetAppGeoportalCodes resoruceGeoportalCodes, @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { @@ -366,14 +395,14 @@ public class GeoportalResolver { } /** - * Generic post. + * Generic create link. * * @param req the req * @param jsonRequest the json request * @param targetAppGeoportalCodes the target app geoportal codes * @return the response */ - protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest, + protected Response genericCreateLink(@Context HttpServletRequest req, GeoportalRequest jsonRequest, TargetAppGeoportalCodes targetAppGeoportalCodes) { LOG.info(this.getClass().getSimpleName() + " POST starts..."); From 312f9c9fa849a5981f8b3bc7677eea3a89349ecf Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 27 Mar 2023 10:58:45 +0200 Subject: [PATCH 32/35] Updated logs --- .../datatransfer/resolver/services/GeoportalResolver.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 7ce7412..2bed5c2 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -142,7 +142,7 @@ public class GeoportalResolver { @QueryParam(GeoportalRequest.P_ITEM_ID) String itemId, @QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType) throws WebApplicationException { - LOG.info(this.getClass().getSimpleName() + " resolveGeoportalNoAppDef - GET starts..."); + LOG.info(this.getClass().getSimpleName() + " createDataViewerLink - GET starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); LOG.info("The target app is: " + targetAppGeoportalCodes); GeoportalRequest geoportalRequest = new GeoportalRequest(); @@ -245,6 +245,8 @@ public class GeoportalResolver { @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { + + LOG.info(this.getClass().getSimpleName() + " genericResolveLink starts..."); try { InnerMethodName.instance.set("resolveGeoportalPublicLink"); @@ -405,7 +407,7 @@ public class GeoportalResolver { protected Response genericCreateLink(@Context HttpServletRequest req, GeoportalRequest jsonRequest, TargetAppGeoportalCodes targetAppGeoportalCodes) { - LOG.info(this.getClass().getSimpleName() + " POST starts..."); + LOG.info(this.getClass().getSimpleName() + " genericCreateLink starts..."); try { From 40e13d9c8185ffb99ec1ea1d97cb7fc3ad11b0b4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 27 Mar 2023 15:46:44 +0200 Subject: [PATCH 33/35] Updated method `resolveDataViewerLink` --- .settings/org.eclipse.wst.common.component | 29 +++++++----- .../resolver/services/GeoportalResolver.java | 44 ++++++++++++------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index e322491..74e2995 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -13,7 +14,8 @@ - + + @@ -27,7 +29,8 @@ - + + @@ -41,7 +44,8 @@ - + + @@ -55,7 +59,8 @@ - + + @@ -69,10 +74,11 @@ - + uses - + + @@ -86,7 +92,8 @@ - + + @@ -100,7 +107,8 @@ - + + @@ -114,7 +122,8 @@ - + + diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 2bed5c2..34fd8e7 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -1,5 +1,7 @@ package org.gcube.datatransfer.resolver.services; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; import java.util.List; @@ -126,30 +128,40 @@ public class GeoportalResolver { } /** - * Creates the data viewer link. + * Resolve data viewer link. * * @param req the req * @param gcubeScope the gcube scope * @param itemId the item id * @param itemType the item type + * @param resolveAs the resolve as * @return the response * @throws WebApplicationException the web application exception */ @GET @Path("/") - public Response createDataViewerLink(@Context HttpServletRequest req, + public Response resolveDataViewerLink(@Context HttpServletRequest req, @QueryParam(GeoportalRequest.P_GCUBE_SCOPE) String gcubeScope, @QueryParam(GeoportalRequest.P_ITEM_ID) String itemId, - @QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType) throws WebApplicationException { + @QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType, + @QueryParam(QP_RESOLVE_AS) String resolveAs) + throws WebApplicationException { - LOG.info(this.getClass().getSimpleName() + " createDataViewerLink - GET starts..."); + LOG.info(this.getClass().getSimpleName() + " resolveDataViewerLink - GET starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); LOG.info("The target app is: " + targetAppGeoportalCodes); - GeoportalRequest geoportalRequest = new GeoportalRequest(); - geoportalRequest.setGcubeScope(gcubeScope); - geoportalRequest.setItemID(itemId); - geoportalRequest.setItemType(itemType); - return genericCreateLink(req, geoportalRequest, targetAppGeoportalCodes); + + if (gcubeScope == null || gcubeScope.isEmpty()) { + + LOG.error("The query parameter '" + GeoportalRequest.P_GCUBE_SCOPE + "' not found or empty"); + throw ExceptionManager.badRequestException(req, + "Mandatory query parameter '" + GeoportalRequest.P_GCUBE_SCOPE + "' not found or empty", + this.getClass(), helpURI); + + } + + String scope = gcubeScope.substring(gcubeScope.lastIndexOf("/") + 1, gcubeScope.length()); + return genericResolveLink(req, targetAppGeoportalCodes, scope, itemType, itemId, resolveAs); } @@ -171,7 +183,8 @@ public class GeoportalResolver { LOG.info(this.getClass().getSimpleName() + " postGeoportalNoAppDef - POST starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, null); LOG.info("The target app is: " + targetAppGeoportalCodes); - return genericCreateLink(req, jsonRequest, targetAppGeoportalCodes); + String linkURL = genericCreateLink(req, jsonRequest, targetAppGeoportalCodes); + return Response.ok(linkURL).header("Location", linkURL).build(); } /** @@ -193,7 +206,8 @@ public class GeoportalResolver { LOG.info(this.getClass().getSimpleName() + " postGeoportal - POST starts..."); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId); LOG.info("The target app is: " + targetAppGeoportalCodes); - return genericCreateLink(req, jsonRequest, targetAppGeoportalCodes); + String linkURL = genericCreateLink(req, jsonRequest, targetAppGeoportalCodes); + return Response.ok(linkURL).header("Location", linkURL).build(); } /** @@ -245,7 +259,7 @@ public class GeoportalResolver { @PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { - + LOG.info(this.getClass().getSimpleName() + " genericResolveLink starts..."); try { @@ -402,9 +416,9 @@ public class GeoportalResolver { * @param req the req * @param jsonRequest the json request * @param targetAppGeoportalCodes the target app geoportal codes - * @return the response + * @return the URL */ - protected Response genericCreateLink(@Context HttpServletRequest req, GeoportalRequest jsonRequest, + protected String genericCreateLink(@Context HttpServletRequest req, GeoportalRequest jsonRequest, TargetAppGeoportalCodes targetAppGeoportalCodes) { LOG.info(this.getClass().getSimpleName() + " genericCreateLink starts..."); @@ -465,7 +479,7 @@ public class GeoportalResolver { } LOG.info("Returning " + GeoportalResolver.class.getSimpleName() + " URL: " + linkURL); - return Response.ok(linkURL).header("Location", linkURL).build(); + return linkURL; } catch (Exception e) { From ca398b5f8208fd2b8424ed19bddc7adf13d06deb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Mar 2023 12:27:02 +0200 Subject: [PATCH 34/35] Updated comment --- CHANGELOG.md | 2 +- .../datatransfer/resolver/services/GeoportalResolver.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b28d88..849df58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v2.9.0-SNAPSHOT] -- GeoPortalResolver implemented [#24792] +- GeoPortal-Resolver implemented [#24792] ## [v2.8.1] - 2022-06-13 diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 34fd8e7..7bfc785 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -66,7 +66,7 @@ public class GeoportalResolver { private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver"; /** - * The Enum RESOLVE_AS. + * The Enum RESOLVE_AS_PARAMETER. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @@ -320,7 +320,7 @@ public class GeoportalResolver { } } - LOG.info("Found RESOLVE_AS: " + resolveAs); + LOG.info("Found RESOLVE_AS_PARAMETER: " + resolveAs); String originalScope = ScopeProvider.instance.get(); GeoportalDataViewerConfigProfileReader reader; From 5d793b8500547a1429c4552dddfdfd51ea3dd9f4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 28 Mar 2023 12:27:25 +0200 Subject: [PATCH 35/35] Removed unused imports --- .../gcube/datatransfer/resolver/services/GeoportalResolver.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java index 7bfc785..eab1704 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeoportalResolver.java @@ -1,7 +1,5 @@ package org.gcube.datatransfer.resolver.services; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.util.Arrays; import java.util.List;