Moving JSON:API reply separate methods
This commit is contained in:
parent
cbcb4804b7
commit
2d9f469a46
|
@ -39,20 +39,29 @@ public class License extends REST<CKANLicense> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue