From b55a67787366fff093834f7cb565800b368f2e12 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Thu, 7 Nov 2019 16:37:48 -0500 Subject: [PATCH] Always upload geometry when user uploads molecule This ensures that the user's drawn geometry actually gets uploaded into the database, even when the molecule already exists. Signed-off-by: Patrick Avery --- .../qtplugins/mongochem/mongochemwidget.cpp | 46 ++++++++++++++++++- .../qtplugins/mongochem/mongochemwidget.h | 2 + 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/avogadro/qtplugins/mongochem/mongochemwidget.cpp b/avogadro/qtplugins/mongochem/mongochemwidget.cpp index ed6462ee81..eee1b01108 100644 --- a/avogadro/qtplugins/mongochem/mongochemwidget.cpp +++ b/avogadro/qtplugins/mongochem/mongochemwidget.cpp @@ -263,7 +263,51 @@ void MongoChemWidget::uploadMolecule() void MongoChemWidget::finishUploadMolecule(const QVariant& results) { - Q_UNUSED(results) + auto moleculeId = results.toMap()["_id"].toString(); + if (moleculeId.isEmpty()) { + QString message = "Failed to upload molecule"; + qDebug() << message; + QMessageBox::critical(this, "MongoChem", message); + return; + } + + // Now, upload the particular geometry + uploadGeometry(moleculeId); +} + +void MongoChemWidget::uploadGeometry(const QString& moleculeId) +{ + QByteArray postData = m_plugin->currentMoleculeCjson().toLatin1(); + + QString url =(m_girderUrl + "/molecules/%1/geometries").arg(moleculeId); + + QList> urlQueries = { + { "provenanceType", "Uploaded by Avogadro2 User" } + }; + + auto* request = + new GirderRequest(m_networkManager.data(), url, m_girderToken); + request->setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + request->setUrlQueries(urlQueries); + request->post(postData); + + connect(request, &GirderRequest::result, this, + &MongoChemWidget::finishUploadGeometry); + connect(request, &GirderRequest::error, this, &MongoChemWidget::error); + connect(request, &GirderRequest::result, request, + &GirderRequest::deleteLater); + connect(request, &GirderRequest::error, request, &GirderRequest::deleteLater); +} + +void MongoChemWidget::finishUploadGeometry(const QVariant& results) +{ + auto geometryId = results.toMap()["_id"].toString(); + if (geometryId.isEmpty()) { + QString message = "Failed to upload geometry"; + qDebug() << message; + QMessageBox::critical(this, "MongoChem", message); + return; + } QString message = "Upload successful!"; qDebug() << message; diff --git a/avogadro/qtplugins/mongochem/mongochemwidget.h b/avogadro/qtplugins/mongochem/mongochemwidget.h index 697726d110..35a9beb48c 100644 --- a/avogadro/qtplugins/mongochem/mongochemwidget.h +++ b/avogadro/qtplugins/mongochem/mongochemwidget.h @@ -54,6 +54,8 @@ private slots: void finishDownloadMolecule(const QVariant& results); void uploadMolecule(); void finishUploadMolecule(const QVariant& results); + void uploadGeometry(const QString& moleculeId); + void finishUploadGeometry(const QVariant& results); void submitCalculation(); void finishSubmitCalculation(const QVariantMap& results); void finishWatchCalculation(const QByteArray& cjson);