diff --git a/src/InfrastructureSystems.jl b/src/InfrastructureSystems.jl index d20c6d101..495b83784 100644 --- a/src/InfrastructureSystems.jl +++ b/src/InfrastructureSystems.jl @@ -64,7 +64,7 @@ Required interface functions for subtypes: Optional interface functions: - get_time_series_container() - - get_components_uuids() + - get_component_uuids() - get_uuid() Subtypes may contain time series. Which requires @@ -83,7 +83,7 @@ function get_time_series_container(value::InfrastructureSystemsComponent) return nothing end -set_time_series_container!(value::InfrastructureSystemsComponent) = nothing +set_time_series_container!(value::InfrastructureSystemsComponent, _) = nothing get_name(value::InfrastructureSystemsComponent) = value.name diff --git a/src/component.jl b/src/component.jl index cb4f28b49..7ac4d7067 100644 --- a/src/component.jl +++ b/src/component.jl @@ -309,7 +309,8 @@ function attach_supplemental_attribute!( attribute_container[T] = Set{T}() end push!(attribute_container[T], attribute) - @debug "SupplementalAttribute type $T with UUID $(get_uuid(attribute)) stored in component $(get_name(component))" + @debug "SupplementalAttribute type $T with UUID $(get_uuid(attribute)) stored in component $(summary(component))" _group = + LOG_GROUP_SYSTEM return end @@ -325,11 +326,11 @@ function clear_supplemental_attributes!(component::InfrastructureSystemsComponen container = get_supplemental_attributes_container(component) for attribute_set in values(container) for i in attribute_set - delete!(get_components_uuids(i), get_uuid(component)) + delete!(get_component_uuids(i), get_uuid(component)) end end empty!(container) - @debug "Cleared attributes in $(get_name(component))." + @debug "Cleared attributes in $(summary(component))." return end @@ -341,7 +342,7 @@ function remove_supplemental_attribute!( if !haskey(container, T) throw( ArgumentError( - "supplemental attribute type $T is not stored in component $(get_name(component))", + "SupplementalAttribute type $T is not stored in component $(summary(component))", ), ) end @@ -358,7 +359,7 @@ function detach_supplemental_attribute!( if !haskey(container, T) throw( ArgumentError( - "Attribute of type $T is not stored in component $(summary(component))", + "SupplementalAttribute of type $T is not stored in component $(summary(component))", ), ) end diff --git a/src/geographic_supplemental_attribute.jl b/src/geographic_supplemental_attribute.jl index 1ed0cc952..4f7477727 100644 --- a/src/geographic_supplemental_attribute.jl +++ b/src/geographic_supplemental_attribute.jl @@ -4,26 +4,28 @@ Base type for structs that store attributes Required interface functions for subtypes: - get_internal() - - get_components_uuids() + - get_component_uuids() - get_time_series_container() Subtypes may contain time series, if no time series container is implemented return nothing """ struct GeographicInfo <: InfrastructureSystemsSupplementalAttribute geo_json::Dict{String, Any} - components_uuids::Set{UUIDs.UUID} + component_uuids::Set{UUIDs.UUID} internal::InfrastructureSystemsInternal end function GeographicInfo(; geo_json::Dict{String, Any}=Dict{String, Any}(), - components_uuids::Set{UUIDs.UUID}=Set{UUIDs.UUID}(), + component_uuids::Set{UUIDs.UUID}=Set{UUIDs.UUID}(), ) - return GeographicInfo(geo_json, components_uuids, InfrastructureSystemsInternal()) + return GeographicInfo(geo_json, component_uuids, InfrastructureSystemsInternal()) end get_geo_json(geo::GeographicInfo) = geo.geo_json get_internal(geo::GeographicInfo) = geo.internal get_uuid(geo::GeographicInfo) = get_uuid(get_internal(geo)) get_time_series_container(::GeographicInfo) = nothing -get_components_uuids(geo::GeographicInfo) = geo.components_uuids +get_component_uuids(geo::GeographicInfo) = geo.component_uuids + +set_time_series_container!(geo::GeographicInfo, _) = nothing diff --git a/src/supplemental_attribute.jl b/src/supplemental_attribute.jl index b99cfba70..02ea656f3 100644 --- a/src/supplemental_attribute.jl +++ b/src/supplemental_attribute.jl @@ -4,7 +4,7 @@ function attach_component!( ) where {T <: InfrastructureSystemsSupplementalAttribute} component_uuid = get_uuid(component) - if component_uuid ∈ get_components_uuids(attribute) + if component_uuid ∈ get_component_uuids(attribute) throw( ArgumentError( "SupplementalAttribute type $T with UUID $(get_uuid(attribute)) already attached to component $(summary(component))", @@ -12,7 +12,7 @@ function attach_component!( ) end - push!(get_components_uuids(attribute), component_uuid) + push!(get_component_uuids(attribute), component_uuid) return end @@ -20,7 +20,7 @@ function detach_component!( attribute::InfrastructureSystemsSupplementalAttribute, component::InfrastructureSystemsComponent, ) - delete!(get_components_uuids(attribute), get_uuid(component)) + delete!(get_component_uuids(attribute), get_uuid(component)) return end @@ -64,7 +64,7 @@ This function must be called when an attribute is removed from a system. function prepare_for_removal!( attribute::T, ) where {T <: InfrastructureSystemsSupplementalAttribute} - if !isempty(get_components_uuids(attribute)) + if !isempty(get_component_uuids(attribute)) throw( ArgumentError( "attribute type $T with uuid $(get_uuid(attribute)) still attached to a component", diff --git a/src/supplemental_attributes.jl b/src/supplemental_attributes.jl index fe6536105..960e850a3 100644 --- a/src/supplemental_attributes.jl +++ b/src/supplemental_attributes.jl @@ -44,7 +44,7 @@ function _add_supplemental_attribute!( end supplemental_attribute_uuid = get_uuid(supplemental_attribute) - if isempty(get_components_uuids(supplemental_attribute)) + if isempty(get_component_uuids(supplemental_attribute)) throw( ArgumentError( "SupplementalAttribute type $T with UUID $supplemental_attribute_uuid is not attached to any component", @@ -55,7 +55,8 @@ function _add_supplemental_attribute!( if !haskey(supplemental_attributes.data, T) supplemental_attributes.data[T] = Dict{UUIDs.UUID, T}() elseif haskey(supplemental_attributes.data[T], supplemental_attribute_uuid) - @debug "SupplementalAttribute type $T with UUID $supplemental_attribute_uuid already stored" + @debug "SupplementalAttribute type $T with UUID $supplemental_attribute_uuid already stored" _group = + LOG_GROUP_SYSTEM return end @@ -136,10 +137,10 @@ function remove_supplemental_attribute!( supplemental_attributes::SupplementalAttributes, supplemental_attribute::T, ) where {T <: InfrastructureSystemsSupplementalAttribute} - if !isempty(get_components_uuids(supplemental_attribute)) + if !isempty(get_component_uuids(supplemental_attribute)) throw( ArgumentError( - "SupplementalAttribute type $T with uuid $(get_uuid(supplemental_attribute)) still attached to devices $(get_components_uuids(supplemental_attribute))", + "SupplementalAttribute type $T with uuid $(get_uuid(supplemental_attribute)) still attached to devices $(get_component_uuids(supplemental_attribute))", ), ) end @@ -170,6 +171,7 @@ function remove_supplemental_attributes!( return values(_supplemental_attributes) end +# TODO: This function could be merged with the getter for components if no additional functionality is needed """ Returns an iterator of supplemental_attributes. T can be concrete or abstract. Call collect on the result if an array is desired. diff --git a/src/system_data.jl b/src/system_data.jl index 2244c0d90..6f1cc716e 100644 --- a/src/system_data.jl +++ b/src/system_data.jl @@ -845,11 +845,11 @@ function remove_supplemental_attribute!( data::SystemData, info::T, ) where {T <: InfrastructureSystemsSupplementalAttribute} - current_components_uuid = collect(get_components_uuids(info)) + current_components_uuid = collect(get_component_uuids(info)) for c_uuid in current_components_uuid component = get_component(data, c_uuid) delete!(get_supplemental_attributes_container(component), info) - delete!(get_components_uuids(info), get_uuid(component)) + delete!(get_component_uuids(info), get_uuid(component)) end return remove_supplemental_attribute!(data.attributes, info) @@ -861,11 +861,11 @@ function remove_supplemental_attributes!( ) where {T <: InfrastructureSystemsSupplementalAttribute} attributes = get_supplemental_attributes(T, data.attributes) for info in attributes - for c_uuid in get_components_uuids(info) + for c_uuid in get_component_uuids(info) comp = get_component(data, c_uuid) delete!(get_supplemental_attributes_container(comp), info) end - empty!(get_components_uuids(info)) + empty!(get_component_uuids(info)) end return remove_supplemental_attributes!(T, data.attributes) end diff --git a/test/test_supplemental_attributes.jl b/test/test_supplemental_attributes.jl index 8d19b53d5..f537ef3f1 100644 --- a/test/test_supplemental_attributes.jl +++ b/test/test_supplemental_attributes.jl @@ -28,7 +28,7 @@ end @test IS.get_num_supplemental_attributes(container) == 1 IS.clear_supplemental_attributes!(component) - @test isempty(IS.get_components_uuids(geo_supplemental_attribute)) + @test isempty(IS.get_component_uuids(geo_supplemental_attribute)) IS.clear_supplemental_attributes!(container) supplemental_attributes = IS.get_supplemental_attributes(IS.GeographicInfo, container) @test length(supplemental_attributes) == 0 @@ -43,7 +43,7 @@ end IS.remove_supplemental_attribute!(component, geo_supplemental_attribute) @test isempty(IS.get_supplemental_attributes_container(component)) - @test isempty(IS.get_components_uuids(geo_supplemental_attribute)) + @test isempty(IS.get_component_uuids(geo_supplemental_attribute)) end @testset "Test iterate_SupplementalAttributes" begin