mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Refactor: move RiaOsduConnector to Tools/Cloud.
This commit is contained in:
@@ -2,15 +2,22 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSumoConnector.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSumoDefines.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaConnectorTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOsduConnector.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOsduOAuthHttpServerReplyHandler.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSumoConnector.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSumoDefines.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaConnectorTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOsduConnector.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOsduOAuthHttpServerReplyHandler.cpp
|
||||
)
|
||||
|
||||
list(APPEND QT_MOC_HEADERS ${CMAKE_CURRENT_LIST_DIR}/RiaSumoConnector.h)
|
||||
list(APPEND QT_MOC_HEADERS ${CMAKE_CURRENT_LIST_DIR}/RiaSumoConnector.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOsduConnector.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaOsduOAuthHttpServerReplyHandler.h
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
||||
|
||||
930
ApplicationLibCode/Application/Tools/Cloud/RiaOsduConnector.cpp
Normal file
930
ApplicationLibCode/Application/Tools/Cloud/RiaOsduConnector.cpp
Normal file
@@ -0,0 +1,930 @@
|
||||
#include "RiaOsduConnector.h"
|
||||
#include "RiaFileDownloader.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaOsduDefines.h"
|
||||
#include "RiaOsduOAuthHttpServerReplyHandler.h"
|
||||
|
||||
#include <QAbstractOAuth>
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QOAuth2AuthorizationCodeFlow>
|
||||
#include <QOAuthHttpServerReplyHandler>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaOsduConnector::RiaOsduConnector( QObject* parent,
|
||||
const QString& server,
|
||||
const QString& dataPartitionId,
|
||||
const QString& authority,
|
||||
const QString& scopes,
|
||||
const QString& clientId )
|
||||
: QObject( parent )
|
||||
, m_server( server )
|
||||
, m_dataPartitionId( dataPartitionId )
|
||||
, m_authority( authority )
|
||||
, m_scopes( scopes )
|
||||
, m_clientId( clientId )
|
||||
{
|
||||
m_networkAccessManager = new QNetworkAccessManager( this );
|
||||
|
||||
m_osdu = new QOAuth2AuthorizationCodeFlow( this );
|
||||
|
||||
RiaLogging::debug( "SSL BUILD VERSION: " + QSslSocket::sslLibraryBuildVersionString() );
|
||||
RiaLogging::debug( "SSL VERSION STRING: " + QSslSocket::sslLibraryVersionString() );
|
||||
|
||||
RiaLogging::debug( "OSDU config:" );
|
||||
RiaLogging::debug( " server: '" + server + "'" );
|
||||
RiaLogging::debug( " data partition id: '" + dataPartitionId + "'" );
|
||||
RiaLogging::debug( " authority: '" + authority + "'" );
|
||||
RiaLogging::debug( " scopes: '" + scopes + "'" );
|
||||
RiaLogging::debug( " client id: '" + clientId + "'" );
|
||||
|
||||
int port = 35327;
|
||||
|
||||
connect( m_osdu,
|
||||
&QOAuth2AuthorizationCodeFlow::authorizeWithBrowser,
|
||||
[]( QUrl url )
|
||||
{
|
||||
RiaLogging::debug( "Authorize with url: " + url.toString() );
|
||||
QUrlQuery query( url );
|
||||
url.setQuery( query );
|
||||
QDesktopServices::openUrl( url );
|
||||
} );
|
||||
|
||||
QString authUrl = constructAuthUrl( m_authority );
|
||||
m_osdu->setAuthorizationUrl( QUrl( authUrl ) );
|
||||
|
||||
QString tokenUrl = constructTokenUrl( m_authority );
|
||||
m_osdu->setAccessTokenUrl( QUrl( tokenUrl ) );
|
||||
|
||||
// App key
|
||||
m_osdu->setClientIdentifier( m_clientId );
|
||||
m_osdu->setScope( m_scopes );
|
||||
|
||||
auto replyHandler = new RiaOsduOAuthHttpServerReplyHandler( port, this );
|
||||
m_osdu->setReplyHandler( replyHandler );
|
||||
RiaLogging::debug( "Osdu server callback: " + replyHandler->callback() );
|
||||
|
||||
connect( m_osdu, SIGNAL( granted() ), this, SLOT( accessGranted() ) );
|
||||
connect( m_osdu,
|
||||
SIGNAL( error( const QString&, const QString&, const QUrl& ) ),
|
||||
this,
|
||||
SLOT( errorReceived( const QString&, const QString&, const QUrl& ) ) );
|
||||
|
||||
connect( m_osdu,
|
||||
SIGNAL( authorizationCallbackReceived( const QVariantMap& ) ),
|
||||
this,
|
||||
SLOT( authorizationCallbackReceived( const QVariantMap& ) ) );
|
||||
|
||||
connect( this,
|
||||
SIGNAL( parquetDownloadFinished( const QByteArray&, const QString&, const QString& ) ),
|
||||
this,
|
||||
SLOT( parquetDownloadComplete( const QByteArray&, const QString&, const QString& ) ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::accessGranted()
|
||||
{
|
||||
RiaLogging::debug( "Access granted." );
|
||||
m_token = m_osdu->token();
|
||||
emit tokenReady( m_token );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::errorReceived( const QString& error, const QString& errorDescription, const QUrl& uri )
|
||||
{
|
||||
RiaLogging::debug( "OSDU Error Received: " + error + ". Description: " + errorDescription );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::authorizationCallbackReceived( const QVariantMap& data )
|
||||
{
|
||||
RiaLogging::debug( "Authorization callback received:" );
|
||||
for ( const auto& [key, value] : data.toStdMap() )
|
||||
{
|
||||
RiaLogging::debug( " Key: " + key + " Value: " + value.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestToken()
|
||||
{
|
||||
if ( m_token.isEmpty() )
|
||||
{
|
||||
RiaLogging::debug( "Requesting token." );
|
||||
m_osdu->grant();
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::debug( "Has token: skipping token request." );
|
||||
emit accessGranted();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaOsduConnector::~RiaOsduConnector()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::clearCachedData()
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_fields.clear();
|
||||
m_wells.clear();
|
||||
m_wellbores.clear();
|
||||
m_wellboreTrajectories.clear();
|
||||
m_wellLogs.clear();
|
||||
m_parquetData.clear();
|
||||
m_parquetErrors.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestFieldsByName( const QString& token, const QString& fieldName )
|
||||
{
|
||||
requestFieldsByName( m_server, m_dataPartitionId, token, fieldName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestFieldsByName( const QString& fieldName )
|
||||
{
|
||||
requestFieldsByName( m_token, fieldName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestFieldsByName( const QString& server, const QString& dataPartitionId, const QString& token, const QString& fieldName )
|
||||
{
|
||||
std::map<QString, QString> params;
|
||||
params["kind"] = RiaDefines::osduFieldKind();
|
||||
params["limit"] = "10000";
|
||||
params["query"] = "data.FieldName:" + fieldName;
|
||||
|
||||
auto reply = makeSearchRequest( params, server, dataPartitionId, token );
|
||||
connect( reply,
|
||||
&QNetworkReply::finished,
|
||||
[this, reply, fieldName]()
|
||||
{
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
parseFields( reply );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage =
|
||||
QString( "Download failed for fields by name (%1). Error: %2" ).arg( fieldName ).arg( reply->errorString() );
|
||||
RiaLogging::error( errorMessage );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellsByFieldId( const QString& fieldId )
|
||||
{
|
||||
requestWellsByFieldId( m_server, m_dataPartitionId, m_token, fieldId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellsByFieldId( const QString& server, const QString& dataPartitionId, const QString& token, const QString& fieldId )
|
||||
{
|
||||
std::map<QString, QString> params;
|
||||
params["kind"] = RiaDefines::osduWellKind();
|
||||
params["limit"] = "10000";
|
||||
params["query"] = QString( "nested(data.GeoContexts, (FieldID:\"%1\"))" ).arg( fieldId );
|
||||
|
||||
auto reply = makeSearchRequest( params, server, dataPartitionId, token );
|
||||
connect( reply,
|
||||
&QNetworkReply::finished,
|
||||
[this, reply, fieldId]()
|
||||
{
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
parseWells( reply );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage =
|
||||
QString( "Request failed for wells for field (%1). Error: %2" ).arg( fieldId ).arg( reply->errorString() );
|
||||
RiaLogging::error( errorMessage );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellboresByWellId( const QString& wellId )
|
||||
{
|
||||
requestWellboresByWellId( m_server, m_dataPartitionId, m_token, wellId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellboresByWellId( const QString& server, const QString& dataPartitionId, const QString& token, const QString& wellId )
|
||||
{
|
||||
std::map<QString, QString> params;
|
||||
params["kind"] = RiaDefines::osduWellboreKind();
|
||||
params["limit"] = "10000";
|
||||
params["query"] = "data.WellID: \"" + wellId + "\"";
|
||||
|
||||
auto reply = makeSearchRequest( params, server, dataPartitionId, token );
|
||||
connect( reply,
|
||||
&QNetworkReply::finished,
|
||||
[this, reply, wellId]()
|
||||
{
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
parseWellbores( reply, wellId );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage =
|
||||
QString( "Request failed for wellbores for well (%1). Error: %2" ).arg( wellId ).arg( reply->errorString() );
|
||||
RiaLogging::error( errorMessage );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<OsduWellLog> RiaOsduConnector::requestWellLogsByWellboreIdBlocking( const QString& wellboreId )
|
||||
{
|
||||
QString token = requestTokenBlocking();
|
||||
|
||||
QEventLoop loop;
|
||||
connect( this, SIGNAL( wellLogsFinished( const QString& ) ), &loop, SLOT( quit() ) );
|
||||
requestWellLogsByWellboreId( m_server, m_dataPartitionId, token, wellboreId );
|
||||
loop.exec();
|
||||
|
||||
return m_wellLogs[wellboreId];
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellLogsByWellboreId( const QString& wellboreId )
|
||||
{
|
||||
requestWellLogsByWellboreId( m_server, m_dataPartitionId, m_token, wellboreId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellLogsByWellboreId( const QString& server,
|
||||
const QString& dataPartitionId,
|
||||
const QString& token,
|
||||
const QString& wellboreId )
|
||||
{
|
||||
std::map<QString, QString> params;
|
||||
params["kind"] = RiaDefines::osduWellLogKind();
|
||||
params["limit"] = "10000";
|
||||
params["query"] = "data.WellboreID: \"" + wellboreId + "\"";
|
||||
|
||||
auto reply = makeSearchRequest( params, server, dataPartitionId, token );
|
||||
connect( reply,
|
||||
&QNetworkReply::finished,
|
||||
[this, reply, wellboreId]()
|
||||
{
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
parseWellLogs( reply, wellboreId );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage =
|
||||
QString( "Request failed for well logs by wellbore (%1). Error: %2" ).arg( wellboreId ).arg( reply->errorString() );
|
||||
RiaLogging::error( errorMessage );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellboreTrajectoryByWellboreId( const QString& wellboreId )
|
||||
{
|
||||
requestWellboreTrajectoryByWellboreId( m_server, m_dataPartitionId, m_token, wellboreId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellboreTrajectoryByWellboreId( const QString& server,
|
||||
const QString& dataPartitionId,
|
||||
const QString& token,
|
||||
const QString& wellboreId )
|
||||
{
|
||||
std::map<QString, QString> params;
|
||||
params["kind"] = RiaDefines::osduWellboreTrajectoryKind();
|
||||
params["limit"] = "10000";
|
||||
params["query"] = "data.WellboreID: \"" + wellboreId + "\"";
|
||||
|
||||
auto reply = makeSearchRequest( params, server, dataPartitionId, token );
|
||||
connect( reply,
|
||||
&QNetworkReply::finished,
|
||||
[this, reply, wellboreId]()
|
||||
{
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
parseWellTrajectory( reply, wellboreId );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage =
|
||||
QString( "Request failed for well trajectory by wellbore (%1). Error: %2" ).arg( wellboreId ).arg( reply->errorString() );
|
||||
RiaLogging::error( errorMessage );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
//
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::constructSearchUrl( const QString& server )
|
||||
{
|
||||
return server + "/api/search/v2/query";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::constructFileDownloadUrl( const QString& server, const QString& fileId )
|
||||
{
|
||||
return server + "/api/file/v2/files/" + fileId + "/downloadURL";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::constructAuthUrl( const QString& authority )
|
||||
{
|
||||
return authority + "/oauth2/v2.0/authorize";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::constructTokenUrl( const QString& authority )
|
||||
{
|
||||
return authority + "/oauth2/v2.0/token";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::constructWellLogDownloadUrl( const QString& server, const QString& wellLogId )
|
||||
{
|
||||
return server + "/api/os-wellbore-ddms/ddms/v3/welllogs/" + wellLogId + "/data";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::constructWellboreTrajectoriesDownloadUrl( const QString& server, const QString& wellboreTrajectoryId )
|
||||
{
|
||||
return server + "/api/os-wellbore-ddms/ddms/v3/wellboretrajectories/" + wellboreTrajectoryId + "/data";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QNetworkReply* RiaOsduConnector::makeSearchRequest( const std::map<QString, QString>& parameters,
|
||||
const QString& server,
|
||||
const QString& dataPartitionId,
|
||||
const QString& token )
|
||||
{
|
||||
QNetworkRequest m_networkRequest;
|
||||
m_networkRequest.setUrl( QUrl( constructSearchUrl( server ) ) );
|
||||
|
||||
addStandardHeader( m_networkRequest, token, dataPartitionId, RiaDefines::contentTypeJson() );
|
||||
|
||||
QJsonObject obj;
|
||||
for ( auto [key, value] : parameters )
|
||||
{
|
||||
obj.insert( key, value );
|
||||
}
|
||||
|
||||
QJsonDocument doc( obj );
|
||||
QString strJson( doc.toJson( QJsonDocument::Compact ) );
|
||||
|
||||
auto reply = m_networkAccessManager->post( m_networkRequest, strJson.toUtf8() );
|
||||
return reply;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::parseFields( QNetworkReply* reply )
|
||||
{
|
||||
QByteArray result = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson( result );
|
||||
QJsonObject jsonObj = doc.object();
|
||||
QJsonArray resultsArray = jsonObj["results"].toArray();
|
||||
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_fields.clear();
|
||||
|
||||
for ( const QJsonValue& value : resultsArray )
|
||||
{
|
||||
QJsonObject resultObj = value.toObject();
|
||||
|
||||
QString id = resultObj["id"].toString();
|
||||
QString kind = resultObj["kind"].toString();
|
||||
QString fieldName = resultObj["data"].toObject()["FieldName"].toString();
|
||||
m_fields.push_back( OsduField{ id, kind, fieldName } );
|
||||
}
|
||||
|
||||
RiaLogging::debug( QString( "Found %1 fields." ).arg( m_fields.size() ) );
|
||||
}
|
||||
|
||||
emit fieldsFinished();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::parseWells( QNetworkReply* reply )
|
||||
{
|
||||
QByteArray result = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson( result );
|
||||
QJsonObject jsonObj = doc.object();
|
||||
QJsonArray resultsArray = jsonObj["results"].toArray();
|
||||
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_wells.clear();
|
||||
for ( const QJsonValue& value : resultsArray )
|
||||
{
|
||||
QJsonObject resultObj = value.toObject();
|
||||
QString id = resultObj["id"].toString();
|
||||
QString kind = resultObj["kind"].toString();
|
||||
QString name = resultObj["data"].toObject()["FacilityName"].toString();
|
||||
m_wells.push_back( OsduWell{ id, kind, name } );
|
||||
}
|
||||
}
|
||||
|
||||
emit wellsFinished();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::parseWellbores( QNetworkReply* reply, const QString& wellId )
|
||||
{
|
||||
QByteArray result = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson( result );
|
||||
QJsonObject jsonObj = doc.object();
|
||||
QJsonArray resultsArray = jsonObj["results"].toArray();
|
||||
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_wellbores[wellId].clear();
|
||||
for ( const QJsonValue& value : resultsArray )
|
||||
{
|
||||
QJsonObject resultObj = value.toObject();
|
||||
QString id = resultObj["id"].toString();
|
||||
QString kind = resultObj["kind"].toString();
|
||||
QString name = resultObj["data"].toObject()["FacilityName"].toString();
|
||||
|
||||
// Extract datum elevation. The DefaultVerticalMeasurementID is probably the datum elevation needed.
|
||||
// Default to 0.0 if nothing is found, but finding nothing is suspicious.
|
||||
double datumElevation = std::numeric_limits<double>::infinity();
|
||||
QString defaultVerticalMeasurementId = resultObj["data"].toObject()["DefaultVerticalMeasurementID"].toString();
|
||||
QJsonArray verticalMeasurementsArray = resultObj["data"].toObject()["VerticalMeasurements"].toArray();
|
||||
for ( const QJsonValue& vma : verticalMeasurementsArray )
|
||||
{
|
||||
QString verticalMeasurementId = vma["VerticalMeasurementID"].toString();
|
||||
if ( verticalMeasurementId == defaultVerticalMeasurementId )
|
||||
{
|
||||
double verticalMeasurement = vma["VerticalMeasurement"].toDouble( 0.0 );
|
||||
datumElevation = verticalMeasurement;
|
||||
}
|
||||
}
|
||||
|
||||
if ( std::isinf( datumElevation ) )
|
||||
{
|
||||
RiaLogging::warning( QString( "Missing datum elevation for well bore '%1'. Id: %2" ).arg( name ).arg( id ) );
|
||||
datumElevation = 0.0;
|
||||
}
|
||||
|
||||
m_wellbores[wellId].push_back( OsduWellbore{ id, kind, name, wellId, datumElevation } );
|
||||
}
|
||||
}
|
||||
|
||||
emit wellboresFinished( wellId );
|
||||
}
|
||||
else
|
||||
{
|
||||
RiaLogging::error( "Failed to download well with id " + wellId + ": " + reply->errorString() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::parseWellTrajectory( QNetworkReply* reply, const QString& wellboreId )
|
||||
{
|
||||
QByteArray result = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson( result );
|
||||
QJsonObject jsonObj = doc.object();
|
||||
QJsonArray resultsArray = jsonObj["results"].toArray();
|
||||
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_wellboreTrajectories[wellboreId].clear();
|
||||
for ( const QJsonValue& value : resultsArray )
|
||||
{
|
||||
QJsonObject resultObj = value.toObject();
|
||||
QString id = resultObj["id"].toString();
|
||||
QString kind = resultObj["kind"].toString();
|
||||
|
||||
m_wellboreTrajectories[wellboreId].push_back( OsduWellboreTrajectory{ id, kind, wellboreId } );
|
||||
}
|
||||
}
|
||||
|
||||
emit wellboreTrajectoryFinished( wellboreId, resultsArray.size(), "" );
|
||||
}
|
||||
else
|
||||
{
|
||||
emit wellboreTrajectoryFinished( wellboreId, 0, "Failed to download: " + reply->errorString() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::parseWellLogs( QNetworkReply* reply, const QString& wellboreId )
|
||||
{
|
||||
QByteArray result = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson( result );
|
||||
QJsonObject jsonObj = doc.object();
|
||||
QJsonArray resultsArray = jsonObj["results"].toArray();
|
||||
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_wellLogs[wellboreId].clear();
|
||||
for ( const QJsonValue& value : resultsArray )
|
||||
{
|
||||
QJsonObject resultObj = value.toObject();
|
||||
QString id = resultObj["id"].toString();
|
||||
QString kind = resultObj["kind"].toString();
|
||||
|
||||
QJsonObject dataObj = resultObj["data"].toObject();
|
||||
QString name = dataObj["Name"].toString();
|
||||
QString description = dataObj["Description"].toString();
|
||||
double samplingStart = dataObj["SamplingStart"].toDouble( std::numeric_limits<double>::infinity() );
|
||||
double samplingStop = dataObj["SamplingStop"].toDouble( std::numeric_limits<double>::infinity() );
|
||||
|
||||
QJsonArray curvesArray = dataObj["Curves"].toArray();
|
||||
QStringList curveMnemonics;
|
||||
RiaLogging::debug( QString( "Curves for '%1':" ).arg( id ) );
|
||||
|
||||
std::vector<OsduWellLogChannel> channels;
|
||||
for ( const QJsonValue& curve : curvesArray )
|
||||
{
|
||||
QString mnemonic = curve["Mnemonic"].toString();
|
||||
QString curveDescription = curve["CurveDescription"].toString();
|
||||
double curveBaseDepth = curve["BaseDepth"].toDouble( std::numeric_limits<double>::infinity() );
|
||||
double curveTopDepth = curve["TopDepth"].toDouble( std::numeric_limits<double>::infinity() );
|
||||
QString interpreterName = curve["InterpreterName"].toString();
|
||||
QString quality = curve["CurveQuality"].toString();
|
||||
QString unit = curve["CurveUnit"].toString();
|
||||
QString depthUnit = curve["DepthUnit"].toString();
|
||||
|
||||
curveMnemonics << mnemonic;
|
||||
RiaLogging::debug(
|
||||
QString( "%1: '%2' (%3 - %4)" ).arg( mnemonic ).arg( curveDescription ).arg( curveTopDepth ).arg( curveBaseDepth ) );
|
||||
channels.push_back( OsduWellLogChannel{ .mnemonic = mnemonic,
|
||||
.description = curveDescription,
|
||||
.topDepth = curveTopDepth,
|
||||
.baseDepth = curveBaseDepth,
|
||||
.interpreterName = interpreterName,
|
||||
.quality = quality,
|
||||
.unit = unit,
|
||||
.depthUnit = depthUnit } );
|
||||
}
|
||||
|
||||
m_wellLogs[wellboreId].push_back( OsduWellLog{ .id = id,
|
||||
.kind = kind,
|
||||
.name = name,
|
||||
.description = description,
|
||||
.samplingStart = samplingStart,
|
||||
.samplingStop = samplingStop,
|
||||
.wellboreId = wellboreId,
|
||||
.channels = channels } );
|
||||
}
|
||||
}
|
||||
|
||||
emit wellLogsFinished( wellboreId );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::addStandardHeader( QNetworkRequest& networkRequest,
|
||||
const QString& token,
|
||||
const QString& dataPartitionId,
|
||||
const QString& contentType )
|
||||
{
|
||||
networkRequest.setHeader( QNetworkRequest::ContentTypeHeader, contentType );
|
||||
networkRequest.setRawHeader( "Authorization", "Bearer " + token.toUtf8() );
|
||||
networkRequest.setRawHeader( QByteArray( "Data-Partition-Id" ), dataPartitionId.toUtf8() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QNetworkReply*
|
||||
RiaOsduConnector::makeDownloadRequest( const QString& url, const QString& dataPartitionId, const QString& token, const QString& contentType )
|
||||
{
|
||||
QNetworkRequest networkRequest;
|
||||
networkRequest.setUrl( QUrl( url ) );
|
||||
|
||||
addStandardHeader( networkRequest, token, dataPartitionId, contentType );
|
||||
|
||||
auto reply = m_networkAccessManager->get( networkRequest );
|
||||
return reply;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::server() const
|
||||
{
|
||||
return m_server;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::dataPartition() const
|
||||
{
|
||||
return m_dataPartitionId;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<OsduField> RiaOsduConnector::fields() const
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
return m_fields;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<OsduWell> RiaOsduConnector::wells() const
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
return m_wells;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<OsduWellLog> RiaOsduConnector::wellLogs( const QString& wellboreId ) const
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
|
||||
auto it = m_wellLogs.find( wellboreId );
|
||||
if ( it != m_wellLogs.end() )
|
||||
return it->second;
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<OsduWellbore> RiaOsduConnector::wellbores( const QString& wellId ) const
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
|
||||
auto it = m_wellbores.find( wellId );
|
||||
if ( it != m_wellbores.end() )
|
||||
return it->second;
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::wellIdForWellboreId( const QString& wellboreId ) const
|
||||
{
|
||||
auto findWellIdForWellboreId = []( const std::vector<OsduWellbore>& wellbores, const QString& wellboreId )
|
||||
{
|
||||
auto it = std::find_if( wellbores.begin(), wellbores.end(), [wellboreId]( const OsduWellbore& w ) { return w.id == wellboreId; } );
|
||||
if ( it != wellbores.end() )
|
||||
return it->wellId;
|
||||
else
|
||||
return QString();
|
||||
};
|
||||
|
||||
QMutexLocker lock( &m_mutex );
|
||||
for ( auto [wellId, wellbores] : m_wellbores )
|
||||
{
|
||||
if ( auto res = findWellIdForWellboreId( wellbores, wellboreId ); !res.isEmpty() )
|
||||
{
|
||||
return wellId;
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<OsduWellboreTrajectory> RiaOsduConnector::wellboreTrajectories( const QString& wellboreId ) const
|
||||
{
|
||||
QMutexLocker lock( &m_mutex );
|
||||
|
||||
auto it = m_wellboreTrajectories.find( wellboreId );
|
||||
if ( it != m_wellboreTrajectories.end() )
|
||||
return it->second;
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellboreTrajectoryParquetDataById( const QString& wellboreTrajectoryId )
|
||||
{
|
||||
QString url = constructWellboreTrajectoriesDownloadUrl( m_server, wellboreTrajectoryId );
|
||||
RiaLogging::debug( "Wellbore trajectory URL: " + url );
|
||||
requestParquetDataByUrl( url, wellboreTrajectoryId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestWellLogParquetDataById( const QString& wellLogId )
|
||||
{
|
||||
QString url = constructWellLogDownloadUrl( m_server, wellLogId );
|
||||
RiaLogging::debug( "Well log URL: " + url );
|
||||
requestParquetDataByUrl( url, wellLogId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestParquetDataByUrl( const QString& url, const QString& id )
|
||||
{
|
||||
QString token = m_token;
|
||||
requestParquetData( url, m_dataPartitionId, token, id );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<QByteArray, QString> RiaOsduConnector::requestWellboreTrajectoryParquetDataByIdBlocking( const QString& wellboreTrajectoryId )
|
||||
{
|
||||
QString url = constructWellboreTrajectoriesDownloadUrl( m_server, wellboreTrajectoryId );
|
||||
RiaLogging::debug( "Wellbore trajectory URL: " + url );
|
||||
return requestParquetDataByUrlBlocking( url, wellboreTrajectoryId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<QByteArray, QString> RiaOsduConnector::requestWellLogParquetDataByIdBlocking( const QString& wellLogId )
|
||||
{
|
||||
QString url = constructWellLogDownloadUrl( m_server, wellLogId );
|
||||
RiaLogging::debug( "Well log URL: " + url );
|
||||
return requestParquetDataByUrlBlocking( url, wellLogId );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<QByteArray, QString> RiaOsduConnector::requestParquetDataByUrlBlocking( const QString& url, const QString& id )
|
||||
{
|
||||
QString token = requestTokenBlocking();
|
||||
|
||||
QEventLoop loop;
|
||||
connect( this, SIGNAL( parquetDownloadFinished( const QByteArray&, const QString&, const QString& ) ), &loop, SLOT( quit() ) );
|
||||
requestParquetData( url, m_dataPartitionId, token, id );
|
||||
loop.exec();
|
||||
|
||||
QMutexLocker lock( &m_mutex );
|
||||
return { m_parquetData[id], m_parquetErrors[id] };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::requestParquetData( const QString& url, const QString& dataPartitionId, const QString& token, const QString& id )
|
||||
{
|
||||
RiaLogging::info( "Requesting download of parquet from: " + url );
|
||||
|
||||
auto reply = makeDownloadRequest( url, dataPartitionId, token, RiaDefines::contentTypeParquet() );
|
||||
|
||||
connect( reply,
|
||||
&QNetworkReply::finished,
|
||||
[this, reply, url, id]()
|
||||
{
|
||||
if ( reply->error() == QNetworkReply::NoError )
|
||||
{
|
||||
QByteArray contents = reply->readAll();
|
||||
RiaLogging::info( QString( "Download succeeded: %1 bytes." ).arg( contents.length() ) );
|
||||
emit parquetDownloadFinished( contents, "", id );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage = "Request failed: " + url + " failed." + reply->errorString();
|
||||
RiaLogging::error( errorMessage );
|
||||
emit parquetDownloadFinished( QByteArray(), errorMessage, id );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaOsduConnector::parquetDownloadComplete( const QByteArray& contents, const QString& errorMessage, const QString& id )
|
||||
{
|
||||
CAF_ASSERT( !id.isEmpty() );
|
||||
QMutexLocker lock( &m_mutex );
|
||||
m_parquetData[id] = contents;
|
||||
m_parquetErrors[id] = errorMessage;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduConnector::requestTokenBlocking()
|
||||
{
|
||||
if ( m_token.isEmpty() )
|
||||
{
|
||||
QEventLoop loop;
|
||||
connect( this, SIGNAL( tokenReady( const QString& ) ), &loop, SLOT( quit() ) );
|
||||
requestToken();
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
return m_token;
|
||||
}
|
||||
180
ApplicationLibCode/Application/Tools/Cloud/RiaOsduConnector.h
Normal file
180
ApplicationLibCode/Application/Tools/Cloud/RiaOsduConnector.h
Normal file
@@ -0,0 +1,180 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QOAuth2AuthorizationCodeFlow>
|
||||
|
||||
#include <map>
|
||||
|
||||
struct OsduField
|
||||
{
|
||||
QString id;
|
||||
QString kind;
|
||||
QString name;
|
||||
};
|
||||
|
||||
struct OsduWell
|
||||
{
|
||||
QString id;
|
||||
QString kind;
|
||||
QString name;
|
||||
};
|
||||
|
||||
struct OsduWellbore
|
||||
{
|
||||
QString id;
|
||||
QString kind;
|
||||
QString name;
|
||||
QString wellId;
|
||||
double datumElevation;
|
||||
};
|
||||
|
||||
struct OsduWellboreTrajectory
|
||||
{
|
||||
QString id;
|
||||
QString kind;
|
||||
QString wellboreId;
|
||||
};
|
||||
|
||||
struct OsduWellLogChannel
|
||||
{
|
||||
QString mnemonic;
|
||||
QString description;
|
||||
double topDepth;
|
||||
double baseDepth;
|
||||
QString interpreterName;
|
||||
QString quality;
|
||||
QString unit;
|
||||
QString depthUnit;
|
||||
};
|
||||
|
||||
struct OsduWellLog
|
||||
{
|
||||
QString id;
|
||||
QString kind;
|
||||
QString name;
|
||||
QString description;
|
||||
double samplingStart;
|
||||
double samplingStop;
|
||||
QString wellboreId;
|
||||
std::vector<OsduWellLogChannel> channels;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaOsduConnector : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RiaOsduConnector( QObject* parent,
|
||||
const QString& server,
|
||||
const QString& dataParitionId,
|
||||
const QString& authority,
|
||||
const QString& scopes,
|
||||
const QString& clientId );
|
||||
~RiaOsduConnector() override;
|
||||
|
||||
void requestFieldsByName( const QString& fieldName );
|
||||
void requestWellsByFieldId( const QString& fieldId );
|
||||
void requestWellboresByWellId( const QString& wellId );
|
||||
void requestWellboreTrajectoryByWellboreId( const QString& wellboreId );
|
||||
void requestWellLogsByWellboreId( const QString& wellboreId );
|
||||
std::vector<OsduWellLog> requestWellLogsByWellboreIdBlocking( const QString& wellboreId );
|
||||
|
||||
void requestWellLogParquetDataById( const QString& wellLogId );
|
||||
void requestWellboreTrajectoryParquetDataById( const QString& wellboreTrajectoryId );
|
||||
|
||||
std::pair<QByteArray, QString> requestWellLogParquetDataByIdBlocking( const QString& wellLogId );
|
||||
std::pair<QByteArray, QString> requestWellboreTrajectoryParquetDataByIdBlocking( const QString& wellboreTrajectoryId );
|
||||
|
||||
QString wellIdForWellboreId( const QString& wellboreId ) const;
|
||||
|
||||
void clearCachedData();
|
||||
|
||||
QString server() const;
|
||||
QString dataPartition() const;
|
||||
|
||||
std::vector<OsduField> fields() const;
|
||||
std::vector<OsduWell> wells() const;
|
||||
std::vector<OsduWellbore> wellbores( const QString& wellId ) const;
|
||||
std::vector<OsduWellboreTrajectory> wellboreTrajectories( const QString& wellboreId ) const;
|
||||
std::vector<OsduWellLog> wellLogs( const QString& wellboreId ) const;
|
||||
|
||||
public slots:
|
||||
void requestToken();
|
||||
void parseFields( QNetworkReply* reply );
|
||||
void parseWells( QNetworkReply* reply );
|
||||
void parseWellbores( QNetworkReply* reply, const QString& wellId );
|
||||
void parseWellTrajectory( QNetworkReply* reply, const QString& wellboreId );
|
||||
void parseWellLogs( QNetworkReply* reply, const QString& wellboreId );
|
||||
|
||||
void accessGranted();
|
||||
void parquetDownloadComplete( const QByteArray&, const QString& url, const QString& id );
|
||||
|
||||
signals:
|
||||
void parquetDownloadFinished( const QByteArray& contents, const QString& url, const QString& id );
|
||||
void fieldsFinished();
|
||||
void wellsFinished();
|
||||
void wellboresFinished( const QString& wellId );
|
||||
void wellboreTrajectoryFinished( const QString& wellboreId, int numTrajectories, const QString& errorMessage );
|
||||
void wellLogsFinished( const QString& wellboreId );
|
||||
void tokenReady( const QString& token );
|
||||
|
||||
private slots:
|
||||
void errorReceived( const QString& error, const QString& errorDescription, const QUrl& uri );
|
||||
void authorizationCallbackReceived( const QVariantMap& data );
|
||||
void requestParquetData( const QString& url, const QString& dataPartitionId, const QString& token, const QString& id );
|
||||
|
||||
private:
|
||||
void addStandardHeader( QNetworkRequest& networkRequest, const QString& token, const QString& dataPartitionId, const QString& contentType );
|
||||
|
||||
QNetworkReply* makeSearchRequest( const std::map<QString, QString>& parameters,
|
||||
const QString& server,
|
||||
const QString& dataPartitionId,
|
||||
const QString& token );
|
||||
|
||||
QNetworkReply* makeDownloadRequest( const QString& url, const QString& dataPartitionId, const QString& token, const QString& contentType );
|
||||
|
||||
void requestFieldsByName( const QString& token, const QString& fieldName );
|
||||
void requestFieldsByName( const QString& server, const QString& dataPartitionId, const QString& token, const QString& fieldName );
|
||||
void requestWellsByFieldId( const QString& server, const QString& dataPartitionId, const QString& token, const QString& fieldId );
|
||||
void requestWellboresByWellId( const QString& server, const QString& dataPartitionId, const QString& token, const QString& wellId );
|
||||
void requestWellboreTrajectoryByWellboreId( const QString& server,
|
||||
const QString& dataPartitionId,
|
||||
const QString& token,
|
||||
const QString& wellboreId );
|
||||
void requestWellLogsByWellboreId( const QString& server, const QString& dataPartitionId, const QString& token, const QString& wellboreId );
|
||||
|
||||
static QString constructSearchUrl( const QString& server );
|
||||
static QString constructFileDownloadUrl( const QString& server, const QString& fileId );
|
||||
static QString constructAuthUrl( const QString& authority );
|
||||
static QString constructTokenUrl( const QString& authority );
|
||||
static QString constructWellLogDownloadUrl( const QString& server, const QString& wellLogId );
|
||||
static QString constructWellboreTrajectoriesDownloadUrl( const QString& server, const QString& wellboreTrajectoryId );
|
||||
|
||||
std::pair<QByteArray, QString> requestParquetDataByUrlBlocking( const QString& url, const QString& id );
|
||||
void requestParquetDataByUrl( const QString& url, const QString& id );
|
||||
|
||||
QString requestTokenBlocking();
|
||||
|
||||
QOAuth2AuthorizationCodeFlow* m_osdu;
|
||||
QNetworkAccessManager* m_networkAccessManager;
|
||||
|
||||
const QString m_server;
|
||||
const QString m_dataPartitionId;
|
||||
const QString m_authority;
|
||||
const QString m_scopes;
|
||||
const QString m_clientId;
|
||||
|
||||
mutable QMutex m_mutex;
|
||||
QString m_token;
|
||||
std::vector<OsduField> m_fields;
|
||||
std::vector<OsduWell> m_wells;
|
||||
std::map<QString, std::vector<OsduWellbore>> m_wellbores;
|
||||
std::map<QString, std::vector<OsduWellboreTrajectory>> m_wellboreTrajectories;
|
||||
std::map<QString, std::vector<OsduWellLog>> m_wellLogs;
|
||||
std::map<QString, QByteArray> m_parquetData;
|
||||
std::map<QString, QString> m_parquetErrors;
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "RiaOsduOAuthHttpServerReplyHandler.h"
|
||||
|
||||
#include <QAbstractOAuth>
|
||||
#include <QOAuthHttpServerReplyHandler>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaOsduOAuthHttpServerReplyHandler::RiaOsduOAuthHttpServerReplyHandler( quint16 port, QObject* parent )
|
||||
: QOAuthHttpServerReplyHandler( port, parent )
|
||||
, m_port( port )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiaOsduOAuthHttpServerReplyHandler::callback() const
|
||||
{
|
||||
const QUrl url( QString::fromLatin1( "http://localhost:%1/" ).arg( m_port ) );
|
||||
return url.toString( QUrl::EncodeDelimiters );
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2024- Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QOAuthHttpServerReplyHandler>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RiaOsduOAuthHttpServerReplyHandler : public QOAuthHttpServerReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RiaOsduOAuthHttpServerReplyHandler( quint16 port, QObject* parent );
|
||||
|
||||
QString callback() const override;
|
||||
|
||||
private:
|
||||
quint16 m_port;
|
||||
};
|
||||
@@ -22,8 +22,7 @@
|
||||
#include "RiaFileDownloader.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaOsduDefines.h"
|
||||
|
||||
#include "OsduImportCommands/RiaOsduOAuthHttpServerReplyHandler.h"
|
||||
#include "RiaOsduOAuthHttpServerReplyHandler.h"
|
||||
|
||||
#include <QAbstractOAuth>
|
||||
#include <QDesktopServices>
|
||||
|
||||
Reference in New Issue
Block a user