mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 21:59:53 +05:00
Merge pull request #1890 from TeoV/master
Remove pathPrfx from DataProviders for ERs
This commit is contained in:
@@ -28,17 +28,15 @@ import (
|
||||
)
|
||||
|
||||
// NewfwvProvider constructs a DataProvider
|
||||
func NewFWVProvider(record, pathPrfx string) (dP DataProvider) {
|
||||
dP = &FWVProvider{req: record, cache: NewNavigableMap(nil), pathPrfx: pathPrfx}
|
||||
func NewFWVProvider(record string) (dP DataProvider) {
|
||||
dP = &FWVProvider{req: record, cache: NewNavigableMap(nil)}
|
||||
return
|
||||
}
|
||||
|
||||
// fwvProvider implements engine.DataProvider so we can pass it to filters
|
||||
type FWVProvider struct {
|
||||
req string
|
||||
cache *NavigableMap
|
||||
pathPrfx string // if this comes in path it will be ignored
|
||||
// pathPrfx should be reviewed once the cdrc is removed
|
||||
req string
|
||||
cache *NavigableMap
|
||||
}
|
||||
|
||||
// String is part of engine.DataProvider interface
|
||||
@@ -53,12 +51,6 @@ func (fP *FWVProvider) FieldAsInterface(fldPath []string) (data interface{}, err
|
||||
return
|
||||
}
|
||||
fwvIdx := fldPath[0]
|
||||
if len(fldPath) == 2 {
|
||||
fwvIdx = fldPath[1]
|
||||
}
|
||||
if fP.pathPrfx != utils.EmptyString && (fldPath[0] != fP.pathPrfx || len(fldPath) < 2) {
|
||||
return "", utils.ErrPrefixNotFound(strings.Join(fldPath, utils.NestingSep))
|
||||
}
|
||||
if data, err = fP.cache.FieldAsInterface(fldPath); err == nil ||
|
||||
err != utils.ErrNotFound { // item found in cache
|
||||
return
|
||||
|
||||
@@ -22,23 +22,20 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// NewSliceDP constructs a DataProvider
|
||||
func NewSliceDP(record []string, pathPrfx string) (dP DataProvider) {
|
||||
dP = &SliceDP{req: record, cache: NewNavigableMap(nil), pathPrfx: pathPrfx}
|
||||
func NewSliceDP(record []string) (dP DataProvider) {
|
||||
dP = &SliceDP{req: record, cache: NewNavigableMap(nil)}
|
||||
return
|
||||
}
|
||||
|
||||
// SliceDP implements engine.DataProvider so we can pass it to filters
|
||||
type SliceDP struct {
|
||||
req []string
|
||||
cache *NavigableMap
|
||||
pathPrfx string // if this comes in path it will be ignored
|
||||
// pathPrfx should be reviewed once the cdrc is removed
|
||||
req []string
|
||||
cache *NavigableMap
|
||||
}
|
||||
|
||||
// String is part of engine.DataProvider interface
|
||||
@@ -52,13 +49,10 @@ func (cP *SliceDP) FieldAsInterface(fldPath []string) (data interface{}, err err
|
||||
if len(fldPath) == 0 {
|
||||
return
|
||||
}
|
||||
if len(fldPath) != 1 {
|
||||
return nil, fmt.Errorf("Invalid fieldPath %+v", fldPath)
|
||||
}
|
||||
idx := fldPath[0]
|
||||
if len(fldPath) == 2 {
|
||||
idx = fldPath[1]
|
||||
}
|
||||
if cP.pathPrfx != utils.EmptyString && (fldPath[0] != cP.pathPrfx || len(fldPath) < 2) {
|
||||
return "", utils.ErrPrefixNotFound(strings.Join(fldPath, utils.NestingSep))
|
||||
}
|
||||
if data, err = cP.cache.FieldAsInterface(fldPath); err == nil ||
|
||||
err != utils.ErrNotFound { // item found in cache
|
||||
return
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -143,7 +143,7 @@ func (rdr *CSVFileER) processFile(fPath, fName string) (err error) {
|
||||
}
|
||||
rowNr++ // increment the rowNr after checking if it's not the end of file
|
||||
agReq := agents.NewAgentRequest(
|
||||
config.NewSliceDP(record, utils.EmptyString), reqVars,
|
||||
config.NewSliceDP(record), reqVars,
|
||||
nil, nil, rdr.Config().Tenant,
|
||||
rdr.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(rdr.Config().Timezone,
|
||||
|
||||
@@ -169,7 +169,7 @@ func (rdr *FWVFileER) processFile(fPath, fName string) (err error) {
|
||||
rowNr++ // increment the rowNr after checking if it's not the end of file
|
||||
record := string(buf)
|
||||
agReq := agents.NewAgentRequest(
|
||||
config.NewFWVProvider(record, utils.EmptyString), reqVars,
|
||||
config.NewFWVProvider(record), reqVars,
|
||||
nil, nil, rdr.Config().Tenant,
|
||||
rdr.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(rdr.Config().Timezone,
|
||||
@@ -251,7 +251,7 @@ func (rdr *FWVFileER) processTrailer(file *os.File, rowNr, evsPosted int, absPat
|
||||
record := string(buf)
|
||||
reqVars := make(map[string]interface{})
|
||||
agReq := agents.NewAgentRequest(
|
||||
config.NewFWVProvider(record, utils.EmptyString), reqVars,
|
||||
config.NewFWVProvider(record), reqVars,
|
||||
nil, nil, rdr.Config().Tenant,
|
||||
rdr.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(rdr.Config().Timezone,
|
||||
@@ -288,7 +288,7 @@ func (rdr *FWVFileER) processHeader(file *os.File, rowNr, evsPosted int, absPath
|
||||
func (rdr *FWVFileER) createHeaderMap(record string, rowNr, evsPosted int, absPath string) (err error) {
|
||||
reqVars := make(map[string]interface{})
|
||||
agReq := agents.NewAgentRequest(
|
||||
config.NewFWVProvider(record, utils.EmptyString), reqVars,
|
||||
config.NewFWVProvider(record), reqVars,
|
||||
nil, nil, rdr.Config().Tenant,
|
||||
rdr.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(rdr.Config().Timezone,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -182,7 +182,7 @@ func (rdr *FlatstoreER) processFile(fPath, fName string) (err error) {
|
||||
}
|
||||
rowNr++ // increment the rowNr after checking if it's not the end of file
|
||||
agReq := agents.NewAgentRequest(
|
||||
config.NewSliceDP(record, utils.EmptyString), reqVars,
|
||||
config.NewSliceDP(record), reqVars,
|
||||
nil, nil, rdr.Config().Tenant,
|
||||
rdr.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(rdr.Config().Timezone,
|
||||
|
||||
@@ -158,7 +158,7 @@ func (rdr *PartialCSVFileER) processFile(fPath, fName string) (err error) {
|
||||
}
|
||||
rowNr++ // increment the rowNr after checking if it's not the end of file
|
||||
agReq := agents.NewAgentRequest(
|
||||
config.NewSliceDP(record, utils.EmptyString), reqVars,
|
||||
config.NewSliceDP(record), reqVars,
|
||||
nil, nil, rdr.Config().Tenant,
|
||||
rdr.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(rdr.Config().Timezone,
|
||||
|
||||
Reference in New Issue
Block a user