@@ -67,29 +67,35 @@ namespace nmos
6767
6868 namespace details
6969 {
70+ // BCP-002-01 Group Hint tag and BCP-002-02 Asset Distinguishing Information tags are read-only
71+ // all other tags are read/write
7072 bool is_read_only_tag (const utility::string_t & key)
7173 {
7274 return boost::algorithm::starts_with (key, U (" urn:x-nmos:tag:asset:" ))
7375 || boost::algorithm::starts_with (key, U (" urn:x-nmos:tag:grouphint/" ));
7476 }
7577
76- void merge_annotation_patch (web::json::value& value, const web::json::value& patch)
78+ const web::json::field_as_string_or default_label{ nmos::fields::label.key , U (" " ) };
79+ const web::json::field_as_string_or default_description{ nmos::fields::description.key , U (" " ) };
80+ const web::json::field_as_value_or default_tags{ nmos::fields::tags.key , web::json::value::object () };
81+
82+ void merge_annotation_patch (web::json::value& value, const web::json::value& patch, annotation_tag_predicate is_read_only_tag, const web::json::value& default_value)
7783 {
7884 // reject changes to read-ony tags
7985
8086 if (patch.has_object_field (nmos::fields::tags))
8187 {
8288 const auto & tags = nmos::fields::tags (patch);
83- auto patch_readonly = std::find_if (tags.begin (), tags.end (), [](const std::pair<utility::string_t , web::json::value>& field)
89+ auto patch_readonly = std::find_if (tags.begin (), tags.end (), [& ](const std::pair<utility::string_t , web::json::value>& field)
8490 {
8591 return is_read_only_tag (field.first );
8692 });
8793 if (tags.end () != patch_readonly) throw std::runtime_error (" cannot patch read-only tag: " + utility::us2s (patch_readonly->first ));
8894 }
8995
90- // save existing read-only tags
96+ // save existing read-only tags (so that read-only tags don't need to be included in default_value)
9197
92- auto readonly_tags = web::json::value_from_fields (nmos::fields::tags (value) | boost::adaptors::filtered ([](const std::pair<utility::string_t , web::json::value>& field)
98+ auto readonly_tags = web::json::value_from_fields (nmos::fields::tags (value) | boost::adaptors::filtered ([& ](const std::pair<utility::string_t , web::json::value>& field)
9399 {
94100 return is_read_only_tag (field.first );
95101 }));
@@ -100,16 +106,21 @@ namespace nmos
100106
101107 // apply defaults to properties that have been reset
102108
103- web::json::insert (value, std::make_pair (nmos::fields::label, U ( " " )));
104- web::json::insert (value, std::make_pair (nmos::fields::description, U ( " " )));
109+ web::json::insert (value, std::make_pair (nmos::fields::label, details::default_label (default_value )));
110+ web::json::insert (value, std::make_pair (nmos::fields::description, details::default_description (default_value )));
105111 web::json::insert (value, std::make_pair (nmos::fields::tags, readonly_tags));
112+ auto & tags = value.at (nmos::fields::tags);
113+ for (const auto & default_tag : details::default_tags (default_value).as_object ())
114+ {
115+ web::json::insert (tags, default_tag);
116+ }
106117 }
107118
108119 void assign_annotation_patch (web::json::value& value, web::json::value&& patch)
109120 {
110- if (value .has_string_field (nmos::fields::label)) value[nmos::fields::label] = std::move (patch.at (nmos::fields::label));
111- if (value .has_string_field (nmos::fields::description)) value[nmos::fields::description] = std::move (patch.at (nmos::fields::description));
112- if (value .has_object_field (nmos::fields::tags)) value[nmos::fields::tags] = std::move (patch.at (nmos::fields::tags));
121+ if (patch .has_string_field (nmos::fields::label)) value[nmos::fields::label] = std::move (patch.at (nmos::fields::label));
122+ if (patch .has_string_field (nmos::fields::description)) value[nmos::fields::description] = std::move (patch.at (nmos::fields::description));
123+ if (patch .has_object_field (nmos::fields::tags)) value[nmos::fields::tags] = std::move (patch.at (nmos::fields::tags));
113124 }
114125
115126 void handle_annotation_patch (nmos::resources& resources, const nmos::resource& resource, const web::json::value& patch, const nmos::annotation_patch_merger& merge_patch, slog::base_gate& gate)
0 commit comments