mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add optional import of SUMO/OSDU settings from JSON (#11630)
Add optionally import of SUMO/OSDU settings from JSON. Check for sumo_config.json and osdu_config.json. If present, import settings to preferences and set fields read only.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
|
|
||||||
|
#include "Cloud/RiaConnectorTools.h"
|
||||||
#include "Cloud/RiaOsduConnector.h"
|
#include "Cloud/RiaOsduConnector.h"
|
||||||
#include "Cloud/RiaSumoConnector.h"
|
#include "Cloud/RiaSumoConnector.h"
|
||||||
#include "Cloud/RiaSumoDefines.h"
|
#include "Cloud/RiaSumoDefines.h"
|
||||||
@@ -1529,6 +1530,34 @@ cvf::Font* RiaApplication::defaultWellLabelFont()
|
|||||||
return m_defaultWellLabelFont.p();
|
return m_defaultWellLabelFont.p();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
auto readConfigFiles = []( RiaPreferences* preferences )
|
||||||
|
{
|
||||||
|
if ( preferences == nullptr ) return;
|
||||||
|
|
||||||
|
{
|
||||||
|
QString osduConfigPath = QDir::homePath() + "/.resinsight/osdu_config.json";
|
||||||
|
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( osduConfigPath );
|
||||||
|
if ( !keyValuePairs.empty() )
|
||||||
|
{
|
||||||
|
preferences->osduPreferences()->setData( keyValuePairs );
|
||||||
|
preferences->osduPreferences()->setFieldsReadOnly();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QString sumoConfigPath = QDir::homePath() + "/.resinsight/sumo_config.json";
|
||||||
|
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( sumoConfigPath );
|
||||||
|
if ( !keyValuePairs.empty() )
|
||||||
|
{
|
||||||
|
preferences->sumoPreferences()->setData( keyValuePairs );
|
||||||
|
preferences->sumoPreferences()->setFieldsReadOnly();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -1547,6 +1576,8 @@ void RiaApplication::initialize()
|
|||||||
caf::SelectionManager::instance()->setPdmRootObject( project() );
|
caf::SelectionManager::instance()->setPdmRootObject( project() );
|
||||||
|
|
||||||
initializeDataLoadController();
|
initializeDataLoadController();
|
||||||
|
|
||||||
|
readConfigFiles( m_preferences.get() );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -43,6 +43,48 @@ RiaPreferencesOsdu* RiaPreferencesOsdu::current()
|
|||||||
return RiaApplication::instance()->preferences()->osduPreferences();
|
return RiaApplication::instance()->preferences()->osduPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaPreferencesOsdu::setData( const std::map<QString, QString>& keyValuePairs )
|
||||||
|
{
|
||||||
|
for ( const auto& [key, value] : keyValuePairs )
|
||||||
|
{
|
||||||
|
if ( key == "server" )
|
||||||
|
{
|
||||||
|
m_server = value;
|
||||||
|
}
|
||||||
|
else if ( key == "dataPartitionId" )
|
||||||
|
{
|
||||||
|
m_dataPartitionId = value;
|
||||||
|
}
|
||||||
|
else if ( key == "authority" )
|
||||||
|
{
|
||||||
|
m_authority = value;
|
||||||
|
}
|
||||||
|
else if ( key == "scopes" )
|
||||||
|
{
|
||||||
|
m_scopes = value;
|
||||||
|
}
|
||||||
|
else if ( key == "clientId" )
|
||||||
|
{
|
||||||
|
m_clientId = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaPreferencesOsdu::setFieldsReadOnly()
|
||||||
|
{
|
||||||
|
m_server.uiCapability()->setUiReadOnly( true );
|
||||||
|
m_dataPartitionId.uiCapability()->setUiReadOnly( true );
|
||||||
|
m_authority.uiCapability()->setUiReadOnly( true );
|
||||||
|
m_scopes.uiCapability()->setUiReadOnly( true );
|
||||||
|
m_clientId.uiCapability()->setUiReadOnly( true );
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ public:
|
|||||||
|
|
||||||
static RiaPreferencesOsdu* current();
|
static RiaPreferencesOsdu* current();
|
||||||
|
|
||||||
|
void setData( const std::map<QString, QString>& keyValuePairs );
|
||||||
|
void setFieldsReadOnly();
|
||||||
|
|
||||||
QString server() const;
|
QString server() const;
|
||||||
QString dataPartitionId() const;
|
QString dataPartitionId() const;
|
||||||
QString authority() const;
|
QString authority() const;
|
||||||
|
|||||||
@@ -42,6 +42,43 @@ RiaPreferencesSumo* RiaPreferencesSumo::current()
|
|||||||
return RiaApplication::instance()->preferences()->sumoPreferences();
|
return RiaApplication::instance()->preferences()->sumoPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaPreferencesSumo::setData( const std::map<QString, QString>& keyValuePairs )
|
||||||
|
{
|
||||||
|
for ( const auto& [key, value] : keyValuePairs )
|
||||||
|
{
|
||||||
|
if ( key == "server" )
|
||||||
|
{
|
||||||
|
m_server = value;
|
||||||
|
}
|
||||||
|
else if ( key == "authority" )
|
||||||
|
{
|
||||||
|
m_authority = value;
|
||||||
|
}
|
||||||
|
else if ( key == "scopes" )
|
||||||
|
{
|
||||||
|
m_scopes = value;
|
||||||
|
}
|
||||||
|
else if ( key == "clientId" )
|
||||||
|
{
|
||||||
|
m_clientId = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiaPreferencesSumo::setFieldsReadOnly()
|
||||||
|
{
|
||||||
|
m_server.uiCapability()->setUiReadOnly( true );
|
||||||
|
m_authority.uiCapability()->setUiReadOnly( true );
|
||||||
|
m_scopes.uiCapability()->setUiReadOnly( true );
|
||||||
|
m_clientId.uiCapability()->setUiReadOnly( true );
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ public:
|
|||||||
|
|
||||||
static RiaPreferencesSumo* current();
|
static RiaPreferencesSumo* current();
|
||||||
|
|
||||||
|
void setData( const std::map<QString, QString>& keyValuePairs );
|
||||||
|
void setFieldsReadOnly();
|
||||||
|
|
||||||
QString server() const;
|
QString server() const;
|
||||||
QString authority() const;
|
QString authority() const;
|
||||||
QString scopes() const;
|
QString scopes() const;
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ void RiaCloudConnector::exportTokenToFile()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiaCloudConnector::importTokenFromFile()
|
void RiaCloudConnector::importTokenFromFile()
|
||||||
{
|
{
|
||||||
auto tokenDataJson = RiaConnectorTools::readTokenData( m_tokenDataFilePath );
|
auto tokenDataJson = RiaConnectorTools::readStringFromFile( m_tokenDataFilePath );
|
||||||
if ( !tokenDataJson.isEmpty() )
|
if ( !tokenDataJson.isEmpty() )
|
||||||
{
|
{
|
||||||
RiaConnectorTools::initializeTokenDataFromJson( m_authCodeFlow, tokenDataJson );
|
RiaConnectorTools::initializeTokenDataFromJson( m_authCodeFlow, tokenDataJson );
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void RiaConnectorTools::writeTokenData( const QString& filePath, const QString&
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RiaConnectorTools::readTokenData( const QString& filePath )
|
QString RiaConnectorTools::readStringFromFile( const QString& filePath )
|
||||||
{
|
{
|
||||||
QFile file( filePath );
|
QFile file( filePath );
|
||||||
if ( file.open( QIODevice::ReadOnly ) )
|
if ( file.open( QIODevice::ReadOnly ) )
|
||||||
@@ -102,3 +102,22 @@ QString RiaConnectorTools::readTokenData( const QString& filePath )
|
|||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::map<QString, QString> RiaConnectorTools::readKeyValuePairs( const QString& filePath )
|
||||||
|
{
|
||||||
|
auto content = readStringFromFile( filePath );
|
||||||
|
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson( content.toUtf8() );
|
||||||
|
QJsonObject obj = doc.object();
|
||||||
|
|
||||||
|
std::map<QString, QString> keyValuePairs;
|
||||||
|
for ( auto it = obj.begin(); it != obj.end(); ++it )
|
||||||
|
{
|
||||||
|
keyValuePairs[it.key()] = it.value().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyValuePairs;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class QOAuth2AuthorizationCodeFlow;
|
class QOAuth2AuthorizationCodeFlow;
|
||||||
|
|
||||||
@@ -27,5 +28,7 @@ namespace RiaConnectorTools
|
|||||||
QString tokenDataAsJson( QOAuth2AuthorizationCodeFlow* authCodeFlow );
|
QString tokenDataAsJson( QOAuth2AuthorizationCodeFlow* authCodeFlow );
|
||||||
void initializeTokenDataFromJson( QOAuth2AuthorizationCodeFlow* authCodeFlow, const QString& tokenDataJson );
|
void initializeTokenDataFromJson( QOAuth2AuthorizationCodeFlow* authCodeFlow, const QString& tokenDataJson );
|
||||||
void writeTokenData( const QString& filePath, const QString& tokenDataJson );
|
void writeTokenData( const QString& filePath, const QString& tokenDataJson );
|
||||||
QString readTokenData( const QString& filePath );
|
QString readStringFromFile( const QString& filePath );
|
||||||
|
|
||||||
|
std::map<QString, QString> readKeyValuePairs( const QString& filePath );
|
||||||
} // namespace RiaConnectorTools
|
} // namespace RiaConnectorTools
|
||||||
|
|||||||
Reference in New Issue
Block a user