diff --git a/src/main/java/org/gcube/gcat/rest/BaseREST.java b/src/main/java/org/gcube/gcat/rest/BaseREST.java index e1547ab..e0556c3 100644 --- a/src/main/java/org/gcube/gcat/rest/BaseREST.java +++ b/src/main/java/org/gcube/gcat/rest/BaseREST.java @@ -1,6 +1,7 @@ package org.gcube.gcat.rest; import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.UriInfo; @@ -22,6 +23,9 @@ public class BaseREST { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + @Context + protected HttpHeaders headers; + @Context protected UriInfo uriInfo; diff --git a/src/main/java/org/gcube/gcat/rest/Item.java b/src/main/java/org/gcube/gcat/rest/Item.java index a11fd10..45d8a1d 100644 --- a/src/main/java/org/gcube/gcat/rest/Item.java +++ b/src/main/java/org/gcube/gcat/rest/Item.java @@ -300,7 +300,7 @@ public class Item extends REST implements org.gcube.gcat.api.interf * @param limit (Default:10) To get unlimited results the limit query parameters must be set to -1. * If the results are too much the operation could fail. * It is recommended to request no more than 1000 results. - * @param offset Default:0) The offset parameter indicates the starting position of the result. + * @param offset (Default:0) The offset parameter indicates the starting position of the result. * @return It returns an array list of string containing the ids (i.e. names) of the items. * E.g.
["item0","items1",...,"item10"]
* diff --git a/src/main/java/org/gcube/gcat/rest/Profile.java b/src/main/java/org/gcube/gcat/rest/Profile.java index 837bec8..b6b8fe0 100644 --- a/src/main/java/org/gcube/gcat/rest/Profile.java +++ b/src/main/java/org/gcube/gcat/rest/Profile.java @@ -35,9 +35,10 @@ import com.webcohesion.enunciate.metadata.rs.ResourceGroup; import com.webcohesion.enunciate.metadata.rs.ResourceLabel; /** - * At creation and update time the provided profile is validated against the defined XSD schema. + * A Profile must comply with the defined XSD schema . * - * + * Please find the documentation of profile schema at: + * at Metadata Profile * * @author Luca Frosini (ISTI - CNR) */ @@ -81,13 +82,28 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P } } + /** + * Returns the list of profiles name available for the + * context of the request + * (i.e. the context where the token has been generated). + * + * @param count (Default:false) If count=true the API returns total number of profile instead of the list. + * @return a JSON Array. + * + * @pathExample /profiles + * @responseExample application/json;charset=UTF-8 ["EmptyProfile","TestProfile",...,"ComplexProfile"] + * + * @pathExample /profiles?count=true + * @responseExample application/json;charset=UTF-8 {"count":5} + * + */ @GET @Produces(MediaType.APPLICATION_JSON) - public String listOrCount(@QueryParam(GCatConstants.COUNT_QUERY_PARAMETER) @DefaultValue("false") Boolean countOnly) { + public String listOrCount(@QueryParam(GCatConstants.COUNT_QUERY_PARAMETER) @DefaultValue("false") Boolean count) { setCalledMethod("GET /" + PROFILES); try { ISProfile isProfile = new ISProfile(); - if(countOnly) { + if(count) { return createCountJson(isProfile.count()); }else{ ArrayNode arrayNode = isProfile.list(); @@ -118,8 +134,29 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P public static int PRETTY_PRINT_INDENT_FACTOR = 4; + /** + * This API allow to read a profile definition.
+ * + * @param accept This API return by default the content in XML. + *

+ * It is possible reading a profile in JSON by specifing the HTTP Header:
+ * Accept: application/json + *

+ * @param name the name of the profile + * @return the profile definition + * + * @pathExample /profiles/EmptyProfile + * @requestExample application/json;charset=UTF-8 + * @responseExample application/json;charset=UTF-8 classpath:/api-docs-examples/profile/read-profile-response.json + * + * @pathExample /profiles/EmptyProfile + * @requestExample application/xml + * @responseExample application/xml classpath:/api-docs-examples/profile/read-profile-response.xml + * + */ @GET @Path("/{" + PROFILE_NAME_PARAMETER + "}") + @Consumes({MediaType.APPLICATION_XML, GCatConstants.APPLICATION_JSON_CHARSET_UTF_8}) @Produces({MediaType.APPLICATION_XML, GCatConstants.APPLICATION_JSON_CHARSET_UTF_8}) public String read(@PathParam(PROFILE_NAME_PARAMETER) String name, @DefaultValue(MediaType.APPLICATION_XML) @HeaderParam("Accept") String accept) { @@ -131,9 +168,9 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P } ISProfile isProfile = new ISProfile(); - boolean xml = false; - if(accept.startsWith(MediaType.APPLICATION_XML)) { - xml = true; + boolean xml = true; + if(accept.startsWith(MediaType.APPLICATION_JSON)) { + xml = false; } return isProfile.read(name, xml); } catch(WebApplicationException e) { diff --git a/src/main/java/org/gcube/gcat/rest/administration/Configuration.java b/src/main/java/org/gcube/gcat/rest/administration/Configuration.java index 2809a40..d961da3 100644 --- a/src/main/java/org/gcube/gcat/rest/administration/Configuration.java +++ b/src/main/java/org/gcube/gcat/rest/administration/Configuration.java @@ -49,6 +49,7 @@ import com.webcohesion.enunciate.metadata.swagger.OperationId; * A Configuration is described by the following attributes: * *
+ * *
context (string)
*
it must contains the same value of requesting context;
* diff --git a/src/main/resources/api-docs-examples/profile/create-profile-request.xml b/src/main/resources/api-docs-examples/profile/create-profile-request.xml new file mode 100644 index 0000000..ff0812e --- /dev/null +++ b/src/main/resources/api-docs-examples/profile/create-profile-request.xml @@ -0,0 +1,8 @@ + + + test + false + String + Test field + + diff --git a/src/main/resources/api-docs-examples/profile/create-profile-response.xml b/src/main/resources/api-docs-examples/profile/create-profile-response.xml new file mode 100644 index 0000000..ff0812e --- /dev/null +++ b/src/main/resources/api-docs-examples/profile/create-profile-response.xml @@ -0,0 +1,8 @@ + + + test + false + String + Test field + + diff --git a/src/main/resources/api-docs-examples/profile/read-profile-response.json b/src/main/resources/api-docs-examples/profile/read-profile-response.json new file mode 100644 index 0000000..6b8420c --- /dev/null +++ b/src/main/resources/api-docs-examples/profile/read-profile-response.json @@ -0,0 +1,11 @@ +{ + "metadataformat": { + "metadatafield": { + "note": "Test field", + "fieldName": "test", + "dataType": "String", + "mandatory": false + }, + "type": "EmptyProfile" + } +} \ No newline at end of file diff --git a/src/main/resources/api-docs-examples/profile/read-profile-response.xml b/src/main/resources/api-docs-examples/profile/read-profile-response.xml new file mode 100644 index 0000000..ff0812e --- /dev/null +++ b/src/main/resources/api-docs-examples/profile/read-profile-response.xml @@ -0,0 +1,8 @@ + + + test + false + String + Test field + +