Skip to content

Commit

Permalink
[ref] Preparation of implementing license for peakML
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshikukreja14 committed Dec 25, 2020
1 parent 68b6375 commit 7e8f04f
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 63 deletions.
74 changes: 19 additions & 55 deletions src/gui/mzroll/peakdetectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,27 +262,39 @@ void PeakDetectionDialog::getLoginForPeakMl()
}
}

void PeakDetectionDialog::handleAuthorization(QStringList models, QString status) {
if (status != "OK") {
unsuccessfulLogin();
// TODO: Message needs to change once license part is done.
auto htmlText = QString("<p><b>Something went wrong.</b></p>");
htmlText += "<p>Please contact tech support at [email protected] if the problem persists.</p>";
mainwindow->showWarning(htmlText);
} else {
modelTypes->clear();
modelTypes->addItem("Global Model Elucidata");
for (auto model : models)
modelTypes->addItem(model);
}
}

void PeakDetectionDialog::loginSuccessful()
{
{
_peakMlSet = true;
peakMl->setChecked(true);
mainwindow->mavenParameters->classifyUsingPeakMl = true;
modelTypes->setEnabled(true);
getModelsList();
modelTypes->clear();
modelTypes->addItem("Global Model Elucidata");
for (auto model : _modelsList)
modelTypes->addItem(QString::fromStdString(model));
mainwindow->pollyElmavenInterfaceDialog->getModelsForPeakML();
}

void PeakDetectionDialog::unsuccessfulLogin()
{
{
_peakMlSet = false;
peakMl->setChecked(false);
modelTypes->setEnabled(false);
if(mainwindow)
mainwindow->mavenParameters->classifyUsingPeakMl = false;
}

void PeakDetectionDialog::onReset()
{
emit resetSettings(peakSettings->getSettings().keys());
Expand Down Expand Up @@ -486,8 +498,6 @@ void PeakDetectionDialog::inputInitialValuesPeakDetectionDialog() {
matchFragmentationOptions->setChecked(fragmentationWasEnabled);
modelTypes->clear();
modelTypes->addItem("Global Model Elucidata");
for (auto model : _modelsList)
modelTypes->addItem(QString::fromStdString(model));
// selecting the compound database that is selected by the user in the
// ligand widget
QString selectedDB = mainwindow->ligandWidget->getDatabaseName();
Expand Down Expand Up @@ -515,52 +525,6 @@ void PeakDetectionDialog::inputInitialValuesPeakDetectionDialog() {
}
}

void PeakDetectionDialog::getModelsList()
{
QStringList args;
_modelsList.clear();
auto _dlManager = new DownloadManager();
auto _pollyIntegration = new PollyIntegration(_dlManager);

auto cookieFile = QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation)
+ QDir::separator()
+ "El-MAVEN_cookie.json" ;

ifstream readCookie(cookieFile.toStdString());
if(!readCookie.is_open())
return;

json cookieInput = json::parse(readCookie);
string refreshToken = cookieInput["refreshToken"];
string idToken = cookieInput["idToken"];

QString cookies;
cookies += "refreshToken=";
cookies += QString::fromStdString(refreshToken);
cookies += ";";
cookies += "idToken=";
cookies += QString::fromStdString(idToken);

args << cookies;

auto res = _pollyIntegration->runQtProcess("listBucketObjects", args);
QString str(res[0].constData());
if (str.isEmpty())
return;
auto splitString = mzUtils::split(str.toStdString(), "\n");
auto data = splitString[splitString.size() - 2];
json dataObject = json::parse(data);

if (!dataObject["data"]["error"].is_null()){
return;
}

for (int i = 1; i < dataObject["data"]["attributes"]["models"].size(); i++) {
_modelsList.push_back(dataObject["data"]["attributes"]["models"][i].get<string>());
}
}

void PeakDetectionDialog::refreshCompoundDatabases()
{
map<string, int>::iterator itr;
Expand Down
8 changes: 1 addition & 7 deletions src/gui/mzroll/peakdetectiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ class PeakDetectionDialog : public QDialog, public Ui_PeakDetectionDialog
void displayAppropriatePeakDetectionDialog(FeatureDetectionType type); //TODO: Sahil - Kiran, Added while merging mainwindow
void setMavenParameters(QSettings *settings);
bool databaseSearchEnabled();
/**
* @brief Runs QtProcess to hit Polly API that returns the
* list of Models that is stored in S3 bucket for that
* particular organisation of the current user.
* @return vector of model names.
*/
void getModelsList();

public Q_SLOTS:
void findPeaks();
Expand Down Expand Up @@ -71,6 +64,7 @@ class PeakDetectionDialog : public QDialog, public Ui_PeakDetectionDialog
void setQuantType(QString type);
void triggerSettingsUpdate();
void onReset();
void handleAuthorization(QStringList models, QString status);

Q_SIGNALS:
void updateSettings(PeakDetectionSettings* pd);
Expand Down
95 changes: 95 additions & 0 deletions src/gui/mzroll/pollyelmaveninterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "pollywaitdialog.h"
#include "projectdockwidget.h"
#include "tabledockwidget.h"
#include "peakdetectiondialog.h"
#include "json.hpp"

using json = nlohmann::json;

PollyElmavenInterfaceDialog::PollyElmavenInterfaceDialog(MainWindow* mw)
: QDialog(mw), _mainwindow(mw), _loginform(nullptr)
Expand All @@ -30,6 +34,7 @@ PollyElmavenInterfaceDialog::PollyElmavenInterfaceDialog(MainWindow* mw)
_activeTable = nullptr;
_pollyIntegration = _mainwindow->getController()->iPolly;
_loadingDialog = new PollyWaitDialog(this);
_loadingDialogForPeakML = new PollyWaitDialog(_mainwindow->peakDetectionDialog);
_uploadInProgress = false;
_lastCohortFileWasValid = false;

Expand Down Expand Up @@ -191,10 +196,19 @@ PollyElmavenInterfaceDialog::PollyElmavenInterfaceDialog(MainWindow* mw)
SIGNAL(filesUploaded(QStringList, QString, QString)),
this,
SLOT(_performPostFilesUploadTasks(QStringList, QString, QString)));
connect(_worker,
&EPIWorkerThread::peakMLAuthenticationFinished,
this,
&PollyElmavenInterfaceDialog::peakMLAccessControl);
connect(sendModeTab,
&QTabWidget::currentChanged,
this,
&PollyElmavenInterfaceDialog::_changeMode);

connect(this,
&PollyElmavenInterfaceDialog::peakMLAccess,
_mainwindow->peakDetectionDialog,
&PeakDetectionDialog::handleAuthorization);
}
PollyElmavenInterfaceDialog::~PollyElmavenInterfaceDialog()
{
Expand All @@ -217,6 +231,9 @@ void EPIWorkerThread::run()
case RunMethod::SendEmail:
_sendEmail();
break;
case RunMethod::FetchPeakMLModels:
_getModels();
break;
default:
break;
}
Expand Down Expand Up @@ -430,6 +447,84 @@ void PollyElmavenInterfaceDialog::loginForPeakMl()
}
}

