Added support for JSON:API to item list method

This commit is contained in:
Luca Frosini 2023-02-23 15:59:44 +01:00
parent 39de19d109
commit 72842ff53b
3 changed files with 18 additions and 7 deletions

View File

@ -248,7 +248,14 @@ public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interf
} }
} }
@GET
@Produces(GCatConstants.APPLICATION_JSON_API)
public String listAsJsonAPI(@QueryParam(GCatConstants.LIMIT_QUERY_PARAMETER) @DefaultValue("10") int limit,
@QueryParam(GCatConstants.OFFSET_QUERY_PARAMETER) @DefaultValue("0") int offset) {
String ret = this.list(limit, offset);
return resultAsJsonAPI(ret);
}
/** /**
* *
* The create API allows to create an item. * The create API allows to create an item.

View File

@ -49,12 +49,8 @@ public class License extends REST<CKANLicense> implements org.gcube.gcat.api.int
@GET @GET
@Produces(GCatConstants.APPLICATION_JSON_API) @Produces(GCatConstants.APPLICATION_JSON_API)
public String listAsJsonAPI() { public String listAsJsonAPI() {
String ret = super.list(-1, -1); String ret = this.list();
StringBuffer stringBuffer = new StringBuffer(); return resultAsJsonAPI(ret);
stringBuffer.append("{ \"data\":");
stringBuffer.append(ret);
stringBuffer.append("}");
return stringBuffer.toString();
} }
} }

View File

@ -98,4 +98,12 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Resp
return delete(id, true); return delete(id, true);
} }
protected String resultAsJsonAPI(String data) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("{ \"data\":");
stringBuffer.append(data);
stringBuffer.append("}");
return stringBuffer.toString();
}
} }