Search in sources :

Example 1 with UpdateResourceComment

use of io.lumeer.engine.api.event.UpdateResourceComment in project engine by Lumeer.

the class MongoResourceCommentDao method updateComment.

@Override
public ResourceComment updateComment(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.");
        }
        if (updateResourceCommentEvent != null) {
            updateResourceCommentEvent.fire(new UpdateResourceComment(comment));
        }
        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) UpdateResourceComment(io.lumeer.engine.api.event.UpdateResourceComment) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson)

Aggregations

MongoException (com.mongodb.MongoException)1 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)1 ReturnDocument (com.mongodb.client.model.ReturnDocument)1 ResourceComment (io.lumeer.api.model.ResourceComment)1 CreateResourceComment (io.lumeer.engine.api.event.CreateResourceComment)1 RemoveResourceComment (io.lumeer.engine.api.event.RemoveResourceComment)1 UpdateResourceComment (io.lumeer.engine.api.event.UpdateResourceComment)1 StorageException (io.lumeer.storage.api.exception.StorageException)1 Document (org.bson.Document)1 Bson (org.bson.conversions.Bson)1