| 354 | } |
| 355 | |
| 356 | NodePredicateBase::Pointer DataStorageBridge::BuildNodePredicate(const NodeQueryParams& params) const |
| 357 | { |
| 358 | auto dataStorage = m_DataStorage.Lock(); |
| 359 | if (dataStorage.IsNull()) |
| 360 | mitkThrow() << "BuildNodePredicate called without a valid DataStorage."; |
| 361 | |
| 362 | std::vector<NodePredicateBase::Pointer> predicates; |
| 363 | |
| 364 | // Hierarchy filter (toplevel = root nodes only) |
| 365 | if (params.hierarchy == Hierarchy::Toplevel) |
| 366 | { |
| 367 | auto isRootPredicate = NodePredicateFunction::New( |
| 368 | [dataStorage](const DataNode* node) -> bool { |
| 369 | auto sources = dataStorage->GetSources(node); |
| 370 | return sources->Size() == 0; |
| 371 | }); |
| 372 | predicates.push_back(isRootPredicate.GetPointer()); |
| 373 | } |
| 374 | |
| 375 | // Path filter |
| 376 | if (params.path.has_value()) |
| 377 | { |
| 378 | const std::string targetPath = params.path.value(); |
| 379 | auto pathPredicate = NodePredicateFunction::New( |
| 380 | [this, targetPath](const DataNode* node) -> bool { |
| 381 | return this->BuildNodePath(node) == targetPath; |
| 382 | }); |
| 383 | predicates.push_back(pathPredicate.GetPointer()); |
| 384 | } |
| 385 | |
| 386 | // Data type filter |
| 387 | if (params.dataType.has_value()) |
| 388 | { |
| 389 | std::string dataType = params.dataType.value(); |
| 390 | |
| 391 | auto dataTypePredicate = NodePredicateDataType::New(dataType.c_str()); |
| 392 | predicates.push_back(dataTypePredicate.GetPointer()); |
| 393 | } |
| 394 | |
| 395 | // Parent UID filter |
| 396 | if (params.parentUid.has_value()) |
| 397 | { |
| 398 | const std::string targetParentUid = params.parentUid.value(); |
| 399 | auto parentPredicate = NodePredicateFunction::New( |
| 400 | [this, dataStorage, targetParentUid](const DataNode* node) -> bool { |
| 401 | auto sources = dataStorage->GetSources(node); |
| 402 | |
| 403 | if (targetParentUid == "null") |
| 404 | { |
| 405 | // Filter for root nodes (no parent) |
| 406 | return sources->Size() == 0; |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | // Check if parent matches the target UID |
| 411 | for (auto srcIt = sources->Begin(); srcIt != sources->End(); ++srcIt) |
| 412 | { |
| 413 | auto parentUid = m_UidMapper->GetUid(srcIt->Value().GetPointer()); |
no test coverage detected