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("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest)
throws WebApplicationException {
public Response postGeoportal(@Context HttpServletRequest req, GeoportalRequest jsonRequest,
@PathParam(PATH_TARGET_APP) String targetAppId) throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " POST starts...");
try {
@ -285,29 +285,45 @@ public class GeoportalResolver {
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
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) {
targetAppGeoportalCodes = TargetAppGeoportalCodes.GEO;
LOG.error("Target application parameter is null, using default: " + targetAppGeoportalCodes);
} else {
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);
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,
jsonRequest.getItemType(), jsonRequest.getItemID());