Search in sources :

Example 6 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class DocumentFacadeIT method testDocumentComments.

@Test
public void testDocumentComments() {
    setCollectionGroupRoles(collectionFacade.getCollection(collection.getId()), Set.of(new Role(RoleType.Read), new Role(RoleType.DataContribute), new Role(RoleType.CommentContribute)));
    final String firstMessage = "hello this is a cool comment";
    final String secondMessage = "Hello, I fixed this!";
    final Document doc = createDocument();
    final ResourceComment comment1 = new ResourceComment(firstMessage, null);
    comment1.setResourceType(ResourceType.DOCUMENT);
    comment1.setResourceId(doc.getId());
    final ResourceComment comment2 = resourceCommentFacade.createResourceComment(comment1);
    assertThat(comment2.getComment()).isEqualTo(firstMessage);
    assertThat(comment2.getAuthor()).isEqualTo(user.getId());
    assertThat(comment2.getAuthorEmail()).isEqualTo(user.getEmail());
    assertThat(comment2.getAuthorName()).isEqualTo(user.getName());
    assertThat(comment2.getCreationDate().plusSeconds(5).toInstant().getEpochSecond()).isGreaterThan(System.currentTimeMillis() / 1000);
    assertThat(comment2.getUpdateDate()).isNull();
    comment2.setComment(secondMessage);
    final ResourceComment comment3 = resourceCommentFacade.updateResourceComment(comment2);
    assertThat(comment3.getComment()).isEqualTo(secondMessage);
    assertThat(comment3.getUpdateDate().plusSeconds(5).toInstant().getEpochSecond()).isGreaterThan(System.currentTimeMillis() / 1000);
    final List<ResourceComment> comments1 = resourceCommentFacade.getComments(ResourceType.DOCUMENT, doc.getId(), 0, 0);
    assertThat(comments1).hasSize(1);
    assertThat(comments1.get(0)).isEqualTo(comment3);
    Map<String, Integer> counts = resourceCommentFacade.getCommentsCounts(ResourceType.DOCUMENT, Set.of(doc.getId()));
    assertThat(counts).hasSize(1);
    assertThat(counts.get(doc.getId())).isNotNull();
    assertThat(counts.get(doc.getId())).isEqualTo(1);
    resourceCommentFacade.deleteComment(comment3);
    final List<ResourceComment> comments2 = resourceCommentFacade.getComments(ResourceType.DOCUMENT, doc.getId(), 0, 0);
    assertThat(comments2).hasSize(0);
    comment1.setId(null);
    final ResourceComment comment4 = resourceCommentFacade.createResourceComment(comment1);
    assertThat(comment4).isNotEqualTo(comment3);
    resourceCommentFacade.removeDocument(new RemoveDocument(doc));
    final List<ResourceComment> comments3 = resourceCommentFacade.getComments(ResourceType.DOCUMENT, doc.getId(), 0, 0);
    assertThat(comments3).hasSize(0);
}
Also used : Role(io.lumeer.api.model.Role) ResourceComment(io.lumeer.api.model.ResourceComment) RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) Test(org.junit.Test)

Example 7 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class ResourceCommentWrapper method getResourceComment.

public ResourceComment getResourceComment() {
    final ResourceComment rc = new ResourceComment(comment, metaData);
    rc.setId(id);
    rc.setResourceType(resourceType);
    rc.setResourceId(resourceId);
    rc.setParentId(parentId);
    if (creationDate != null) {
        rc.setCreationDate(ZonedDateTime.ofInstant(new Date(creationDate).toInstant(), ZoneOffset.UTC));
    }
    if (updateDate != null) {
        rc.setUpdateDate(ZonedDateTime.ofInstant(new Date(updateDate).toInstant(), ZoneOffset.UTC));
    }
    rc.setAuthor(author);
    rc.setAuthorEmail(authorEmail);
    rc.setAuthorName(authorName);
    return rc;
}
Also used : ResourceComment(io.lumeer.api.model.ResourceComment) Date(java.util.Date)

Example 8 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class MongoResourceCommentDao method pureUpdateComment.

@Override
public ResourceComment pureUpdateComment(final ResourceComment comment) {
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
    try {
        Bson update = new org.bson.Document("$set", comment);
        ResourceComment updatedComment = databaseCollection().findOneAndUpdate(idFilter(comment.getId()), update, options);
        if (updatedComment == null) {
            throw new StorageException("Comment '" + comment.getId() + "' has not been updated.");
        }
        return updatedComment;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update comment: " + comment, ex);
    }
}
Also used : UpdateResourceComment(io.lumeer.engine.api.event.UpdateResourceComment) RemoveResourceComment(io.lumeer.engine.api.event.RemoveResourceComment) ResourceComment(io.lumeer.api.model.ResourceComment) CreateResourceComment(io.lumeer.engine.api.event.CreateResourceComment) MongoException(com.mongodb.MongoException) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson)

Example 9 with ResourceComment

use of io.lumeer.api.model.ResourceComment in project engine by Lumeer.

the class ResourceCommentCodec method decode.

@Override
public ResourceComment decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    final ResourceComment comment = new ResourceComment(bson.getString(COMMENT), null);
    comment.setId(bson.getObjectId(ID).toHexString());
    comment.setResourceType(ResourceType.fromString(bson.getString(RESOURCE_TYPE)));
    comment.setResourceId(bson.getString(RESOURCE_ID));
    comment.setParentId(bson.getString(PARENT_ID));
    final Date creationDate = bson.getDate(CREATION_DATE);
    comment.setCreationDate(creationDate != null ? ZonedDateTime.ofInstant(creationDate.toInstant(), ZoneOffset.UTC) : null);
    final Date updatedDate = bson.getDate(UPDATE_DATE);
    comment.setUpdateDate(updatedDate != null ? ZonedDateTime.ofInstant(updatedDate.toInstant(), ZoneOffset.UTC) : null);
    comment.setAuthor(bson.getString(AUTHOR));
    comment.setAuthorEmail(bson.getString(AUTHOR_EMAIL));
    comment.setAuthorName(bson.getString(AUTHOR_NAME));
    Document metaData = bson.get(META_DATA, Document.class);
    comment.setMetaData(new DataDocument(metaData != null ? metaData : new Document()));
    return comment;
}
Also used : ResourceComment(io.lumeer.api.model.ResourceComment) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) Date(java.util.Date)

Aggregations

ResourceComment (io.lumeer.api.model.ResourceComment)9 Document (org.bson.Document)3 MongoException (com.mongodb.MongoException)2 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)2 ReturnDocument (com.mongodb.client.model.ReturnDocument)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 CreateResourceComment (io.lumeer.engine.api.event.CreateResourceComment)2 RemoveResourceComment (io.lumeer.engine.api.event.RemoveResourceComment)2 UpdateResourceComment (io.lumeer.engine.api.event.UpdateResourceComment)2 StorageException (io.lumeer.storage.api.exception.StorageException)2 Date (java.util.Date)2 Bson (org.bson.conversions.Bson)2 Document (io.lumeer.api.model.Document)1 Role (io.lumeer.api.model.Role)1 TemplateNotAvailableException (io.lumeer.core.exception.TemplateNotAvailableException)1 RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1