Updated the paths

This commit is contained in:
Francesco Mangiacrapa 2023-03-24 15:42:11 +01:00
parent 9b1f34312e
commit de4b608051
1 changed files with 71 additions and 132 deletions

View File

@ -46,12 +46,12 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
* *
* Mar 23, 2023 * Mar 23, 2023
*/ */
//@Path("/") @Path("/geo")
public class GeoportalResolver { 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 = "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 QP_RESOLVE_AS = "res";
private static final String PATH_PROJECT_ID = "project_id"; private static final String PATH_PROJECT_ID = "project_id";
@ -76,28 +76,30 @@ public class GeoportalResolver {
/** /**
* Resolve geoportal. * Resolve geoportal.
* *
* @param req the req * @param req the req
* @param targetAppId the target app id * @param targetAppId the target app id
* @param vreName the vre name * @param vreName the vre name
* @param ucdID the ucd ID * @param ucdID the ucd ID
* @param projectID the project ID * @param projectID the project ID
* @param resolveAs the resolve as * @param resolveAs the resolve as
* @return the response * @return the response
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application
* @Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}" + "/{vre_name}/{usecase_id}/{project_id}") * exception @Path("/{targetAppId:" + GEO + "|"
* + GEO_DV + "|" + GEO_DE + "}" +
* "/{vre_name}/{usecase_id}/{project_id}")
*/ */
@GET @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, 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_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 {
// String targetAppId = GEO; // 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. * Resolve geoportal DV.
@ -111,104 +113,83 @@ public class GeoportalResolver {
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application exception
*/ */
@GET @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, public Response resolveGeoportalDV(@Context HttpServletRequest req, @PathParam(PATH_VRE_NAME) String vreName,
@PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID, @PathParam(PATH_USECASE_ID) String ucdID, @PathParam(PATH_PROJECT_ID) String projectID,
@QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException { @QueryParam(QP_RESOLVE_AS) String resolveAs) throws WebApplicationException {
String targetAppId = GEO_DV; TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV;
return genericGet(req, targetAppId, vreName, ucdID, projectID, resolveAs); 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. * Create a Catalogue Link.
* *
* @param req the req * @param req the req
* @param targetAppId the target app id
* @param jsonRequest the json request * @param jsonRequest the json request
* @return the response * @return the response
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application exception
*/ */
@POST @POST
@Path("/{targetAppId:" + GEO + "|" + GEO_DV + "|" + GEO_DE + "}") @Path("/{targetAppId}")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId, GeoportalRequest jsonRequest) public Response postGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
throws WebApplicationException { GeoportalRequest jsonRequest) throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " POST starts..."); LOG.info(this.getClass().getSimpleName() + " POST starts...");
//String targetAppId = GEO; // String targetAppId = GEO;
return genericPost(req, jsonRequest, targetAppId); TargetAppGeoportalCodes targetAppGeoportalCodes = checkTargetApplictionID(req, targetAppId);
LOG.info("The target app is: " + targetAppGeoportalCodes);
return genericPost(req, jsonRequest, targetAppGeoportalCodes);
} }
// /** /**
// * Post geoportal DV. * Check target appliction ID.
// * *
// * @param req the req * @param req the req
// * @param jsonRequest the json request * @param targetAppId the target app id
// * @return the response * @return the target app geoportal codes
// * @throws WebApplicationException the web application exception */
// */ private TargetAppGeoportalCodes checkTargetApplictionID(@Context HttpServletRequest req, String targetAppId) {
// @Path(GEO_DV)
// @Consumes(MediaType.APPLICATION_JSON) TargetAppGeoportalCodes targetAppGeoportalCodes = null;
// @Produces(MediaType.TEXT_PLAIN)
// public Response postGeoportalDV(@Context HttpServletRequest req, GeoportalRequest jsonRequest) if (targetAppId == null) {
// throws WebApplicationException { targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO_DV;
// LOG.info(this.getClass().getSimpleName() + " POST starts..."); LOG.warn("Target application parameter is null, using default: " + targetAppGeoportalCodes);
// String targetAppId = GEO_DV; } else {
// return genericPost(req, jsonRequest, targetAppId);
// } // IF the target application passed in the request. It must be proper.
// targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
// /**
// * Post geoportal DE. if (targetAppGeoportalCodes == null) {
// * LOG.error("Target application parameter is malformed");
// * @param req the req List<String> targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
// * @param jsonRequest the json request .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList());
// * @return the response throw ExceptionManager.badRequestException(req,
// * @throws WebApplicationException the web application exception "Target application is wrong. It must be one value of: " + targetApps, this.getClass(),
// */ helpURI);
// @Path(GEO_DE) }
// @Consumes(MediaType.APPLICATION_JSON) }
// @Produces(MediaType.TEXT_PLAIN)
// public Response postGeoportalDE(@Context HttpServletRequest req, GeoportalRequest jsonRequest) return targetAppGeoportalCodes;
// throws WebApplicationException {
// LOG.info(this.getClass().getSimpleName() + " POST starts..."); }
// String targetAppId = GEO_DE;
// return genericPost(req, jsonRequest, targetAppId);
// }
/** /**
* Generic get. * Generic get.
* *
* @param req the req * @param req the req
* @param targetAppId the target app id * @param resoruceGeoportalCodes the resoruce geoportal codes
* @param vreName the vre name * @param vreName the vre name
* @param ucdID the ucd ID * @param ucdID the ucd ID
* @param projectID the project ID * @param projectID the project ID
* @param resolveAs the resolve as * @param resolveAs the resolve as
* @return the response * @return the response
* @throws WebApplicationException the web application exception * @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_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 {
@ -218,8 +199,6 @@ public class GeoportalResolver {
try { try {
InnerMethodName.instance.set("resolveGeoportalPublicLink"); InnerMethodName.instance.set("resolveGeoportalPublicLink");
TargetAppGeoportalCodes resoruceGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
LOG.info("Found target app: " + resoruceGeoportalCodes); LOG.info("Found target app: " + resoruceGeoportalCodes);
if (resoruceGeoportalCodes == null) { if (resoruceGeoportalCodes == null) {
@ -308,7 +287,6 @@ public class GeoportalResolver {
String itemLink = null; String itemLink = null;
switch (resoruceGeoportalCodes) { switch (resoruceGeoportalCodes) {
case GEO:
case GEO_DV: { case GEO_DV: {
GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile(); GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile();
@ -369,13 +347,13 @@ public class GeoportalResolver {
/** /**
* Generic post. * 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 * @param targetAppGeoportalCodes the target app geoportal codes
* @return the response * @return the response
*/ */
protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest, protected Response genericPost(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
@PathParam(PATH_TARGET_APP) String targetAppId) { TargetAppGeoportalCodes targetAppGeoportalCodes) {
LOG.info(this.getClass().getSimpleName() + " POST starts..."); 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?", "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); String linkURL = String.format("%s/%s%s/%s/%s/%s", serverUrl, GEO, targetAppGeoportalCodes.getId(), vreName,
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<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);
}
}
}
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,
jsonRequest.getItemType(), jsonRequest.getItemID()); jsonRequest.getItemType(), jsonRequest.getItemID());
if (jsonRequest.getQueryString() != null) { if (jsonRequest.getQueryString() != null) {