use of org.alfresco.rest.api.model.Comment in project alfresco-remote-api by Alfresco.
the class JsonJacksonTests method testSerializeMultipleObjects.
@Test
public void testSerializeMultipleObjects() throws IOException {
final Collection<Comment> allComments = new ArrayList<Comment>();
Comment aComment = new Comment();
aComment.setContent("<b>There it is</b>");
allComments.add(aComment);
aComment = new Comment();
aComment.setContent("<p>I agree with the author</p>");
allComments.add(aComment);
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
FilterProvider fp = new SimpleFilterProvider().addFilter(JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
objectMapper.writer(fp).writeValue(generator, allComments);
}
});
assertTrue(out.toString().contains("content\":\"<b>There it is</b>"));
assertTrue(out.toString().contains("content\":\"<p>I agree with the author</p>"));
}
use of org.alfresco.rest.api.model.Comment in project alfresco-remote-api by Alfresco.
the class CommentsImpl method getComments.
public CollectionWithPagingInfo<Comment> getComments(String nodeId, Paging paging, List<String> include) {
final NodeRef nodeRef = nodes.validateNode(nodeId);
/* MNT-10536 : fix */
final Set<QName> contentAndFolders = new HashSet<QName>(Arrays.asList(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT));
if (!nodes.nodeMatches(nodeRef, contentAndFolders, null)) {
throw new InvalidArgumentException("NodeId of folder or content is expected");
}
PagingRequest pagingRequest = Util.getPagingRequest(paging);
final PagingResults<NodeRef> pagingResults = commentService.listComments(nodeRef, pagingRequest);
final List<NodeRef> page = pagingResults.getPage();
List<Comment> comments = new AbstractList<Comment>() {
@Override
public Comment get(int index) {
return toComment(nodeRef, page.get(index), include);
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, comments, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst());
}
use of org.alfresco.rest.api.model.Comment in project alfresco-remote-api by Alfresco.
the class CommentsImpl method toComment.
private Comment toComment(NodeRef nodeRef, NodeRef commentNodeRef, List<String> include) {
Map<QName, Serializable> nodeProps = nodeService.getProperties(commentNodeRef);
ContentReader reader = contentService.getReader(commentNodeRef, ContentModel.PROP_CONTENT);
if (reader != null) {
String content = reader.getContentString();
nodeProps.put(Comment.PROP_COMMENT_CONTENT, content);
nodeProps.remove(ContentModel.PROP_CONTENT);
}
Map<String, Boolean> map = commentService.getCommentPermissions(nodeRef, commentNodeRef);
boolean canEdit = map.get(CommentService.CAN_EDIT);
boolean canDelete = map.get(CommentService.CAN_DELETE);
Person createdBy = people.getPerson((String) nodeProps.get(ContentModel.PROP_CREATOR), include);
nodeProps.put(Comment.PROP_COMMENT_CREATED_BY, createdBy);
Person modifiedBy = people.getPerson((String) nodeProps.get(ContentModel.PROP_MODIFIER), include);
nodeProps.put(Comment.PROP_COMMENT_MODIFIED_BY, modifiedBy);
Comment comment = new Comment(commentNodeRef.getId(), nodeProps, canEdit, canDelete);
return comment;
}
use of org.alfresco.rest.api.model.Comment in project alfresco-remote-api by Alfresco.
the class InspectorTests method testNodesCommentsRelation.
@Test
public void testNodesCommentsRelation() {
List<ResourceMetadata> metainfo = ResourceInspector.inspect(NodeCommentsRelation.class);
assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
ResourceMetadata metaData = metainfo.get(0);
assertNotNull(metaData);
ResourceOperation op = metaData.getOperation(HttpMethod.POST);
assertTrue("NodeCommentsRelation must support Comment", Comment.class.equals(metaData.getObjectType(op)));
}
use of org.alfresco.rest.api.model.Comment in project alfresco-remote-api by Alfresco.
the class JsonJacksonTests method testDeserializeComment.
@Test
public void testDeserializeComment() throws IOException {
String json = "{\"title\":\"fred\", \"content\":\"lots of noise\"}";
Comment aComment = jsonHelper.construct(new StringReader(json), Comment.class);
assertEquals(Comment.class, aComment.getClass());
assertEquals("fred", aComment.getTitle());
assertEquals("lots of noise", aComment.getContent());
}
Aggregations