void PollyElmavenInterfaceDialog::getModelsForPeakML()
{
_worker->wait();
_worker->setMethodToRun(EPIWorkerThread::RunMethod::FetchPeakMLModels);
_worker->start();

_loadingDialogForPeakML->setWindowFlag(Qt::WindowTitleHint, true);
_loadingDialogForPeakML->open();
_loadingDialogForPeakML->statusLabel->setVisible(true);
_loadingDialogForPeakML->statusLabel->setStyleSheet("QLabel {color : green;}");
_loadingDialogForPeakML->statusLabel->setText("Fetching user data...");
_loadingDialogForPeakML->label->setVisible(true);
_loadingDialogForPeakML->label->setMovie(_loadingDialogForPeakML->movie);
_loadingDialogForPeakML->label->setAlignment(Qt::AlignCenter);
QCoreApplication::processEvents();
}

void PollyElmavenInterfaceDialog::peakMLAccessControl(QStringList models, QString status) {
_loadingDialogForPeakML->close();
emit peakMLAccess(models, status);
}

void EPIWorkerThread::_getModels() {
QStringList args;
QStringList models;

auto cookieFile = QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation)
+ QDir::separator()
+ "El-MAVEN_cookie.json" ;

ifstream readCookie(cookieFile.toStdString());
if(!readCookie.is_open()) {
emit peakMLAuthenticationFinished(models, "Error");
return;
}

