Static Paths

This commit is contained in:
Francesco Mangiacrapa 2023-03-24 12:28:57 +01:00
parent df02f4aa27
commit a70c7b5f10
1 changed files with 153 additions and 23 deletions

View File

@ -46,7 +46,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
*
* Mar 23, 2023
*/
@Path("/{targetAppId:geo|geo-dv|geo-de}")
@Path("")
public class GeoportalResolver {
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 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 {
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
@Path("/{vre_name}/{usecase_id}/{project_id}")
public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
@Path("geo/{vre_name}/{usecase_id}/{project_id}")
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_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
throws WebApplicationException {
@ -220,21 +352,18 @@ public class GeoportalResolver {
throw (WebApplicationException) e;
}
}
/**
* Create a Catalogue Link.
* Generic post.
*
* @param req the req
* @param jsonRequest the json request
* @param targetAppId the target app id
* @return the response
* @throws WebApplicationException the web application exception
*/
@POST
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
@PathParam(PATH_TARGET_APP) String targetAppId) throws WebApplicationException {
protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
@PathParam(PATH_TARGET_APP) String targetAppId) {
LOG.info(this.getClass().getSimpleName() + " POST starts...");
try {
@ -285,23 +414,23 @@ 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
// 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
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.
// IF the target application passed in the request. It must be proper.
targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName());
if (targetAppGeoportalCodes == null) {
@ -313,17 +442,17 @@ public class GeoportalResolver {
helpURI);
}
}
}
case GEO_DV:
case GEO_DE: {
LOG.debug("With "+targetAppId+" do nothing");
LOG.debug("With " + targetAppId + " do nothing");
break;
}
default:
break;
}
String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName,
jsonRequest.getItemType(), jsonRequest.getItemID());
@ -346,6 +475,7 @@ public class GeoportalResolver {
LOG.error("Exception:", e);
throw (WebApplicationException) e;
}
}
}