mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 22:29:55 +05:00
Remove pathPrfx from xmlDP
This commit is contained in:
@@ -29,18 +29,16 @@ import (
|
||||
)
|
||||
|
||||
// NewXmlProvider constructs a DataProvider
|
||||
func NewXmlProvider(req *xmlquery.Node, cdrPath utils.HierarchyPath, pathPrfx string) (dP DataProvider) {
|
||||
dP = &XmlProvider{req: req, cdrPath: cdrPath, cache: NewNavigableMap(nil), pathPrfx: pathPrfx}
|
||||
func NewXmlProvider(req *xmlquery.Node, cdrPath utils.HierarchyPath) (dP DataProvider) {
|
||||
dP = &XmlProvider{req: req, cdrPath: cdrPath, cache: NewNavigableMap(nil)}
|
||||
return
|
||||
}
|
||||
|
||||
// XmlProvider implements engine.DataProvider so we can pass it to filters
|
||||
type XmlProvider struct {
|
||||
req *xmlquery.Node
|
||||
cdrPath utils.HierarchyPath //used to compute relative path
|
||||
cache *NavigableMap
|
||||
pathPrfx string // if this comes in path it will be ignored
|
||||
// pathPrfx should be reviewed once the cdrc is removed
|
||||
req *xmlquery.Node
|
||||
cdrPath utils.HierarchyPath //used to compute relative path
|
||||
cache *NavigableMap
|
||||
}
|
||||
|
||||
// String is part of engine.DataProvider interface
|
||||
@@ -54,18 +52,12 @@ func (xP *XmlProvider) FieldAsInterface(fldPath []string) (data interface{}, err
|
||||
if len(fldPath) == 0 {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
if xP.pathPrfx != utils.EmptyString && fldPath[0] != xP.pathPrfx {
|
||||
return "", utils.ErrPrefixNotFound(strings.Join(fldPath, utils.NestingSep))
|
||||
}
|
||||
if data, err = xP.cache.FieldAsInterface(fldPath); err == nil ||
|
||||
err != utils.ErrNotFound { // item found in cache
|
||||
return
|
||||
}
|
||||
err = nil // cancel previous err
|
||||
relPath := utils.HierarchyPath(fldPath[len(xP.cdrPath)+1:]) // Need relative path to the xmlElmnt
|
||||
if xP.pathPrfx == utils.EmptyString { // temporary fix untile re remove cdrc
|
||||
relPath = utils.HierarchyPath(fldPath[len(xP.cdrPath):])
|
||||
}
|
||||
err = nil // cancel previous err
|
||||
relPath := utils.HierarchyPath(fldPath[len(xP.cdrPath):])
|
||||
var slctrStr string
|
||||
for i := range relPath {
|
||||
if sIdx := strings.Index(relPath[i], "["); sIdx != -1 {
|
||||
|
||||
@@ -409,28 +409,28 @@ func TestXMLIndexes(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dP := NewXmlProvider(doc, utils.HierarchyPath([]string{}), utils.MetaReq)
|
||||
if data, err := dP.FieldAsString([]string{"*req", "complete-success-notification", "userid"}); err != nil {
|
||||
dP := NewXmlProvider(doc, utils.HierarchyPath([]string{}))
|
||||
if data, err := dP.FieldAsString([]string{"complete-success-notification", "userid"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "386" {
|
||||
t.Errorf("expecting: 386, received: <%s>", data)
|
||||
}
|
||||
if data, err := dP.FieldAsString([]string{"*req", "complete-success-notification", "username"}); err != nil {
|
||||
if data, err := dP.FieldAsString([]string{"complete-success-notification", "username"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "sampleusername" {
|
||||
t.Errorf("expecting: sampleusername, received: <%s>", data)
|
||||
}
|
||||
if data, err := dP.FieldAsString([]string{"*req", "complete-success-notification", "callleg", "seconds"}); err != nil {
|
||||
if data, err := dP.FieldAsString([]string{"complete-success-notification", "callleg", "seconds"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "38" {
|
||||
t.Errorf("expecting: 38, received: <%s>", data)
|
||||
}
|
||||
if data, err := dP.FieldAsString([]string{"*req", "complete-success-notification", "callleg[1]", "seconds"}); err != nil {
|
||||
if data, err := dP.FieldAsString([]string{"complete-success-notification", "callleg[1]", "seconds"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "37" {
|
||||
t.Errorf("expecting: 37, received: <%s>", data)
|
||||
}
|
||||
if data, err := dP.FieldAsString([]string{"*req", "complete-success-notification", "callleg[@calllegid='222147']", "seconds"}); err != nil {
|
||||
if data, err := dP.FieldAsString([]string{"complete-success-notification", "callleg[@calllegid='222147']", "seconds"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if data != "37" {
|
||||
t.Errorf("expecting: 37, received: <%s>", data)
|
||||
|
||||
@@ -135,7 +135,7 @@ func (rdr *XMLFileER) processFile(fPath, fName string) (err error) {
|
||||
for _, xmlElmt := range xmlElmts {
|
||||
rowNr++ // increment the rowNr after checking if it's not the end of file
|
||||
agReq := agents.NewAgentRequest(
|
||||
config.NewXmlProvider(xmlElmt, rdr.Config().XmlRootPath, utils.EmptyString), reqVars,
|
||||
config.NewXmlProvider(xmlElmt, rdr.Config().XmlRootPath), reqVars,
|
||||
nil, nil, rdr.Config().Tenant,
|
||||
rdr.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(rdr.Config().Timezone,
|
||||
|
||||
Reference in New Issue
Block a user