Skip to content

Commit

Permalink
WIP: display fields and start download of wells.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Apr 29, 2024
1 parent b9b202a commit 9953b46
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ void RiaOsduConnector::requestFieldsByName( const QString& server, const QString
params["query"] = "data.FieldName:IVAR*";
makeRequest( params, server, dataPartitionId, token );

connect( m_networkAccessManager, SIGNAL( finished( QNetworkReply* ) ), this, SLOT( parseWells( QNetworkReply* ) ) );
connect( m_networkAccessManager, SIGNAL( finished( QNetworkReply* ) ), this, SLOT( parseFields( QNetworkReply* ) ) );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaOsduConnector::requestWellsByFieldId( const QString& fieldId )
{
requestWellsByFieldId( m_server, m_dataPartitionId, m_token, fieldId );
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -244,6 +252,46 @@ QNetworkReply* RiaOsduConnector::makeRequest( const std::map<QString, QString>&
return reply;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaOsduConnector::parseFields( QNetworkReply* reply )
{
qDebug() << "REQUEST FINISHED. Error? " << ( reply->error() != QNetworkReply::NoError );

QByteArray result = reply->readAll();

reply->deleteLater();

QJsonDocument doc = QJsonDocument::fromJson( result );
// Extract the JSON object from the QJsonDocument
QJsonObject jsonObj = doc.object();

// Access "results" array from the JSON object
QJsonArray resultsArray = jsonObj["results"].toArray();

// Iterate through each element in the "results" array
qDebug() << "Found " << resultsArray.size() << " items.";

m_fields.clear();

foreach ( const QJsonValue& value, resultsArray )
{
QJsonObject resultObj = value.toObject();

// Accessing specific fields from the result object
QString id = resultObj["id"].toString();
QString kind = resultObj["kind"].toString();
QString fieldName = resultObj["data"].toObject()["FieldName"].toString();

qDebug() << "Id:" << id << " kind: " << kind << " name: " << fieldName;
qDebug() << resultObj;
m_fields.push_back( OsduField{ id, kind, fieldName } );
}

emit wellsFinished();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -269,10 +317,11 @@ void RiaOsduConnector::parseWells( QNetworkReply* reply )
QJsonObject resultObj = value.toObject();

// Accessing specific fields from the result object
QString id = resultObj["id"].toString();
QString kind = resultObj["kind"].toString();
QString id = resultObj["id"].toString();
QString kind = resultObj["kind"].toString();
QString fieldName = resultObj["data"].toObject()["FieldName"].toString();

qDebug() << "Id:" << id << " kind: " << kind;
qDebug() << "Id:" << id << " kind: " << kind << " name: " << fieldName;
qDebug() << resultObj;
}

Expand Down Expand Up @@ -416,3 +465,11 @@ QString RiaOsduConnector::dataPartition() const
{
return m_dataPartitionId;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<OsduField> RiaOsduConnector::fields() const
{
return m_fields;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

#include <map>

struct OsduField
{
QString id;
QString kind;
QString name;
};

//==================================================================================================
///
//==================================================================================================
Expand All @@ -25,18 +32,24 @@ class RiaOsduConnector : public QObject
void requestFieldsByName( const QString& token, const QString& fieldName );
void requestFieldsByName( const QString& fieldName );

void requestWellsByFieldId( const QString& fieldId );

QString server() const;
QString dataPartition() const;

std::vector<OsduField> fields() const;

public slots:
void requestToken();
void parseFields( QNetworkReply* reply );
void parseWells( QNetworkReply* reply );
void parseWellTrajectory( QNetworkReply* reply );
void saveFile( QNetworkReply* reply );
void accessGranted();

signals:
void finished();
void wellsFinished();
void tokenReady( const QString& token );

private:
Expand Down Expand Up @@ -71,5 +84,6 @@ public slots:
const QString m_scopes;
const QString m_clientId;

QString m_token;
QString m_token;
std::vector<OsduField> m_fields;
};
Loading

0 comments on commit 9953b46

Please sign in to comment.