Search in sources :

Example 1 with AnnotationStub

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

the class AbstractAnnotationRESTResource method prepareAnnotationStubsSet.

/**
 * Helper function to translate a collection of annotations from the {@link Annotation} model to the JAXB model to
 * be serialized for REST communication.
 *
 * @param annotations the annotations collection to be translated
 * @param requestedFields the extra parameters that should be set for the prepared annotations
 * @return translate set of org.xwiki.annotation.internal.annotation.Annotation to set of
 *         org.xwiki.annotation.internal.annotation.Annotation
 */
private Collection<AnnotationStub> prepareAnnotationStubsSet(Collection<Annotation> annotations, List<String> requestedFields) {
    ObjectFactory factory = new ObjectFactory();
    List<AnnotationStub> set = new ArrayList<AnnotationStub>();
    for (Annotation xwikiAnnotation : annotations) {
        AnnotationStub annotation = factory.createAnnotationStub();
        annotation.setAnnotationId(xwikiAnnotation.getId());
        annotation.setState(xwikiAnnotation.getState().toString());
        // for all the requested extra fields, get them from the annotation and send them
        for (String extraField : requestedFields) {
            Object value = xwikiAnnotation.get(extraField);
            AnnotationField field = new AnnotationField();
            field.setName(extraField);
            // value.toString() by default, null if value is missing
            field.setValue(value != null ? value.toString() : null);
            annotation.getFields().add(field);
        }
        set.add(annotation);
    }
    return set;
}
Also used : ObjectFactory(org.xwiki.annotation.rest.model.jaxb.ObjectFactory) AnnotationField(org.xwiki.annotation.rest.model.jaxb.AnnotationField) ArrayList(java.util.ArrayList) AnnotationStub(org.xwiki.annotation.rest.model.jaxb.AnnotationStub) Annotation(org.xwiki.annotation.Annotation)

Aggregations

ArrayList (java.util.ArrayList)1 Annotation (org.xwiki.annotation.Annotation)1 AnnotationField (org.xwiki.annotation.rest.model.jaxb.AnnotationField)1 AnnotationStub (org.xwiki.annotation.rest.model.jaxb.AnnotationStub)1 ObjectFactory (org.xwiki.annotation.rest.model.jaxb.ObjectFactory)1