Search in sources :

Example 1 with UnsuccessfulOperationException

use of io.lumeer.engine.api.exception.UnsuccessfulOperationException in project engine by Lumeer.

the class MongoDbStorage method createOldDocument.

@Override
public void createOldDocument(final String collectionName, final DataDocument dataDocument, final String documentId, final int version) throws UnsuccessfulOperationException {
    Document doc = new Document(dataDocument);
    doc.put(DOCUMENT_ID, new BasicDBObject(DOCUMENT_ID, new ObjectId(documentId)));
    try {
        database.getCollection(collectionName).insertOne(doc);
    } catch (MongoWriteException e) {
        if (e.getError().getCategory().equals(ErrorCategory.DUPLICATE_KEY)) {
            throw new UnsuccessfulOperationException(e.getMessage(), e.getCause());
        } else {
            throw e;
        }
    }
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) UnsuccessfulOperationException(io.lumeer.engine.api.exception.UnsuccessfulOperationException) MongoWriteException(com.mongodb.MongoWriteException) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) BsonDocument(org.bson.BsonDocument)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)1 MongoWriteException (com.mongodb.MongoWriteException)1 ReturnDocument (com.mongodb.client.model.ReturnDocument)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 UnsuccessfulOperationException (io.lumeer.engine.api.exception.UnsuccessfulOperationException)1 BsonDocument (org.bson.BsonDocument)1 Document (org.bson.Document)1 ObjectId (org.bson.types.ObjectId)1