MCPcopy Create free account
hub / github.com/MITK/MITK / GetNodes

Method GetNodes

Modules/RESTAPI/src/mitkDataStorageBridge.cpp:478–606  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476 }
477
478 DataStorageBridge::NodeQueryResult DataStorageBridge::GetNodes(const NodeQueryParams& params) const
479 {
480 std::lock_guard<std::mutex> lock(m_Mutex);
481 return this->DispatchTask<NodeQueryResult>([this, params]()
482 {
483 NodeQueryResult result;
484 result.nodes = Json::array();
485 result.totalCount = 0;
486 result.limit = params.limit;
487 result.offset = params.offset;
488
489 auto dataStorage = m_DataStorage.Lock();
490 if (dataStorage.IsNull())
491 {
492 return result;
493 }
494
495 // Build predicate from query parameters
496 auto predicate = this->BuildNodePredicate(params);
497
498 // Get filtered nodes using the predicate
499 auto filteredNodes = dataStorage->GetSubset(predicate);
500
501 // Convert to vector for sorting and pagination
502 std::vector<DataNode*> matchingNodes;
503 matchingNodes.reserve(filteredNodes->Size());
504 for (auto it = filteredNodes->Begin(); it != filteredNodes->End(); ++it)
505 {
506 matchingNodes.push_back(it->Value().GetPointer());
507 }
508
509 // Apply sorting if specified
510 // Sorting is done by JSON result fields: uid, name, path, parent_uid, data_type, children_count, timestamp
511 if (params.sort.has_value())
512 {
513 const auto& sortSpec = params.sort.value();
514 std::sort(matchingNodes.begin(), matchingNodes.end(),
515 [this, &sortSpec, &dataStorage](DataNode* a, DataNode* b) {
516 const std::string& field = sortSpec.field;
517
518 // Handle numeric fields (children_count, timestamp)
519 if (field == "children_count")
520 {
521 int countA = this->GetChildrenCount(a);
522 int countB = this->GetChildrenCount(b);
523 return sortSpec.ascending ? (countA < countB) : (countA > countB);
524 }
525 else if (field == "timestamp")
526 {
527 unsigned long timeA = a->GetMTime();
528 unsigned long timeB = b->GetMTime();
529 return sortSpec.ascending ? (timeA < timeB) : (timeA > timeB);
530 }
531
532 // Handle string fields
533 std::string valA, valB;
534
535 if (field == "uid")

Callers 15

OuterSequenceIndexFunction · 0.45
GetFirstNodeUidMethod · 0.45
FindUidByNameMethod · 0.45
DeleteNodeMethod · 0.45
FindUidByNameMethod · 0.45
GetRootNodesOnlyMethod · 0.45
GetChildrenOfParentMethod · 0.45

Calls 15

BuildNodePredicateMethod · 0.95
GetChildrenCountMethod · 0.95
BuildNodePathMethod · 0.95
NodeToJsonMethod · 0.95
GetSubsetMethod · 0.80
GetPointerMethod · 0.80
ValueMethod · 0.80
GetOrCreateUidMethod · 0.80
GetSourcesMethod · 0.80
containsMethod · 0.80
LockMethod · 0.45
IsNullMethod · 0.45

Tested by 15

GetFirstNodeUidMethod · 0.36
FindUidByNameMethod · 0.36
DeleteNodeMethod · 0.36
FindUidByNameMethod · 0.36
GetRootNodesOnlyMethod · 0.36
GetChildrenOfParentMethod · 0.36