Search in sources :

Example 1 with AnnotatedContent

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

the class AbstractAnnotationRESTResource method getSuccessResponseWithAnnotatedContent.

/**
 * Builds an annotation response containing the annotated content along with the annotation stubs, according to the
 * requirements in the passed annotations request.
 *
 * @param request the annotations request
 * @param documentName the name of the document to provide an annotated response for
 * @return an annotation response with the annotated content and the annotation stubs
 * @throws AnnotationServiceException in case something goes wrong handling the annotations
 * @throws XWikiException in case something goes wrong manipulating the xwiki context & documents
 */
protected AnnotationResponse getSuccessResponseWithAnnotatedContent(String documentName, AnnotationRequest request) throws AnnotationServiceException, XWikiException {
    ObjectFactory factory = new ObjectFactory();
    AnnotationResponse response = factory.createAnnotationResponse();
    // get the annotations on this content
    Collection<Annotation> annotations = annotationService.getAnnotations(documentName);
    // filter them according to the request
    Collection<Annotation> filteredAnnotations = filterAnnotations(annotations, request);
    // render the document with the filtered annotations on it
    String renderedHTML = renderDocumentWithAnnotations(documentName, null, DEFAULT_ACTION, filteredAnnotations);
    // prepare the annotated content
    AnnotatedContent annotatedContentResponse = factory.createAnnotatedContent();
    annotatedContentResponse.getAnnotations().addAll(prepareAnnotationStubsSet(filteredAnnotations, request.getRequest().getFields()));
    annotatedContentResponse.setContent(renderedHTML);
    // set the annotated content along with the return code in the response and return it
    response.setAnnotatedContent(annotatedContentResponse);
    response.setResponseCode(0);
    return response;
}
Also used : AnnotatedContent(org.xwiki.annotation.rest.model.jaxb.AnnotatedContent) ObjectFactory(org.xwiki.annotation.rest.model.jaxb.ObjectFactory) AnnotationResponse(org.xwiki.annotation.rest.model.jaxb.AnnotationResponse) Annotation(org.xwiki.annotation.Annotation)

Aggregations

Annotation (org.xwiki.annotation.Annotation)1 AnnotatedContent (org.xwiki.annotation.rest.model.jaxb.AnnotatedContent)1 AnnotationResponse (org.xwiki.annotation.rest.model.jaxb.AnnotationResponse)1 ObjectFactory (org.xwiki.annotation.rest.model.jaxb.ObjectFactory)1