From 2d9f469a460fa64590dfe1cfb689319d37eaa382 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 17 Feb 2023 17:39:38 +0100 Subject: [PATCH] Moving JSON:API reply separate methods --- .../java/org/gcube/gcat/rest/License.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/gcat/rest/License.java b/src/main/java/org/gcube/gcat/rest/License.java index 857c832..9c564e5 100644 --- a/src/main/java/org/gcube/gcat/rest/License.java +++ b/src/main/java/org/gcube/gcat/rest/License.java @@ -39,20 +39,29 @@ public class License extends REST implements org.gcube.gcat.api.int * @responseExample application/json classpath:/api-docs-examples/license/list-license-response.json */ @GET - @Produces({MediaType.APPLICATION_JSON, GCatConstants.APPLICATION_JSON_API}) + @Produces(MediaType.APPLICATION_JSON) public String list() throws WebServiceException { + return super.list(-1, -1); + } + + /** + * @return the json array containing the licenses available in the catalogue + * + * @pathExample /licenses + * @responseExample application/json classpath:/api-docs-examples/license/list-license-response.json + */ + @GET + @Produces(GCatConstants.APPLICATION_JSON_API) + public String listAsJsonAPI() throws WebServiceException { String ret = super.list(-1, -1); - String accept = httpHeaders.getHeaderString("Accept"); - if(accept.startsWith(GCatConstants.APPLICATION_JSON_API)) { - ObjectMapper objectMapper = new ObjectMapper(); - ObjectNode objectNode = objectMapper.createObjectNode(); - try { - JsonNode licenses = objectMapper.readTree(ret); - objectNode.set(GCatConstants.JSON_API_DATA_FIELD_NAME, licenses); - ret = objectMapper.writeValueAsString(objectNode); - }catch (Exception e) { - throw new InternalServerErrorException(e); - } + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode objectNode = objectMapper.createObjectNode(); + try { + JsonNode licenses = objectMapper.readTree(ret); + objectNode.set(GCatConstants.JSON_API_DATA_FIELD_NAME, licenses); + ret = objectMapper.writeValueAsString(objectNode); + }catch (Exception e) { + throw new InternalServerErrorException(e); } return ret; }