Updated method `resolveDataViewerLink`

This commit is contained in:
Francesco Mangiacrapa 2023-03-27 15:46:44 +02:00
parent 312f9c9fa8
commit 40e13d9c81
2 changed files with 48 additions and 25 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -13,7 +14,8 @@
<wb-module deploy-name="uri-resolver-2.8.1">
@ -27,7 +29,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -41,7 +44,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -55,7 +59,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -69,10 +74,11 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="uri-resolver-manager-1.6.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/uri-resolver-manager/uri-resolver-manager">
<dependent-module archiveName="uri-resolver-manager-1.7.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/uri-resolver-manager/uri-resolver-manager">
<dependency-type>uses</dependency-type>
</dependent-module>
@ -86,7 +92,8 @@
<property name="context-root" value="uri-resolver"/>
@ -100,7 +107,8 @@
<property name="java-output-path" value="/uri-resolver/target/classes"/>
@ -114,7 +122,8 @@
</wb-module>

View File

@ -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) {