Skip to content

Commit 5f1e193

Browse files
fix sorting of keys, implement better handling of identityref
1 parent 4de1c5a commit 5f1e193

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

pkg/datastore/target/netconf/xml2SchemapbAdapter.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ func (x *XML2sdcpbConfigAdapter) transformContainer(ctx context.Context, e *etre
124124
if cPElem[len(cPElem)-1].Key == nil {
125125
cPElem[len(cPElem)-1].Key = map[string]string{}
126126
}
127-
cPElem[len(cPElem)-1].Key[ls.Name] = e.FindElement("./" + ls.Name).Text()
127+
tv, err := utils.Convert(e.FindElement("./"+ls.Name).Text(), ls.Type)
128+
if err != nil {
129+
return err
130+
}
131+
keyValue := utils.TypedValueToString(tv)
132+
133+
cPElem[len(cPElem)-1].Key[ls.Name] = keyValue
128134
}
129135

130136
ntc := NewTransformationContext(cPElem)

pkg/tree/sharedEntryAttributes.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,18 +1659,18 @@ func (s *sharedEntryAttributes) getKeyName() (string, error) {
16591659
return "", fmt.Errorf("error %s is a schema element, can only get KeyNames for key element", strings.Join(s.Path(), " "))
16601660
}
16611661

1662-
// get ancestro schema
1662+
// get ancestor schema
16631663
ancestorWithSchema, levelUp := s.GetFirstAncestorWithSchema()
16641664

1665-
// only Contaieners have keys, so check for that
1666-
switch sch := ancestorWithSchema.GetSchema().GetSchema().(type) {
1667-
case *sdcpb.SchemaElem_Container:
1668-
// return the name of the levelUp-1 key
1669-
return sch.Container.GetKeys()[levelUp-1].Name, nil
1665+
// only Containers have keys, so check for that
1666+
schemaKeys := ancestorWithSchema.GetSchemaKeys()
1667+
if len(schemaKeys) == 0 {
1668+
// we probably called the function on a LeafList or LeafEntry which is not a valid call to be made.
1669+
return "", fmt.Errorf("error LeafList and Field should not have keys %s", strings.Join(s.Path(), " "))
16701670
}
16711671

1672-
// we probably called the function on a LeafList or LeafEntry which is not a valid call to be made.
1673-
return "", fmt.Errorf("error LeafList and Field should not have keys %s", strings.Join(s.Path(), " "))
1672+
slices.Sort(schemaKeys)
1673+
return schemaKeys[levelUp-1], nil
16741674
}
16751675

16761676
func (s *sharedEntryAttributes) getOrCreateChilds(ctx context.Context, path types.PathSlice) (Entry, error) {

pkg/utils/converter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ func TypedValueToYANGType(tv *sdcpb.TypedValue, schemaObject *sdcpb.SchemaElem)
422422
return tv, nil
423423
case *sdcpb.TypedValue_AnyVal:
424424
return tv, nil
425+
case *sdcpb.TypedValue_IdentityrefVal:
426+
return ConvertToTypedValue(schemaObject, tv.GetStringVal(), tv.GetTimestamp())
425427
}
426428
return tv, nil
427429
}

0 commit comments

Comments
 (0)