Fixing profile

This commit is contained in:
Luca Frosini 2022-09-30 14:02:15 +02:00
parent 816effa271
commit bcd4038932
2 changed files with 11 additions and 19 deletions

View File

@ -24,7 +24,7 @@ public class BaseREST {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Context
protected HttpHeaders headers;
protected HttpHeaders httpHeaders;
@Context
protected UriInfo uriInfo;

View File

@ -5,7 +5,6 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.NotAllowedException;
@ -16,12 +15,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
//import org.gcube.common.authorization.control.annotations.AuthorizationControl;
@ -63,9 +60,6 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
PROFILE_VALIDATION_ERROR = validationError.toString();
}
@Context
private UriInfo uriInfo;
/*
* Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface
*/
@ -137,11 +131,12 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
/**
* This API allow to read a profile definition.<br/>
*
* @param accept This API return by default the content in XML.
* <p>
* It is possible reading a profile in JSON by specifing the HTTP Header:<br/>
* <code>Accept: application/json</code>
* </p>
* This API return by default the content in XML.
* <p>
* It is possible reading a profile in JSON by specifing the HTTP Header:<br/>
* <code>Accept: application/json</code>
*</p>
*
* @param name the name of the profile
* @return the profile definition
*
@ -158,8 +153,8 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
@Path("/{" + PROFILE_NAME_PARAMETER + "}")
@Consumes({MediaType.APPLICATION_XML, GCatConstants.APPLICATION_JSON_CHARSET_UTF_8})
@Produces({MediaType.APPLICATION_XML, GCatConstants.APPLICATION_JSON_CHARSET_UTF_8})
public String read(@PathParam(PROFILE_NAME_PARAMETER) String name,
@DefaultValue(MediaType.APPLICATION_XML) @HeaderParam("Accept") String accept) {
@Override
public String read(@PathParam(PROFILE_NAME_PARAMETER) String name) { // @DefaultValue(MediaType.APPLICATION_XML) @HeaderParam("Accept") String accept) {
setCalledMethod("GET /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
try {
// If the name is SCHEMA
@ -167,6 +162,8 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
return DataCalogueMetadataFormatReader.getProfileSchemaString();
}
String accept = httpHeaders.getHeaderString("Accept");
ISProfile isProfile = new ISProfile();
boolean xml = true;
if(accept.startsWith(MediaType.APPLICATION_JSON)) {
@ -239,11 +236,6 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P
}
@Override
public String read(String name) {
return read(name, MediaType.APPLICATION_XML);
}
@Override
public String update(String name, String xml) {
return createOrUpdate(name, xml).getEntity().toString();