| 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 | } |
no test coverage detected