Class AggregationService

Class Documentation

class AggregationService

Service for aggregating resources across entity hierarchy.

Implements x-medkit aggregation extension while maintaining SOVD compliance through explicit metadata.

Aggregation rules:

  • APP: No aggregation (leaf entity) - returns own resources

  • COMPONENT: Aggregates from hosted Apps

  • AREA: Aggregates from all Components in area (x-medkit extension)

  • FUNCTION: Aggregates from all Apps implementing function

All aggregated responses include x-medkit metadata: { “x-medkit”: { “aggregated”: true, “aggregation_sources”: [“entity_id_1”, “entity_id_2”], “aggregation_level”: “component” | “area” | “function” } }

Public Functions

explicit AggregationService(const ThreadSafeEntityCache *cache)

Construct aggregation service.

Parameters:

cache – Pointer to thread-safe entity cache (must outlive this service)

AggregatedOperations get_operations(SovdEntityType type, const std::string &entity_id) const

Get aggregated operations for any entity type.

Automatically determines aggregation behavior based on entity type.

Parameters:
  • type – Entity type

  • entity_id – Entity identifier

Returns:

Aggregated operations with source tracking

AggregatedOperations get_operations_by_id(const std::string &entity_id) const

Get operations for entity by ID (auto-detects type)

Parameters:

entity_id – Entity identifier

Returns:

Aggregated operations with source tracking

std::vector<std::string> get_child_app_ids(SovdEntityType type, const std::string &entity_id) const

Get child app IDs for an aggregated entity.

Resolves the leaf App entity IDs that contribute resources to an aggregated entity (Function, Area, or Component).

  • FUNCTION: returns app IDs from the function’s hosts list

  • AREA: returns app IDs from all components in the area

  • COMPONENT: returns app IDs hosted by the component

  • APP: returns the app’s own ID

Parameters:
  • type – Entity type

  • entity_id – Entity identifier

Returns:

Vector of child app IDs

nlohmann::json build_collection_x_medkit(SovdEntityType type, const std::string &entity_id) const

Build x-medkit extension JSON for any aggregated collection response.

Creates a standardized x-medkit metadata object with:

  • aggregated: true/false

  • aggregation_sources: […] (child app IDs)

  • aggregation_level: “app” | “component” | “area” | “function”

Parameters:
  • type – Entity type (determines aggregation_level)

  • entity_id – Entity identifier (used to resolve sources)

Returns:

JSON object for x-medkit field

Public Static Functions

static nlohmann::json build_x_medkit(const AggregatedOperations &result)

Build x-medkit extension JSON for aggregated response.

Creates the x-medkit metadata object: { “aggregated”: true/false, “aggregation_sources”: […], “aggregation_level”: “app” | “component” | “area” | “function” }

Parameters:

result – Aggregation result

Returns:

JSON object for x-medkit field

static bool supports_operations(SovdEntityType type)

Check if entity type supports operations collection.

Parameters:

type – Entity type

Returns:

true if operations collection is supported

static bool should_aggregate(SovdEntityType type)

Check if operations should be aggregated for entity type.

Returns true for COMPONENT, AREA, and FUNCTION. Returns false for APP (leaf entity).

Parameters:

type – Entity type

Returns:

true if aggregation applies