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