Improved documetnation

This commit is contained in:
Luca Frosini 2022-09-27 15:22:28 +02:00
parent e22cbcc0f5
commit c7c8ffa332
2 changed files with 49 additions and 1 deletions

View File

@ -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<CKANPackage> 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<CKANPackage> 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<CKANPackage> 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<CKANPackage> 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<CKANPackage> 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<CKANPackage> 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<CKANPackage> 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<CKANPackage> 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<CKANPackage> 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 + "}");

View File

@ -0,0 +1,4 @@
{
"system:cm_item_status":"rejected",
"message": "The indicated language does not match with the item resource language"
}