From de4b6080519e38d330d03fe95af9ba3d184d0b04 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 24 Mar 2023 15:42:11 +0100 Subject: [PATCH] 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) {