Updated paths and behaviour

This commit is contained in:
Francesco Mangiacrapa 2023-03-24 11:31:22 +01:00
parent 011f57cb25
commit ad9bd54412
1 changed files with 36 additions and 20 deletions

View File

@ -233,8 +233,8 @@ public class GeoportalResolver {
@Path("") @Path("")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest) public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
throws WebApplicationException { @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,29 +285,45 @@ 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);
String targetAppName = jsonRequest.getTargetAppName();
TargetAppGeoportalCodes targetAppGeoportalCodes = null; TargetAppGeoportalCodes targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
LOG.info("The target app is: " + targetAppGeoportalCodes);
//Checking the application towards redirect according the PATH
switch (targetAppGeoportalCodes) {
case GEO: {
//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 (targetAppName == null) { if (targetAppGeoportalCodes == null) {
targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO; LOG.error("Target application parameter is malformed");
LOG.error("Target application parameter is null, using default: " + targetAppGeoportalCodes); List<String> targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
} else { .map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList());
throw ExceptionManager.badRequestException(req,
targetAppGeoportalCodes = TargetAppGeoportalCodes.valueOfName(jsonRequest.getTargetAppName()); "Target application is wrong. It must be one value of: " + targetApps, this.getClass(),
helpURI);
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.info("Do nothing");
break;
}
default:
break;
} }
LOG.info("The target app is: " + targetAppGeoportalCodes);
String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName, String linkURL = String.format("%s/%s/%s/%s/%s", serverUrl, targetAppGeoportalCodes.getId(), vreName,
jsonRequest.getItemType(), jsonRequest.getItemID()); jsonRequest.getItemType(), jsonRequest.getItemID());