Search in sources :

Example 1 with Comment

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>"));
}
Also used : Comment(org.alfresco.rest.api.model.Comment) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ReturnAllBeanProperties(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with Comment

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());
}
Also used : AbstractList(java.util.AbstractList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Comment(org.alfresco.rest.api.model.Comment) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) PagingRequest(org.alfresco.query.PagingRequest) HashSet(java.util.HashSet)

Example 3 with Comment

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;
}
Also used : Comment(org.alfresco.rest.api.model.Comment) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ContentReader(org.alfresco.service.cmr.repository.ContentReader) Person(org.alfresco.rest.api.model.Person)

Example 4 with 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)));
}
Also used : Comment(org.alfresco.rest.api.model.Comment) ResourceMetadata(org.alfresco.rest.framework.core.ResourceMetadata) ResourceOperation(org.alfresco.rest.framework.core.ResourceOperation) Test(org.junit.Test)

Example 5 with Comment

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());
}
Also used : Comment(org.alfresco.rest.api.model.Comment) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

Comment (org.alfresco.rest.api.model.Comment)7 Test (org.junit.Test)5 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)3 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 ReturnAllBeanProperties (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties)3 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)3 QName (org.alfresco.service.namespace.QName)2 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1 AbstractList (java.util.AbstractList)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PagingRequest (org.alfresco.query.PagingRequest)1 Person (org.alfresco.rest.api.model.Person)1