| 1025 | } |
| 1026 | |
| 1027 | DataStorageBridge::OperationStatus DataStorageBridge::SetNodeProperty( |
| 1028 | const std::string& uid, |
| 1029 | const std::string& key, |
| 1030 | const Json& value, |
| 1031 | const PropertyQueryParams& params) |
| 1032 | { |
| 1033 | // Reject modification of internal properties (no dispatch needed for this check) |
| 1034 | if (IsInternalProperty(key)) |
| 1035 | { |
| 1036 | return OperationStatus::InvalidInput; |
| 1037 | } |
| 1038 | |
| 1039 | // Mutation operations only support Node and Data scopes, not All |
| 1040 | if (params.scope == PropertyScope::All) |
| 1041 | { |
| 1042 | return OperationStatus::InvalidInput; |
| 1043 | } |
| 1044 | |
| 1045 | std::lock_guard<std::mutex> lock(m_Mutex); |
| 1046 | return this->DispatchTask<OperationStatus>([this, uid, key, value, params]() |
| 1047 | { |
| 1048 | auto dataStorage = m_DataStorage.Lock(); |
| 1049 | if (dataStorage.IsNull()) |
| 1050 | { |
| 1051 | return OperationStatus::InternalError; |
| 1052 | } |
| 1053 | |
| 1054 | auto node = m_UidMapper->FindNodeByUid(uid); |
| 1055 | if (node == nullptr) |
| 1056 | { |
| 1057 | return OperationStatus::NodeNotFound; |
| 1058 | } |
| 1059 | |
| 1060 | try |
| 1061 | { |
| 1062 | // Handle the case the also simple value forms are wrapped in {"value": ...} |
| 1063 | Json propValue = value; |
| 1064 | if (value.is_object() && value.contains("value") && !value.contains("type")) |
| 1065 | { |
| 1066 | propValue = value["value"]; |
| 1067 | } |
| 1068 | auto prop = ConvertPropertyFromSelfContainedJson(propValue); |
| 1069 | if (prop.IsNotNull()) |
| 1070 | { |
| 1071 | const std::string contextName = params.context.has_value() ? params.context.value() : ""; |
| 1072 | |
| 1073 | if (params.scope == PropertyScope::Data) |
| 1074 | { |
| 1075 | auto data = node->GetData(); |
| 1076 | if (data != nullptr) |
| 1077 | { |
| 1078 | data->SetProperty(key, prop, contextName); |
| 1079 | // Mark node as modified via REST API |
| 1080 | MarkNodeAsModified(node, "property_set:" + key); |
| 1081 | return OperationStatus::Success; |
| 1082 | } |
| 1083 | return OperationStatus::InvalidInput; |
| 1084 | } |
no test coverage detected