diff --git a/src/main/java/org/gcube/gcat/rest/Item.java b/src/main/java/org/gcube/gcat/rest/Item.java index fc33fd0..290628a 100644 --- a/src/main/java/org/gcube/gcat/rest/Item.java +++ b/src/main/java/org/gcube/gcat/rest/Item.java @@ -27,6 +27,9 @@ import org.gcube.gcat.persistence.ckan.CKANPackage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.webcohesion.enunciate.metadata.rs.ResponseCode; +import com.webcohesion.enunciate.metadata.rs.StatusCodes; + /** * @author Luca Frosini (ISTI - CNR) */ @@ -212,6 +215,9 @@ public class Item extends REST implements org.gcube.gcat.api.interf */ @GET @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The request succeded") + }) /* Catalogue-Member is not added to VRE members and is assumed as the default role in the catalogue for the VRE members. So we can't enforce * @AuthorizationControl(allowedRoles={Role.CATALOGUE_MEMBER, Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) */ @@ -390,6 +396,9 @@ public class Item extends REST implements org.gcube.gcat.api.interf @POST @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 201, condition = "The item has been created successfully.") + }) @Override // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) public Response create(String json) { @@ -403,6 +412,9 @@ public class Item extends REST implements org.gcube.gcat.api.interf @GET @Path("/{" + ITEM_ID_PARAMETER + "}") @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The item exists") + }) @Override /* Catalogue-Member is not added to VRE members and is assumed as the default role in the catalogue for the VRE members. So we can't enforce * @AuthorizationControl(allowedRoles={Role.CATALOGUE_MEMBER, Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) @@ -411,20 +423,34 @@ public class Item extends REST implements org.gcube.gcat.api.interf return super.read(id); } + /** + * @pathExample /items/my_test_item + * @responseExample application/json;charset=UTF-8 classpath:/read-item-response.json + */ @PUT @Path("/{" + ITEM_ID_PARAMETER + "}") @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The item has been updated successfully.") + }) @Override // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) public String update(@PathParam(ITEM_ID_PARAMETER) String id, String json) { return super.update(id, json); } + /** + * @pathExample /items/my_test_item + * @responseExample application/json;charset=UTF-8 classpath:/read-item-response.json + */ @PATCH @Path("/{" + ITEM_ID_PARAMETER + "}") @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The item has been patched successfully.") + }) @Override // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) public String patch(@PathParam(ITEM_ID_PARAMETER) String id, String json) { @@ -436,6 +462,10 @@ public class Item extends REST implements org.gcube.gcat.api.interf */ @DELETE @Path("/{" + ITEM_ID_PARAMETER + "}") + @StatusCodes ({ + @ResponseCode ( code = 204, condition = "The item has been deleted successfully."), + @ResponseCode ( code = 404, condition = "The item was not found.") + }) @Override // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) public Response delete(@PathParam(ITEM_ID_PARAMETER) String id, @@ -448,6 +478,10 @@ public class Item extends REST implements org.gcube.gcat.api.interf */ @PURGE @Path("/{" + ITEM_ID_PARAMETER + "}") + @StatusCodes ({ + @ResponseCode ( code = 204, condition = "The item has been purged successfully."), + @ResponseCode ( code = 404, condition = "The item was not found.") + }) @Override // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) public Response purge(@PathParam(ITEM_ID_PARAMETER) String id) { @@ -512,9 +546,13 @@ public class Item extends REST implements org.gcube.gcat.api.interf * @throws WebServiceException if an error occurs. * * @pathExample /items?purge=false + * */ @DELETE @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 202, condition = "The bulk delete/purge has been accepted successfully.") + }) @Override // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) public Response bulkDelete(@QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") boolean purge) { @@ -561,6 +599,9 @@ public class Item extends REST implements org.gcube.gcat.api.interf */ @PURGE @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 202, condition = "The bulk purge has been accepted successfully.") + }) @Override // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class) public Response bulkPurge() { @@ -600,12 +641,15 @@ public class Item extends REST implements org.gcube.gcat.api.interf * The operation will continue in background. * * @pathExample /items/my_test_item - * + * @requestExample application/json;charset=UTF-8 classpath:/reject.json */ @POST @Path("/{" + ITEM_ID_PARAMETER + "}") @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 202, condition = "The moderation operation has been accepted successfully.") + }) // @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER, Moderated.CATALOGUE_MODERATOR}, exception=NotAuthorizedException.class) public Response moderate(@PathParam(ITEM_ID_PARAMETER) String id, String json) { setCalledMethod("POST /" + COLLECTION_PARAMETER + "/{" + ID_PARAMETER + "}"); diff --git a/src/main/resources/reject.json b/src/main/resources/reject.json new file mode 100644 index 0000000..b1e04d6 --- /dev/null +++ b/src/main/resources/reject.json @@ -0,0 +1,4 @@ +{ + "system:cm_item_status":"rejected", + "message": "The indicated language does not match with the item resource language" +} \ No newline at end of file