#include #include #include "ApplicationConfig.hpp" using namespace Bloom; void ApplicationConfig::init(QJsonObject jsonObject) { if (!jsonObject.contains("environments")) { throw Exceptions::InvalidConfig("No environments found."); } // Extract all environment objects from JSON config. auto environments = jsonObject.find("environments").value().toObject(); for (auto environmentIt = environments.begin(); environmentIt != environments.end(); environmentIt++) { auto environmentName = environmentIt.key().toStdString(); try { auto environmentConfig = EnvironmentConfig(); environmentConfig.init(environmentName, environmentIt.value().toObject()); this->environments.insert( std::pair(environmentName, environmentConfig) ); } catch (Exceptions::InvalidConfig& exception) { Logger::error("Invalid environment config for environment '" + environmentName + "': " + exception.getMessage() + " Environment will be ignored."); } } if (jsonObject.contains("debugServer")) { auto debugServerConfig = DebugServerConfig(); debugServerConfig.init(jsonObject.find("debugServer")->toObject()); this->debugServerConfig = debugServerConfig; } if (jsonObject.contains("insight")) { this->insightConfig.init(jsonObject.find("insight")->toObject()); } if (jsonObject.contains("debugLoggingEnabled")) { this->debugLoggingEnabled = jsonObject.find("debugLoggingEnabled").value().toBool(); } } void InsightConfig::init(QJsonObject jsonObject) { if (jsonObject.contains("enabled")) { this->insightEnabled = jsonObject.find("enabled").value().toBool(); } } void EnvironmentConfig::init(std::string name, QJsonObject jsonObject) { this->name = name; this->debugToolName = jsonObject.find("debugToolName")->toString().toLower().toStdString(); // Extract target data if (!jsonObject.contains("target")) { // Environment has no target data - ignore throw Exceptions::InvalidConfig("No target configuration provided"); } this->targetConfig.init(jsonObject.find("target")->toObject()); if (jsonObject.contains("debugServer")) { auto debugServerConfig = DebugServerConfig(); debugServerConfig.init(jsonObject.find("debugServer")->toObject()); this->debugServerConfig = debugServerConfig; } if (jsonObject.contains("insight")) { auto insightConfig = InsightConfig(); insightConfig.init(jsonObject.find("insight")->toObject()); this->insightConfig = insightConfig; } } void TargetConfig::init(QJsonObject jsonObject) { if (!jsonObject.contains("name")) { throw Exceptions::InvalidConfig("No target name found."); } this->name = jsonObject.find("name")->toString().toLower().toStdString(); this->jsonObject = jsonObject; } void DebugServerConfig::init(QJsonObject jsonObject) { this->name = jsonObject.find("name")->toString().toLower().toStdString(); this->jsonObject = jsonObject; }