Search in sources :

Example 1 with StorageException

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

the class MongoViewDao method createView.

@Override
public View createView(final View view) {
    try {
        JsonView jsonView = new JsonView(view);
        databaseCollection().insertOne(jsonView);
        return jsonView;
    } catch (MongoException ex) {
        throw new StorageException("Cannot create view: " + view, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) JsonView(io.lumeer.api.dto.JsonView) StorageException(io.lumeer.storage.api.exception.StorageException)

Example 2 with StorageException

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

the class MongoDataDao method patchData.

@Override
public DataDocument patchData(final String collectionId, final String documentId, final DataDocument data) {
    data.remove(ID);
    Document updateDocument = new Document("$set", new Document(data));
    FindOneAndUpdateOptions options = new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER);
    Document patchedDocument = dataCollection(collectionId).findOneAndUpdate(idFilter(documentId), updateDocument, options);
    if (patchedDocument == null) {
        throw new StorageException("Document '" + documentId + "' has not been patched (partially updated).");
    }
    return MongoUtils.convertDocument(patchedDocument);
}
Also used : FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException)

Example 3 with StorageException

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

the class MongoViewDao method updateView.

@Override
public View updateView(final String id, final View view) {
    JsonView jsonView = new JsonView(view);
    FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER);
    try {
        View updatedView = databaseCollection().findOneAndReplace(idFilter(id), jsonView, options);
        if (updatedView == null) {
            throw new StorageException("View '" + view.getId() + "' has not been updated.");
        }
        return updatedView;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update view: " + view, ex);
    }
}
Also used : FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) MongoException(com.mongodb.MongoException) JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) StorageException(io.lumeer.storage.api.exception.StorageException)

Example 4 with StorageException

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

the class MongoDataDao method updateData.

@Override
public DataDocument updateData(final String collectionId, final String documentId, final DataDocument data) {
    Document document = new Document(data);
    FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER);
    Document updatedDocument = dataCollection(collectionId).findOneAndReplace(idFilter(documentId), document, options);
    if (updatedDocument == null) {
        throw new StorageException("Document '" + documentId + "' has not been updated (replaced).");
    }
    return MongoUtils.convertDocument(updatedDocument);
}
Also used : FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException)

Aggregations

StorageException (io.lumeer.storage.api.exception.StorageException)4 MongoException (com.mongodb.MongoException)2 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)2 ReturnDocument (com.mongodb.client.model.ReturnDocument)2 JsonView (io.lumeer.api.dto.JsonView)2 DataDocument (io.lumeer.engine.api.data.DataDocument)2 Document (org.bson.Document)2 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)1 View (io.lumeer.api.model.View)1