MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / datasetGetByPath

Method datasetGetByPath

app/src/API/Handlers/ProjectHandler.cpp:3432–3484  ·  view source on GitHub ↗

* @brief Find a dataset by 'Group/Dataset' or 'Source/Group/Dataset' path. */

Source from the content-addressed store, hash-verified

3430 * @brief Find a dataset by 'Group/Dataset' or 'Source/Group/Dataset' path.
3431 */
3432API::CommandResponse API::Handlers::ProjectHandler::datasetGetByPath(const QString& id,
3433 const QJsonObject& params)
3434{
3435 if (!params.contains(QStringLiteral("path")))
3436 return CommandResponse::makeError(
3437 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: path"));
3438
3439 const QString path = params.value(QStringLiteral("path")).toString();
3440 const auto segments = path.split(QChar('/'), Qt::SkipEmptyParts);
3441
3442 if (segments.size() != 2 && segments.size() != 3)
3443 return CommandResponse::makeError(
3444 id,
3445 ErrorCode::InvalidParam,
3446 QStringLiteral("path must be 'Group/Dataset' or 'Source/Group/Dataset'"));
3447
3448 const QString sourceTitle = segments.size() == 3 ? segments.at(0) : QString();
3449 const QString groupTitle = segments.size() == 3 ? segments.at(1) : segments.at(0);
3450 const QString datasetTitle = segments.last();
3451
3452 const auto& pm = DataModel::ProjectModel::instance();
3453 const auto& sources = pm.sources();
3454 const auto& groups = pm.groups();
3455
3456 int sourceFilterId = -1;
3457 if (!sourceTitle.isEmpty()) {
3458 for (const auto& src : sources)
3459 if (src.title == sourceTitle) {
3460 sourceFilterId = src.sourceId;
3461 break;
3462 }
3463
3464 if (sourceFilterId < 0)
3465 return CommandResponse::makeError(
3466 id, ErrorCode::InvalidParam, QStringLiteral("Source not found: '%1'").arg(sourceTitle));
3467 }
3468
3469 for (const auto& group : groups) {
3470 if (group.title != groupTitle)
3471 continue;
3472
3473 for (const auto& dataset : group.datasets) {
3474 if (sourceFilterId >= 0 && dataset.sourceId != sourceFilterId)
3475 continue;
3476
3477 if (dataset.title == datasetTitle)
3478 return CommandResponse::makeSuccess(id, buildDatasetObject(dataset, group));
3479 }
3480 }
3481
3482 return CommandResponse::makeError(
3483 id, ErrorCode::InvalidParam, QStringLiteral("No dataset matched path '%1'").arg(path));
3484}
3485
3486/**
3487 * @brief Compute the new ordinal for an item after a list move; mirrors std::vector reorder.

Callers

nothing calls this directly

Calls 6

buildDatasetObjectFunction · 0.85
lastMethod · 0.80
isEmptyMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected