From bcd40389326ec82af1ad9760764224f3a45ff0a6 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 30 Sep 2022 14:02:15 +0200 Subject: [PATCH] Fixing profile --- .../java/org/gcube/gcat/rest/BaseREST.java | 2 +- .../java/org/gcube/gcat/rest/Profile.java | 28 +++++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/gcube/gcat/rest/BaseREST.java b/src/main/java/org/gcube/gcat/rest/BaseREST.java index e0556c3..3ae58a2 100644 --- a/src/main/java/org/gcube/gcat/rest/BaseREST.java +++ b/src/main/java/org/gcube/gcat/rest/BaseREST.java @@ -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; diff --git a/src/main/java/org/gcube/gcat/rest/Profile.java b/src/main/java/org/gcube/gcat/rest/Profile.java index b6b8fe0..755b316 100644 --- a/src/main/java/org/gcube/gcat/rest/Profile.java +++ b/src/main/java/org/gcube/gcat/rest/Profile.java @@ -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.
* - * @param accept This API return by default the content in XML. - *

- * It is possible reading a profile in JSON by specifing the HTTP Header:
- * Accept: application/json - *

+ * This API return by default the content in XML. + *

+ * It is possible reading a profile in JSON by specifing the HTTP Header:
+ * Accept: application/json + *

+ * * @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();