|
Medical Imaging Interaction Toolkit
2026.06.00
Medical Imaging Interaction Toolkit
|
Thread-safe bridge between the REST API layer and MITK DataStorage. More...
#include <mitkDataStorageBridge.h>
Classes | |
| struct | CreateNodeResult |
| Result of a node creation operation. More... | |
| struct | DeleteResult |
| Result of a node deletion operation. More... | |
| struct | GetNodeDataResult |
| Result of a GetNodeData operation. More... | |
| struct | NodeQueryResult |
| Result of a node query with pagination metadata. More... | |
| struct | ReplacePropertiesResult |
| Result of a ReplaceNodeProperties operation. More... | |
Public Types | |
| enum class | OperationStatus { Success , NodeNotFound , PropertyNotFound , InvalidInput , InternalError } |
| Status codes for mutation operations. More... | |
| using | Json = nlohmann::json |
Public Member Functions | |
| DataStorageBridge () | |
| ~DataStorageBridge () | |
| DataStorageBridge (const DataStorageBridge &)=delete | |
| DataStorageBridge & | operator= (const DataStorageBridge &)=delete |
| DataStorageBridge (DataStorageBridge &&)=delete | |
| DataStorageBridge & | operator= (DataStorageBridge &&)=delete |
| void | SetDispatcher (StorageThreadDispatcherBase *dispatcher) |
| Set the dispatcher for thread-safe DataStorage operations. More... | |
| void | SetDataStorage (DataStorage *dataStorage) |
| Set the DataStorage to operate on. More... | |
| DataStorage::Pointer | GetDataStorage () const |
| Get the current DataStorage. More... | |
| bool | HasDataStorage () const |
| Check if a DataStorage is connected. More... | |
| std::string | GetNodeUid (DataNode *node) const |
| Get the UID for a DataNode. More... | |
| NodeQueryResult | GetNodes (const NodeQueryParams ¶ms) const |
| Get nodes with full query parameter support. More... | |
| std::optional< Json > | GetNode (const std::string &uid) const |
| Get a single node by UID. More... | |
| CreateNodeResult | CreateNode (const Json &nodeData, const std::optional< std::string > &parentUid=std::nullopt) |
| Create a new node. More... | |
| bool | UpdateNode (const std::string &uid, const Json &updates) |
| Update a node. More... | |
| DeleteResult | DeleteNode (const std::string &uid, bool recursive=false) |
| Delete a node. More... | |
| GetNodeDataResult | GetNodeData (const std::string &uid) const |
| Get a clone of the node's data for thread-safe processing. More... | |
| DataNode::ConstPointer | FindDataNode (const std::string &uid) const |
| Look up a DataNode by UID. More... | |
| OperationStatus | SetNodeData (const std::string &uid, BaseData *data) |
| Set or replace the data on a node. More... | |
| std::optional< Json > | GetNodeProperties (const std::string &uid, const PropertyQueryParams ¶ms={}) const |
| Get properties of a node with scope filtering. More... | |
| std::optional< Json > | GetNodeProperty (const std::string &uid, const std::string &key, const PropertyQueryParams ¶ms={}) const |
| Get a single property of a node. More... | |
| OperationStatus | SetNodeProperty (const std::string &uid, const std::string &key, const Json &value, const PropertyQueryParams ¶ms) |
| Set a single property on a node. More... | |
| OperationStatus | DeleteNodeProperty (const std::string &uid, const std::string &key, const PropertyQueryParams ¶ms) |
| Delete a property from a node. More... | |
| ReplacePropertiesResult | ReplaceNodeProperties (const std::string &uid, const Json &properties, const PropertyQueryParams ¶ms) |
| Replace all properties on a node (PUT semantics). More... | |
| std::optional< Json > | GetNodeAvailableContexts (const std::string &uid) const |
| Get available property contexts for a node. More... | |
Static Public Attributes | |
| static constexpr const char * | INTERNAL_PROPERTY_PREFIX |
| Prefix for internal REST API properties (filtered from responses, protected from modification). More... | |
| static constexpr const char * | MODIFIED_PROPERTY_KEY |
| Property key for tracking if a node was modified via the REST API. More... | |
| static constexpr const char * | LAST_MODIFICATION_PROPERTY_KEY |
| Property key for tracking the last modification operation (string property). More... | |
Thread-safe bridge between the REST API layer and MITK DataStorage.
This class abstracts between the concrete REST/HTTP implementation and MITK-specific handling of requests, translating between DataStorage content and REST message content (as JSON).
Provides:
Properties with keys starting with "restapi." are internal metadata used by the REST API (e.g., "restapi.uid" for node identification). These properties are:
When a node is modified through the bridge (create, update, property changes), the bridge automatically adds two internal properties to the node:
Possible lastmodification values:
All public methods are thread-safe.
Definition at line 74 of file mitkDataStorageBridge.h.
Definition at line 77 of file mitkDataStorageBridge.h.
|
strong |
Status codes for mutation operations.
Enables controllers to produce precise HTTP responses:
| Enumerator | |
|---|---|
| Success | |
| NodeNotFound | Target node does not exist 404. |
| PropertyNotFound | Property absent in target scope 404. |
| InvalidInput | Malformed value or unsupported scope 400. |
| InternalError | No DataStorage or unexpected state 500. |
Definition at line 141 of file mitkDataStorageBridge.h.
| mitk::DataStorageBridge::DataStorageBridge | ( | ) |
| mitk::DataStorageBridge::~DataStorageBridge | ( | ) |
|
delete |
|
delete |
| CreateNodeResult mitk::DataStorageBridge::CreateNode | ( | const Json & | nodeData, |
| const std::optional< std::string > & | parentUid = std::nullopt |
||
| ) |
Create a new node.
Creates a new DataNode with the specified name and properties. Properties that fail to deserialize are logged and reported in the result, but do not prevent node creation.
| nodeData | JSON object with node data (name, properties). |
| parentUid | Optional parent node UID. If provided, creates as child of parent. |
| DeleteResult mitk::DataStorageBridge::DeleteNode | ( | const std::string & | uid, |
| bool | recursive = false |
||
| ) |
Delete a node.
| uid | The node UID. |
| recursive | If true, also delete all children recursively. |
| OperationStatus mitk::DataStorageBridge::DeleteNodeProperty | ( | const std::string & | uid, |
| const std::string & | key, | ||
| const PropertyQueryParams & | params | ||
| ) |
Delete a property from a node.
| uid | The node UID. |
| key | The property key. |
| params | Query parameters for scope and context. |
| DataNode::ConstPointer mitk::DataStorageBridge::FindDataNode | ( | const std::string & | uid | ) | const |
Look up a DataNode by UID.
Returns a const strong reference to the node, keeping it alive for the duration of the caller's use. Returns null if the UID is not registered.
Intended for read-only access (e.g. inspecting geometry, properties). Do not retain the returned pointer beyond the immediate call site without understanding the threading implications.
| uid | The node UID. |
| DataStorage::Pointer mitk::DataStorageBridge::GetDataStorage | ( | ) | const |
Get the current DataStorage.
nullptr if not connected. | std::optional<Json> mitk::DataStorageBridge::GetNode | ( | const std::string & | uid | ) | const |
Get a single node by UID.
| uid | The node UID. |
| std::optional<Json> mitk::DataStorageBridge::GetNodeAvailableContexts | ( | const std::string & | uid | ) | const |
Get available property contexts for a node.
Returns a JSON array containing null (for default context) and strings for each named context available on the node.
| uid | The node UID. |
| GetNodeDataResult mitk::DataStorageBridge::GetNodeData | ( | const std::string & | uid | ) | const |
Get a clone of the node's data for thread-safe processing.
Returns a clone of the BaseData attached to the node. The clone is independent of the original data and can be safely processed (e.g., serialized) without holding locks and without affecting the original.
This method is designed for scenarios where the caller needs to perform potentially slow operations on the data (like serialization) without blocking other DataStorage operations.
| uid | The node UID. |
| std::optional<Json> mitk::DataStorageBridge::GetNodeProperties | ( | const std::string & | uid, |
| const PropertyQueryParams & | params = {} |
||
| ) | const |
Get properties of a node with scope filtering.
| uid | The node UID. |
| params | Query parameters for property filtering. |
| std::optional<Json> mitk::DataStorageBridge::GetNodeProperty | ( | const std::string & | uid, |
| const std::string & | key, | ||
| const PropertyQueryParams & | params = {} |
||
| ) | const |
Get a single property of a node.
Returns the property in standard JSON serialization format:
| uid | The node UID. |
| key | The property key. |
| params | Query parameters for scope and context. |
| NodeQueryResult mitk::DataStorageBridge::GetNodes | ( | const NodeQueryParams & | params | ) | const |
Get nodes with full query parameter support.
| params | Query parameters including filters, pagination, etc. |
| std::string mitk::DataStorageBridge::GetNodeUid | ( | DataNode * | node | ) | const |
Get the UID for a DataNode.
Creates a UID if the node doesn't have one yet.
| [in] | node | The node to get the UID for. Must not be nullptr. |
| std::invalid_argument | if node is nullptr. |
| bool mitk::DataStorageBridge::HasDataStorage | ( | ) | const |
Check if a DataStorage is connected.
|
delete |
|
delete |
| ReplacePropertiesResult mitk::DataStorageBridge::ReplaceNodeProperties | ( | const std::string & | uid, |
| const Json & | properties, | ||
| const PropertyQueryParams & | params | ||
| ) |
Replace all properties on a node (PUT semantics).
| uid | The node UID. |
| properties | JSON object with all properties (replaces existing). |
| params | Query parameters for scope and context. |
| void mitk::DataStorageBridge::SetDataStorage | ( | DataStorage * | dataStorage | ) |
Set the DataStorage to operate on.
| [in] | dataStorage | The DataStorage, or nullptr to disconnect. |
| void mitk::DataStorageBridge::SetDispatcher | ( | StorageThreadDispatcherBase * | dispatcher | ) |
Set the dispatcher for thread-safe DataStorage operations.
If set, all public operations (reads and writes) are dispatched to the storage-owning thread. This is necessary because even read operations may set restapi.uid properties on first access, triggering Modified events that cascade into Qt widget updates.
If not set, operations execute directly on the calling thread (suitable for tests/headless scenarios).
| [in] | dispatcher | The dispatcher, or nullptr to clear. |
| OperationStatus mitk::DataStorageBridge::SetNodeData | ( | const std::string & | uid, |
| BaseData * | data | ||
| ) |
Set or replace the data on a node.
Thread-safe assignment of BaseData to a node. The data is assigned directly (not cloned), so the caller should not modify the data object after calling this method.
Can be used to:
| uid | The node UID. |
| data | The data to assign. Can be nullptr to clear the node's data. |
| OperationStatus mitk::DataStorageBridge::SetNodeProperty | ( | const std::string & | uid, |
| const std::string & | key, | ||
| const Json & | value, | ||
| const PropertyQueryParams & | params | ||
| ) |
Set a single property on a node.
| uid | The node UID. |
| key | The property key. |
| value | The property value as JSON. |
| params | Query parameters for scope and context. |
| bool mitk::DataStorageBridge::UpdateNode | ( | const std::string & | uid, |
| const Json & | updates | ||
| ) |
Update a node.
Currently supports reparenting via "parent_uid" field. Reparenting is done by removing the node from DataStorage and re-adding it under the new parent (same approach as Data Manager UI).
| uid | The node UID. |
| updates | JSON object with fields to update (e.g., "parent_uid"). |
|
staticconstexpr |
Prefix for internal REST API properties (filtered from responses, protected from modification).
Definition at line 80 of file mitkDataStorageBridge.h.
|
staticconstexpr |
Property key for tracking the last modification operation (string property).
Definition at line 91 of file mitkDataStorageBridge.h.
|
staticconstexpr |
Property key for tracking if a node was modified via the REST API.
If this string property exists on a node, it was modified via the REST API and its value is the timestamp of the last modification.
Definition at line 88 of file mitkDataStorageBridge.h.