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