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

Method CreateNode

Modules/RESTAPI/src/mitkDataStorageBridge.cpp:629–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

627 }
628
629 DataStorageBridge::CreateNodeResult DataStorageBridge::CreateNode(const Json& nodeData, const std::optional<std::string>& parentUid)
630 {
631 std::lock_guard<std::mutex> lock(m_Mutex);
632 return this->DispatchTask<CreateNodeResult>([this, nodeData, parentUid]()
633 {
634 CreateNodeResult result;
635 result.success = false;
636
637 auto dataStorage = m_DataStorage.Lock();
638 if (dataStorage.IsNull())
639 {
640 return result;
641 }
642
643 // Find parent node if specified
644 DataNode::Pointer parentNode;
645 if (parentUid.has_value())
646 {
647 parentNode = m_UidMapper->FindNodeByUid(parentUid.value());
648 if (parentNode.IsNull())
649 {
650 return result; // Parent not found
651 }
652 }
653
654 auto node = DataNode::New();
655
656 // Set name if provided
657 if (nodeData.contains("name") && nodeData["name"].is_string())
658 {
659 node->SetName(nodeData["name"].get<std::string>());
660 }
661
662 // Apply properties if provided
663 if (nodeData.contains("properties") && nodeData["properties"].is_object())
664 {
665 for (auto& [key, value] : nodeData["properties"].items())
666 {
667 try
668 {
669 auto prop = ConvertPropertyFromSelfContainedJson(value);
670 if (prop.IsNotNull())
671 {
672 node->SetProperty(key, prop);
673 }
674 else
675 {
676 MITK_WARN << "REST API: Failed to deserialize property '" << key << "' - null result from deserialization";
677 result.failedProperties.push_back(key);
678 }
679 }
680 catch (const std::exception& e)
681 {
682 MITK_WARN << "REST API: Failed to deserialize property '" << key << "': " << e.what();
683 result.failedProperties.push_back(key);
684 }
685 }
686 }

Callers 1

Calls 13

MarkNodeAsModifiedFunction · 0.85
FindNodeByUidMethod · 0.80
containsMethod · 0.80
IsNotNullMethod · 0.80
whatMethod · 0.80
GetOrCreateUidMethod · 0.80
NewFunction · 0.50
LockMethod · 0.45
IsNullMethod · 0.45
valueMethod · 0.45
SetNameMethod · 0.45
SetPropertyMethod · 0.45

Tested by

no test coverage detected