use of io.lumeer.engine.api.event.UpdateResource in project engine by Lumeer.
the class MongoCollectionDao method updateCollection.
@Override
public Collection updateCollection(final String id, final Collection collection, final Collection originalCollection, final boolean pushNotification) {
FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
try {
Bson update = new Document("$set", collection).append("$inc", new Document(CollectionCodec.VERSION, 1L));
final Collection updatedCollection = databaseCollection().findOneAndUpdate(idFilter(id), update, options);
if (updatedCollection == null) {
throw new StorageException("Collection '" + id + "' has not been updated.");
}
if (pushNotification && updateResourceEvent != null) {
updateResourceEvent.fire(new UpdateResource(updatedCollection, originalCollection));
}
return updatedCollection;
} catch (MongoException ex) {
throw new StorageException("Cannot update collection: " + collection, ex);
}
}
Aggregations