Moved JSON:API to single function to control default

This commit is contained in:
Luca Frosini 2023-02-28 15:51:12 +01:00
parent 53be7fcd10
commit 29202bf152
2 changed files with 19 additions and 26 deletions

View File

@ -221,7 +221,7 @@ public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interf
* @responseExample application/json;charset=UTF-8 ["item0","items1",...,"item10"] * @responseExample application/json;charset=UTF-8 ["item0","items1",...,"item10"]
*/ */
@GET @GET
@Produces({GCatConstants.APPLICATION_JSON_CHARSET_UTF_8, "*/*"}) @Produces({GCatConstants.APPLICATION_JSON_CHARSET_UTF_8, GCatConstants.APPLICATION_JSON_API})
@StatusCodes ({ @StatusCodes ({
@ResponseCode ( code = 200, condition = "The request succeeded.") @ResponseCode ( code = 200, condition = "The request succeeded.")
}) })
@ -238,22 +238,22 @@ public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interf
countOnly = Boolean.parseBoolean(queryParameters.get(GCatConstants.COUNT_QUERY_PARAMETER).get(0)); countOnly = Boolean.parseBoolean(queryParameters.get(GCatConstants.COUNT_QUERY_PARAMETER).get(0));
} }
String ret = null;
if(countOnly) { if(countOnly) {
setCalledMethod("GET /" + COLLECTION_PARAMETER); setCalledMethod("GET /" + COLLECTION_PARAMETER);
CKANPackage ckan = getInstance(); CKANPackage ckan = getInstance();
int size = ckan.count(); int size = ckan.count();
return createCountJson(size); ret = createCountJson(size);
}else { }else {
return super.list(limit, offset); ret = super.list(limit, offset);
} }
}
String accept = httpHeaders.getHeaderString("Accept");
@GET if(accept.contains(GCatConstants.APPLICATION_JSON_API)) {
@Produces(GCatConstants.APPLICATION_JSON_API) return resultAsJsonAPI(ret);
public String listAsJsonAPI(@QueryParam(GCatConstants.LIMIT_QUERY_PARAMETER) @DefaultValue("10") int limit, }
@QueryParam(GCatConstants.OFFSET_QUERY_PARAMETER) @DefaultValue("0") int offset) { return ret;
String ret = this.list(limit, offset);
return resultAsJsonAPI(ret);
} }
/** /**

View File

@ -35,22 +35,15 @@ public class License extends REST<CKANLicense> implements org.gcube.gcat.api.int
* @responseExample application/json classpath:/api-docs-examples/license/list-license-response.json * @responseExample application/json classpath:/api-docs-examples/license/list-license-response.json
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,GCatConstants.APPLICATION_JSON_API})
public String list() throws WebServiceException { public String list() throws WebServiceException {
return super.list(-1, -1); String ret = super.list(-1, -1);
}
String accept = httpHeaders.getHeaderString("Accept");
/** if(accept.contains(GCatConstants.APPLICATION_JSON_API)) {
* @return the json array containing the licenses available in the catalogue return resultAsJsonAPI(ret);
* }
* @pathExample /licenses return ret;
* @responseExample application/json classpath:/api-docs-examples/license/list-license-response.json
*/
@GET
@Produces(GCatConstants.APPLICATION_JSON_API)
public String listAsJsonAPI() {
String ret = this.list();
return resultAsJsonAPI(ret);
} }
} }