task_24792 #7
|
@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||||
*
|
*
|
||||||
* Mar 23, 2023
|
* Mar 23, 2023
|
||||||
*/
|
*/
|
||||||
@Path("/{targetAppId:geo|geo-dv|geo-de}")
|
@Path("")
|
||||||
public class GeoportalResolver {
|
public class GeoportalResolver {
|
||||||
|
|
||||||
private static final String QP_RESOLVE_AS = "res";
|
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 final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class);
|
||||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver";
|
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 {
|
private static enum RESOLVE_AS {
|
||||||
PUBLIC, PRIVATE
|
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
|
@GET
|
||||||
@Path("/{vre_name}/{usecase_id}/{project_id}")
|
@Path("geo/{vre_name}/{usecase_id}/{project_id}")
|
||||||
public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
|
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_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID,
|
||||||
@PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
|
@PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
|
||||||
throws WebApplicationException {
|
throws WebApplicationException {
|
||||||
|
@ -222,19 +354,16 @@ public class GeoportalResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Catalogue Link.
|
* Generic post.
|
||||||
*
|
*
|
||||||
* @param req the req
|
* @param req the req
|
||||||
* @param jsonRequest the json request
|
* @param jsonRequest the json request
|
||||||
|
* @param targetAppId the target app id
|
||||||
* @return the response
|
* @return the response
|
||||||
* @throws WebApplicationException the web application exception
|
|
||||||
*/
|
*/
|
||||||
@POST
|
protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
|
||||||
@Path("")
|
@PathParam(PATH_TARGET_APP) String targetAppId) {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
|
||||||
public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
|
|
||||||
@PathParam(PATH_TARGET_APP) String targetAppId) throws WebApplicationException {
|
|
||||||
LOG.info(this.getClass().getSimpleName() + " POST starts...");
|
LOG.info(this.getClass().getSimpleName() + " POST starts...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -285,15 +414,15 @@ public class GeoportalResolver {
|
||||||
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
|
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
|
||||||
this.getClass(), helpURI);
|
this.getClass(), helpURI);
|
||||||
|
|
||||||
|
|
||||||
TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
|
TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
|
||||||
LOG.info("The target app is: " + targetAppGeoportalCodes);
|
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) {
|
switch (targetAppGeoportalCodes) {
|
||||||
case GEO: {
|
case GEO: {
|
||||||
LOG.debug("With "+targetAppId+" checking the JSON body passed 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
|
// If the PATH is /geo going to check the target_app_name parameter in the
|
||||||
|
// request
|
||||||
String targetAppName = jsonRequest.getTargetAppName();
|
String targetAppName = jsonRequest.getTargetAppName();
|
||||||
|
|
||||||
if (targetAppName == null) {
|
if (targetAppName == null) {
|
||||||
|
@ -301,7 +430,7 @@ public class GeoportalResolver {
|
||||||
LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes);
|
LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes);
|
||||||
} else {
|
} 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());
|
targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName());
|
||||||
|
|
||||||
if (targetAppGeoportalCodes == null) {
|
if (targetAppGeoportalCodes == null) {
|
||||||
|
@ -317,7 +446,7 @@ public class GeoportalResolver {
|
||||||
}
|
}
|
||||||
case GEO_DV:
|
case GEO_DV:
|
||||||
case GEO_DE: {
|
case GEO_DE: {
|
||||||
LOG.debug("With "+targetAppId+" do nothing");
|
LOG.debug("With " + targetAppId + " do nothing");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -346,6 +475,7 @@ public class GeoportalResolver {
|
||||||
LOG.error("Exception:", e);
|
LOG.error("Exception:", e);
|
||||||
throw (WebApplicationException) e;
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue