Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Dec 18, 2023
1 parent be0e6c5 commit 01c7911
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/InfrastructureSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
11 changes: 6 additions & 5 deletions src/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/geographic_supplemental_attribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/supplemental_attribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ 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))",
),
)
end

push!(get_components_uuids(attribute), component_uuid)
push!(get_component_uuids(attribute), component_uuid)
return
end

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

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions src/supplemental_attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/system_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
4 changes: 2 additions & 2 deletions test/test_supplemental_attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 01c7911

Please sign in to comment.