* @brief Load project configuration from JSON object */
| 3982 | * @brief Load project configuration from JSON object |
| 3983 | */ |
| 3984 | API::CommandResponse API::Handlers::ProjectHandler::loadFromJSON(const QString& id, |
| 3985 | const QJsonObject& params) |
| 3986 | { |
| 3987 | if (!params.contains(QStringLiteral("config"))) { |
| 3988 | return CommandResponse::makeError( |
| 3989 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: config")); |
| 3990 | } |
| 3991 | |
| 3992 | const QJsonObject config = params.value(QStringLiteral("config")).toObject(); |
| 3993 | if (config.isEmpty()) { |
| 3994 | return CommandResponse::makeError( |
| 3995 | id, ErrorCode::InvalidParam, QStringLiteral("config cannot be empty")); |
| 3996 | } |
| 3997 | |
| 3998 | const bool isDryRun = params.value(QStringLiteral("dryRun")).toBool(false); |
| 3999 | if (isDryRun) { |
| 4000 | QJsonObject result; |
| 4001 | result[QStringLiteral("dryRun")] = true; |
| 4002 | result[QStringLiteral("wouldDiscard")] = summarizeCurrentProject(); |
| 4003 | result[QStringLiteral("wouldApply")] = summarizeProjectJson(config); |
| 4004 | result[QStringLiteral("warning")] = |
| 4005 | QStringLiteral("DRY RUN: no project was loaded. wouldDiscard shows what would be lost; " |
| 4006 | "wouldApply shows what would replace it. Confirm before re-issuing " |
| 4007 | "without dryRun:true."); |
| 4008 | return CommandResponse::makeSuccess(id, result); |
| 4009 | } |
| 4010 | |
| 4011 | auto& project = DataModel::ProjectModel::instance(); |
| 4012 | project.setSuppressMessageBoxes(true); |
| 4013 | const bool ok = project.loadFromJsonDocument(QJsonDocument(config)); |
| 4014 | project.setSuppressMessageBoxes(false); |
| 4015 | |
| 4016 | if (!ok) { |
| 4017 | return CommandResponse::makeError( |
| 4018 | id, |
| 4019 | ErrorCode::OperationFailed, |
| 4020 | QStringLiteral("Failed to load project from JSON (validation error)")); |
| 4021 | } |
| 4022 | |
| 4023 | QJsonObject result; |
| 4024 | result[QStringLiteral("loaded")] = true; |
| 4025 | result[QStringLiteral("title")] = project.title(); |
| 4026 | result[QStringLiteral("groupCount")] = project.groupCount(); |
| 4027 | result[QStringLiteral("datasetCount")] = project.datasetCount(); |
| 4028 | |
| 4029 | return CommandResponse::makeSuccess(id, result); |
| 4030 | } |
| 4031 | |
| 4032 | /** |
| 4033 | * @brief Configure frame parser settings for a specific source. |
nothing calls this directly
no test coverage detected