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;
}
Aggregations