Search in sources :

Example 1 with CreateOrUpdatePayment

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

the class MongoPaymentDao method updatePayment.

private Payment updatePayment(final Organization organization, final Payment payment, final Bson filter) {
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
    try {
        Bson update = new Document("$set", payment).append("$inc", new Document(PaymentCodec.VERSION, 1L));
        final Payment returnedPayment = databaseCollection(organization).findOneAndUpdate(filter, update, options);
        if (returnedPayment == null) {
            throw new StorageException("Payment '" + payment.getId() + "' has not been updated.");
        }
        if (createOrUpdatePaymentEvent != null) {
            createOrUpdatePaymentEvent.fire(new CreateOrUpdatePayment(organization, returnedPayment));
        }
        return returnedPayment;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update payment " + payment, ex);
    }
}
Also used : ReferralPayment(io.lumeer.api.model.ReferralPayment) CreateOrUpdatePayment(io.lumeer.engine.api.event.CreateOrUpdatePayment) Payment(io.lumeer.api.model.Payment) MongoException(com.mongodb.MongoException) CreateOrUpdatePayment(io.lumeer.engine.api.event.CreateOrUpdatePayment) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException) Bson(org.bson.conversions.Bson)

Example 2 with CreateOrUpdatePayment

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

the class MongoPaymentDao method updatePayment.

private Payment updatePayment(final String organizationId, final Payment payment, final Bson filter) {
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
    try {
        Bson update = new Document("$set", payment).append("$inc", new Document(PaymentCodec.VERSION, 1L));
        final Payment returnedPayment = databaseCollection(organizationId).findOneAndUpdate(filter, update, options);
        if (returnedPayment == null) {
            throw new StorageException("Payment '" + payment.getId() + "' has not been updated.");
        }
        if (createOrUpdatePaymentEvent != null) {
            createOrUpdatePaymentEvent.fire(new CreateOrUpdatePayment(organizationId, returnedPayment));
        }
        return returnedPayment;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update payment " + payment, ex);
    }
}
Also used : CreateOrUpdatePayment(io.lumeer.engine.api.event.CreateOrUpdatePayment) Payment(io.lumeer.api.model.Payment) MongoException(com.mongodb.MongoException) CreateOrUpdatePayment(io.lumeer.engine.api.event.CreateOrUpdatePayment) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) 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)2 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)2 ReturnDocument (com.mongodb.client.model.ReturnDocument)2 Payment (io.lumeer.api.model.Payment)2 CreateOrUpdatePayment (io.lumeer.engine.api.event.CreateOrUpdatePayment)2 StorageException (io.lumeer.storage.api.exception.StorageException)2 Document (org.bson.Document)2 Bson (org.bson.conversions.Bson)2 ReferralPayment (io.lumeer.api.model.ReferralPayment)1