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