Search in sources :

Example 1 with UpdateLinkType

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

the class MongoLinkTypeDao method updateLinkType.

@Override
public LinkType updateLinkType(final String id, final LinkType linkType, final LinkType originalLinkType, final boolean sendPushNotification) {
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER).upsert(false);
    try {
        Bson update = new Document("$set", linkType).append("$inc", new Document(LinkTypeCodec.VERSION, 1L));
        LinkType updatedLinkType = databaseCollection().findOneAndUpdate(idFilter(id), update, options);
        if (updatedLinkType == null) {
            throw new StorageException("Link type '" + id + "' has not been updated.");
        }
        if (sendPushNotification && updateLinkTypeEvent != null) {
            updateLinkTypeEvent.fire(new UpdateLinkType(updatedLinkType, originalLinkType));
        }
        return updatedLinkType;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update link type: " + linkType, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) CreateLinkType(io.lumeer.engine.api.event.CreateLinkType) RemoveLinkType(io.lumeer.engine.api.event.RemoveLinkType) LinkType(io.lumeer.api.model.LinkType) UpdateLinkType(io.lumeer.engine.api.event.UpdateLinkType) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson) UpdateLinkType(io.lumeer.engine.api.event.UpdateLinkType)

Aggregations

MongoException (com.mongodb.MongoException)1 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)1 ReturnDocument (com.mongodb.client.model.ReturnDocument)1 LinkType (io.lumeer.api.model.LinkType)1 CreateLinkType (io.lumeer.engine.api.event.CreateLinkType)1 RemoveLinkType (io.lumeer.engine.api.event.RemoveLinkType)1 UpdateLinkType (io.lumeer.engine.api.event.UpdateLinkType)1 StorageException (io.lumeer.storage.api.exception.StorageException)1 Document (org.bson.Document)1 Bson (org.bson.conversions.Bson)1