Search in sources :

Example 6 with AnnotationResponse

use of org.xwiki.annotation.rest.model.jaxb.AnnotationResponse in project xwiki-platform by xwiki.

the class SingleAnnotationRESTResource method doDelete.

/**
 * Deletes the specified annotation.
 *
 * @param space the space of the document to delete the annotation from
 * @param page the name of the document to delete the annotation from
 * @param wiki the wiki of the document to delete the annotation from
 * @param id the id of the annotation to delete
 * @param request the annotation request to configure the returned annotated content after the execution of the
 *            operation
 * @return a annotation response for which the response code will be 0 in case of success and non-zero otherwise
 * @throws XWikiRestException when failing to parse space
 */
@DELETE
public AnnotationResponse doDelete(@PathParam("spaceName") String space, @PathParam("pageName") String page, @PathParam("wikiName") String wiki, @PathParam("id") String id, AnnotationRequest request) throws XWikiRestException {
    try {
        DocumentReference documentReference = new DocumentReference(wiki, parseSpaceSegments(space), page);
        // Initialize the context with the correct value.
        updateContext(documentReference);
        String documentName = referenceSerializer.serialize(documentReference);
        // check access to this function
        if (!annotationRightService.canEditAnnotation(id, documentName, getXWikiUser())) {
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
        // remove the annotation
        annotationService.removeAnnotation(documentName, id);
        // and then return the annotated content, as specified by the annotation request
        AnnotationResponse response = getSuccessResponseWithAnnotatedContent(documentName, request);
        return response;
    } catch (XWikiException e) {
        getLogger().error(e.getMessage(), e);
        return getErrorResponse(e);
    } catch (AnnotationServiceException e) {
        getLogger().error(e.getMessage(), e);
        return getErrorResponse(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AnnotationServiceException(org.xwiki.annotation.AnnotationServiceException) AnnotationResponse(org.xwiki.annotation.rest.model.jaxb.AnnotationResponse) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) DELETE(javax.ws.rs.DELETE)

Aggregations

AnnotationResponse (org.xwiki.annotation.rest.model.jaxb.AnnotationResponse)6 XWikiException (com.xpn.xwiki.XWikiException)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 AnnotationServiceException (org.xwiki.annotation.AnnotationServiceException)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 Annotation (org.xwiki.annotation.Annotation)2 AnnotationField (org.xwiki.annotation.rest.model.jaxb.AnnotationField)2 ObjectFactory (org.xwiki.annotation.rest.model.jaxb.ObjectFactory)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Request (org.restlet.Request)1 Form (org.restlet.data.Form)1 AnnotatedContent (org.xwiki.annotation.rest.model.jaxb.AnnotatedContent)1 AnnotationAddRequest (org.xwiki.annotation.rest.model.jaxb.AnnotationAddRequest)1