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