Adding support for JSON:API
This commit is contained in:
parent
e5adc1e3a7
commit
0a79e2d769
|
@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
- Delete of item in a moderated catalogue produces a notification [#24305]
|
||||
- The user performing create/update item in moderated catalogue receive confirmation via notification of the action [#23575]
|
||||
- Enhanced gcube-smartgears-bom version
|
||||
- Added support for JSON:API on 'licenses' collection [#24601]
|
||||
|
||||
|
||||
## [v2.4.1] [r5.14.0] - 2022-12-07
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
package org.gcube.gcat.rest;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.InternalServerErrorException;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.gcat.api.GCatConstants;
|
||||
import org.gcube.gcat.persistence.ckan.CKANLicense;
|
||||
|
||||
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
||||
|
@ -33,9 +39,22 @@ 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)
|
||||
public String list() {
|
||||
return super.list(-1, -1);
|
||||
@Produces({MediaType.APPLICATION_JSON, GCatConstants.APPLICATION_JSON_API})
|
||||
public String list() throws WebServiceException {
|
||||
String ret = super.list(-1, -1);
|
||||
String accept = httpHeaders.getHeaderString("Accept");
|
||||
if(accept.compareTo(GCatConstants.APPLICATION_JSON_API)==0) {
|
||||
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