Skip to content

Commit

Permalink
Always upload geometry when user uploads molecule
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
psavery committed Nov 7, 2019
1 parent 250453e commit b55a677
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 45 additions & 1 deletion avogadro/qtplugins/mongochem/mongochemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QPair<QString, QString>> 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;
Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtplugins/mongochem/mongochemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b55a677

Please sign in to comment.