Search in sources :

Example 1 with CreateOrUpdateSequence

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

the class MongoSequenceDao method updateSequence.

private Sequence updateSequence(final Sequence sequence, final Bson filter) {
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
    try {
        Bson update = new Document("$set", sequence);
        final Sequence returnedSequence = databaseCollection().findOneAndUpdate(filter, update, options);
        if (returnedSequence == null) {
            throw new StorageException("Sequence '" + sequence.getId() + "' has not been updated.");
        }
        if (createOrUpdateSequenceEvent != null) {
            createOrUpdateSequenceEvent.fire(new CreateOrUpdateSequence(returnedSequence));
        }
        return returnedSequence;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update sequence " + sequence, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Sequence(io.lumeer.api.model.Sequence) RemoveSequence(io.lumeer.engine.api.event.RemoveSequence) CreateOrUpdateSequence(io.lumeer.engine.api.event.CreateOrUpdateSequence) CreateOrUpdateSequence(io.lumeer.engine.api.event.CreateOrUpdateSequence) 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 Sequence (io.lumeer.api.model.Sequence)1 CreateOrUpdateSequence (io.lumeer.engine.api.event.CreateOrUpdateSequence)1 RemoveSequence (io.lumeer.engine.api.event.RemoveSequence)1 StorageException (io.lumeer.storage.api.exception.StorageException)1 Document (org.bson.Document)1 Bson (org.bson.conversions.Bson)1