json cookieInput = json::parse(readCookie);
string refreshToken = cookieInput["refreshToken"];
string idToken = cookieInput["idToken"];

QString cookies;
cookies += "refreshToken=";
cookies += QString::fromStdString(refreshToken);
cookies += ";";
cookies += "idToken=";
cookies += QString::fromStdString(idToken);

args << cookies;

auto res = _pollyIntegration->runQtProcess("listBucketObjects", args);
if (!res.size()) {
emit peakMLAuthenticationFinished(models, "Error");
return;
}

QString str(res[0].constData());
if (str.isEmpty()) {
emit peakMLAuthenticationFinished(models, "Error");
return;
}

auto splitString = mzUtils::split(str.toStdString(), "\n");
auto data = splitString[splitString.size() - 2];
json dataObject = json::parse(data);

if (!dataObject["data"]["error"].is_null()){
emit peakMLAuthenticationFinished(models, "Error");
}

for (int i = 1; i < dataObject["data"]["attributes"]["models"].size(); i++) {
QString modelName = QString::fromStdString(dataObject["data"]["attributes"]["models"][i].get<string>());
models.push_back(modelName);
}

emit peakMLAuthenticationFinished(models, "OK");
}

void PollyElmavenInterfaceDialog::initialSetup()
{
int nodeStatus = _pollyIntegration->checkNodeExecutable();
Expand Down
27 changes: 26 additions & 1 deletion src/gui/mzroll/pollyelmaveninterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class EPIWorkerThread : public QThread
{
AuthenticateAndFetchData,
UploadFiles,
SendEmail
SendEmail,
FetchPeakMLModels
};

EPIWorkerThread(PollyIntegration *pi) : _pollyIntegration(pi) {}
Expand Down Expand Up @@ -67,6 +68,7 @@ class EPIWorkerThread : public QThread
void licensesReady(QMap<PollyApp, bool> licenseMap);
void projectsReady(QVariantMap projectNamesId);
void authenticationFinished(QString username, QString status);
void peakMLAuthenticationFinished(QStringList models, QString status);

private:

Expand Down Expand Up @@ -101,6 +103,8 @@ class EPIWorkerThread : public QThread
void _sendEmail();

void _removeFilesFromDir(QDir dir, QStringList files);

void _getModels();
};

/**
Expand Down Expand Up @@ -176,6 +180,14 @@ class PollyElmavenInterfaceDialog : public QDialog,
*/
void loginForPeakMl();

/**
* @brief Runs QtProcess to hit Polly API that returns the
* list of Models that is stored in S3 bucket for that
* particular organisation of the current user.
* @return vector of model names.
*/
void getModelsForPeakML();

public Q_SLOTS:

/**
Expand All @@ -196,6 +208,8 @@ public Q_SLOTS:

void showEPIError(QString errorMessage);

void peakMLAccessControl(QStringList models, QString status);

Q_SIGNALS:

/**
Expand All @@ -204,6 +218,11 @@ public Q_SLOTS:
*/
void uploadFinished(bool success);

/**
*
*/
void peakMLAccess(QStringList models, QString status);

private:

/**
Expand Down Expand Up @@ -238,6 +257,12 @@ public Q_SLOTS:
*/
PollyWaitDialog* _loadingDialog;

/**
* @brief A pointer to the loading dialog that fetches user data for peakML
* and appear on the top of peak detection dialog.
*/
PollyWaitDialog* _loadingDialogForPeakML;

/**
* @brief A pointer to loginform class.
*/
Expand Down

0 comments on commit 7e8f04f

Please sign in to comment.