2023-03-23 15:54:00 +01:00
|
|
|
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;
|
2023-03-24 09:49:57 +01:00
|
|
|
import org.gcube.datatransfer.resolver.geoportal.TargetAppGeoportalCodes;
|
2023-03-23 15:54:00 +01:00
|
|
|
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
|
|
|
|
*/
|
2023-03-24 14:47:32 +01:00
|
|
|
@Path("/")
|
2023-03-23 15:54:00 +01:00
|
|
|
public class GeoportalResolver {
|
|
|
|
|
2023-03-24 14:00:24 +01:00
|
|
|
public static final String GEO_DE = "geo-de";
|
|
|
|
public static final String GEO = "geo";
|
|
|
|
public static final String GEO_DV = "geo-dv";
|
2023-03-24 14:47:32 +01:00
|
|
|
|
2023-03-24 09:49:57 +01:00
|
|
|
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";
|
2023-03-24 14:47:32 +01:00
|
|
|
|
2023-03-23 15:54:00 +01:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class);
|
|
|
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver";
|
|
|
|
|
2023-03-24 12:28:57 +01:00
|
|
|
/**
|
|
|
|
* The Enum RESOLVE_AS.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Mar 24, 2023
|
|
|
|
*/
|
2023-03-23 15:54:00 +01:00
|
|
|
private static enum RESOLVE_AS {
|
|
|
|
PUBLIC, PRIVATE
|
|
|
|
}
|
|
|
|
|
2023-03-24 12:28:57 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2023-03-24 14:54:23 +01:00
|
|
|
@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,
|
2023-03-24 12:28:57 +01:00
|
|
|
@PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID,
|
|
|
|
@QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException {
|
2023-03-24 14:54:23 +01:00
|
|
|
String targetAppId = GEO_DV;
|
2023-03-24 12:28:57 +01:00
|
|
|
return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs);
|
|
|
|
|
|
|
|
}
|
2023-03-24 14:47:32 +01:00
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * 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);
|
|
|
|
//
|
|
|
|
// }
|
2023-03-24 12:28:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Catalogue Link.
|
|
|
|
*
|
|
|
|
* @param req the req
|
|
|
|
* @param jsonRequest the json request
|
|
|
|
* @return the response
|
|
|
|
* @throws WebApplicationException the web application exception
|
|
|
|
*/
|
|
|
|
@POST
|
2023-03-24 14:00:24 +01:00
|
|
|
@Path(GEO)
|
2023-03-24 12:28:57 +01:00
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.TEXT_PLAIN)
|
2023-03-24 14:47:32 +01:00
|
|
|
public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest)
|
|
|
|
throws WebApplicationException {
|
2023-03-24 12:28:57 +01:00
|
|
|
LOG.info(this.getClass().getSimpleName() + " POST starts...");
|
2023-03-24 14:00:24 +01:00
|
|
|
String targetAppId = GEO;
|
2023-03-24 12:28:57 +01:00
|
|
|
return genericPost(req, jsonRequest, targetAppId);
|
|
|
|
}
|
|
|
|
|
2023-03-24 14:47:32 +01:00
|
|
|
// /**
|
|
|
|
// * 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);
|
|
|
|
// }
|
2023-03-24 12:28:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2023-03-24 09:49:57 +01:00
|
|
|
@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 {
|
2023-03-23 15:54:00 +01:00
|
|
|
|
|
|
|
LOG.info(this.getClass().getSimpleName() + " GET starts...");
|
|
|
|
|
|
|
|
try {
|
|
|
|
InnerMethodName.instance.set("resolveGeoportalPublicLink");
|
|
|
|
|
2023-03-24 09:49:57 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-03-23 15:54:00 +01:00
|
|
|
if (vreName == null || vreName.isEmpty()) {
|
2023-03-24 09:49:57 +01:00
|
|
|
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);
|
2023-03-23 15:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ucdID == null) {
|
2023-03-24 09:49:57 +01:00
|
|
|
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);
|
2023-03-23 15:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (projectID == null) {
|
2023-03-24 09:49:57 +01:00
|
|
|
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);
|
2023-03-23 15:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2023-03-24 09:49:57 +01:00
|
|
|
if (resolveAs != null) {
|
|
|
|
switch (resolveAs.toLowerCase()) {
|
2023-03-23 15:54:00 +01:00
|
|
|
case "public":
|
|
|
|
resolveTO = RESOLVE_AS.PUBLIC;
|
|
|
|
break;
|
|
|
|
case "private":
|
|
|
|
resolveTO = RESOLVE_AS.PRIVATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 09:49:57 +01:00
|
|
|
LOG.info("Found RESOLVE_AS: " + resolveAs);
|
|
|
|
|
2023-03-23 15:54:00 +01:00
|
|
|
String originalScope = ScopeProvider.instance.get();
|
|
|
|
GeoportalDataViewerConfigProfileReader reader;
|
|
|
|
try {
|
2023-03-24 09:49:57 +01:00
|
|
|
String theScope = fullScopeBean.toString();
|
|
|
|
LOG.info("Full scope is: " + theScope);
|
|
|
|
ScopeProvider.instance.set(theScope);
|
2023-03-23 15:54:00 +01:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 09:49:57 +01:00
|
|
|
// Resolving towards Data-Viewer or Data-Entry Application
|
2023-03-23 15:54:00 +01:00
|
|
|
String itemLink = null;
|
|
|
|
|
2023-03-24 09:49:57 +01:00
|
|
|
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;
|
|
|
|
}
|
2023-03-23 15:54:00 +01:00
|
|
|
|
|
|
|
break;
|
2023-03-24 09:49:57 +01:00
|
|
|
}
|
2023-03-23 15:54:00 +01:00
|
|
|
|
2023-03-24 09:49:57 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
2023-03-23 15:54:00 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-03-24 09:49:57 +01:00
|
|
|
LOG.info("Returning link: " + itemLink);
|
2023-03-23 15:54:00 +01:00
|
|
|
return Response.seeOther(new URL(itemLink).toURI()).build();
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
if (!(e instanceof WebApplicationException)) {
|
|
|
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
2023-03-24 09:49:57 +01:00
|
|
|
String error = "Error occurred on resolving the " + GeoportalResolver.class.getSimpleName()
|
|
|
|
+ " URL. Please, contact the support!";
|
2023-03-23 15:54:00 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-03-24 12:28:57 +01:00
|
|
|
|
2023-03-23 15:54:00 +01:00
|
|
|
/**
|
2023-03-24 12:28:57 +01:00
|
|
|
* Generic post.
|
2023-03-23 15:54:00 +01:00
|
|
|
*
|
|
|
|
* @param req the req
|
|
|
|
* @param jsonRequest the json request
|
2023-03-24 12:28:57 +01:00
|
|
|
* @param targetAppId the target app id
|
2023-03-23 15:54:00 +01:00
|
|
|
* @return the response
|
|
|
|
*/
|
2023-03-24 12:28:57 +01:00
|
|
|
protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
|
|
|
|
@PathParam(PATH_TARGET_APP) String targetAppId) {
|
|
|
|
|
2023-03-23 15:54:00 +01:00
|
|
|
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);
|
|
|
|
|
2023-03-24 11:31:22 +01:00
|
|
|
TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
|
|
|
|
LOG.info("The target app is: " + targetAppGeoportalCodes);
|
2023-03-24 12:28:57 +01:00
|
|
|
|
|
|
|
// Checking the application towards redirect according the PATH
|
2023-03-24 11:31:22 +01:00
|
|
|
switch (targetAppGeoportalCodes) {
|
|
|
|
case GEO: {
|
2023-03-24 12:28:57 +01:00
|
|
|
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
|
2023-03-24 11:31:22 +01:00
|
|
|
String targetAppName = jsonRequest.getTargetAppName();
|
2023-03-24 12:28:57 +01:00
|
|
|
|
2023-03-24 11:31:22 +01:00
|
|
|
if (targetAppName == null) {
|
|
|
|
targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV;
|
|
|
|
LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes);
|
|
|
|
} else {
|
2023-03-24 12:28:57 +01:00
|
|
|
|
|
|
|
// IF the target application passed in the request. It must be proper.
|
2023-03-24 11:31:22 +01:00
|
|
|
targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName());
|
|
|
|
|
|
|
|
if (targetAppGeoportalCodes == null) {
|
|
|
|
LOG.error("Target application parameter is malformed");
|
|
|
|
List<String> 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);
|
|
|
|
}
|
2023-03-24 10:35:59 +01:00
|
|
|
}
|
2023-03-24 12:28:57 +01:00
|
|
|
|
2023-03-24 11:31:22 +01:00
|
|
|
}
|
|
|
|
case GEO_DV:
|
|
|
|
case GEO_DE: {
|
2023-03-24 12:28:57 +01:00
|
|
|
LOG.debug("With " + targetAppId + " do nothing");
|
2023-03-24 11:31:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2023-03-23 15:54:00 +01:00
|
|
|
}
|
2023-03-24 12:28:57 +01:00
|
|
|
|
2023-03-24 10:55:34 +01:00
|
|
|
String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName,
|
2023-03-23 15:54:00 +01:00
|
|
|
jsonRequest.getItemType(), jsonRequest.getItemID());
|
|
|
|
|
|
|
|
if (jsonRequest.getQueryString() != null) {
|
|
|
|
linkURL += "?" + jsonRequest.getQueryString();
|
|
|
|
}
|
|
|
|
|
2023-03-24 10:46:52 +01:00
|
|
|
LOG.info("Returning " + GeoportalResolver.class.getSimpleName() + " URL: " + linkURL);
|
2023-03-23 15:54:00 +01:00
|
|
|
return Response.ok(linkURL).header("Location", linkURL).build();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
if (!(e instanceof WebApplicationException)) {
|
|
|
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
2023-03-24 09:49:57 +01:00
|
|
|
String error = "Error occurred on creating the " + GeoportalResolver.class.getSimpleName()
|
|
|
|
+ " URL. Please, contact the support!";
|
2023-03-23 15:54:00 +01:00
|
|
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
|
|
|
}
|
|
|
|
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
|
|
|
LOG.error("Exception:", e);
|
|
|
|
throw (WebApplicationException) e;
|
|
|
|
}
|
2023-03-24 12:28:57 +01:00
|
|
|
|
2023-03-23 15:54:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|